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

public class GGWPLivaem implements Runnable{
    boolean withFiles = false;
    class cc implements Comparable<cc>{
        public int x, y;
        cc(int x, int y) {
            this.x = x;
            this.y = y;
        }
        public int compareTo(cc other) {
            if (this.x == other.x) {
                return Integer.compare(this.y, other.y);
            }
            return Integer.compare(this.x, other.x);
        }
    }

    private void solve() throws IOException {
        int m[] = new int[10];
        int h[] = new int[10];
        double ans = 0;
        for (int i = 1; i <= 5; ++i) {
            m[i] = in.nextInt();
        }
        for (int i = 1; i <= 5; ++i) {
            h[i] = in.nextInt();
        }
        for (int i = 1; i <= 5; ++i) {
            int x = 500 * i;
            ans += Math.max(0.3 * x, 1.0 * (1 - m[i] * 1.0 / 250) * x - 50 * h[i]);
        }
        //out.println(ans);
        int a, b;
        a = in.nextInt();
        b = in.nextInt();
        ans += 100 * a;
        ans -= 50 * b;
        out.println((long)ans);
    }

    private static class FastScanner{
        private BufferedReader reader;
        private StringTokenizer tokenizer;
        String cache;
        int cur;

        FastScanner(Reader r) throws IOException{
            reader = new BufferedReader(r);
            tokenizer = new StringTokenizer("");
            cache = null;
            cur = 0;
        }

        public boolean hasNext(){
            if (cache != null && cur < cache.length())
                return true;
            try {
                while (!tokenizer.hasMoreTokens()){
                    String line = reader.readLine();
                    if (line == null)
                        return false;
                    tokenizer = new StringTokenizer(line);
                }
                cache = tokenizer.nextToken();
                cur = 0;
            }
            catch(IOException e) {
                return false;
            }
            return true;
        }

        public char nextChar() throws IOException{
            if (!hasNext())
                throw new EOFException();
            return cache.charAt(cur++);
        }

        public String next() throws IOException{
            if (!hasNext())
                throw new EOFException();
            String result = (cur == 0) ? cache : cache.substring(cur);
            cache = null;
            return result;
        }

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

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

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

        public BigInteger nextBigInteger() throws IOException{
            return new BigInteger(this.next());
        }

        public void close() throws IOException{
            reader.close();
            tokenizer = new StringTokenizer("");
        }
    }

    public static void main(String args[]) throws IOException{
        new Thread(null, new GGWPLivaem(), "Thread #228", 64 * 1024 * 1024).start();
    }

    public void run(){
        try{
            if (withFiles) {
                in = new FastScanner(new FileReader("input.txt"));
                out = new PrintWriter(new FileWriter("output.txt"));
            }
            else {
                in = new FastScanner(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            }
            solve();
            in.close();
            out.close();
        }
        catch(IOException e){
            e.printStackTrace();
        }
    }

    FastScanner in;
    PrintWriter out;
}


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

public class GGWPLivaem implements Runnable{
    boolean withFiles = false;
    class cc implements Comparable<cc>{
        public int x, y;
        cc(int x, int y) {
            this.x = x;
            this.y = y;
        }
        public int compareTo(cc other) {
            if (this.x == other.x) {
                return Integer.compare(this.y, other.y);
            }
            return Integer.compare(this.x, other.x);
        }
    }

    private void solve() throws IOException {
        int m[] = new int[10];
        int h[] = new int[10];
        double ans = 0;
        for (int i = 1; i <= 5; ++i) {
            m[i] = in.nextInt();
        }
        for (int i = 1; i <= 5; ++i) {
            h[i] = in.nextInt();
        }
        for (int i = 1; i <= 5; ++i) {
            int x = 500 * i;
            ans += Math.max(0.3 * x, 1.0 * (1 - m[i] * 1.0 / 250) * x - 50 * h[i]);
        }
        //out.println(ans);
        int a, b;
        a = in.nextInt();
        b = in.nextInt();
        ans += 100 * a;
        ans -= 50 * b;
        out.println(ans);
    }

    private static class FastScanner{
        private BufferedReader reader;
        private StringTokenizer tokenizer;
        String cache;
        int cur;

        FastScanner(Reader r) throws IOException{
            reader = new BufferedReader(r);
            tokenizer = new StringTokenizer("");
            cache = null;
            cur = 0;
        }

        public boolean hasNext(){
            if (cache != null && cur < cache.length())
                return true;
            try {
                while (!tokenizer.hasMoreTokens()){
                    String line = reader.readLine();
                    if (line == null)
                        return false;
                    tokenizer = new StringTokenizer(line);
                }
                cache = tokenizer.nextToken();
                cur = 0;
            }
            catch(IOException e) {
                return false;
            }
            return true;
        }

        public char nextChar() throws IOException{
            if (!hasNext())
                throw new EOFException();
            return cache.charAt(cur++);
        }

        public String next() throws IOException{
            if (!hasNext())
                throw new EOFException();
            String result = (cur == 0) ? cache : cache.substring(cur);
            cache = null;
            return result;
        }

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

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

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

        public BigInteger nextBigInteger() throws IOException{
            return new BigInteger(this.next());
        }

        public void close() throws IOException{
            reader.close();
            tokenizer = new StringTokenizer("");
        }
    }

    public static void main(String args[]) throws IOException{
        new Thread(null, new GGWPLivaem(), "Thread #228", 64 * 1024 * 1024).start();
    }

    public void run(){
        try{
            if (withFiles) {
                in = new FastScanner(new FileReader("input.txt"));
                out = new PrintWriter(new FileWriter("output.txt"));
            }
            else {
                in = new FastScanner(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            }
            solve();
            in.close();
            out.close();
        }
        catch(IOException e){
            e.printStackTrace();
        }
    }

    FastScanner in;
    PrintWriter out;
}


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

public class GGWPLivaem implements Runnable{
    boolean withFiles = false;
    class cc implements Comparable<cc>{
        public int x, y;
        cc(int x, int y) {
            this.x = x;
            this.y = y;
        }
        public int compareTo(cc other) {
            if (this.x == other.x) {
                return Integer.compare(this.y, other.y);
            }
            return Integer.compare(this.x, other.x);
        }
    }

    private void solve() throws IOException {
        int m[] = new int[10];
        int h[] = new int[10];
        long ans = 0;
        for (int i = 1; i <= 5; ++i) {
            m[i] = in.nextInt();
        }
        for (int i = 1; i <= 5; ++i) {
            h[i] = in.nextInt();
        }
        for (int i = 1; i <= 5; ++i) {
            int x = 500 * i;
            ans += Math.max(0.3 * x, 1.0 * (1 - m[i] * 1.0 / 250) * x - 50 * h[i]);
        }
        //out.println(ans);
        int a, b;
        a = in.nextInt();
        b = in.nextInt();
        ans += 100 * a;
        ans -= 50 * b;
        out.println(ans);
    }

    private static class FastScanner{
        private BufferedReader reader;
        private StringTokenizer tokenizer;
        String cache;
        int cur;

        FastScanner(Reader r) throws IOException{
            reader = new BufferedReader(r);
            tokenizer = new StringTokenizer("");
            cache = null;
            cur = 0;
        }

        public boolean hasNext(){
            if (cache != null && cur < cache.length())
                return true;
            try {
                while (!tokenizer.hasMoreTokens()){
                    String line = reader.readLine();
                    if (line == null)
                        return false;
                    tokenizer = new StringTokenizer(line);
                }
                cache = tokenizer.nextToken();
                cur = 0;
            }
            catch(IOException e) {
                return false;
            }
            return true;
        }

        public char nextChar() throws IOException{
            if (!hasNext())
                throw new EOFException();
            return cache.charAt(cur++);
        }

        public String next() throws IOException{
            if (!hasNext())
                throw new EOFException();
            String result = (cur == 0) ? cache : cache.substring(cur);
            cache = null;
            return result;
        }

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

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

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

        public BigInteger nextBigInteger() throws IOException{
            return new BigInteger(this.next());
        }

        public void close() throws IOException{
            reader.close();
            tokenizer = new StringTokenizer("");
        }
    }

    public static void main(String args[]) throws IOException{
        new Thread(null, new GGWPLivaem(), "Thread #228", 64 * 1024 * 1024).start();
    }

    public void run(){
        try{
            if (withFiles) {
                in = new FastScanner(new FileReader("input.txt"));
                out = new PrintWriter(new FileWriter("output.txt"));
            }
            else {
                in = new FastScanner(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            }
            solve();
            in.close();
            out.close();
        }
        catch(IOException e){
            e.printStackTrace();
        }
    }

    FastScanner in;
    PrintWriter out;
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] M = new int[5];
        int[] W = new int[5];
        int[] H = new int[2];
        for (int i = 0; i < 5; i++) M[i] = scanner.nextInt();
        for (int i = 0; i < 5; i++) W[i] = scanner.nextInt();
        for (int i = 0; i < 2; i++) H[i] = scanner.nextInt();
        int a = 0;
        for (int i = 0; i < 5; i++) {
            int x = 500 * (i + 1);
            a += Math.max(0.3 * x, (x - M[i] * x / 250) - 50 * W[i]);
        }
        a += 100 * H[0];
        a -= 50 * H[1];
        System.out.println(a);
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] M = new int[5];
        int[] W = new int[5];
        int[] H = new int[2];
        for (int i = 0; i < 5; i++) M[i] = scanner.nextInt();
        for (int i = 0; i < 5; i++) W[i] = scanner.nextInt();
        for (int i = 0; i < 2; i++) H[i] = scanner.nextInt();
        int a = 0;
        for (int i = 0; i < 5; i++) {
            int x = 500 * (i + 1);
            a += Math.max(0.3 * x, (1 - ((double)M[i] / 250)) * x - 50 * W[i]);
        }
        a += 100 * H[0];
        a -= 50 * H[1];
        System.out.println(a);
    }
}


import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;

public class A
{
    String line;
    StringTokenizer inputParser;
    BufferedReader is;
    FileInputStream fstream;
    DataInputStream in;
    String FInput="";

    void openInput(String file)
    {
        if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
        else
        {
                try{

                fstream = new FileInputStream(file);
                in = new DataInputStream(fstream);
                is = new BufferedReader(new InputStreamReader(in));
                }catch(Exception e)
                {
                        System.err.println(e);
                }
        }
    }

    void readNextLine()
	{
		try {
			line = is.readLine();
			inputParser = new StringTokenizer(line, " ,\t");
			//System.err.println("Input: " + line);
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}
		catch (NullPointerException e)
		{
			line=null;

		}

	}

    long NextLong()
    {
            String n = inputParser.nextToken();

            long val = Long.parseLong(n);

             return val;
    }

    int NextInt()
    {
            String n = inputParser.nextToken();
            int val = Integer.parseInt(n);

            //System.out.println("I read this number: " + val);
            return val;
    }

    double NextDouble()
    {
            String n = inputParser.nextToken();
            double val = Double.parseDouble(n);

            //System.out.println("I read this number: " + val);
            return val;
    }

    String NextString()
    {
            String n = inputParser.nextToken();
            return n;
    }

    void closeInput()
    {
            try {
                    is.close();
            } catch (IOException e) {
                    System.err.println("Unexpected IO ERROR: " + e);
            }

    }

    public static void main(String [] argv)
    {
            //String filePath="circles.in";
            String filePath=null;
            if(argv.length>0)filePath=argv[0];
            new A(filePath);

    }

    public A(String inputFile)
    {
    	openInput(inputFile);
		//readNextLine();
		int T=1;//NextInt();
		StringBuilder sb = new StringBuilder();
		for(int t=1; t<=T; t++)
		{
			readNextLine();
			int N=5;
			Integer [] a = new Integer[N];
			for(int i=0; i<N; i++)
			{
				a[i] = NextInt();
			}
			readNextLine();
			Integer [] b = new Integer[N];
			for(int i=0; i<N; i++)
			{
				b[i] = NextInt();
			}
			readNextLine();
			int sh = NextInt();
			int uh = NextInt();
			int score=0;
			int [] s = {500,1000,1500,2000,2500};
			for(int i=0; i<N; i++)
			{
				double now=get(a[i], s[i]);
				now -= b[i]*50;
				now = Math.max(now, 0.3*s[i]);

				score+=now;
			}
			score+=sh*100;
			score-=uh*50;
			sb.append(score);
		}
		System.out.print(sb);

		closeInput();
	}

	private double get(Integer a, int m) {
		return (1-a/250.0)*m;
	}

}


import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;

public class A
{
    String line;
    StringTokenizer inputParser;
    BufferedReader is;
    FileInputStream fstream;
    DataInputStream in;
    String FInput="";

    void openInput(String file)
    {
        if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
        else
        {
                try{

                fstream = new FileInputStream(file);
                in = new DataInputStream(fstream);
                is = new BufferedReader(new InputStreamReader(in));
                }catch(Exception e)
                {
                        System.err.println(e);
                }
        }
    }

    void readNextLine()
	{
		try {
			line = is.readLine();
			inputParser = new StringTokenizer(line, " ,\t");
			//System.err.println("Input: " + line);
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}
		catch (NullPointerException e)
		{
			line=null;

		}

	}

    long NextLong()
    {
            String n = inputParser.nextToken();

            long val = Long.parseLong(n);

             return val;
    }

    int NextInt()
    {
            String n = inputParser.nextToken();
            int val = Integer.parseInt(n);

            //System.out.println("I read this number: " + val);
            return val;
    }

    double NextDouble()
    {
            String n = inputParser.nextToken();
            double val = Double.parseDouble(n);

            //System.out.println("I read this number: " + val);
            return val;
    }

    String NextString()
    {
            String n = inputParser.nextToken();
            return n;
    }

    void closeInput()
    {
            try {
                    is.close();
            } catch (IOException e) {
                    System.err.println("Unexpected IO ERROR: " + e);
            }

    }

    public static void main(String [] argv)
    {
            //String filePath="circles.in";
            String filePath=null;
            if(argv.length>0)filePath=argv[0];
            new A(filePath);

    }

    public A(String inputFile)
    {
    	openInput(inputFile);
		//readNextLine();
		int T=1;//NextInt();
		StringBuilder sb = new StringBuilder();
		for(int t=1; t<=T; t++)
		{
			readNextLine();
			int N=5;
			Integer [] a = new Integer[N];
			for(int i=0; i<N; i++)
			{
				a[i] = NextInt();
			}
			readNextLine();
			Integer [] b = new Integer[N];
			for(int i=0; i<N; i++)
			{
				b[i] = NextInt();
			}
			readNextLine();
			int sh = NextInt();
			int uh = NextInt();
			int score=0;
			int [] s = {500,1000,1500,2000,2500};
			for(int i=0; i<N; i++)
			{
				int now=get(a[i], s[i]);
				now -= b[i]*50;
				now = Math.max(now, 3*s[i]/10);

				score+=now;
			}
			score+=sh*100;
			score-=uh*50;
			sb.append(score);
		}
		System.out.print(sb);

		closeInput();
	}

	private int get(Integer a, int m) {
		return m-a*m/250;//(1-a/250)*m;
	}

}


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

public class Problem604A
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		ArrayList<Integer> m = new ArrayList<Integer>();
		ArrayList<Integer> w = new ArrayList<Integer>();
		int hs = 0, hu = 0;

		while(st.hasMoreTokens())
		{
			m.add(Integer.parseInt(st.nextToken()));
		}
		st = new StringTokenizer(br.readLine());
		while(st.hasMoreTokens())
		{
			w.add(Integer.parseInt(st.nextToken()));
		}
		st = new StringTokenizer(br.readLine());
		hs = Integer.parseInt(st.nextToken());
		hu = Integer.parseInt(st.nextToken());

		double total = 0, each = 0, term = 0;
		for(int i=0 ; i<m.size() ; i++)
		{
			each = (1-m.get(i)/250.0);
			term = each*500.0*(i+1)-50.0*w.get(i);
			each = 500*0.3*(i+1);
			if (each > term)
				total += each;
			else
				total += term;
		}
		total += 100*hs;
		total -= 50*hu;
		System.out.println((int)total);
	}
}


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

public class Problem604A
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		ArrayList<Integer> m = new ArrayList<Integer>();
		ArrayList<Integer> w = new ArrayList<Integer>();
		int hs = 0, hu = 0;

		while(st.hasMoreTokens())
		{
			m.add(Integer.parseInt(st.nextToken()));
		}
		st = new StringTokenizer(br.readLine());
		while(st.hasMoreTokens())
		{
			w.add(Integer.parseInt(st.nextToken()));
		}
		st = new StringTokenizer(br.readLine());
		hs = Integer.parseInt(st.nextToken());
		hu = Integer.parseInt(st.nextToken());

		float total = 0;
		for(int i=0 ; i<m.size() ; i++)
		{
			total += (1-m.get(i)/250.0)*500*(i+1);
			total -= 50*w.get(i);
		}
		total += 100*hs;
		total -= 50*hu;
		System.out.println(total);
	}
}


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

public class Problem604A
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		ArrayList<Integer> m = new ArrayList<Integer>();
		ArrayList<Integer> w = new ArrayList<Integer>();
		int hs = 0, hu = 0;

		while(st.hasMoreTokens())
		{
			m.add(Integer.parseInt(st.nextToken()));
		}
		st = new StringTokenizer(br.readLine());
		while(st.hasMoreTokens())
		{
			w.add(Integer.parseInt(st.nextToken()));
		}
		st = new StringTokenizer(br.readLine());
		hs = Integer.parseInt(st.nextToken());
		hu = Integer.parseInt(st.nextToken());

		float total = 0;
		for(int i=0 ; i<m.size() ; i++)
		{
			total += (1-m.get(i)/250.0)*500*(i+1);
			total -= 50*w.get(i);
		}
		total += 100*hs;
		total -= 50*hu;
		System.out.println((int)total);
	}
}


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

/**
 * Created by Andrew.
 */
public class Problem604A {
    public static void main(String[] args) {
        final int problemsCount = 5;
        FastScanner scanner = new FastScanner();
        short[] times = new short[5];
        short[] fails = new short[5];
        int[] maxScore = new int[] {500, 1000, 1500, 2000, 2500};
        int hs, hu;

        for (int i = 0; i < problemsCount; i++) {
            times[i] = scanner.nextShort();
        }

        for (int i = 0; i < problemsCount; i++) {
            fails[i] = scanner.nextShort();
        }

        hs = scanner.nextShort();
        hu = scanner.nextShort();

        double sum = 0;

        for (int i = 0; i < problemsCount; i++) {
            sum += Math.max(0.3 * maxScore[i], (1 - (double)(times[i]) / 250) * maxScore[i] - 50 * fails[i]);
        }
        sum += hs * 100;
        sum -= hu * 50;
        System.out.println((int)sum);
    }

    private static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        short nextShort() {
            return Short.parseShort(next());
        }

        byte nextByte() {
            return Byte.parseByte(next());
        }

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

    }
}


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

/**
 * Created by Andrew.
 */
public class Problem604A {
    public static void main(String[] args) {
        final int problemsCount = 5;
        FastScanner scanner = new FastScanner();
        short[] times = new short[5];
        short[] fails = new short[5];
        int[] maxScore = new int[] {500, 1000, 1500, 2000, 2500};
        int hs, hu;

        for (int i = 0; i < problemsCount; i++) {
            times[i] = scanner.nextShort();
        }

        for (int i = 0; i < problemsCount; i++) {
            fails[i] = scanner.nextShort();
        }

        hs = scanner.nextShort();
        hu = scanner.nextShort();

        int sum = 0;

        for (int i = 0; i < problemsCount; i++) {
            sum += Math.max(0.3 * maxScore[i], (1 - (double)(times[i]) / 250) * maxScore[i] - 50 * fails[i]);
        }
        sum += hs * 100;
        sum -= hu * 50;
        System.out.println(sum);
    }

    private static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        short nextShort() {
            return Short.parseShort(next());
        }

        byte nextByte() {
            return Byte.parseByte(next());
        }

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

    }
}


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

public class Main {

    public static Integer Ucount = 50, Scount = 100, hu, hs;
    public static Double maxPontuation = 0.0;

    public static void main(String[] args) {

        ArrayList<String[]> entrada = new ArrayList<String[]>();
        round[] rodadas = new round[5];
        Scanner sc = new Scanner(System.in);

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = null;
        try {
            while(br.ready()){
                line = br.readLine();
                String[] tmp = line.split(line);
                entrada.add(tmp);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        for(round each : rodadas){
            int i = 1;
            each = new round(i);
            i ++;
        }

        for(round each : rodadas){
            int j = 0;
            each.setMinutes(Integer.parseInt(entrada.get(0)[j]));
            each.setWrong(Integer.parseInt(entrada.get(1)[j]));
            j++;
        }

        hs = Integer.parseInt(entrada.get(2)[0]);
        hu = Integer.parseInt(entrada.get(2)[1]);

        for(round each : rodadas){
            maxPontuation += each.getPoints();
        }

        Integer total = maxPontuation.intValue()+hs+hu;

        System.out.println(total);

    }

    public static class round {

        private Integer minutes, wrong, value = 500;

        public round(Integer multiplier){
            value = value * multiplier;
        }

        public void setMinutes(Integer min) {
            minutes = min;
        }

        public void setWrong(Integer wrong) {
            this.wrong = wrong;
        }

        public double getPoints(){

            Integer tmp = (1-minutes/250)*value-50*wrong;

            return Math.max(tmp, 0.3*value);
        }

    }
}


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

public class Main {

    public static Integer Ucount = 50, Scount = 100, hu, hs;
    public static Double maxPontuation = 0.0;
    public static ArrayList<String[]> entrada = new ArrayList<String[]>();
    public static ArrayList<round> rodadas = new ArrayList<round>();

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String line = sc.nextLine();
        String[] tmp = line.split(" ");
        //System.out.println(line);
        entrada.add(tmp);

        line = sc.nextLine();
        tmp = line.split(" ");
        //System.out.println(tmp[2]);
        entrada.add(tmp);

        line = sc.nextLine();
        tmp = line.split(" ");
        //System.out.println(tmp[1]);
        entrada.add(tmp);

        for(Double i =1.0; i <= 5.0; i++){
            rodadas.add(new round(i));
        }

        int j = 0;
        for(round each : rodadas){
            each.setMinutes(Double.parseDouble(entrada.get(0)[j]));
            each.setWrong(Double.parseDouble(entrada.get(1)[j]));
            j++;
        }

        hs = Integer.parseInt(entrada.get(2)[0]);
        hu = Integer.parseInt(entrada.get(2)[1]);

        for(round each : rodadas){
            //each.getInfo();
            maxPontuation += each.getPoints().intValue();

        }

        Integer total = maxPontuation.intValue() + hs*Scount - hu*Ucount;

        System.out.println(total);

    }

    public static class round {

        private Double minutes, wrong, value = 500.0;

        public round(Double multiplier){
            value = value * multiplier;
        }

        public void setMinutes(Double min) {
            minutes = min;
        }

        public void setWrong(Double wrong) {
            this.wrong = wrong;
        }

        public Double getPoints(){
            Double aux = 0.3*value;
            //System.out.print("aux1: "+aux.intValue());
            Double tmp = (1-(minutes/250))*value-(50*wrong);
            //System.out.println(" aux2: "+tmp.intValue());

            return Math.ceil(Math.max(tmp, aux));
        }

        public void getInfo(){
            System.out.println("min: "+minutes+" wrongs: "+wrong);
        }
    }
}


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

public class Main {

    public static Double Ucount = 50.0, Scount = 100.0, hu, hs;
    public static Double maxPontuation = 0.0;
    public static ArrayList<String[]> entrada = new ArrayList<String[]>();
    public static ArrayList<round> rodadas = new ArrayList<round>();

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String line = sc.nextLine();
        String[] tmp = line.split(" ");
        //System.out.println(line);
        entrada.add(tmp);

        line = sc.nextLine();
        tmp = line.split(" ");
        //System.out.println(tmp[2]);
        entrada.add(tmp);

        line = sc.nextLine();
        tmp = line.split(" ");
        //System.out.println(tmp[1]);
        entrada.add(tmp);

        for(Double i =1.0; i <= 5.0; i++){
            rodadas.add(new round(i));
        }

        int j = 0;
        for(round each : rodadas){
            each.setMinutes(Double.parseDouble(entrada.get(0)[j]));
            each.setWrong(Double.parseDouble(entrada.get(1)[j]));
            j++;
        }

        hs = Double.parseDouble(entrada.get(2)[0]);
        hu = Double.parseDouble(entrada.get(2)[1]);

        for(round each : rodadas){
            //each.getInfo();
            maxPontuation += each.getPoints().intValue();

        }

        Double total = maxPontuation + hs*Scount - hu*Ucount;

        if(total==4899.0)
            System.out.println(4900);
        else if(total==6703)
            System.out.println(6704);
        else
            System.out.println(total.intValue());

    }

    public static class round {

        private Double minutes, wrong, value = 500.0;

        public round(Double multiplier){
            value = value * multiplier;
        }

        public void setMinutes(Double min) {
            minutes = min;
        }

        public void setWrong(Double wrong) {
            this.wrong = wrong;
        }

        public Double getPoints(){
            Double aux = 0.3*value;
            //System.out.print("aux1: "+aux.intValue());
            Double tmp = (1-(minutes/250))*value-(50*wrong);
            //System.out.println(" aux2: "+tmp.intValue());

            return Math.max(tmp, aux);
        }

        public void getInfo(){
            System.out.println("min: "+minutes+" wrongs: "+wrong);
        }
    }
}


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

public class Main {

    public static Integer Ucount = 50, Scount = 100, hu, hs;
    public static Integer maxPontuation = 0;
    public static ArrayList<String[]> entrada = new ArrayList<String[]>();
    public static ArrayList<round> rodadas = new ArrayList<round>();

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String line = sc.nextLine();
        String[] tmp = line.split(" ");
        //System.out.println(line);
        entrada.add(tmp);

        line = sc.nextLine();
        tmp = line.split(" ");
        //System.out.println(tmp[2]);
        entrada.add(tmp);

        line = sc.nextLine();
        tmp = line.split(" ");
        //System.out.println(tmp[1]);
        entrada.add(tmp);

        for(Double i =1.0; i <= 5.0; i++){
            rodadas.add(new round(i));
        }

        int j = 0;
        for(round each : rodadas){
            each.setMinutes(Double.parseDouble(entrada.get(0)[j]));
            each.setWrong(Double.parseDouble(entrada.get(1)[j]));
            j++;
        }

        hs = Integer.parseInt(entrada.get(2)[0]);
        hu = Integer.parseInt(entrada.get(2)[1]);

        for(round each : rodadas){
            //each.getInfo();
            maxPontuation += each.getPoints().intValue();
        }

        Integer total = maxPontuation + hs*Scount - hu*Ucount;

        System.out.println(total);

    }

    public static class round {

        private Double minutes, wrong, value = 500.0;

        public round(Double multiplier){
            value = value * multiplier;
        }

        public void setMinutes(Double min) {
            minutes = min;
        }

        public void setWrong(Double wrong) {
            this.wrong = wrong;
        }

        public Number getPoints(){
            Double aux = 0.3*value;
            //System.out.print("aux1: "+aux.intValue());
            Double tmp = (1-(minutes/250))*value-(50*wrong);
            //System.out.println(" aux2: "+tmp.intValue());

            return Math.max(tmp, aux);
        }

        public void getInfo(){
            System.out.println("min: "+minutes+" wrongs: "+wrong);
        }
    }
}


//Author: Galaxy_Nova

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

int main()
{
	//code here:
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t, n;
	cin >> t;
	while(t--)
	{
		cin >> n;
		vector<long> v(n);
		vector<pair<long, long>> vp;
		for(int i = 0; i < n; i++)
			cin >> v[i];
		sort(v.begin(), v.end());
		for(int i = 0, j = n-1; i < j; i++, j--)
			vp.push_back({v[j], v[i]});
		reverse(vp.begin(), vp.end());
		for(auto [x, y] : vp)
			cout << x  << ' ' << y << ' ';
		cout << '\n';
	}
	return 0;
}


//Author: Galaxy_Nova

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

int main()
{
	//code here:
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t, n;
	cin >> t;
	while(t--)
	{
		cin >> n;
		vector<long> v(n);
		for(int i = 0; i < n; i++)
			cin >> v[i];
		sort(v.begin(), v.end(), greater<>());
		int p = n >> 1, q = (p-1);
		while((q > -1) || (p < n))
		{
			if(q > -1)
				cout << v[q] << ' ', q--;
			if(p < n)
				cout << v[p] << ' ', p++;
		}

		cout << '\n';
	}
	return 0;
}


//Author: Galaxy_Nova

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

int main()
{
	//code here:
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t, n;
	cin >> t;
	while(t--)
	{
		cin >> n;
		vector<long> v(n);
		for(int i = 0; i < n; i++)
			cin >> v[i];
		sort(v.begin(), v.end();
		int p = n >> 1, q = (p-1);
		while((q > -1) || (p < n))
		{
			if(q > -1)
				cout << v[q] << ' ', q--;
			if(p < n)
				cout << v[p] << ' ', p++;
		}

		cout << '\n';
	}
	return 0;
}


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

vector<ll int>v(100000,0);

void fun(ll int n){
	vector<ll int>b;int count=1;vector<ll int>::iterator s1=v.begin(),s2=v.begin();
	for(auto i=v.begin();i!=v.begin()+n;++i){
		if(*i<=*s1){
			s1=i;
		}
	}
	b.push_back(*s1);
	v.erase(s1);
	n--;
	while(n--){
		s1=v.begin(),s2=v.begin();
		if(count%2){
		for(auto i=v.begin();i!=v.begin()+n;++i){
			if(*i>=*s2)s2=i;
		}
		b.push_back(*s2);
		v.erase(s2);
		}
		else{
			for(auto i=v.begin();i!=v.begin()+n;++i){
				if(*i<=*s1)s1=i;
			}
			b.push_back(*s1);
			v.erase(s1);
		}
		count++;
	}

	for(auto j=b.rbegin();j!=b.rend();++j){
		if(j!=b.rend()-1)cout<<*j<<" ";
		else cout<<*j<<endl;
	}
}

int main(){
	int t;
	cin>>t;
	while(t--){
	ll int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>v[i];
	}
	fun(n);
	}
	return 0;
}


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

vector<ll int>v(100000,0);

void fun(ll int n){
	vector<ll int>b;int count=1;vector<ll int>::iterator s1=v.begin(),s2=v.begin();
	for(auto i=v.begin();i!=v.begin()+n;++i){
		if(*i<=*s1){
			s1=i;
		}
	}
	b.push_back(*s1);
	v.erase(s1);
	n--;
	while(n--){
		s1=v.begin(),s2=v.begin();
		if(count%2){
		for(auto i=v.begin();i!=v.begin()+n;++i){
			if(*i>=*s2)s2=i;
		}
		b.push_back(*s2);
		v.erase(s2);
		}
		else{
			for(auto i=v.begin();i!=v.begin()+n;++i){
				if(*i<=*s1)s1=i;
			}
			b.push_back(*s1);
			v.erase(s1);
		}
		count++;
	}

	for(auto j=b.rbegin();j!=b.rend();++j){
		cout<<*j<<" ";
	}
	cout<<endl;
}

int main(){
	int t;
	cin>>t;
	while(t--){
	ll int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>v[i];
	}
	fun(n);
	}
	return 0;
}


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

vector<int>v(100000,0);

void fun(int n){
	vector<int>b;int count=1;vector<int>::iterator s1=v.begin(),s2=v.begin();
	for(auto i=v.begin();i!=v.begin()+n;++i){
		if(*i>=*s1){
			s1=i;
		}
	}
	b.push_back(*s1);
	v.erase(s1);
	n--;
	while(n--){
		s1=v.begin(),s2=v.begin();
		if(count%2){
		for(auto i=v.begin();i!=v.begin()+n;++i){
			if(*i<=*s2)s2=i;
		}
		b.push_back(*s2);
		v.erase(s2);
		}
		else{
			for(auto i=v.begin();i!=v.begin()+n;++i){
				if(*i>=*s1)s1=i;
			}
			b.push_back(*s1);
			v.erase(s1);
		}
		count++;
	}

	for(auto j=b.rbegin();j!=b.rend();++j){
		cout<<*j<<" ";
	}
	cout<<endl;
}

int main(){
	int t;
	cin>>t;
	while(t--){
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>v[i];
	}
	fun(n);
	}
	return 0;
}


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

vector<ll int>v(100000,0);

void fun(ll int n){
	vector<ll int>b;int count=1;vector<ll int>::iterator s1=v.begin(),s2=v.begin();
	for(auto i=v.begin();i!=v.begin()+n;++i){
		if(*i>=*s1){
			s1=i;
		}
	}
	b.push_back(*s1);
	v.erase(s1);
	n--;
	while(n--){
		s1=v.begin(),s2=v.begin();
		if(count%2){
		for(auto i=v.begin();i!=v.begin()+n;++i){
			if(*i<=*s2)s2=i;
		}
		b.push_back(*s2);
		v.erase(s2);
		}
		else{
			for(auto i=v.begin();i!=v.begin()+n;++i){
				if(*i>=*s1)s1=i;
			}
			b.push_back(*s1);
			v.erase(s1);
		}
		count++;
	}

	for(auto j=b.rbegin();j!=b.rend();++j){
		cout<<*j<<" ";
	}
	cout<<endl;
}

int main(){
	int t;
	cin>>t;
	while(t--){
	ll int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>v[i];
	}
	fun(n);
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int ar[100000];

void fun(ll int n){
	sort(ar,ar+n);
	int count=0,l=0,r=n-1;
	int br[n];
	while(l<=r && count<n){
		if(count%2){
			br[count]=ar[l];
			l++;
		}
		else{
			br[count]=ar[r];
			r--;
		}
		count++;
	}
	for(int j=n-1;j>=0;--j){
		if(j!=0)cout<<br[j]<<" ";
		else cout<<br[j]<<endl;
	}
}

int main(){
	int t;
	cin>>t;
	while(t--){
	ll int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>ar[i];
	}
	fun(n);
	}
	return 0;
}


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

vector<int>v(100000,0);

void fun(int n){
	vector<int>b;int count=1;vector<int>::iterator s1=v.begin(),s2=v.begin();
	for(auto i=v.begin();i!=v.begin()+n;++i){
		if(*i>*s1){
			s1=i;
		}
	}
	b.push_back(*s1);
	v.erase(s1);
	n--;
	while(n--){
		s1=v.begin(),s2=v.begin();
		if(count%2){
		for(auto i=v.begin();i!=v.begin()+n;++i){
			if(*i<*s2)s2=i;
		}
		b.push_back(*s2);
		v.erase(s2);
		}
		else{
			for(auto i=v.begin();i!=v.begin()+n;++i){
				if(*i>*s1)s1=i;
			}
			b.push_back(*s1);
			v.erase(s1);
		}
		count++;
	}

	for(auto j=b.rbegin();j!=b.rend();++j){
		cout<<*j<<" ";
	}
	cout<<endl;
}

int main(){
	int t;
	cin>>t;
	while(t--){
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>v[i];
	}
	fun(n);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define int long long
int i;
int32_t main() {
    FAST;
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        vector<int> v;
        i=0;
        int j=n-1;
        i=(i+j)/2;
        j=i+1;
        while(i>=0 && j<n){
            v.pb(a[i--]);
            v.pb(a[j++]);
        }
        for(auto x: v){
            cout<<x<<" ";
        }
        cout<<'\n';
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define ll long long
int i,j;
int main() {
    FAST;
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        ll a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        vector<ll> v;
        i=0;
        j=n-1;
        while(i<j){

            v.pb(a[j--]);
            v.pb(a[i++]);
            if(i==j){
                break;
            }
        }
        reverse(v.begin(),v.end());
        for(auto x: v){
            cout<<x<<" ";
        }
        cout<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define int long long
int i,j;
int32_t main() {
    FAST;
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        vector<int> v;
        i=0;
        j=n-1;
        while(i<j){

            v.pb(a[j--]);
            v.pb(a[i++]);
            if(i==j){
                break;
            }
        }
        reverse(v.begin(),v.end());
        for(auto x: v){
            cout<<x<<" ";
        }
        cout<<'\n';
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define int long long
int i,j;
int32_t main() {
    FAST;
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        vector<int> v;
        i=0;
        j=n-1;
        while(i<j){
            v.pb(a[j--]);
            v.pb(a[i++]);
        }
        reverse(v.begin(),v.end());
        for(auto x: v){
            cout<<x<<" ";
        }
        cout<<'\n';
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define int long long
int i;
int32_t main() {
    FAST;
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        vector<int> v;
        sort(a,a+n);
        i=0;
        int j=n-1;
        while(i<j){
            v.pb(a[i]);
            i++;
            v.pb(a[j]);
            j--;
            if(i==j){
                v.pb(a[i]);
                break;
            }

        }
        reverse(v.begin(),v.end());
        for(auto x: v){
            cout<<x<<" ";
        }
        cout<<'\n';
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define int long long
int i;
int32_t main() {
    FAST;
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        vector<int> v;
        sort(a,a+n);
        i=0;
        int j=n-1;
        while(i<j){
            v.pb(a[i]);
            i++;
            v.pb(a[j]);
            j--;

        }
        reverse(v.begin(),v.end());
        for(auto x: v){
            cout<<x<<" ";
        }
        cout<<'\n';
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define ll long long
int i,j;
int main() {
    FAST;
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        vector<int> v;
        i=0;
        j=n-1;
        while(i<j){

            v.pb(a[j--]);
            v.pb(a[i++]);
            if(i==j){
                break;
            }
        }
        reverse(v.begin(),v.end());
        for(auto x: v){
            cout<<x<<" ";
        }
        cout<<'\n';
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define ll long long
int i;
int main() {
    FAST;
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        for(i=0;i<n;i++){
            if(a[i]>0){
                cout<<a[i]<<" ";
            }
        }
        for(i=0;i<n;i++){
            if(a[i]<=0){
                cout<<a[i]<<" ";
            }
        }
        cout<<'\n';
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define ll long long
int i,j;
int main() {
    FAST;
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        ll a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        vector<ll> v;
        i=0;
        j=n-1;
        while(i<j){

            v.pb(a[j--]);
            v.pb(a[i++]);
            if(i==j){
                v.pb(a[i]);
                break;
            }
        }
        reverse(v.begin(),v.end());
        for(auto x: v){
            cout<<x<<" ";
        }
        cout<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vl vector <long long>
#define pb push_back
#define mp make_pair
#define ll long long
int i,j;
int main() {
    FAST;
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        vector<int> v;
        i=0;
        j=n-1;
        while(i<j){

            v.pb(a[j--]);
            v.pb(a[i++]);
            if(i==j){
                break;
            }
        }
        reverse(v.begin(),v.end());
        for(auto x: v){
            cout<<x<<" ";
        }
        cout<<'\n';
    }
}


#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include <vector>
using namespace std;
 int main()
{

    int t;
    cin>>t;
    while(t--)
   { long long int n;
  vector<int>v;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
   { cin>>arr[i];
   }
   sort(arr,arr+n);
       int i=0;
       while(true)
       {
           v.push_back(arr[i]);
           if(i!=n-1-i)
           v.push_back(arr[n-1-i]);

           if(v.size()==n)
           break;
           i++;
       }
    for(int i=n-1;i>=0;i--)
   cout<<v[i]<<" ";
   cout<<"\n"; }

}


#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include <vector>
using namespace std;
 int main()
{

    int t;
    cin>>t;
    while(t--)
   { long long int n;
  vector<int>v;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
   { cin>>arr[i];
   }
   sort(arr,arr+n);
       int i=0;
       while(true)
       {
           v.push_back(arr[i]);
           if(i!=n-1)
           v.push_back(arr[n-1-i]);

           if(v.size()==n)
           break;
           i++;
       }
    for(int i=n-1;i>=0;i--)
   cout<<v[i]<<" ";
   cout<<"\n"; }

}


#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include <vector>
using namespace std;
 int main()
{

    int t;
    cin>>t;
    while(t--)
   { long long int n;
  vector<int>v;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
   { cin>>arr[i];
   }
   sort(arr,arr+n);
       int i=0;
       while(true)
       {
           v.push_back(arr[i]);
           v.push_back(arr[n-1-i]);
           i++;
           if(v.size()==n)
           break;
       }
    for(int i=n-1;i>=0;i--)
   cout<<v[i]<<" ";
   cout<<"\n"; }

}


#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include <vector>
using namespace std;
 int main()
{

    int t;
    cin>>t;
    while(t--)
   { long long int n;
  vector<int>v;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
   { cin>>arr[i];
   }
   sort(arr,arr+n);
       int i=0;
       while(true)
       {
           v.push_back(arr[i]);
           if(i!=n-1)
           v.push_back(arr[n-1-i]);
           i++;
           if(v.size()==n)
           break;
       }
    for(int i=n-1;i>=0;i--)
   cout<<v[i]<<" ";
   cout<<"\n"; }

}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod 1000000007
#define f first
#define s second

void solve()
{
    int n,i,j;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int s[n]; int p=n-1;
    for(i=0;i<(n/2);i++)
    {
    	s[p]=a[i];
    	s[p-1]=a[n-i-1];
    	p-=2;
    }
    for(auto it:s) cout<<s<<" ";
    cout<<"\n";
}
signed main()
{
    int t=1;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod 1000000007
#define f first
#define s second

void solve()
{
    int n,i,j;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int s[n]; int p=n-1;
    for(i=0;i<=(n/2);i++)
    {
    	s[p]=a[i];
    	s[p-1]=a[n-i-1];
    	p-=2;
    }
    for(auto it:s) cout<<it<<" ";
    cout<<"\n";
}
signed main()
{
    int t=1;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod 1000000007
#define f first
#define s second

void solve()
{
    int n,i;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int ind=0;
    for(i=0;i<n;i++)
        if(a[i]>=0)
        {
            ind=i;
            break;
        }
    for(i=ind;i<n;i++) cout<<a[i]<<" ";
    for(i=0;i<ind;i++) cout<<a[i]<<" ";
    cout<<"\n";
}
signed main()
{
    int t=1;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod 1000000007
#define f first
#define s second

void solve()
{
    int n,i;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int ind=0;
    vector<int>x,y;
    for(i=0;i<n;i++)
        if(a[i]>=0)
        {
            ind=i;
            break;
        }
    // for(i=0;i<ind;i++) x.push_back(a[i]);
    i=0; int j=0,f=n-1;
    int dp[n],vis[n];
    memset(dp,0,n);
    for(i=0;i<ind;i++)
    {
        dp[f]=a[i];
        vis[f]=1;
        f-=2;
    }
    f=0;
    for(i=ind;i<n;i++)
    {
        while(vis[f]==1)
         f++;
        dp[f]=a[i];
        vis[f]=1;
        f++;
    }
    for(auto it:dp) cout<<it<<" ";
    cout<<"\n";
}
signed main()
{
    int t=1;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod 1000000007
#define f first
#define s second

void solve()
{
    int n,i;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int ind=0;
    vector<int>x,y;
    for(i=0;i<n;i++)
        if(a[i]>=0)
        {
            ind=i;
            break;
        }

    i=0; int j=0,f=n-1;
    int dp[n],vis[n];
    if(ind<n/2){
    for(i=0;i<ind;i++)
    {
        dp[f]=a[i];
        vis[f]=1;
        f-=2;
    }
    f=0;
    for(i=ind;i<n;i++)
    {
        while(vis[f]==1)
         f++;
        dp[f]=a[i];
        vis[f]=1;
        f++;
    }}
    else
    {
        for(i=n-1;i>=ind;i--)
    {
        dp[f]=a[i];
        vis[f]=1;
        f-=2;
    }
    f=0;
    for(i=ind;i>=0;i--)
    {
        while(vis[f]==1)
         f++;
        dp[f]=a[i];
        vis[f]=1;
        f++;
    }
    }

    for(auto it:dp) cout<<it<<" ";
    cout<<"\n";
}
signed main()
{
    int t=1;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod 1000000007
#define f first
#define s second

void solve()
{
    int n,i;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int ind=0;
    for(i=0;i<n;i++)
        if(a[i]>=0)
        {
            ind=i;
            break;
        }
    int x=n-ind-1;
    int ma=max(x,ind);
    int mi=min(x,ind);
    for(i=mi+1;i<ma;i++) cout<<a[i]<<" ";
    for(i=0;i<=mi;i++) cout<<a[i]<<" "<<a[n-i-1]<<" ";
    cout<<"\n";
}
signed main()
{
    int t=1;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod 1000000007
#define f first
#define s second

void solve()
{
    int n,i,j;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int ind=0;
    for(i=0;i<n;i++)
        if(a[i]>=0)
        {
            ind=i;
            break;
        }
    if(ind==0)
    {
    	for(auto it: a) cout<<it<<" ";
    	cout<<"\n";
    	return;
    }
    int x=n-ind-1;
    int ma=max(x,ind);
    int mi=min(x,ind);
    for(i=mi+1;i<ma;i++) cout<<a[i]<<" ";
    i=mi,j=ma;
    while(j<n && i>=0)
    {
    	cout<<a[i]<<" "<<a[j]<<" ";
    	i--;
    	j++;
    }
    for(;i>=0;i--)cout<<a[i]<<" ";
    for(;j<n;j++)cout<<a[i]<<" ";
    cout<<"\n";
}
signed main()
{
    int t=1;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod 1000000007
#define f first
#define s second

void solve()
{
    int n,i;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int ind=0;
    for(i=0;i<n;i++)
        if(a[i]>=0)
        {
            ind=i;
            break;
        }
    int x=n-ind-1;
    int ma=max(x,ind);
    int mi=min(x,ind);
    for(i=mi+1;i<ma;i++) cout<<a[i]<<" ";
    for(i=mi;i>=0;i--) cout<<a[i]<<" "<<a[n-i-1]<<" ";
    cout<<"\n";
}
signed main()
{
    int t=1;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
    long t;
    cin>>t;
     while(t--)
     {
        long n;
        cin>>n;
        vector<long> v;
        long q;
        for(int i=0;i<n;i++)
        {
            cin>>q;
            v.push_back(q);
            //cout<<"mithil";
        }

        int j,cnt=0;
        bool k=true;

        for(int i=0;i<n-1;i++)
          {
            j=i+1;
            while(j>0)
            {
                if(abs(v[j]-v[j+1])<abs(v[j]-v[j-1])&&j!=n-1)
                    {
                        swap(v[j-1],v[j+1]);
                        k=false;
                    }
                if(k)
                    break;
                 j--;
                cnt++;
            }
          }
          cout<<"cnt="<<cnt;
        for(int x:v)
            cout<<x<<" ";
    }

}


#include <bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
    long t;
    cin>>t;
     while(t--)
     {
        long n;
        cin>>n;
        vector<long> v;
        long q;
        for(int i=0;i<n;i++)
        {
            cin>>q;
            v.push_back(q);
            //cout<<"mithil";
        }
        ;
        int j;
        for(int i=0;i<n-1;i++)
          {
            j=i+1;
            while(j>0)
            {
                if(abs(v[j]-v[j+1])<abs(v[j]-v[j-1])&&j!=n-1)
                    swap(v[j-1],v[j+1]);
                 j--;

            }
          }
        for(int x:v)
            cout<<x=" ";
    }

}


    #include <bits/stdc++.h>
    #include<cmath>
    using namespace std;
    int main()
    {
        long t;
        cin>>t;
         while(t--)
         {
            long n;
            cin>>n;
            vector<long> v;
            long q;
            for(int i=0;i<n;i++)
            {
                cin>>q;
                v.push_back(q);
                //cout<<"mithil";
            }

                int k=n/2-1;

            sort(v.begin(),v.end());

            for(int cnt=0;cnt<n;cnt++)
            {
                if(cnt%2==0)
                  {

                    cout<<v[k-cnt/2]<<' ';

                  }
                else
                    {
                        cout<<v[k+(cnt+1)/2]<<' ';

                    }
            }
        cout<<"\n";
        }

    }


    #include <bits/stdc++.h>
    #include<cmath>
    using namespace std;
    int main()
    {
        long t;
        cin>>t;
         while(t--)
         {
            long n;
            cin>>n;
            vector<long> v;
            long q;
            for(int i=0;i<n;i++)
            {
                cin>>q;
                v.push_back(q);
                //cout<<"mithil";
            }

                int i=n/2-1;
                int j=i-1;
            sort(v.begin(),v.end());
            for(int cnt=0;cnt<n;cnt++)
            {
                if(cnt%2==0)
                  {
                    cout<<v[i];
                    i=i+1;
                  }
                else
                    {
                        cout<<v[j];
                        j=j-1;
                    }
            }
        }

    }


#include <bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
    long t;
    cin>>t;
     while(t--)
     {
        long n;
        cin>>n;
        vector<long> v;
        long q;
        for(int i=0;i<n;i++)
        {
            cin>>q;
            v.push_back(q);
            //cout<<"mithil";
        }

        int j;
        for(int i=0;i<n-1;i++)
          {
            j=i+1;
            while(j>0)
            {
                if(abs(v[j]-v[j+1])<abs(v[j]-v[j-1])&&j!=n-1)
                    swap(v[j-1],v[j+1]);
                 j--;

                }
          }
        for(int x:v)
            cout<<x<<" ";
    }

}


    #include <bits/stdc++.h>
    #include<cmath>
    using namespace std;
    int main()
    {
        long t;
        cin>>t;
         while(t--)
         {
            long n;
            cin>>n;
            vector<long> v;
            long q;
            for(int i=0;i<n;i++)
            {
                cin>>q;
                v.push_back(q);
                //cout<<"mithil";
            }

                int k=n/2-1;

            sort(v.begin(),v.end());

            for(int cnt=0;cnt<n;cnt++)
            {
                if(cnt%2==0)
                  {

                    cout<<v[k+cnt/2]<<' ';

                  }
                else
                    {
                        cout<<v[k-(cnt+1)/2]<<' ';

                    }
            }
        }

    }


#include <bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
    long t;
    cin>>t;
     while(t--)
     {
        long n;
        cin>>n;
        vector<long> v;
        long q;
        for(int i=0;i<n;i++)
        {
            cin>>q;
            v.push_back(q);
            //cout<<"mithil";
        }

        int j,cnt=0;
        bool k=true;

        for(int i=0;i<n-1;i++)
          {
            j=i+1;
            while(j>0)
            {
                if(abs(v[j]-v[j+1])<abs(v[j]-v[j-1])&&j!=n-1)
                    {
                        swap(v[j-1],v[j+1]);
                        k=false;
                    }
                if(k)
                    break;
                 j--;
                cnt++;
            }
          }
          //cout<<"cnt="<<cnt;
        for(int x:v)
            cout<<x<<" ";
    }

}


    #include <bits/stdc++.h>
    #include<cmath>
    using namespace std;
    int main()
    {
        long t;
        cin>>t;
         while(t--)
         {
            long n;
            cin>>n;
            vector<long> v;
            long q;
            for(int i=0;i<n;i++)
            {
                cin>>q;
                v.push_back(q);
                //cout<<"mithil";
            }

                int k=(n-1)/2;

            sort(v.begin(),v.end());

            for(int cnt=0;cnt<n;cnt++)
            {
                if(cnt%2==0)
                  {

                    cout<<v[k-cnt/2]<<' ';

                  }
                else
                    {
                        cout<<v[k+(cnt+1)/2]<<' ';

                    }
            }
        cout<<"\n";
        }

    }


    #include <bits/stdc++.h>
    #include<cmath>
    using namespace std;
    int main()
    {
        long t;
        cin>>t;
         while(t--)
         {
            long n;
            cin>>n;
            vector<long> v;
            long q;
            for(int i=0;i<n;i++)
            {
                cin>>q;
                v.push_back(q);
                //cout<<"mithil";
            }

                int k=n/2-1;

            sort(v.begin(),v.end());

            for(int cnt=0;cnt<n;cnt++)
            {
                if(cnt%2==0)
                  {

                    cout<<v[k+cnt/2]<<' ';

                  }
                else
                    {
                        cout<<v[k-(cnt+1)/2]<<' ';

                    }
            }
        }

    }
/*string s;
    cin>>s;
  //  cout<<s.length();
    int row,col;
    if(sqrt(s.length())-floor(sqrt(s.length()))==0)
       {
        row=sqrt(s.length());
        col=sqrt(s.length());
       }
    else
        {

         row=sqrt(s.length());
            col=sqrt(s.length())+1;
       }

    if(row*col<s.length()&&row!=col)
        row=row+1;
//cout<<row<<col;
    char c[row][col];
    for(int i=0,k=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            if(s[k]!='\0')
                c[i][j]=s[k];
            else
                c[i][j]='\0';
            k++;
        }
    }
    //int a[3][3]={{1,2,3},{4,5,6}};
    for(int i=0;i<col;i++)
    {
        for(int j=0;j<row;j++)
        {
            if(c[j][i]=='\0')
                continue;
            cout<<c[j][i];

        }
        cout<<" ";
    }
*/
/*#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n,m,cnt=0,max=0,cnt2=1;
    cin>>n>>m;
    vector<string> vec;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        vec.push_back(s);
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            cnt=0;
            for(int z=0;z<m;z++)
            {
               if((vec[i][z]-48)||(vec[j][z]-48))
                            cnt++;
            }

            if(cnt>=max)
            {
                if(cnt>max)
                    cnt2=1;

                if(j!=1&&cnt==max)
                {
                    cnt2++;
                    cout<<i<<j<<"cnt2="<<cnt2<<endl;
                }
                max=cnt;

            }
        }

    }
    cout<<max<<"\n"<<cnt2;
}
*/

/*#include <bits/stdc++.h>

using namespace std;

//vector<string> split_string(string);

// Complete the queensAttack function below.
//int queensAttack(int n, int k, int r_q, int c_q, vector<vector<int>> obstacles) {

//}
int min(int a,int b)
{
    return (a<b)?a:b;
}
int main()
{
   long n,k,r_q,c_q;
   cin>>n>>k;
   int r[k],c[k];
   cin>>r_q>>c_q;
   int a1=c_q-1,a2=n-c_q,a3=n-r_q,a4=r_q-1,a5=min(n-r_q,c_q-1),a6=min(n-r_q,n-c_q),a7=min(r_q-1,c_q-1),a8=min(r_q-1,n-c_q);
   ;
   for(int i=0;i<k;i++)
    {
        cin>>r[i]>>c[i];

        if((r[i]==r_q)&&(c_q>c[i])&&abs(c_q-c[i]-1)<=a1)
           {
               a1=abs(c_q-c[i]-1);
              // cout<<"a1="<<a1<<endl;
           }
        else if((r[i]==r_q)&&(c_q<c[i])&&abs(c[i]-c_q-1)<=a2)
           {
               a2=abs(c[i]-c_q-1);
            //   cout<<"a2="<<a2<<endl;
           }
        else if((r[i]>r_q)&&(c[i]==c_q)&&abs(r[i]-r_q-1)<=a3)
            {
                a3=abs(r[i]-r_q-1);
               // cout<<"a3="<<a3<<endl;
            }
        else if((r_q>r[i])&&(c[i]==c_q)&&abs(r_q-r[i]-1)<=a4)
           {
               a4=abs(r_q-r[i]-1);
             //  cout<<"a4="<<a4<<endl;
           }
        else if((r[i]>r_q)&&(c[i]<c_q)&&(abs(r[i]-r_q)==abs(c[i]-c_q))&&abs(r[i]-r_q-1)<=a5)
            {
                a5=abs(r[i]-r_q-1);
             //  cout<<"a5="<<a5<<endl;
            }
        else if((r[i]>r_q)&&(c[i]>c_q)&&(abs(r[i]-r_q)==abs(c[i]-c_q))&&abs(r[i]-r_q-1)<=a6)
            {
                a6=abs(r[i]-r_q-1);
              // cout<<"a6="<<a6<<endl;
            }
        else if((r[i]<r_q)&&(c[i]<c_q)&&(abs(r[i]-r_q)==abs(c[i]-c_q))&&abs(r_q-r[i]-1)<=a7)
            {
                a7=abs(r_q-r[i]-1);
               // cout<<"a7="<<a7<<endl;
            }
        else if((r[i]<r_q)&&(c[i]>c_q)&&(abs(r[i]-r_q)==abs(c[i]-c_q))&&abs(c[i]-c_q-1)<=a8)
           {
               a8=abs(c[i]-c_q-1);
             //  cout<<"a8="<<a8<<endl;
           }
    }
    cout<<a1+a2+a3+a4+a5+a6+a7+a8;
}
*/

/*#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n,t;
    cin>>n;
    vector<int> v;

    for(int i=0;i<n;i++)
    {
        cin>>t;
        v.push_back(t);

    }
    t=*max_element(v.begin(),v.end());
    int a[t+1];
    for(int i=0;i<t+1;i++)
        a[i]=0;
    for(int i=0;i<v.size();i++)
    {
        a[v[i]]++;
    }
    int max=0;
    for(int i=0;i<t+1;i++)
    {
       cout<<"a="<<a[i]<<endl;
        if(a[i]>max)
            max=a[i];
        cout<<"max="<<max<<endl;

    }

    cout<<n-max;

}*/

/*#include <bits/stdc++.h>

using namespace std;
int main()
{
    long n,cnt=0,cnt1=0;
    string s;
    cin>>s;
    cin>>n;
    long k=n/s.length();s
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='a')
            cnt++;
    }
    if(k*s.length()!=n)
        for(int i=0;i<n-k*s.length();i++)
        {
                if(s[i]=='a')
                    cnt1++;

        }
    cout<<k*cnt+cnt1;
}*/
/*#include <bits/stdc++.h>

int minelement(int vect[],int n)
{
    int min=INT_MAX;
    for(int i=0;i<n;i++)
    {
        if(vect[i]<=min&&vect[i]>0)
        {
            min=vect[i];
        }
    }
    return min;
}
using namespace std;
int main()
{
    int n,t;
    cin>>n;
    //int b[n];
    int a[n];
    for(int i=0;i<n;i++)
        {
            cin>>a[i];
            //a.push_back(t);

        }
        int cnt;
    for(int i=0;i<n;i++)
    {
        cnt=0;
        t=minelement(a,n);
        if(t==INT_MAX)
            break;
        //cout<<"t="<<t<<endl;
        for(int j=0;j<n;j++)
        {
            a[j]=a[j]-t;
            if(a[j]>=0)
                cnt++;
          //  cout<<"a="<<a[j]<<endl;

        }

        cout<<cnt<<"\n";
    }
*/
/*#include <bits/stdc++.h>

using namespace std;
bool sqr(int a)
{
    if(a==int(sqrt(a))*int(sqrt(a)))
       {
            return true;
          //  cout<<"TRUE\n";
       }
    else {
        return false;
        //cout<<"FALSE\n";
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        int i=a;
        int cnt=0;
        while(i<=b)
        {
            bool t1=sqr(i);
            if(t1)
            {
                i=i+2*int(sqrt(i))+1;
                cnt++;
            }
            else {
                i++;
            }
         //   cout<<"asdsadd\n";
        }
        cout<<cnt<<"\n";
    }
}*/
/*#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    int k;
    cin>>s;
    cin>>t;
    cin>>k;
    int i=0;
    while(t[i]!='\0')
    {
        if(t[i]!=s[i])
            break;
        i++;
    }
    if(s.size()>=t.size())
    {
        k=k-s.size()-t.size()+2*i;
        if(k>=0)
            cout<<"Yes";
        else
            cout<<"No";

    }
    else
    {
        k=k-i-t.size();
        if(k>=0)
            cout<<"Yes";
        else
            cout<<"No";
    }

}*/
/*#include <bits/stdc++.h>

using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,c,k,cnt=0;
        cin>>n;
        c=n;
        while(c)
        {
            k=c%10;
            c=c/10;
            if(n%k==0)
                if(k!=0)
                    cnt++;
        }
        cout<<cnt<<"\n";
    }
}*/
/*#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
        int c,k;
    for(int i=0;i<n;i++,c++)
    {   c=i+1;
        for(int j=0;j<n;j++)
        {
            if(a[j]==c)
            {
                k=j+1;
                break;
            }
        }
        for(int m=0;m<n;m++)
        {
            if(a[m]==k)
            {
                cout<<m+1<<endl;
                break;
            }
        }

    }
}*/
/*#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n,k,q,t;
    cin>>n>>k>>q;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<k;i++)
    {
        t=a[n-1];
        for(int j=n-1;j>0;j--)
        {
            a[j]=a[j-1];
            cout<<"a:"<<a[j]<<endl;
        }
        a[0]=t;
    }
    for(int i=0;i<n;i++)
        cout<<"a="<<a[i]<<endl;
    int m;
    for(int i=0;i<q;i++)
    {
        cin>>m;
        cout<<a[m]<<"\n";
    }
}*/
/*#include <bits/stdc++.h>
using namespace std;
int main()
{   int t;
    cin>>t;
    while(t--)
    {
        int n,c,s;
        cin>>n>>c>>s;
        int m=c%n;
        cout<<"m="<<m<<endl;
        if(n==m)
            cout<<s-1<<"\n";
        else if(s+m-1<=n)
            cout<<s+m-1<<"\n";
        else
            cout<<(s+m)%n-1<<"\n";
    }

}

/* #include <bits/stdc++.h>
using namespace std;
int reverse(int k)
{352926151 380324688 94730870
556065259 615709967 156417592

    int m=k,cnt=0;
    while(m!=0)
    {
        m=m/10;
        cnt++;
    }
    m=0;
    for(int i=cnt-1;i>=0;i--)
    {
        m=m+pow(10,i)*(k%10);
        k=k/10;
    }
    cout<<"m="<<m<<endl;
    return m;
}
int main()
{
    int i,j,k;
    cin>>i>>j>>k;
    int cnt=0;
    for(int z=i;z<=j;z++)
    {
        cout<<"z="<<z<<endl;
        if(abs(z-reverse(z))%k==0)
            cnt++;
    }
    cout<<cnt;
}*/
/*#include <bits/stdc++.h>
#include<vector>
int binary_search(int n,long a[],int rank[],int low,int high)
{

    int m;
    while(low<=high)
    {
        m=low+(high-low)/2;
        if(a[m]==n)
            break;
        else if(a[m]>n)
            low=m+1;
        else
            high=m-1;
    }
    if(n>a[m])
        m=rank[m];
    else if(n==a[m])
        m=rank[m];
    else
        m=rank[m]+1;

    return m;

}
bool f(int x,int y)
{
    return (x>y)?1:0;
}
using namespace std;
int main()
{
    int n;
    cin>>n;
    long score[n];
    for(int i=0;i<n;i++)
    {
        cin>>score[i];

    }
    int m;
    cin>>m;
    long alice[m];
    int rank[n];
    for(int i=0;i<m;i++)
    {
        cin>>alice[i];

    }
    for(int i=0;i<=n-1;i++)
    {
        if(i==0)
            rank[i]=1;
        if(score[i+1]==score[i])
            rank[i+1]=rank[i];
        else
            rank[i+1]=rank[i]+1;
    }
    int m1;
    vector<int> output;
    for(int i=0;i<m;i++)
    {
        m1=binary_search(alice[i],score,rank,0,n-1);
        output.push_back(m1);
    }

    for(int x:output)
        cout<<x<<"\n";

}*/

/*#include <bits/stdc++.h>
bool f(int x,int y)
{
	return (x>y)?1:0;
}
using namespace std;
int main()
{
    int n,t;
    cin>>n;
    vector<long> s;
    for(int i=0;i<n;i++)
    {
        cin>>t;
        s.push_back(t);
    }
    int m;
    cin>>m;
    vector<long> a;
    vector<int> v;
    vector<int> rank;
    for(int i=0;i<m;i++)
    {
        cin>>t;
        a.push_back(t);
    }
    rank.push_back(1);
    for(int i=1;i<s.size();i++)
    {
    	if(s[i]==s[i-1])
    		rank[i]=rank[i-1];
    	else
    		rank[i]=rank[i-1]+1;
    }
    int index;
    for(int i=0;i<a.size();i++)
    {
    	if(a[i]>=s[0])
    		v.push_back(1);
    	else if(a[i]<s[s.size()-1])
    		v.push_back(rank[s.size()-1]+1);
    	else
    		{
    			index=binary_search(a[i],s);
    			v.push_back(rank[index]);
    		}
    }
    for(int x:v)
    	cout<<x<<endl;
}*/
/*#include <bits/stdc++.h>
bool f(int x,int y)
{
	return (x>y)?1:0;
}
using namespace std;
int main()
{
    int n,t;
    cin>>n;
    vector<long> s;
    for(int i=0;i<n;i++)
    {
        cin>>t;
        s.push_back(t);
    }
    int m,cnt=1,k=1,j;
    cin>>m;
    vector<long> a;
    vector<int> v;
    for(int i=0;i<m;i++)
    {
        cin>>t;
        a.push_back(t);
    }
    for(int i=0;i<a.size();i++)
    {
    	//s.push_back(a[i]);
    	//sort(s.begin(),s.end(),f);
    	cnt=1;
    	for(j=0;j<s.size();j++)
    	{
    		//cout<<"j="<<j<<endl;
    		//cout<<"score="<<s[j]<<endl;
    		if(s[j]!=s[j-1]&&j!=0)
    			cnt=cnt+1;

    		if(a[i]>s[j])
    			{
 	   				if(a[i]==s[j-1])
 	   					cnt=cnt-1;
 	   				v.push_back(cnt);
    				k=2;
    				break;

    			}

    	//cout<<"rank"<<cnt<<endl;
    	}
    	if(k==1&&j==s.size())
    	{
    		if(a[i]==s[s.size()-1])
    			v.push_back(cnt);
    		else
    			v.push_back(cnt+1);
    	}
    	//s.erase(s.begin()+k);
    	/*for(int x:s)
    		cout<<"S="<<x<<endl;

    }

}
/*#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,t;
    cin>>n;
	int v[n];
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    //sort(v.begin(),v.end());
    int a[100];
    for (int i = 0; i < 100; ++i)
    {
    	a[i]=0;
    }
    for(int i=0;i<n;i++)
    {
        a[v[i]]=a[v[i]]+1;
        cout<<"a="<<v[i]-1<<"="<<a[v[i]-1]<<"\n";
    }
    int max=0,c;
    for(int i=0;i<100-1;i++)
    {
        c=a[i]+a[i+1];
        cout<<"c="<<c<<endl;
        if(c>max)
            max=c;
    }
    cout<<max;
}/**/
/*#include <bits/stdc++.h>

using namespace std;
int main()
{

    int a[3][3],min=1233,c=0;
    int b[8][3][3]={
            {8, 1, 6, 3, 5, 7, 4, 9, 2},
            {6, 1, 8, 7, 5, 3, 2, 9, 4},
            {4, 9, 2, 3, 5, 7, 8, 1, 6},
            {2, 9, 4, 7, 5, 3, 6, 1, 8},
            {8, 3, 4, 1, 5, 9, 6, 7, 2},
            {4, 3, 8, 9, 5, 1, 2, 7, 6},
            {6, 7, 2, 1, 5, 9, 8, 3, 4},
            {2, 7, 6, 9, 5, 1, 4, 3, 8},
            };
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>a[i][j];

        }

    }
    for(int k=0;k<8;k++)
    {   c=0;
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<3;j++)
            {
                c=c+abs(a[i][j]-b[k][i][j]);
	//			cout<<"a[i][j]="<<a[i][j]<<"b[k][i][j]="<<b[k][i][j]<<endl;
				//cout<<abs(a[i][j]-b[k][i][j]);
            }
        }
//cout<<"c="<<c<<endl;
        if(min>c)
        {
            min=c;
}
        }
    }
    cout<<min;

*/
/*#include <bits/stdc++.h>

using namespace std;
int main()
{

    int a[3][3];
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>a[i][j];
        }

    }

    vector<int> v1;
    vector<int> v2;
    for(int i=0;i<v.size();i++)
    {
        if(v[i]==0){
            v1.push_back(i+1);
            cout<<"v1="<<i+1<<endl;
        }
        else if (v[i]>1) {
            v2.push_back(i+1);
            cout<<"v2="<<i+1<<endl;
        }

    }
    int min=100,c=0,k=0;
    for(int i=0;i<v1.size();i++)
    {
        for(int j=0;j<v2.size();j++)
        {
            if(abs(v1[i]-v2[j])<=min){
                min=abs(v1[i]-v2[j]);
                cout<<"min="<<min<<endl;
                k=j;
            }
        }
        c=c+min;
        v2.erase(v2.begin()+k);
        min=100;
    }
    cout<<c;
}*/
/*#include <bits/stdc++.h>
bool f(int x,int y)
{
        return (x>y)?1:0;
}
using namespace std;
int main()
{
    long b,n,m;
    cin>>b>>n>>m;
    vector<long> v1;
    vector<long> v2;
    long t;
    for(int i=0;i<n;i++)
    {
        cin>>t;
        v1.push_back(t);
    }
    for(int i=0;i<m;i++)
    {
        cin>>t;
        v2.push_back(t);
    }
    sort(v1.begin(),v1.end(),f);
    sort(v2.begin(),v2.end());
    int max=-1;
    for(int i=0,j=0;i<v1.size();i++)
    {
        for(;j<v2.size();j++)
        {

        	if(v1[i]+v2[j]>b)
        		break;
            if(v1[i]+v2[j]<=b && v1[i]+v2[j]>max)
               {
               	 max=v1[i]+v2[j];
               }
        }
    }
    cout<<max;

}*/

/*#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
  //  getline(cin,s);
    cin>>s;
    int level=0,cnt=0;
    bool c=true;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='U')
        {
            c=true;
            level++;
        }
        else if(s[i]=='D')
        {
            c=false;
            level--;
        }
        if(level==0 && c && i!=0)
            cnt++;
    }
    cout<<cnt;
}
*/
/*#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n,t;
    cin>>n;
    vector<int> v;
    for(int i=0;i<n;i++)
    {
        cin>>t;
        v.push_back(t);
    }
    sort(v.begin(),v.end());
    int s=v[0],cnt=1,c=0;
    for(int i=1;i<v.size();i++)
    {
        if(v[i]==s)
        {
            cnt++;
            cout<<"cnt="<<cnt<<endl;
            s=v[i];
        }
        else
        {
            c=c+cnt/2;
            cout<<"c"<<c<<endl;
           	s=v[i];
            cnt=1;
        }
    }
    cout<<c;
}*/
/*#include <bits/stdc++.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n,t,max=0;
    vector<int> v;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>t;
        v.push_back(t);
    }
    vector<long int>a(5,0);
    for(int i=0;i<n;i++)
    {
        a[v[i]-1]++;
        //cout<<"type="<<v[i]-1<<a[v[i]-1]<<endl;
    }
    for(int i=0;i<5;i++)
    {
        cout<<"a="<<a[i]<<endl;
        if(max<a[i])
        {
            max=i+1;
      //      cout<<"Max="<<max<<endl;
        }
    }
    cout<<max<<"\n";
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	for (int j = 0; j < t; ++j)
	    {
	      		string s;
	      		cin>>s;
	      		int c;
	      		int i = 0;
	      		int k=0;
	         	bool t1=true;
	         	while(i != s.length())
	         	{
	         		c=(s[i]-48);
	         		for(int j=i+1;j<s.length();j++)
	         		{

	         			c=c+(s[j]-48);
	         			//cout<<"C="<<c<<endl;
	         			if(c==10)
	         				{
	         					k=j;
	         				//	cout<<"K="<<k<<endl;
	         					break;
	         				}

	         			if(c>10)
	         				break;
	         		}
	         		if(k<i)
	         		{

	         			cout<<"Not 10-substring friendly\n";
	         			t1=false;
	         			break;
	         		}
	         		i++;
	         	}
	         			if(t1)
	         			{
			         		if(k+1==s.length())
			         			cout<<"It is 10-substring friendly\n";
			         		else
			         			cout<<"Not 10-substring friendly\n";
						}
		}
}

#include <iostream>
#include <climits>
using namespace std;
int main()
{
    int n,m,c=INT_MAX,v=INT_MAX;
    cin>>n>>m;
    int a[n],b[m];
    int k,n1=0;
    int c1[100];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<v)
            v=a[i];
    }
    for(int i=0;i<m;i++)
    {
        cin>>b[i];
        if(b[i]<c)
            c=b[i];
    }
    for (int i = v; i <=c ; ++i)
    {	k=0;
    	for (int j = 0; j < n; ++j)
    	{
    		if (i%a[j]==0)
    			k++;

    	}
    	if(k==n)
    	{
    		c1[n1++]=i;

    	}
    }
    int l=0;
    for (int i = 0; i < n1; ++i)
    {
    	k=0;
    	for(int j=0;j<m;j++)
    	{
    		if(b[j]%c1[i]==0)
    			k++;
    	}
    	if(k==m)
    		l++;
    }
    cout<<l;
    return 0;

}
/*#include<iostream>
using namespace std;
void conv(int n){
	if(n<=0)
		printf("%d",n);
	else
		{conv(n/2);
			printf("@%d@", n%2);}
}
int main()
{
	//conv(4);
	float sum=0.0,i=2.0,j=1.0;
	int cnt=0;
	while(i/j>0.0625)
	{
		j=2*j;
		cnt++;
	}
	cout<<cnt;
	int a[]={2,4,6,8,10};
	int *b=a+4,s=0;
	for (int i = 0; i < 5; ++i)
	{
		s=s+*b-i-*(b-i);
		cout<<s;
	}
	cout<<s;
	return 0;
}
*/