Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.

Lala Land has exactly n apple trees. Tree number i is located in a position xi and has ai apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in x = 0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.

What is the maximum number of apples he can collect?

Input

The first line contains one number n (1 ≤ n ≤ 100), the number of apple trees in Lala Land.

The following n lines contains two integers each xi, ai ( - 105 ≤ xi ≤ 105, xi ≠ 0, 1 ≤ ai ≤ 105), representing the position of the i-th tree and number of apples on it.

It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.

Output

Output the maximum number of apples Amr can collect.

Examples

Input

2
-1 5
1 5


Output

10

Input

3
-2 2
1 4
-1 3


Output

9

Input

3
1 9
3 5
7 10


Output

9

Note

In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.

In the second sample test the optimal solution is to go left to x = - 1, collect apples from there, then the direction will be reversed, Amr has to go to x = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree x = - 2.

In the third sample test the optimal solution is to go right to x = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left.
import javafx.util.Pair;

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

public class Main {
    private final static InputReader ir = new InputReader(System.in);
    private final static OutputWriter ow = new OutputWriter(System.out);
    private final static int INF = Integer.MAX_VALUE;
    private final static int NINF = Integer.MIN_VALUE;
    private final static double PI = Math.PI;

    public static void main(String[] args) throws IOException {
        try {
            task();
        } finally {
            boolean exc = false;
            try {
                ir.close();
            } catch (IOException e) {
                e.printStackTrace();
                exc = true;
            }
            try {
                ow.close();
            } catch (IOException e) {
                e.printStackTrace();
                exc = true;
            }
            if (exc) System.exit(1);
        }
    }

    private static void task() throws IOException {
        int n = ir.nextInt();
        ArrayList<Pair<Integer, Integer>> pos = new ArrayList<>();
        ArrayList<Pair<Integer, Integer>> neg = new ArrayList<>();
        for (int i = 0; i < n; ++i) {
            int p = ir.nextInt();
            if (p > 0)
                pos.add(new Pair<>(p, ir.nextInt()));
            else neg.add(new Pair<>(p, ir.nextInt()));
        }
        neg.sort((p1, p2) -> p2.getKey().compareTo(p1.getKey()));
        pos.sort(Comparator.comparing(Pair::getKey));
        int ans = 0;
        for (int i = 0; i < min(neg.size(), pos.size()); ++i) {
            ans += neg.get(i).getValue() + pos.get(i).getValue();
        }

        if (neg.size() > pos.size())
            ans += neg.get(min(neg.size(), pos.size())).getValue();
        else if (pos.size() > neg.size())
            ans += pos.get(min(neg.size(), pos.size())).getValue();
        ow.print(ans);
    }

    private static int max(int... objects) {
        if (objects.length == 0)
            throw new IllegalArgumentException("objects.length == 0");
        int max = objects[0];
        for (int i = 1; i < objects.length; ++i) {
            if (max < objects[i])
                max = objects[i];
        }
        return max;
    }

    private static int min(int... objects) {
        if (objects.length == 0)
            throw new IllegalArgumentException("objects.length == 0");
        int min = objects[0];
        for (int i = 1; i < objects.length; ++i) {
            if (min > objects[i])
                min = objects[i];
        }
        return min;
    }

    private static long pow(int x, int n) {
        if (x == 0) return 0;
        if (x == 1 || n == 0) return 1;
        if (x == 2) return x << (n - 1);
        if (n == 1) return x;
        long t = pow(x, n / 2);
        if (n % 2 == 0) return t * t;
        else return t * t * x;
    }

    private static double pow(double x, int n) {
        if (x == 0.0) return 0;
        if (x == 1.0 || n == 0) return 1;
        if (n == 1) return x;
        double t = pow(x, n / 2);
        if (n % 2 == 0) return t * t;
        else return t * t * x;
    }

    private static int abs(int a) {
        return (a >= 0 ? a : -a);
    }
}

class InputReader implements AutoCloseable {
    private final InputStream in;
    private int capacity;
    private byte[] buffer;
    private int len = 0;
    private int cur = 0;

    public InputReader(InputStream stream) {
        this(stream, 100_000);
    }

    public InputReader(InputStream stream, int capacity) {
        this.in = stream;
        this.capacity = capacity;
        buffer = new byte[capacity];
    }

    private boolean update() {
        if (cur >= len) {
            try {
                cur = 0;
                len = in.read(buffer, 0, capacity);
                if (len <= 0)
                    return false;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }
        return true;
    }

    private int read() {
        if (update())
            return buffer[cur++];
        else return -1;
    }

    public boolean isEmpty() {
        return !update();
    }

    private boolean isSpace(int c) {
        return c == '\n' || c == '\t' || c == '\r' || c == ' ';
    }

    private boolean isEscape(int c) {
        return c == '\n' || c == '\t' || c == '\r' || c == -1;
    }

    private int readSkipSpace() {
        int c;
        do {
            c = read();
        } while (isSpace(c));
        return c;
    }

    public int nextInt() {
        int c = readSkipSpace();
        if (c < 0)
            throw new InputMismatchException();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c == -1) break;
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res = res * 10 + c - '0';
            if (res < 0)
                throw new InputMismatchException();
            c = read();
        } while (!isSpace(c));
        res *= sgn;
        return res;
    }

    public int[] getAllInts() {
        List<Integer> list = new LinkedList<>();
        while (true) {
            try {
                int t = nextInt();
                list.add(t);
            } catch (InputMismatchException e) {
                break;
            }
        }
        int[] a = new int[list.size()];
        Iterator<Integer> it = list.iterator();
        for (int i = 0; it.hasNext(); ++i)
            a[i] = it.next();
        return a;
    }

    public int[] getIntArray1D(int n) {
        int[] array = new int[n];
        for (int i = 0; i < n; ++i) {
            array[i] = nextInt();
        }
        return array;
    }

    public int[][] getIntArray2D(int n, int m) {
        int[][] array = new int[n][m];
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j)
                array[i][j] = nextInt();
        }
        return array;
    }

    public long nextLong() {
        int c = readSkipSpace();
        if (c < 0)
            throw new InputMismatchException();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c == -1) break;
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res = res * 10 + c - '0';
            if (res < 0)
                throw new InputMismatchException();
            c = read();
        } while (!isSpace(c));
        res *= sgn;
        return res;
    }

    public long[] getAllLongs() {
        List<Long> list = new LinkedList<>();
        while (true) {
            try {
                long t = nextLong();
                list.add(t);
            } catch (InputMismatchException e) {
                break;
            }
        }
        long[] a = new long[list.size()];
        Iterator<Long> it = list.iterator();
        for (int i = 0; it.hasNext(); ++i)
            a[i] = it.next();
        return a;
    }

    public long[] getLongArray1D(int n) {
        long[] array = new long[n];
        for (int i = 0; i < n; ++i) {
            array[i] = nextLong();
        }
        return array;
    }

    public long[][] getLongArray2D(int n, int m) {
        long[][] array = new long[n][m];
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j)
                array[i][j] = nextLong();
        }
        return array;
    }

    public int nextChar() {
        int c = readSkipSpace();
        if (c < 0)
            throw new InputMismatchException();
        return c;
    }

    public String nextLine(int initialCapacity) {
        StringBuilder res = new StringBuilder(initialCapacity);
        int c = readSkipSpace();
        do {
            res.append((char) (c));
            c = read();
        } while (!isEscape(c));
        return res.toString();
    }

    @Override
    public void close() throws IOException {
        in.close();
    }
}

class OutputWriter implements Flushable, AutoCloseable {
    private byte[] buf;
    private final int capacity;
    private int count;
    private OutputStream out;

    public OutputWriter(OutputStream stream) {
        this(stream, 10_000);
    }

    public OutputWriter(OutputStream stream, int capacity) {
        if (capacity < 0)
            throw new IllegalArgumentException("capacity < 0");
        out = stream;
        this.capacity = capacity;
        if (capacity != 0) {
            buf = new byte[capacity];
        }
    }

    public void write(int b) throws IOException {
        if (capacity != 0) {
            if (count >= capacity)
                flushBuffer();
            buf[count++] = (byte) b;
        } else {
            out.write(b);
        }
    }

    public void write(byte[] bytes, int off, int len) throws IOException {
        if (capacity != 0) {
            if (len >= capacity) {
                flushBuffer();
                out.write(bytes, off, len);
                return;
            }
            if (len > capacity - count)
                flushBuffer();
            System.arraycopy(bytes, off, buf, count, len);
            count += len;
        } else out.write(bytes, off, len);
    }

    public void write(byte[] bytes) throws IOException {
        write(bytes, 0, bytes.length);
    }

    public void println() throws IOException {
        print("\n");
    }

    public void print(Object object) throws IOException {
        write(String.valueOf(object).getBytes());
    }

    public void println(Object object) throws IOException {
        print(object);
        println();
    }

    public void print(int... ints) throws IOException {
        print(" ", ints);
    }

    public void println(int... ints) throws IOException {
        print(ints);
        println();
    }

    public void println(String separator, int... ints) throws IOException {
        print(separator, ints);
        println();
    }

    public void print(String separator, int... ints) throws IOException {
        if (ints.length == 0) throw new IllegalArgumentException("ints.length == 0");
        for (int i = 0; i < ints.length; ++i) {
            if (i != 0) print(separator);
            print(ints[i]);
        }
    }

    private void flushBuffer() throws IOException {
        if (count > 0) {
            out.write(buf, 0, count);
            count = 0;
        }
    }

    @Override
    public void flush() throws IOException {
        flushBuffer();
        out.flush();
    }

    @Override
    public void close() throws IOException {
        flush();
        out.close();
    }
}

