def pow2(x): cnt = 0 while x%2==0: cnt += 1 x //= 2 return cnt N = int(input()) C = {0:0,1:0,2:0,3:0} for _ in range(N): a,b = map(int,input().split()) n = pow2(a) if n>=3: C[3] += b else: C[n] += b ans = C[3] m = min(C[1],C[2]) ans += m C[1] -= m C[2] -= m ans += C[1]//3+C[2]//2 print(ans)