Problem:
貴金属リサイクル
会津特産の貴金属であるアイヅニウムをリサイクルするＰＣＫ社は、全国各地にネットワークを持ち、たくさんの回収車でアイヅニウムを集めてきます。この会社は、処理の効率化のために、塊の重さと個数の単位を規格で定めています。
塊の重さには「ボッコ」という単位を使います。
x
ボッコのアイヅニウムの重さは 2
x
グラムです。宝石で例えると、「カラット」のようなものです。また、塊の個数には「マルグ」という単位を使います。
y
マルグは 2
y
個です。１箱に入っている品物の個数である「ダース」のようなものです。ただし、
x
と
y
は ０ 以上の整数でなければいけません。
回収車
i
は、
a
i
ボッコの重さのアイヅニウムを
b
i
マルグずつ集めます。こうして集まったアイヅニウムを、炉の中に入れて溶かし、いくつかのアイヅニウムの塊を再生しますが、なるべくアイヅニウムの塊の数が少なくなるようにします。このとき、集めてきたアイヅニウムの重さの合計と、再生してできるアイヅニウムの重さの合計は変わりません。
回収車が集めたアイヅニウムの塊のボッコ単位の重さとマルグ単位の個数が与えられたとき、再生後のアイヅニウムの塊の数が最小になるような結果を求めるプログラムを作成せよ。
Input
入力は以下の形式で与えられる。
N
a
1
b
1
a
2
b
2
:
a
N
b
N
１行目に、回収車の数
N
(1 ≤
N
≤ 100000) が与えられる。続く
N
行に、回収車
i
が回収したアイヅニウムの塊の、「ボッコ」単位の重さを表す整数
a
i
(0 ≤
a
i
≤ 100000) と「マルグ」単位の個数を表す整数
b
i
(0 ≤
b
i
≤ 100000) が与えられる。
Output
再生した後に得られるアイヅニウムの塊の数が最小になるような、ボッコ単位の重さとマルグ単位の個数を、重さの小さい順に出力する。
Sample Input 1
3
2 1
1 3
2 2
Sample Output 1
3 0
5 0
Sample Input 2
1
100000 2
Sample Output 2
100002 0

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	int n; cin >> n;
	vi cnt(333333);
	REP(i, n)
	{
		int a, b; cin >> a >> b;
		cnt[a + b]++;
	}
	REP(i, 333333)
	{
		cnt[i + 1] += cnt[i] / 2;
		cnt[i] %= 2;
	}
	REP(i, 333333)
	{
		if (cnt[i] == 1) cout << i << " " << 0 << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 4432
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;

// #include<atcoder/all>
// using namespace atcoder;
// using mint=atcoder::modint998244353;

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define int long long

int dp[300009];

signed main(){
	int n;cin>>n;

	while(n--){
		int a,b;cin>>a>>b;
		dp[a+b]+=1;
	}

	for(int i=0;i<300000;i++){
		if(dp[i]>=2){
			dp[i+1]+=dp[i]/2;
			dp[i]%=2;
		}
	}

	for(int i=0;i<300000;i++){
		if(dp[i]){
			cout<<i<<" "<<0<<endl;
		}
	}
}
accuracy: 1
time_ms: 70
memory_kb: 4888
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;

// #include<atcoder/all>
// using namespace atcoder;
// using mint=atcoder::modint998244353;

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define int long long

int dp[200009];

signed main(){
	int n;cin>>n;

	while(n--){
		int a,b;cin>>a>>b;
		dp[a+b]+=1;
	}

	for(int i=0;i<200000;i++){
		if(dp[i]>=2){
			dp[i+1]+=dp[i]/2;
			dp[i]%=2;
		}
	}

	for(int i=0;i<200000;i++){
		if(dp[i]){
			cout<<i<<" "<<0<<endl;
		}
	}
}
accuracy: 0.9583333333333334
time_ms: 70
memory_kb: 4724
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;

// #include<atcoder/all>
// using namespace atcoder;
// using mint=atcoder::modint998244353;

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define int long long

int dp[150009];

signed main(){
	int n;cin>>n;

	while(n--){
		int a,b;cin>>a>>b;
		dp[a+b]+=1;
	}

	for(int i=0;i<150000;i++){
		if(dp[i]>=2){
			dp[i+1]+=dp[i]/2;
			dp[i]%=2;
		}
	}

	for(int i=0;i<150000;i++){
		if(dp[i]){
			cout<<i<<" "<<0<<endl;
		}
	}
}
accuracy: 0.875
time_ms: 20
memory_kb: 3484
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    vector<int> s(n);
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        s[i] = a[i] + b[i];
    }
    for (int i = 0; i < n; i++) {
        if (mp[s[i]] > 0) {
            mp[s[i]]--;
            mp[s[i] + 1]++;
            int me = s[i] + 1;
            while (mp[me] >= 2) {
                mp[me] -= 2;
                mp[me + 1]++;
                me++;
            }
        } else {
            mp[s[i]]++;
        }
    }
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        if (itr->second > 0) {
            cout << itr->first << " " << 0 << "\n";
        }
    }
    return(0);
}
accuracy: 1
time_ms: 60
memory_kb: 8272
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    vector<int> s(n);
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        s[i] = a[i] + b[i];
    }
    sort(s.begin(), s.end());
    for (int i = 0; i < n; i++) {
        if (mp[s[i]] > 0) {
            mp[s[i]]--;
            mp[s[i] + 1]++;
            int me = s[i] + 1;
            while (mp[me] >= 2) {
                mp[me] -= 2;
                mp[me + 1]++;
                me++;
            }
        } else {
            mp[s[i]]++;
        }
    }
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        if (itr->second > 0) {
            cout << itr->first << " " << 0 << "\n";
        }
    }
    return(0);
}
accuracy: 1
time_ms: 60
memory_kb: 8080
final_rank: 17

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template <typename T>
T POP(queue<T> &que) {
  T a = que.front();
  que.pop();
  return a;
}
template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
f128 binary_search_real(F check, f128 ok, f128 ng, ll iter = 100) {
  rep(iter) {
    f128 x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vc<T> cumsum(vc<U> &A, ll off = 1) {
  ll N = A.size();
  vc<T> B(N + 1);
  rep(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vi argsort(const vector<T> &A) {
  vi ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  cout << (x);
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}
template <typename T>
void wt_integer128(T x) {
  char buf[64];
  char *d = end(buf);
  d--; *d = '\0';
  __uint128_t tmp = ((x < 0)? -x : x);
  do {
    d--; *d = char(tmp%10 + '0'); tmp /= 10;
  } while (tmp);
  if (x < 0) {
    d--; *d = '-';
  }
  cout << d;
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer128(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer128(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll N, a, b;
  cin >> N;
  map<ll, ll> cnt;
  rep(N) {
    cin >> a >> b;
    cnt[a+b]++;
  }
  pqg<pi> pq;
  for (auto [k, v] : cnt) {
    pq.emplace(mp(k, v));
  }
  vc<pi> ans;
  while (!pq.empty()) {
    auto [k, v] = POP(pq);
    if (v >= 2) {
      if (!pq.empty() and (pq.top().fi == k+1)) {
        auto [k2, v2] = POP(pq);
        pq.emplace(mp(k+1, v2+v/2));
      } else {
        pq.emplace(mp(k+1, v/2));
      }
      v %= 2;
    }
    if (v == 1) ans.eb(mp(k, 0));
  }
  rep(i, len(ans)) print(ans[i]);
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10744
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int a[250000];
    for(int i=0;i<250000;i+=1){
        a[i]=0;
    }
    int b;
    cin>>b;
    for(int i=0;i<b;i+=1){
        int c,d;
        cin>>c>>d;
        a[c+d]+=1;
    }
    for(int i=0;i<249999;i+=1){
        a[i+1]+=a[i]/2;
        a[i]%=2;
    }
    for(int i=0;i<250000;i+=1){
        if(a[i]!=0){
            cout<<i<<" "<<0<<endl;
        }
    }
}
accuracy: 1
time_ms: 70
memory_kb: 4388
final_rank: 8

code_snippet: #include <iostream>
using namespace std;

int main() {
    int N, sum[200017] = {};
    cin >> N;
    for (int a, b, i = 0; i < N; i++) {
        cin >> a >> b; 
        sum[a+b]++;
    }

    for (int i = 0; i < 200016; i++) {
        sum[i+1] += sum[i] / 2;
        sum[i] %= 2;
    }

    for (int i = 0; i < 200017; i++) {
        if (sum[i]) {
            cout << i << " " << 0 << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 4196
final_rank: 7

code_snippet: #include"bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef vector<vbool> vvbool;
typedef vector<vpllint> vvpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)
#define mod9 998244353
#define Inf 2147483647
#define llInf 9223372036854775807
#define all(x) x.begin(),x.end()
#define isin(i,n) (0<=i&&i<n)

int main() {
	int n;
	cin >> n;
	priority_queue<int>que;
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		que.push(-a - b);
	}
	while (que.size()) {
		auto p = que.top(); que.pop();
		if (que.size() && p == que.top()) {
			que.pop(); que.push(p - 1);
		}
		else {
			cout << -p << " " << 0 << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 3740
final_rank: 10

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0328.cc: 貴金属リサイクル
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

/* typedef */

typedef vector<int> vi;

/* global variables */

/* subroutines */

/* main */

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  int n;
  scanf("%d", &n);

  vi ds;
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    int x = a + b;
    if (ds.size() <= x) ds.resize(x + 1);
    ds[x]++;
  }

  for (int i = 0, co = 0; i < ds.size() || co > 0; i++) {
    if (i == ds.size()) ds.push_back(0);
    int di = co + ds[i];
    ds[i] = di & 1;
    co = di >> 1;
  }

  for (int x = 0; x < ds.size(); x++)
    if (ds[x] > 0) printf("%d 0\n", x);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4056
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<ll> cnt(200020);
    for(int i = 0, a, b; i < n; i++){
        cin >> a >> b;
        cnt[a + b]++;
    }
    for(int i = 0; i + 1 < 200020; i++){
        cnt[i + 1] += cnt[i] / 2;
        if(cnt[i] & 1){
            cout << i << " " << 0 << '\n';
        }
    }
}
accuracy: 1
time_ms: 30
memory_kb: 4656
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

// {{{ Templates

// clang-format off

// Macros
#define over_load_(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) over_load_(__VA_ARGS__, rep4, rep3, rep2)(__VA_ARGS__)
#define rep2(i, r) for ( int i = 0; i < static_cast<int>(r); (i) += 1)
#define rep3(i, l, r) for ( int i = static_cast<int>(l); i < static_cast<int>(r); (i) += 1)
#define rep4(i, l, r, stride) for ( int i = static_cast<int>(l); i < static_cast<int>(r); (i) += (stride))
#define rrep(...) over_load_(__VA_ARGS__, rrep4, rrep3, rrep2)(__VA_ARGS__)
#define rrep2(i, r) for ( int i = static_cast<int>(r) - 1; i >= 0; (i) -= 1)
#define rrep3(i, l, r) for ( int i = static_cast<int>(r) - 1; i >= static_cast<int>(l); (i) -= 1)
#define rrep4(i, l, r, stride) for ( int i = static_cast<int>(r) - 1; i >= static_cast<int>(l); (i) -= (stride))
#define len(x) (static_cast<int>((x).size()))
#define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)
#define debug(...) debug_function(#__VA_ARGS__, __VA_ARGS__)

// Operators
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &v) { bool is_first = true; for (auto x: v) { os << (is_first ? "" : " ") << x; is_first = false; } return os; }
template <typename T> ostream &operator<<(ostream &os, queue<T> v) { bool is_first = true; while (!v.empty()) { os << (is_first?"":" ")<<v.front(); v.pop(); is_first = false; } return os; }
template <typename T> ostream &operator<<(ostream &os, stack<T> v) { bool is_first = true; while (!v.empty()) { os << (is_first?"":" ") << v.top(); v.pop(); is_first=false; } return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { rep (i, len(v)) os << v[i] << (i == len(v) - 1 ? "" : " "); return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { for (const auto &vec: v) { os << vec << '\n'; } return os; }
template <typename T> ostream &operator<<(ostream &os, const deque<T> &v) { rep (i, len(v)) os << v[i] << (i == len(v) - 1 ? "" : " "); return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { bool is_first = true; for (T x: v) { os << (is_first ? "" : " ") << x; is_first = false; } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in: v) { is >> in; } return is; }

// For debug macro
int find_comma_not_bracketed(string_view s){ stack<char> bs; string lbs = "({[", rbs = ")}]"; for (size_t i = 0; i < s.size(); i++) { if (lbs.find(s[i]) != string::npos) bs.push(s[i]); if (rbs.find(s[i]) != string::npos and !bs.empty()) bs.pop(); if (s[i] == ',' and bs.empty()) return i; } return s.size(); }
template <typename T, typename... Ts> void debug_function(string_view name, const T &a, Ts &&...rest) { int end = find_comma_not_bracketed(name); cerr << name.substr(0, end) << ":" << a; if constexpr (sizeof...(rest) == 0) { cerr << '\n'; } else { cerr << ' '; debug_function(name.substr(name.find_first_not_of(' ', end + 1)), forward<Ts>(rest)...); } }

// Functions
template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b and (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b and (a = b, true); }

// Structs
struct IoSetup { IoSetup(int x = 15) { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

// Type aliases
using ull = unsigned long long;
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;

// Literals
constexpr ll INF64 = INT64_MAX / 2;
constexpr int INF32 = INT32_MAX / 2;
constexpr int dy[] = { 0, 1, -1, 0, -1, 1, -1, 1 };
constexpr int dx[] = { 1, 0, 0, -1, -1, -1, 1, 1 };
constexpr int mod998244353 = 998244353;
constexpr int mod1000000007 = static_cast<int>(1e9) + 7;
constexpr char newl = '\n';

// clang-format on

// }}} Templates



int main() {
  int n;
  cin >> n;

  map<int, int> cnt;
  rep(i, n) {
    int a, b;
    cin >> a >> b;

    cnt[a + b]++;
  }

  for (auto &[val, count]: cnt) {
    int carry = count / 2;
    count %= 2;

    if (carry > 0)
      cnt[val + 1] += carry;
    // debug(val, count);
  }

  for (auto [val, count]: cnt) {
    if (count == 0)
      continue;

    cout << val << ' ' << 0 << newl;
  }
}
accuracy: 1
time_ms: 30
memory_kb: 7580
final_rank: 6

code_snippet: #pragma region my_template
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using ti = tuple<int, int, int>;
using tl = tuple<ll, ll, ll>;
using vi = vector<int>;
using vpi = vector<pi>;
using vti = vector<ti>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vpl = vector<pl>;
using vtl = vector<tl>;
using vvl = vector<vl>;

#define range(i, l, r) for(int i = (int)(l); i < (int)(r); i++)
#define rrange(i, l, r) for(int i = (int)(r)-1; i >= (int)(l); i--)
#define rep(i, n) range(i, 0, n)
#define rrep(i, n) rrange(i, 0, n)
#define len(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define elif else if

namespace io {
    template<typename T>
    istream &operator >> (istream &in, vector<T> &a){
        for(T &x: a) in >> x;
        return in;
    }
    template<typename T, typename U>
    istream &operator >> (istream &in, pair<T, U> &a){
        in >> a.first >> a.second;
        return in;
    }
    template<typename T>
    ostream &operator << (ostream &out, const vector<T> &a) {
        rep(i, len(a)) out << a[i] << (i == len(a)-1 ? "" : " ");
        return out;
    }
    template<typename T, typename U>
    ostream &operator << (ostream &out, const pair<T, U> &a){
        out << a.first << " " << a.second;
        return out;
    }
    inline void print() { cout << "\n"; }
    template <typename T, typename ...U>
    inline void print(const T &t, const U &...u) {
        cout << t;
        if (sizeof...(u)) cout << " ";
        print(u...);
    }
}
using namespace io;

template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr int MOD = 1e9+7;
//constexpr int MOD = 998244353;

#pragma endregion

void solve() {
    int n; cin >> n;
    vi s(200200);
    rep(_, n) {
        int a, b; cin >> a >> b;
        s[a+b]++;
    }
    rep(i, 200020) {
        s[i+1] += s[i]/2;
        s[i] %= 2;
    }
    rep(i, 200020) {
        if (s[i]) print(i, 0);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    solve();
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3876
final_rank: 1

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<regex>
#include<random>
using namespace std;
#define int long long
#define uint unsigned long long
const int mod=1e9+7;
const int inf=mod*mod;
const double eps=1e-9;
int tmp[200020];
signed main(){
	int n,a,b;
	cin>>n;
	while(cin>>a>>b)
		tmp[a+b]++;
	for(int i=0;i<200019;i++){
		tmp[i+1]+=tmp[i]/2;
		if(tmp[i]%2)
			cout<<i<<' '<<0<<endl;
	}
}
accuracy: 1
time_ms: 70
memory_kb: 5000
final_rank: 12

code_snippet: #include <iostream>
#include <vector>
using namespace std;
static const int PMAX = 100000;
vector <int> T(2 * PMAX + 20);
int main(){
int N, a, b;
cin >> N;
for ( int i = 0; i < N; i++ ){
cin >> a >> b;
T[a + b]++;
}
for ( int i = 0; i < 2 * PMAX + 20 - 1; i++ ){
T[i + 1] += T[i] / 2;
T[i] %= 2;
if ( T[i] ) cout << i << " " << 0 << endl;
}
return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3456
final_rank: 13

code_snippet: #include<iostream>
using namespace std;
int N;
int c[2<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int a,b;cin>>a>>b;
		c[a+b]++;
	}
	for(int i=0;i+1<2<<17;i++)
	{
		c[i+1]+=c[i]/2;
		if(c[i]%2)cout<<i<<" 0"<<endl;
	}
}
accuracy: 1
time_ms: 90
memory_kb: 4140
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
#define INF 1000000000

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n; cin>>n;
    vector<int> v(303030,0);
    rep(i,n){
        int a,b; cin>>a>>b;
        v[a+b]++;
    }

    rep(i,303030-1){
        v[i+1] += v[i] / 2;
        v[i] %= 2;

        if(v[i] == 1){
            cout << i << " " << 0 << endl;
        }
    }

    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 4164
final_rank: 4

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> cnt(250001);
    for(int i=0;i<n;i++){
        int a, b;
        cin >> a >> b;
        cnt[a+b]++;    
    }
    for(int i=0;i<250000;i++){
        cnt[i+1] += cnt[i]/2;
        cnt[i] %= 2;
    }
    for(int i=0;i<=250000;i++){
        if(cnt[i]){
            cout << i << " " << 0 << endl;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3900
final_rank: 14

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
#define LOCAL
using namespace std;
//using namespace atcoder;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
//#define int long long
using P = pair<int,int>;
//#########################################
int main(){
    int n;cin >> n;
    vector<int>cnt(220000);
    int ret = 0;
    rep(i,n){
        int a,b;cin >> a >> b;
        cnt[a+b]++;
    }
  	for(int i = 0; i < 220000; i++){
		if(cnt[i] != 0){ 
			int tmp = cnt[i];
			cnt[i] = 0;
			for(int k = 0; tmp != 0;k++,tmp /= 2){
				if(tmp%2 == 1){
					cnt[i+k]++;
				}
			}
		}
	}
    rep(i,220000){
        if(cnt[i])cout << i << " " << '0' << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3896
final_rank: 5