import java.io.*; import java.math.BigInteger; import java.util.*; import java.util.StringTokenizer; import java.util.function.ToIntBiFunction; public class Main2 { // Mark's Solution public static void main(String[] args) throws IOException { FastReader fr = new FastReader(); TreeMap cnts = new TreeMap<>(); PriorityQueue duos = new PriorityQueue<>(Comparator.comparingDouble(Duo::a).reversed()); int N = fr.nextInt(); long summ = 0; double score = 0; for (int i = 0; i < N; ++i) { long pos = fr.nextLong(), wei = fr.nextLong(); summ += pos * wei; cnts.put(pos, new Duo(pos, wei, 1L)); duos.add(new Duo(pos, wei, 1)); } boolean goingDown = summ >= 0; summ = Math.abs(summ); while (summ != 0) { Duo duo = duos.poll(); if (!cnts.containsKey(duo.pos) || cnts.get(duo.pos).cnt != duo.cnt) continue; cnts.remove(duo.pos); Long target = goingDown ? cnts.lowerKey(duo.pos) : cnts.higherKey(duo.pos); double diff = (double) summ / duo.weight; if (target != null && Math.abs(duo.pos - target) < diff) { summ -= Math.abs(duo.pos - target) * duo.weight; score += Math.abs(duo.pos - target) * duo.cnt; Duo newDuo = new Duo(target, cnts.get(target).weight + duo.weight, cnts.get(target).cnt + duo.cnt); cnts.put(target, newDuo); duos.add(newDuo); continue; } score += diff * duo.cnt; break; } System.out.println(score); } static class Duo { long pos; long weight; long cnt; public Duo (long p, long w, long c) { this.pos = p; this.weight = w; this.cnt = c; } public double a() {return (double) weight / cnt;} } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); //br = new BufferedReader(new FileReader("D:\\Coding\\ICPC\\pp-naq20251011\\Problems\\seesaw\\data\\secret\\max_1.in")); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } st = null; return str; } } }