#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; long long one = 0,two = 0,three = 0; while(N--){ int a,b; cin >> a >> b; int c = 0; while(a%2 == 0) a /= 2,c++; c = min(c,3); if(c == 1) one += b; if(c == 2) two += b; if(c == 3) three += b; } long long answer = three; long long v = min(one,two); answer += v; one -= v,two -= v; answer += one/3; answer += two/2; cout << answer << endl; }