from collections import Counter def count_f2(n: int) -> int: cnt = 0 x = n while x > 0 and x % 2 == 0: cnt += 1 x //= 2 return cnt N = int(input()) freq = Counter() ans = 0 for _ in range(N): A, B = map(int, input().split()) match count_f2(A): case 1: freq[1] += B case 2: freq[2] += B case x if x > 2: ans += B x = min(freq[1], freq[2]) ans += x ans += (freq[1] - x) // 3 ans += (freq[2] - x) // 2 print(ans)