#include <bits/stdc++.h>
#define F first
#define S second
typedef long long ll;
using namespace std;

int n;
int q;
pair<pair<int,int>,int>  f[100010];

set<pair<int,int> > rem;

int ST[500010];

void build (int l,int r,int nod){
    if (l==r){
        ST[nod]=f[l].F.F+f[l].F.S;
        return;
    }
    int mid =(l+r)/2;
    build(l,mid,nod*2);
    build(mid+1,r,nod*2+1);
    ST[nod]=max(ST[nod*2],ST[nod*2+1]);
}

int fnd (int x,int l,int r,int nod){
    //cout <<l<<" "<<r<<endl;
    if (l==r){
        if (ST[nod]>=x)
            return l;
        return -1;
    }
    int mid=(l+r)/2;
    if (ST[nod*2]>=x){
        return fnd(x,l,mid,nod*2);
    }else if (ST[nod*2+1]>=x){
        return fnd(x,mid+1,r,nod*2+1);
    }else return -1;
}
void update(int idx,int val,int l,int r,int nod){

    if (l==idx&&r==idx){
        ST[nod]+=val;
        return;
    }
    if (l>idx||r<idx)return;
    int mid=(l+r)/2;
    update(idx,val,l,mid,nod*2);
    update(idx,val,mid+1,r,nod*2+1);
    ST[nod]=max(ST[nod*2],ST[nod*2+1]);
}
pair<int,int> ans[100010];
int res[100010];
int main()
{

    cin >>n;
    cin >>q;
    for (int i=0;i<n;i++){
        cin >>f[i].F.F>>f[i].F.S;
        f[i].S=i;
    }
    sort(f,f+n);

    build (0,n-1,1);
    for (int i=0;i<q;i++){
        //cout <<"------------\n";

        int a,b;
        cin >>a>>b;
        int z=fnd(a,0,n-1,1);

//        cout <<z<<endl;
        if (f[z].F.F>a)z=-1;
        if (z==-1){
            rem.insert({a,b});
            continue;
        }
        res[f[z].S]++;
        f[z].F.S+=b;
        update(z,b,0,n-1,1);
        while (rem.size()){
            pair<int,int> k=*rem.begin();
            if (k.F<=f[z].F.F+f[z].F.S){
                res[f[z].S]++;
                f[z].F.S+=k.S;
                update(z,k.S,0,n-1,1);
                rem.erase(rem.begin()++);
                continue;
            }
            break;
        }
    }
    for (int i=0;i<n;i++){
        ans[f[i].S]=f[i].F;
    }
    for (int i=0;i<n;i++){
        cout <<res[i]<<" "<<ans[i].S<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
typedef long long ll;
using namespace std;

ll n;
ll q;
pair<pair<ll,ll>,ll>  f[200010];

multiset<pair<ll,ll> > rem;

ll ST[1000010];

void build (ll l,ll r,ll nod){
    if (l==r){
        ST[nod]= f[l].F.F + f[l].F.S;
        return;
    }
    ll mid =(l+r)/2;
    build(l,mid,nod*2);
    build(mid+1,r,nod*2+1);
    ST[nod]=max(ST[nod*2],ST[nod*2+1]);
}

ll fnd (ll x,ll l,ll r,ll nod){
    //cout <<l<<" "<<r<<endl;
    if (l==r){
        if (ST[nod]>=x)
            return l;
        return -1;
    }
    ll mid=(l+r)/2;
    if (ST[nod*2]>=x){
        return fnd(x,l,mid,nod*2);
    }else {
        return fnd(x,mid+1,r,nod*2+1);
    }
}
void update(ll idx,ll val,ll l,ll r,ll nod){
    if (l==idx&&r==idx){
        ST[nod]+=val;
        return;
    }
    if (l>idx||r<idx)return;
    ll mid=(l+r)/2;
    update(idx,val,l,mid,nod*2);
    update(idx,val,mid+1,r,nod*2+1);
    ST[nod]=max(ST[nod*2],ST[nod*2+1]);
}
pair<ll,ll> ans[200010];
ll res[200010];
int main()
{

    cin >>n;
    cin >>q;
    for (ll i=0;i<n;i++){
        cin >>f[i].F.F>>f[i].F.S;
        f[i].S=i;
    }
    sort(f,f+n);

    build (0,n-1,1);
    for (ll i=0;i<q;i++){

        ll a,b;
        cin >>a>>b;
        ll z=fnd(a,0,n-1,1);

//        cout <<z<<endl;
        if (z!=-1&&f[z].F.F>a)z=-1;
        if (z==-1){
            rem.insert({a,b});
            continue;
        }
        res[f[z].S]++;
        f[z].F.S+=b;
        update(z,b,0,n-1,1);
        while (rem.size()){
            auto it=rem.lower_bound({f[z].F.F,-1});
            if (it==rem.end())break;
            if ((*it).F<= f[z].F.F + f[z].F.S){
                res[f[z].S]++;
                f[z].F.S+=(*it).S;
                update(z,(*it).S,0,n-1,1);
                rem.erase(it);
                continue;
            }
            break;
        }
    }
    for (ll i=0;i<n;i++){
        ans[f[i].S]=f[i].F;
    }
    for (ll i=0;i<n;i++){
        cout <<res[i]<<" "<<ans[i].S<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
typedef long long ll;
using namespace std;

ll n;
ll q;
pair<pair<ll,ll>,ll>  f[200010];

set<pair<ll,ll> > rem;

ll ST[1000010];

void build (ll l,ll r,ll nod){
    if (l==r){
        ST[nod]=f[l].F.F+f[l].F.S;
        return;
    }
    ll mid =(l+r)/2;
    build(l,mid,nod*2);
    build(mid+1,r,nod*2+1);
    ST[nod]=max(ST[nod*2],ST[nod*2+1]);
}

ll fnd (ll x,ll l,ll r,ll nod){
    //cout <<l<<" "<<r<<endl;
    if (l==r){
        if (ST[nod]>=x)
            return l;
        return -1;
    }
    ll mid=(l+r)/2;
    if (ST[nod*2]>=x){
        return fnd(x,l,mid,nod*2);
    }else {
        return fnd(x,mid+1,r,nod*2+1);
    }
}
void update(ll idx,ll val,ll l,ll r,ll nod){

    if (l==idx&&r==idx){
        ST[nod]+=val;
        return;
    }
    if (l>idx||r<idx)return;
    ll mid=(l+r)/2;
    update(idx,val,l,mid,nod*2);
    update(idx,val,mid+1,r,nod*2+1);
    ST[nod]=max(ST[nod*2],ST[nod*2+1]);
}
pair<ll,ll> ans[200010];
ll res[200010];
int main()
{

    cin >>n;
    cin >>q;
    for (ll i=0;i<n;i++){
        cin >>f[i].F.F>>f[i].F.S;
        f[i].S=i;
    }
    sort(f,f+n);

    build (0,n-1,1);
    for (ll i=0;i<q;i++){
        //cout <<"------------\n";

        ll a,b;
        cin >>a>>b;
        ll z=fnd(a,0,n-1,1);

//        cout <<z<<endl;
        if (z!=-1&&f[z].F.F>a)z=-1;
        if (z==-1){
            rem.insert({a,b});
            continue;
        }
        res[f[z].S]++;
        f[z].F.S+=b;
        update(z,b,0,n-1,1);
        auto it=rem.lower_bound({f[z].F.F,0});
        while (rem.size()){
            if (it==rem.end())break;
            if ((*it).F<=f[z].F.F+f[z].F.S){
                res[f[z].S]++;
                f[z].F.S+=(*it).S;
                update(z,(*it).S,0,n-1,1);
                rem.erase(it++);
                continue;
            }
            break;
        }
    }
    for (ll i=0;i<n;i++){
        ans[f[i].S]=f[i].F;
    }
    for (ll i=0;i<n;i++){
        cout <<res[i]<<" "<<ans[i].S<<endl;
    }
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second
#define int ll

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=200005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
PR Ans[MAXN],Q[MAXN];
map<int,int> Map;
set<PR> Set;
multiset<PR> V;
void Push(PR lst,PR p)
{
	while (Set.size())
	{
		set<PR>::iterator it=Set.lower_bound(MP(lst.fi,0));
		if (it==Set.end()||(*it).fi>p.fi) break;
		Set.erase(it);
	}
	Set.insert(p);
}
signed main()
{
	int n=read(),m=read();
	for (int i=1,x,y;i<=n;i++) x=read(),y=Ans[i-1].se=read(),Map[x]=i-1,Q[i]=MP(x,y);
	sort(Q+1,Q+n+1);
	for (int i=1;i<=n;i++)
	{
		set<PR>::iterator it=Set.lower_bound(MP(Q[i].fi+Q[i].se,0));
		if (it==Set.end()) Set.insert(MP(Q[i].fi+Q[i].se,Q[i].fi));
	}
	for (int i=1;i<=m;i++)
	{
		PR p;
		p.fi=read(),p.se=read();
		set<PR>::iterator it=Set.lower_bound(MP(p.fi,0));
		if (it==Set.end()||(*it).se>p.fi) { V.insert(p); continue; }
		PR t=*it,lst=t;
		Set.erase(it);
		t.fi+=p.se;
//		cout<<"New:"<<t.se<<" "<<t.fi<<endl;
		Ans[Map[t.se]].fi++,Ans[Map[t.se]].se+=p.se;
		while (V.size())
		{
			multiset<PR>::iterator it=V.lower_bound(MP(t.se,0));
			if (it==V.end()||(*it).fi>t.fi) break;
//			cout<<"New:"<<(*it).se<<" "<<(*it).fi<<endl;
			Ans[Map[t.se]].fi++,Ans[Map[t.se]].se+=(*it).se;
			t.fi+=(*it).se,V.erase(it);
		}
		Push(lst,t);
	}
	for (int i=0;i<n;i++) printf("%lld %lld\n",Ans[i].fi,Ans[i].se);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second
#define int ll

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=200005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
PR Ans[MAXN],Q[MAXN];
map<int,int> Map;
set<PR> Set;
multiset<PR> V;
void Push(PR lst,PR p)
{
	while (Set.size())
	{
		set<PR>::iterator it=Set.lower_bound(MP(lst.fi,0));
		if (it==Set.end()||(*it).fi>p.fi) break;
		Set.erase(it);
	}
	Set.insert(p);
}
signed main()
{
	int n=read(),m=read();
	for (int i=1,x,y;i<=n;i++) x=read(),y=Ans[i-1].se=read(),Map[x]=i-1,Q[i]=MP(x,y);
	sort(Q+1,Q+n+1);
	for (int i=1;i<=n;i++)
	{
		set<PR>::iterator it=Set.lower_bound(MP(Q[i].fi+Q[i].se,0));
		if (it==Set.end()) Set.insert(MP(Q[i].fi+Q[i].se,Q[i].fi));
	}
	for (int i=1;i<=m;i++)
	{
		PR p;
		p.fi=read(),p.se=read();
		set<PR>::iterator it=Set.lower_bound(MP(p.fi,0));
		if (it==Set.end()||(*it).se>p.fi) { V.insert(p); continue; }
		PR t=*it,lst=t;
		Set.erase(it);
		t.fi+=p.se;
//		cout<<"New:"<<t.se<<" "<<t.fi<<endl;
		Ans[Map[t.se]].fi++,Ans[Map[t.se]].se+=p.se;
		while (V.size())
		{
			multiset<PR>::iterator it=V.lower_bound(MP(t.se,0));
			if (it==V.end()||(*it).fi>t.fi) break;
//			cout<<"New:"<<(*it).se<<" "<<(*it).fi<<endl;
			Ans[Map[t.se]].fi++,Ans[Map[t.se]].se+=(*it).se;
			t.fi+=(*it).se,V.erase(it);
		}
		Push(lst,t);
	}
	for (int i=0;i<n;i++) printf("%d %d\n",Ans[i].fi,Ans[i].se);
	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <deque>
#include <algorithm>
#include <cstring>
#include <limits.h>
#include <iomanip>
#include <math.h>
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define left left228
#define right right228
#define pii pair<int, int>
using namespace std;
const int N = 2e5, mod = 1e9 + 7, sz = 750, inf = 1e9 + 100, lg = 20;
struct Node{
    Node* left = nullptr;
    Node* right = nullptr;
    int mn = -inf;
};
using nd = Node*;
nd root = nullptr;
map <int, int> cnt, h;
int f[N];
int getmn(nd n) {
    if(!n)
        return -inf;
    return n -> mn;
}
void update(nd &n, int l, int r, int p) {
    if(l > p || r <= p)
        return;
    if(!n)
        n = new Node();
    if(l == r - 1) {
        n -> mn = l + h[l];
        return;
    }
    int m = (l + r) / 2;
    update(n -> left, l, m, p);
    update(n -> right, m, r, p);
    n -> mn = max(getmn(n -> left), getmn(n -> right));
}
int find(nd &n, int l, int r, int pos) {
    if(l > pos || !n)
        return -1;
    if(l == r - 1) {
        if(l + h[l] >= pos) {
            return l;
        }
        else
            return -1;
    }
    int m = (l + r) / 2;
    if(0) {
        if(getmn(n -> left) >= pos)
            return find(n -> left, l, m, pos);
        else
            return find(n -> right, m, r, pos);
    }
    else {
        auto u = find(n -> left, l, m, pos);
        if(u != -1)
            return u;
        return find(n -> right, m, r, pos);
    }
}
set <pii> s;
signed main() {
    fast;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> f[i] >> h[f[i]];
        update(root, 0, inf, f[i]);
    }
    while(m--) {
        int p, b;
        cin >> p >> b;
        auto u = find(root, 0, inf, p);
        if(u == -1) {
            s.insert({p, b});
            continue;
        }
        cnt[u]++;
        h[u] += b;
        while(!s.empty()) {
            auto it = s.lower_bound({u, -1});
            if(it == s.end() || it -> first > u + h[u])
                break;
            h[u] += it -> second;
            cnt[u]++;
            s.erase(it);
        }
        update(root, 0, inf, u);
    }
    for (int i = 0; i < n; i++) {
        cout << cnt[f[i]] << ' ' << h[f[i]] << '\n';
    }
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <deque>
#include <algorithm>
#include <cstring>
#include <limits.h>
#include <iomanip>
#include <math.h>
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define left left228
#define right right228
#define pii pair<int, int>
using namespace std;
const int N = 2e5, mod = 1e9 + 7, sz = 750, inf = 2e9 + 100, lg = 20;
struct Node{
    Node* left = nullptr;
    Node* right = nullptr;
    int mn = -inf;
};
using nd = Node*;
nd root = nullptr;
map <int, int> cnt, h;
int f[N];
int getmn(nd n) {
    if(!n)
        return -inf;
    return n -> mn;
}
void update(nd &n, int l, int r, int p) {
    if(l > p || r <= p)
        return;
    if(!n)
        n = new Node();
    if(l == r - 1) {
        n -> mn = l + h[l];
        return;
    }
    int m = (l + r) / 2;
    update(n -> left, l, m, p);
    update(n -> right, m, r, p);
    n -> mn = max(getmn(n -> left), getmn(n -> right));
}
int find(nd &n, int l, int r, int pos) {
    if(l > pos || !n)
        return -1;
    if(l == r - 1) {
        if(l + h[l] >= pos) {
            return l;
        }
        else
            return -1;
    }
    int m = (l + r) / 2;
    if(0) {
        if(getmn(n -> left) >= pos)
            return find(n -> left, l, m, pos);
        else
            return find(n -> right, m, r, pos);
    }
    else {
        auto u = find(n -> left, l, m, pos);
        if(u != -1)
            return u;
        return find(n -> right, m, r, pos);
    }
}
multiset <pii> s;
signed main() {
    fast;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> f[i] >> h[f[i]];
        update(root, 0, inf, f[i]);
    }
    while(m--) {
        int p, b;
        cin >> p >> b;
        s.insert({p, b});
        auto u = find(root, 0, inf, p);
        if(u == -1) {
            continue;
        }
        cnt[u]++;
        h[u] += b;
        s.erase({p, b});
        while(!s.empty()) {
            auto it = s.lower_bound({u, -1});
            if(it == s.end() || it -> first > u + h[u])
                break;
            h[u] += it -> second;
            cnt[u]++;
            s.erase(it);
        }
        update(root, 0, inf, u);
    }
    for (int i = 0; i < n; i++) {
        cout << cnt[f[i]] << ' ' << h[f[i]] << '\n';
    }
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <deque>
#include <algorithm>
#include <cstring>
#include <limits.h>
#include <iomanip>
#include <math.h>
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define left left228
#define right right228
#define pii pair<int, int>
using namespace std;
const int N = 2e5, mod = 1e9 + 7, sz = 750, inf = 2e9 + 100, lg = 20;
struct Node{
    Node* left = nullptr;
    Node* right = nullptr;
    int mn = -inf;
};
using nd = Node*;
nd root = nullptr;
map <int, int> cnt, h;
int f[N];
int getmn(nd n) {
    if(!n)
        return -inf;
    return n -> mn;
}
void update(nd &n, int l, int r, int p) {
    if(l > p || r <= p)
        return;
    if(!n)
        n = new Node();
    if(l == r - 1) {
        n -> mn = l + h[l];
        return;
    }
    int m = (l + r) / 2;
    update(n -> left, l, m, p);
    update(n -> right, m, r, p);
    n -> mn = max(getmn(n -> left), getmn(n -> right));
}
int find(nd &n, int l, int r, int pos) {
    if(l > pos || !n)
        return -1;
    if(l == r - 1) {
        if(l + h[l] >= pos) {
            return l;
        }
        else
            return -1;
    }
    int m = (l + r) / 2;
    if(0) {
        if(getmn(n -> left) >= pos)
            return find(n -> left, l, m, pos);
        else
            return find(n -> right, m, r, pos);
    }
    else {
        auto u = find(n -> left, l, m, pos);
        if(u != -1)
            return u;
        return find(n -> right, m, r, pos);
    }
}
set <pii> s;
signed main() {
    fast;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> f[i] >> h[f[i]];
        update(root, 0, inf, f[i]);
    }
    while(m--) {
        int p, b;
        cin >> p >> b;
        s.insert({p, b});
        auto u = find(root, 0, inf, p);
        if(u == -1) {
            continue;
        }
        cnt[u]++;
        h[u] += b;
        s.erase({p, b});
        while(!s.empty()) {
            auto it = s.lower_bound({u, -1});
            if(it == s.end() || it -> first > u + h[u])
                break;
            h[u] += it -> second;
            cnt[u]++;
            s.erase(it);
        }
        update(root, 0, inf, u);
    }
    for (int i = 0; i < n; i++) {
        cout << cnt[f[i]] << ' ' << h[f[i]] << '\n';
    }
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <deque>
#include <algorithm>
#include <cstring>
#include <limits.h>
#include <iomanip>
#include <math.h>

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define left left228
#define right right228
#define pii pair<int, int>
using namespace std;
const int N = 2e5, mod = 1e9 + 7, sz = 750, inf = 1e9 + 100, lg = 20;
struct Node{
    Node* left = nullptr;
    Node* right = nullptr;
    int mn = -inf;
};
using nd = Node*;
nd root = nullptr;
map <int, int> cnt, h;
int f[N];
int getmn(nd n) {
    if(!n)
        return -inf;
    return n -> mn;
}
void update(nd &n, int l, int r, int p) {
    if(l > p || r <= p)
        return;
    if(!n)
        n = new Node();
    if(l == r - 1) {
        n -> mn = l + h[l];
        return;
    }
    int m = (l + r) / 2;
    update(n -> left, l, m, p);
    update(n -> right, m, r, p);
    n -> mn = max(getmn(n -> left), getmn(n -> right));
}
int find(nd &n, int l, int r, int pos) {
    if(l > pos || !n)
        return -1;
    if(l == r - 1) {
        if(l + h[l] >= pos) {
            return l;
        }
        else
            return -1;
    }
    int m = (l + r) / 2;
    if(r <= pos) {
        if(getmn(n -> left) >= pos)
            return find(n -> left, l, m, pos);
        else
            return find(n -> right, m, r, pos);
    }
    else {
        auto u = find(n -> left, l, m, pos);
        if(u != -1)
            return u;
        return find(n -> right, m, r, pos);
    }
}
set <pii> s;
signed main() {
    fast;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> f[i] >> h[f[i]];
        update(root, 0, inf, f[i]);
    }
    while(m--) {
        int p, b;
        cin >> p >> b;
        auto u = find(root, 0, inf, p);
        if(u == -1) {
            s.insert({p, b});
            continue;
        }
       // cout << u << endl;
        cnt[u]++;
        h[u] += b;
        while(!s.empty()) {
            auto it = s.lower_bound({u, -1});
           // cout << it -> first << ' ' << it -> second << endl;
            if(it == s.end() || it -> first > u + h[u])
                break;
            h[u] += it -> second;
            cnt[u]++;
            s.erase(it);
        }
        update(root, 0, inf, u);
    }
    for (int i = 0; i < n; i++) {
        cout << cnt[f[i]] << ' ' << h[f[i]] << '\n';
    }
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <deque>
#include <algorithm>
#include <cstring>
#include <limits.h>
#include <iomanip>
#include <math.h>

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define left left228
#define right right228
#define pii pair<int, int>
using namespace std;
const int N = 2e5, mod = 1e9 + 7, sz = 750, inf = 1e9 + 100, lg = 20;
struct Node{
    Node* left = nullptr;
    Node* right = nullptr;
    int mn = -inf;
};
using nd = Node*;
nd root = nullptr;
map <int, int> cnt, h;
int f[N];
int getmn(nd n) {
    if(!n)
        return -inf;
    return n -> mn;
}
void update(nd &n, int l, int r, int p) {
    if(l > p || r <= p)
        return;
    if(!n)
        n = new Node();
    if(l == r - 1) {
        n -> mn = l + h[l];
        return;
    }
    int m = (l + r) / 2;
    update(n -> left, l, m, p);
    update(n -> right, m, r, p);
    n -> mn = max(getmn(n -> left), getmn(n -> right));
}
int find(nd &n, int l, int r, int pos) {
    if(l > pos || !n)
        return -1;
    if(l == r - 1) {
        if(l + h[l] >= pos) {
            return l;
        }
        else
            return -1;
    }
    int m = (l + r) / 2;
    if(r <= pos + 1) {
        if(getmn(n -> left) >= pos)
            return find(n -> left, l, m, pos);
        else
            return find(n -> right, m, r, pos);
    }
    else {
        auto u = find(n -> left, l, m, pos);
        if(u != -1)
            return u;
        return find(n -> right, m, r, pos);
    }
}
set <pii> s;
signed main() {
    fast;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> f[i] >> h[f[i]];
        update(root, 0, inf, f[i]);
    }
    while(m--) {
        int p, b;
        cin >> p >> b;
        auto u = find(root, 0, inf, p);
        if(u == -1) {
            s.insert({p, b});
            continue;
        }
       // cout << u << endl;
        cnt[u]++;
        h[u] += b;
        while(!s.empty()) {
            auto it = s.lower_bound({u, -1});
           // cout << it -> first << ' ' << it -> second << endl;
            if(it == s.end() || it -> first > u + h[u])
                break;
            h[u] += it -> second;
            cnt[u]++;
            s.erase(it);
        }
        update(root, 0, inf, u);
    }
    for (int i = 0; i < n; i++) {
        cout << cnt[f[i]] << ' ' << h[f[i]] << endl;
    }
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <deque>
#include <algorithm>
#include <cstring>
#include <limits.h>
#include <iomanip>
#include <math.h>
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define left left228
#define right right228
#define pii pair<int, int>
using namespace std;
const int N = 2e5, mod = 1e9 + 7, sz = 750, inf = 2e9 + 100, lg = 20;
struct Node{
    Node* left = nullptr;
    Node* right = nullptr;
    int mn = -inf;
};
using nd = Node*;
nd root = nullptr;
map <int, int> cnt, h;
int f[N];
int getmn(nd n) {
    if(!n)
        return -inf;
    return n -> mn;
}
void update(nd &n, int l, int r, int p) {
    if(l > p || r <= p)
        return;
    if(!n)
        n = new Node();
    if(l == r - 1) {
        n -> mn = l + h[l];
        return;
    }
    int m = (l + r) / 2;
    update(n -> left, l, m, p);
    update(n -> right, m, r, p);
    n -> mn = max(getmn(n -> left), getmn(n -> right));
}
int find(nd &n, int l, int r, int pos) {
    if(l > pos || !n)
        return -1;
    if(l == r - 1) {
        if(l + h[l] >= pos) {
            return l;
        }
        else
            return -1;
    }
    int m = (l + r) / 2;
    if(r <= pos) {
        if(getmn(n -> left) >= pos)
            return find(n -> left, l, m, pos);
        else
            return find(n -> right, m, r, pos);
    }
    else {
        auto u = find(n -> left, l, m, pos);
        if(u != -1)
            return u;
        return find(n -> right, m, r, pos);
    }
}
multiset <pii> s;
signed main() {
    fast;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> f[i] >> h[f[i]];
        update(root, 0, inf, f[i]);
    }
    while(m--) {
        int p, b;
        cin >> p >> b;
        s.insert({p, b});
        auto u = find(root, 0, inf, p);
        if(u == -1) {
            continue;
        }
        cnt[u]++;
        h[u] += b;
        s.erase({p, b});
        while(!s.empty()) {
            auto it = s.lower_bound({u, -1});
            if(it == s.end() || it -> first > u + h[u])
                break;
            h[u] += it -> second;
            cnt[u]++;
            s.erase(it);
        }
        update(root, 0, inf, u);
    }
    for (int i = 0; i < n; i++) {
        cout << cnt[f[i]] << ' ' << h[f[i]] << '\n';
    }
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <deque>
#include <algorithm>
#include <cstring>
#include <limits.h>
#include <iomanip>
#include <math.h>

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define left left228
#define right right228
#define pii pair<int, int>
using namespace std;
const int N = 2e5, mod = 1e9 + 7, sz = 750, inf = 1e9 + 100, lg = 20;
struct Node{
    Node* left = nullptr;
    Node* right = nullptr;
    int mn = -inf;
};
using nd = Node*;
nd root = nullptr;
map <int, int> cnt, h;
int f[N];
int getmn(nd n) {
    if(!n)
        return -inf;
    return n -> mn;
}
void update(nd &n, int l, int r, int p) {
    if(l > p || r <= p)
        return;
    if(!n)
        n = new Node();
    if(l == r - 1) {
        n -> mn = l + h[l];
        return;
    }
    int m = (l + r) / 2;
    update(n -> left, l, m, p);
    update(n -> right, m, r, p);
    n -> mn = max(getmn(n -> left), getmn(n -> right));
}
int find(nd &n, int l, int r, int pos) {
    if(l > pos || !n)
        return -1;
    if(l == r - 1) {
        if(l + h[l] >= pos) {
            return l;
        }
        else
            return -1;
    }
    int m = (l + r) / 2;
    if(0) {
        if(getmn(n -> left) >= pos)
            return find(n -> left, l, m, pos);
        else
            return find(n -> right, m, r, pos);
    }
    else {
        auto u = find(n -> left, l, m, pos);
        if(u != -1)
            return u;
        return find(n -> right, m, r, pos);
    }
}
set <pii> s;
signed main() {
    fast;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> f[i] >> h[f[i]];
        update(root, 0, inf, f[i]);
    }
    while(m--) {
        int p, b;
        cin >> p >> b;
        auto u = find(root, 0, inf, p);
        if(u == -1) {
            s.insert({p, b});
            continue;
        }
       // cout << u << endl;
        cnt[u]++;
        h[u] += b;
        while(!s.empty()) {
            auto it = s.lower_bound({u, -1});
           // cout << it -> first << ' ' << it -> second << endl;
            if(it == s.end() || it -> first > u + h[u])
                break;
            h[u] += it -> second;
            cnt[u]++;
            s.erase(it);
        }
        update(root, 0, inf, u);
    }
    for (int i = 0; i < n; i++) {
        cout << cnt[f[i]] << ' ' << h[f[i]] << '\n';
    }
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <deque>
#include <algorithm>
#include <cstring>
#include <limits.h>
#include <iomanip>
#include <math.h>
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define left left228
#define right right228
#define pii pair<int, int>
using namespace std;
const int N = 2e5, mod = 1e9 + 7, sz = 750, inf = 2e9 + 100, lg = 20;
struct Node{
    Node* left = nullptr;
    Node* right = nullptr;
    int mn = -inf;
};
using nd = Node*;
nd root = nullptr;
map <int, int> cnt, h;
int f[N];
int getmn(nd n) {
    if(!n)
        return -inf;
    return n -> mn;
}
void update(nd &n, int l, int r, int p) {
    if(l > p || r <= p)
        return;
    if(!n)
        n = new Node();
    if(l == r - 1) {
        n -> mn = l + h[l];
        return;
    }
    int m = (l + r) / 2;
    update(n -> left, l, m, p);
    update(n -> right, m, r, p);
    n -> mn = max(getmn(n -> left), getmn(n -> right));
}
int find(nd &n, int l, int r, int pos) {
    if(l > pos || !n)
        return -1;
    if(l == r - 1) {
        if(l + h[l] >= pos) {
            return l;
        }
        else
            return -1;
    }
    int m = (l + r) / 2;
    if(0) {
        if(getmn(n -> left) >= pos)
            return find(n -> left, l, m, pos);
        else
            return find(n -> right, m, r, pos);
    }
    else {
        auto u = find(n -> left, l, m, pos);
        if(u != -1)
            return u;
        return find(n -> right, m, r, pos);
    }
}
set <pii> s;
signed main() {
    fast;
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> f[i] >> h[f[i]];
        update(root, 0, inf, f[i]);
    }
    while(m--) {
        int p, b;
        cin >> p >> b;
        auto u = find(root, 0, inf, p);
        if(u == -1) {
            s.insert({p, b});
            continue;
        }
        cnt[u]++;
        h[u] += b;
        while(!s.empty()) {
            auto it = s.lower_bound({u, -1});
            if(it == s.end() || it -> first > u + h[u])
                break;
            h[u] += it -> second;
            cnt[u]++;
            s.erase(it);
        }
        update(root, 0, inf, u);
    }
    for (int i = 0; i < n; i++) {
        cout << cnt[f[i]] << ' ' << h[f[i]] << '\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;

struct frog {
    ll l, r;
    int idx;
    frog(ll l, ll r, int idx) : l(l), r(r), idx(idx) {}
    bool operator< (const frog &o) const {
        return l < o.l;
    }
};

const int MAXN = 2e5 + 10;
ll x[MAXN], len[MAXN], win[MAXN], n, m;
set<frog> frogs, inverted;
multiset<ii> mos;

void insert_frog(ll l, ll r, int idx) {
    frogs.insert({l, r, idx});
    auto it = frogs.find({l, r, idx});
    assert(it != frogs.end());
    vector<frog> kill;
    while(true) {
        ++it;
        if(it == frogs.end())
            break;
        if(it->r > r)
            break;
        else
            kill.push_back(*it);
    }
    for(auto f : kill) {
        frogs.erase(f);
        inverted.erase({f.r, f.l, f.idx});
    }
    inverted.insert({r, l, idx});
}

bool eat(int idx) {
    auto it = mos.lower_bound({x[idx], 0});
    if(it == mos.end())
        return false;
    if(it->first > x[idx] + len[idx])
        return false;
    int del = it->second;
    mos.erase(it);
    frogs.erase({x[idx], x[idx] + len[idx], idx});
    for(auto f : inverted) {
        if(f.r == x[idx]) {
            inverted.erase(f);
            break;
        }
    }
    len[idx] += del;
    win[idx]++;
    insert_frog(x[idx], x[idx] + len[idx], idx);
    return true;
}

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

    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> x[i] >> len[i];
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int a, int b){ return x[a] > x[b]; });
    for(auto idx : ord)
        insert_frog(x[idx], x[idx] + len[idx], idx);
    for(int i = 0; i < m; i++) {
        ll p, b;
        cin >> p >> b;
        mos.insert({p, b});
        auto it = inverted.lower_bound({p, LLONG_MAX, 0});
        if(it == inverted.end())
            continue;
        if(it->r <= p) {
            int ps = it->idx;
            while(eat(ps)) {}
        }
    }
    for(int i = 0; i < n; i++)
        cout << win[i] << " " << len[i] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;

struct frog {
    ll l, r;
    int idx;
    frog(ll l, ll r, int idx) : l(l), r(r), idx(idx) {}
    bool operator< (const frog &o) const {
        return l < o.l;
    }
};

const int MAXN = 2e5 + 10;
ll x[MAXN], len[MAXN], win[MAXN], n, m;
set<frog> frogs, inverted;
set<array<ll, 3>> mos;

void insert_frog(ll l, ll r, int idx) {
    frogs.insert({l, r, idx});
    auto it = frogs.find({l, r, idx});
    vector<frog> kill;
    while(true) {
        ++it;
        if(it == frogs.end())
            break;
        if(it->r > r)
            break;
        kill.push_back(*it);
    }
    for(auto f : kill) {
        frogs.erase(f);
        inverted.erase({f.r, f.l, f.idx});
    }
    inverted.insert({r, l, idx});
}

bool eat(int idx) {
    auto it = mos.lower_bound({x[idx], 0});
    if(it == mos.end())
        return false;
    if((*it)[0] > x[idx] + len[idx])
        return false;
    ll del = (*it)[2];
    ll ex = (*it)[1];
    mos.erase(it);
    frogs.erase({x[idx], x[idx] + len[idx], idx});
    for(auto f : inverted) {
        if(f.r == x[idx]) {
            inverted.erase(f);
            break;
        }
    }
    len[idx] += del;
    win[idx] += ex;
    insert_frog(x[idx], x[idx] + len[idx], idx);
    return true;
}

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

    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> x[i] >> len[i];
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int a, int b){ return x[a] > x[b]; });
    for(auto idx : ord)
        insert_frog(x[idx], x[idx] + len[idx], idx);
    for(int i = 0; i < m; i++) {
        ll p, b;
        cin >> p >> b;
        int ex = 1;
        auto m = mos.lower_bound({p, 0, 0});
        if((*m)[0] == p) {
            ex += (*m)[1];
            b += (*m)[2];
            mos.erase(m);
        }
        mos.insert({p, ex, b});
        auto it = inverted.lower_bound({p, LLONG_MAX, 0});
        if(it == inverted.end())
            continue;
        if(it->r <= p) {
            int ps = it->idx;
            while(eat(ps)) {}
        }
    }
    for(int i = 0; i < n; i++)
        cout << win[i] << " " << len[i] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;

struct frog {
    ll l, r;
    int idx;
    frog(ll l, ll r, int idx) : l(l), r(r), idx(idx) {}
    bool operator< (const frog &o) const {
        return l < o.l;
    }
};

const int MAXN = 2e5 + 10;
ll x[MAXN], len[MAXN], win[MAXN], n, m;
set<frog> frogs, inverted;
multiset<ii> mos;

void insert_frog(ll l, ll r, int idx) {
    frogs.insert({l, r, idx});
    auto it = frogs.find({l, r, idx});
    assert(it != frogs.end());
    vector<frog> kill;
    while(true) {
        ++it;
        if(it == frogs.end())
            break;
        if(it->r > r)
            break;
        else
            kill.push_back(*it);
    }
    for(auto f : kill) {
        frogs.erase(f);
        inverted.erase({f.r, f.l, f.idx});
    }
    inverted.insert({r, l, idx});
}

bool eat(int idx) {
    auto it = mos.lower_bound({x[idx], 0});
    if(it == mos.end())
        return false;
    if(it->first > x[idx] + len[idx])
        return false;
    int del = it->second;
    mos.erase(it);
    frogs.erase({x[idx], x[idx] + len[idx], idx});
    len[idx] += del;
    win[idx]++;
    insert_frog(x[idx], x[idx] + len[idx], idx);
    return true;
}

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

    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> x[i] >> len[i];
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int a, int b){ return x[a] > x[b]; });
    for(auto idx : ord)
        insert_frog(x[idx], x[idx] + len[idx], idx);
    for(int i = 0; i < m; i++) {
        ll p, b;
        cin >> p >> b;
        mos.insert({p, b});
        auto it = inverted.lower_bound({p, LLONG_MAX, 0});
        if(it == inverted.end())
            continue;
        if(it->r <= p) {
            int ps = it->idx;
            while(eat(ps)) {}
        }
    }
    for(int i = 0; i < n; i++)
        cout << win[i] << " " << len[i] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;

struct frog {
    ll l, r;
    int idx;
    frog(ll l, ll r, int idx) : l(l), r(r), idx(idx) {}
    bool operator< (const frog &o) const {
        return l < o.l;
    }
};

const int MAXN = 2e5 + 10;
ll x[MAXN], len[MAXN], win[MAXN], n, m;
set<frog> frogs, inverted;
multiset<ii> mos;

void insert_frog(ll l, ll r, int idx) {
    frogs.insert({l, r, idx});
    auto it = frogs.find({l, r, idx});
    assert(it != frogs.end());
    vector<frog> kill;
    while(true) {
        ++it;
        if(it == frogs.end())
            break;
        if(it->r > r)
            break;
        else
            kill.push_back(*it);
    }
    for(auto f : kill) {
        frogs.erase(f);
        inverted.erase({f.r, f.l, f.idx});
    }
    inverted.insert({r, l, idx});
}

bool eat(int idx) {
    auto it = mos.lower_bound({x[idx], 0});
    if(it == mos.end())
        return false;
    if(it->first > x[idx] + len[idx])
        return false;
    int del = it->second;
    mos.erase(it);
    frogs.erase({x[idx], x[idx] + len[idx], idx});
    inverted.erase({x[idx] + len[idx], x[idx], idx});
    len[idx] += del;
    win[idx]++;
    insert_frog(x[idx], x[idx] + len[idx], idx);
    return true;
}

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

    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> x[i] >> len[i];
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int a, int b){ return x[a] > x[b]; });
    for(auto idx : ord)
        insert_frog(x[idx], x[idx] + len[idx], idx);
    for(int i = 0; i < m; i++) {
        ll p, b;
        cin >> p >> b;
        mos.insert({p, b});
        auto it = inverted.lower_bound({p, LLONG_MAX, 0});
        if(it == inverted.end())
            continue;
        if(it->r <= p) {
            int ps = it->idx;
            while(eat(ps)) {}
        }
    }
    for(int i = 0; i < n; i++)
        cout << win[i] << " " << len[i] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;

struct frog {
    ll l, r;
    int idx;
    frog(ll l, ll r, int idx) : l(l), r(r), idx(idx) {}
    bool operator< (const frog &o) const {
        return l < o.l;
    }
};

const int MAXN = 2e5 + 10;
ll x[MAXN], len[MAXN], win[MAXN], n, m;
set<frog> frogs, inverted;
set<array<ll, 3>> mos;

void insert_frog(ll l, ll r, int idx) {
    frogs.insert({l, r, idx});
    auto it = frogs.find({l, r, idx});
    vector<frog> kill;
    while(true) {
        ++it;
        if(it == frogs.end())
            break;
        if(it->r > r)
            break;
        kill.push_back(*it);
    }
    for(auto f : kill) {
        frogs.erase(f);
        inverted.erase({f.r, f.l, f.idx});
    }
    inverted.insert({r, l, idx});
}

void eat(int idx) {
    if(mos.empty())
        return;
    auto it = mos.lower_bound({x[idx], 0});
    if(it == mos.end())
        return;
    ll ex = 0, inc = 0;
    auto it2 = it;
    while(it != mos.end()) {
        if((*it)[0] > x[idx] + len[idx] + inc)
            break;
        ex += (*it)[1];
        inc += (*it)[2];
        ++it;
    }
    mos.erase(it2, it);
    frogs.erase({x[idx], x[idx] + len[idx], idx});
    for(auto f : inverted) {
        if(f.r == x[idx]) {
            inverted.erase(f);
            break;
        }
    }
    len[idx] += inc;
    win[idx] += ex;
    insert_frog(x[idx], x[idx] + len[idx], idx);
}

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

    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> x[i] >> len[i];
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int a, int b){ return x[a] > x[b]; });
    for(auto idx : ord)
        insert_frog(x[idx], x[idx] + len[idx], idx);
    for(int i = 0; i < m; i++) {
        ll p, b;
        cin >> p >> b;
        int ex = 1;
        auto m = mos.lower_bound({p, 0, 0});
        if(m != mos.end() && (*m)[0] == p) {
            ex += (*m)[1];
            b += (*m)[2];
            mos.erase(m);
        }
        mos.insert({p, ex, b});
        auto it = inverted.lower_bound({p, LLONG_MAX, 0});
        if(it == inverted.end())
            continue;
        if(it->r <= p) {
            int ps = it->idx;
            eat(ps);
        }
    }
    for(int i = 0; i < n; i++)
        cout << win[i] << " " << len[i] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

struct frog {
    ll l, r;
    int idx;
    bool operator< (const frog &o) const {
        return l < o.l;
    }
};

const int MAXN = 2e5 + 10;
ll x[MAXN], len[MAXN], win[MAXN], n, m;
set<frog> frogs, inverted;
multiset<ii> mos;

void insert_frog(ll l, ll r, int idx) {
    frogs.insert({l, r, idx});
    inverted.insert({r, l, idx});
    auto it = frogs.find({l, r, idx});
    vector<frog> kill;
    while(true) {
        ++it;
        if(it == frogs.end())
            break;
        if(it->r > r)
            break;
        else
            kill.push_back(*it);
    }
    for(auto f : kill) {
        frogs.erase(f);
        inverted.erase({f.r, f.l, f.idx});
    }
}

bool eat(int idx) {
    auto it = mos.lower_bound({x[idx], 0});
    if(it == mos.end())
        return false;
    //cout << "trying " << it->first << '\n';
    if(it->first > x[idx] + len[idx])
        return false;
    //cout << "frog [" << x[idx] << ", " << x[idx] + len[idx] << "] eating " << it->first << " " << it->second << '\n';
    int del = it->second;
    mos.erase(it);
    frogs.erase({x[idx], x[idx] + len[idx], idx});
    inverted.erase({x[idx] + len[idx], x[idx], idx});
    len[idx] += del;
    win[idx]++;
    insert_frog(x[idx], x[idx] + len[idx], idx);
    return true;
}

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

    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> x[i] >> len[i];
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int a, int b){ return x[a] > x[b]; });
    for(auto idx : ord)
        insert_frog(x[idx], x[idx] + len[idx], idx);
    for(int i = 0; i < m; i++) {
        int p, b;
        cin >> p >> b;
        mos.insert({p, b});
        auto it = inverted.lower_bound({p, LLONG_MAX, 0});
        if(it == inverted.end())
            continue;
        if(it->r <= p) {
            while(eat(it->idx)) {}
        }
    }
    for(int i = 0; i < n; i++)
        cout << win[i] << " " << len[i] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;

struct frog {
    ll l, r;
    int idx;
    frog(ll l, ll r, int idx) : l(l), r(r), idx(idx) {}
    bool operator< (const frog &o) const {
        return l < o.l;
    }
};

const int MAXN = 2e5 + 10;
ll x[MAXN], len[MAXN], win[MAXN], n, m;
set<frog> frogs, inverted;
set<array<ll, 3>> mos;

void insert_frog(ll l, ll r, int idx) {
    frogs.insert({l, r, idx});
    auto it = frogs.find({l, r, idx});
    vector<frog> kill;
    while(true) {
        ++it;
        if(it == frogs.end())
            break;
        if(it->r > r)
            break;
        kill.push_back(*it);
    }
    for(auto f : kill) {
        frogs.erase(f);
        inverted.erase({f.r, f.l, f.idx});
    }
    inverted.insert({r, l, idx});
}

bool eat(int idx) {
    auto it = mos.lower_bound({x[idx], 0});
    if(it == mos.end())
        return false;
    if((*it)[0] > x[idx] + len[idx])
        return false;
    ll del = (*it)[2];
    ll ex = (*it)[1];
    mos.erase(it);
    frogs.erase({x[idx], x[idx] + len[idx], idx});
    for(auto f : inverted) {
        if(f.r == x[idx]) {
            inverted.erase(f);
            break;
        }
    }
    len[idx] += del;
    win[idx] += ex;
    insert_frog(x[idx], x[idx] + len[idx], idx);
    return true;
}

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

    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> x[i] >> len[i];
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int a, int b){ return x[a] > x[b]; });
    for(auto idx : ord)
        insert_frog(x[idx], x[idx] + len[idx], idx);
    for(int i = 0; i < m; i++) {
        ll p, b;
        cin >> p >> b;
        int ex = 1;
        auto m = mos.lower_bound({p, 0, 0});
        if(m != mos.end() && (*m)[0] == p) {
            ex += (*m)[1];
            b += (*m)[2];
            mos.erase(m);
        }
        mos.insert({p, ex, b});
        auto it = inverted.lower_bound({p, LLONG_MAX, 0});
        if(it == inverted.end())
            continue;
        if(it->r <= p) {
            int ps = it->idx;
            while(eat(ps)) {}
        }
    }
    for(int i = 0; i < n; i++)
        cout << win[i] << " " << len[i] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;

struct frog {
    ll l, r;
    int idx;
    frog(ll l, ll r, int idx) : l(l), r(r), idx(idx) {}
    bool operator< (const frog &o) const {
        return l < o.l;
    }
};

const int MAXN = 2e5 + 10;
ll x[MAXN], len[MAXN], win[MAXN], n, m;
set<frog> frogs, inverted;
set<array<ll, 3>> mos;

void insert_frog(ll l, ll r, int idx) {
    frogs.insert({l, r, idx});
    auto it = frogs.find({l, r, idx});
    vector<frog> kill;
    while(true) {
        ++it;
        if(it == frogs.end())
            break;
        if(it->r > r)
            break;
        kill.push_back(*it);
    }
    for(auto f : kill) {
        frogs.erase(f);
        inverted.erase({f.r, f.l, f.idx});
    }
    inverted.insert({r, l, idx});
}

void eat(int idx) {
    if(mos.empty())
        return;
    auto it = mos.lower_bound({x[idx], 0});
    if(it == mos.end())
        return;
    ll ex = 0, inc = 0;
    vector<array<ll, 3>> kill;
    while(it != mos.end()) {
        if((*it)[0] > x[idx] + len[idx] + inc)
            break;
        ex += (*it)[1];
        inc += (*it)[2];
        kill.push_back(*it);
        ++it;
    }
    for(auto m : kill)
        mos.erase(m);
    frogs.erase({x[idx], x[idx] + len[idx], idx});
    for(auto f : inverted) {
        if(f.r == x[idx]) {
            inverted.erase(f);
            break;
        }
    }
    len[idx] += inc;
    win[idx] += ex;
    insert_frog(x[idx], x[idx] + len[idx], idx);
}

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

    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> x[i] >> len[i];
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int a, int b){ return x[a] > x[b]; });
    for(auto idx : ord)
        insert_frog(x[idx], x[idx] + len[idx], idx);
    for(int i = 0; i < m; i++) {
        ll p, b;
        cin >> p >> b;
        int ex = 1;
        auto m = mos.lower_bound({p, 0, 0});
        if(m != mos.end() && (*m)[0] == p) {
            ex += (*m)[1];
            b += (*m)[2];
            mos.erase(m);
        }
        mos.insert({p, ex, b});
        auto it = inverted.lower_bound({p, LLONG_MAX, 0});
        if(it == inverted.end())
            continue;
        if(it->r <= p) {
            int ps = it->idx;
            eat(ps);
        }
    }
    for(int i = 0; i < n; i++)
        cout << win[i] << " " << len[i] << '\n';
}


#include <iostream>
#include <set>
#include <cstdio>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
set <pair<int,int> > s1;
set <pair<int,int> > s2;//s1存青蛙右端点和编号，s2存蚊子坐标和大小
int a[200005],sz[200005],ans[200005];
vector <pair<int,int> > v;
pair <int,int> b[200005];
signed main(int argc, char** argv) {
	int n,m;
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i],&sz[i]);
		b[i]={a[i],i};
	}
	sort(b+1,b+n+1);
	int mx=-1;
	for(int i=1;i<=n;i++)
	{
		if(a[b[i].second]+sz[b[i].second]<=mx) continue;
		s1.insert({a[b[i].second]+sz[b[i].second],b[i].second});
		mx=max(mx,a[b[i].second]+sz[b[i].second]);
	}
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%lld%lld",&x,&y);
		set<pair<int,int> >::iterator it=s1.lower_bound({x,-1});
		if(it==s1.end())
		{
			s2.insert({x,y});
			continue;
		}
		int now=(*it).second;
		if(a[now]>x)
		{
			s2.insert({x,y});
			continue;
		}
		s2.insert({x,y});
		set<pair<int,int> >::iterator w=s2.find({x,y});
		v.clear();
		while(w!=s2.end())
		{
			if((*w).first>sz[now]+a[now]) break;
			v.push_back(*w),sz[now]+=(*w).second,++ans[now];
			++w;
		}
		for(auto x:v) s2.erase(x);
		v.clear();
		++it;
		while(it!=s1.end())
		{
			if((*it).first>sz[now]+a[now]) break;
			v.push_back(*it);
			++it;
		}
		for(auto x:v) s1.erase(x);
		s1.erase(*s1.lower_bound({x,-1})),s1.insert({sz[now]+a[now],now});
	}
	for(int i=1;i<=n;i++)
	{
		cout << ans[i] << " " << sz[i] << "\n";
	}
	return 0;
}


#include <iostream>
#include <set>
#include <cstdio>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
set <pair<int,int> > s1;
set <pair<int,int> > s2;//s1存青蛙右端点和编号，s2存蚊子坐标和大小
int a[200005],sz[200005],ans[200005];
vector <pair<int,int> > v;
pair <int,int> b[200005];
signed main(int argc, char** argv) {
	int n,m;
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i],&sz[i]);
		b[i]={a[i],i};
	}
	sort(b+1,b+n+1);
	int mx=-1;
	for(int i=1;i<=n;i++)
	{
		if(a[b[i].second]+sz[b[i].second]<=mx) continue;
		s1.insert({a[b[i].second]+sz[b[i].second],b[i].second});
		mx=max(mx,a[b[i].second]+sz[b[i].second]);
	}
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%lld%lld",&x,&y);
		set<pair<int,int> >::iterator it=s1.lower_bound({x,-1});
		if(it==s1.end())
		{
			s2.insert({x,y});
			continue;
		}
		int now=(*it).second;
		if(a[now]>x)
		{
			s2.insert({x,y});
			continue;
		}
		s2.insert({x,y});
		set<pair<int,int> >::iterator w=s2.find({x,y});
		v.clear();
		while(w!=s2.end())
		{
			if((*w).first>sz[now]+a[now]) break;
			v.push_back(*w),sz[now]+=(*w).second,++ans[now];
			++w;
		}
		for(auto x:v) s2.erase(x);
		v.clear();
		++it;
		while(it!=s1.end())
		{
			if((*it).first>sz[now]+a[now]) break;
			v.push_back(*it);
			++it;
		}
		for(auto x:v) s1.erase(x);
		s1.erase(*it),s1.insert({sz[now]+a[now],now});
	}
	for(int i=1;i<=n;i++)
	{
		cout << ans[i] << " " << sz[i] << "\n";
	}
	return 0;
}


#include <iostream>
#include <set>
#include <cstdio>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
set <pair<int,int> > s1;
multiset <pair<int,int> > s2;//s1存青蛙右端点和编号，s2存蚊子坐标和大小
int a[200005],sz[200005],ans[200005];
vector <pair<int,int> > v;
pair <int,int> b[200005];
signed main(int argc, char** argv) {
	int n,m;
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&a[i],&sz[i]);
		b[i]={a[i],i};
	}
	sort(b+1,b+n+1);
	int mx=-1;
	for(int i=1;i<=n;i++)
	{
		if(a[b[i].second]+sz[b[i].second]<=mx) continue;
		s1.insert({a[b[i].second]+sz[b[i].second],b[i].second});
		mx=max(mx,a[b[i].second]+sz[b[i].second]);
	}
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%lld%lld",&x,&y);
		set<pair<int,int> >::iterator it=s1.lower_bound({x,-1});
		if(it==s1.end())
		{
			s2.insert({x,y});
			continue;
		}
		int now=(*it).second;
		if(a[now]>x)
		{
			s2.insert({x,y});
			continue;
		}
		s2.insert({x,y});
		multiset<pair<int,int> >::iterator w=s2.find({x,y});
		v.clear();
		while(w!=s2.end())
		{
			if((*w).first>sz[now]+a[now]) break;
			v.push_back(*w),sz[now]+=(*w).second,++ans[now];
			++w;
		}
		for(auto x:v) s2.erase(x);
		v.clear();
		++it;
		while(it!=s1.end())
		{
			if((*it).first>sz[now]+a[now]) break;
			v.push_back(*it);
			++it;
		}
		for(auto x:v) s1.erase(x);
		s1.erase(*s1.lower_bound({x,-1})),s1.insert({sz[now]+a[now],now});
	}
	for(int i=1;i<=n;i++)
	{
		cout << ans[i] << " " << sz[i] << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{ int cnt=0;
vector<int>v;
string a,b;int n; cin>>n;
cin>>a>>b;
for(int i=0;i<n;i++)
{
    if(a[i]!=b[i]) v.emplace_back(i);
}
for(int i=0;i<int(v.size())-1;i++)
{
    if(v[i+1]-v[i]>1) cnt+=2;
    else cnt++;
}
cout<<cnt<<endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{ int cnt=0;
vector<int>v;
string a,b;int n; cin>>n;
cin>>a>>b;int j=-1;
if(n==1)
{
    if(a[0]!=b[0]) cout<<1;
    else cout<<0;
}
else
{
for(int i=0;i<n;i++)
{
    if(a[i]!=b[i]){if(j==-1) j=i;}

        if(j!=-1 &&i!=j && a[i]!=b[i]){
        if(abs(i-j)==1){ cnt++; if(a[i]=='0') a[i]='1';else a[i]='0'; }
        else if(abs(i-j)>1) {cnt+=2; if(a[i]=='0') a[i]='1';else a[i]='0';}
        j=-1;}

}
cout<<cnt<<endl;
}

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,i,ans=0,c,d;
    vector<int>v;
        string s,q;
        cin>>a>>s>>q;
        for(i=0;i<a;i++)
        {
            if(s[i]!=q[i])
            {
                v.push_back(i);
            }
        }
        for(i=0;i<v.size();i=i+2)
        {
            ans=ans+min((v[i+1]-v[i]),2);
        }
        cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,i,ans=0,c=0,d;
    vector<int>v;
        string s,q;
        cin>>a>>s>>q;
        for(i=0;i<a;i++)
        {
            if(s[i]!=q[i])
            {
                v.push_back(i);
                c++;
            }
        }
        if(c%2!=0)
        {
            v.pop_back();
            ans=1;
        }
        for(i=0;i<v.size();i=i+2)
        {
            if(s[v[i]]==s[v[i+1]])
            {
                ans=ans+2;
            }
            else
            {
            ans=ans+min((v[i+1]-v[i]),2);
            }
        }
        cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,i,ans=0,c=0,d;
    vector<int>v;
        string s,q;
        cin>>a>>s>>q;
        for(i=0;i<a;i++)
        {
            if(s[i]!=q[i])
            {
                if(i+1<a&&s[i+1]!=q[i+1]&&q[i+1]!=q[i])
                {i++;
                }
                c++;
            }
        }

        cout<<c;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,i,ans=0,c=0,d;
    vector<int>v;
        string s,q;
        cin>>a>>s>>q;
        for(i=0;i<a;i++)
        {
            if(s[i]!=q[i])
            {
                v.push_back(i);
                c++;
            }
        }
        if(c==1)
        {
            cout<<1;
        }
        else
        {
        for(i=0;i<v.size();i=i+2)
        {
            if(s[v[i]]==s[v[i+1]])
            {
                ans=ans+2;
            }
            else
            {
            ans=ans+min((v[i+1]-v[i]),2);
            }
        }
        cout<<ans;
        }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,i,ans=0,c=0,d;
    vector<int>v;
        string s,q;
        cin>>a>>s>>q;
        for(i=0;i<a;i++)
        {
            if(s[i]!=q[i])
            {
                v.push_back(i);
                c++;
            }
        }
        if(c==1)
        {
            cout<<1;
        }
        else
        {
        for(i=0;i<v.size();i=i+2)
        {
            ans=ans+min((v[i+1]-v[i]),2);
        }
        cout<<ans;
        }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t, i, cnt=0, a, b, res=0;
    cin >> t;
    string s1, s2;
    cin >> s1 >> s2;
    for(i=0;i<t;i++) {
        if(s1[i]!=s2[i]) {
            cnt++;
            if((cnt%2)==1) {a=i;}
            else {b=i; res=res+(b-a);}
        }
    }
    cout << res;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t, i, cnt=0, a, b, res=0;
    cin >> t;
    string s1, s2;
    cin >> s1 >> s2;
    for(i=0;i<t;i++) {
        if(s1[i]!=s2[i]) {
            cnt++;
            if((cnt%2)!=0) a=i;
            else if(cnt%2==0){
               b=(i-a);
               if(b<2) cnt--;
            }
        }
    }
    cout << cnt;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t, i, cnt=0;
    cin >> t;
    string s1, s2;
    cin >> s1 >> s2;
    for(i=0;i<t;i++) {
        if(s1[i]!=s2[i]) {
            cnt++;
            if(s1[i+1]!=s2[i+1] && s1[i]!=s1[i+1]) {
                cnt--;
                i++;
            }
        }
    }
    cout << cnt;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t, i, cnt=0, a, b, res=0;
    cin >> t;
    string s1, s2;
    cin >> s1 >> s2;
    for(i=0;i<t;i++) {
        if(s1[i]!=s2[i]) {
            cnt++;
            if((cnt%2)==1) {a=i;}
            else {b=i; res=res+(b-a);}
        }
    }
    if(cnt%2==0) {
       cout << res;
    }
    else cout << cnt;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t, i, cnt=0, a, b, res=0;
    cin >> t;
    string s1, s2;
    cin >> s1 >> s2;
    if(t==1) {
       if(s1[i]!=s2[i]) cout << "1";
       else cout << "0";
       return 0;
    }
    for(i=0;i<t;i++) {
        if(s1[i]!=s2[i]) {
            cnt++;
            if((cnt%2)==1) {a=i;}
            else {
                b=i;
                if((b-a)<2) res=res+(b-a);
                else res=res+2;
            }
        }
    }
    cout << res;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t, i, cnt=0;
    cin >> t;
    string s1, s2;
    cin >> s1 >> s2;
    for(i=0;i<t;i++) {
        if(s1[i]!=s2[i]) {
            cnt++;
            if(s1[i+1]!=s2[i+1] && s1[i]!=s1[i+1]) {
                i++;
            }
        }
    }
    cout << cnt;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t, i, cnt=0, a, b, res=0;
    cin >> t;
    string s1, s2;
    cin >> s1 >> s2;
    for(i=0;i<t;i++) {
        if(s1[i]!=s2[i]) {
            cnt++;
            if((cnt%2)==1) {a=i;}
            else {
                b=i;
                if((b-a)<2) res=res+(b-a);
                else res=res+2;
            }
        }
    }
    cout << res;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t, i, cnt=0;
    cin >> t;
    string s1, s2;
    cin >> s1 >> s2;
    for(i=0;i<t;i++) {
        if(s1[i]!=s2[i]) {
            cnt++;
            if(s1[i+1]!=s2[i+1] && s1[i]!=s1[i+1]) {
                cnt--;
            }
        }
    }
    cout << cnt;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,l,e=0;
	cin>>a;
	char p[a],q[a];
	cin.ignore();
	gets(p);
	gets(q);

	for(int i=0;i<=a;i++)
	{
		if(p[i]==q[i])
		continue;
		else
		{
		  if(i<a)
			{
				if(p[i+1]!=q[i+1])
				{
					e++;
					if(q[i+1]=='0')
					q[i+1]='1';
					else
					q[i+1]='0';
				}
				else
				e++;
			}
			else
			e++;
		}
	}
cout<<e;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int a,i,l,e=0;
	cin>>a;
	char p[a],q[a];
	cin.ignore();
	gets(p);
	gets(q);

	for(i=0;i<=a;i++)
	{
		if(p[i]==q[i])
		continue;
		else
		{
		  if(i<a)
			{
				if((p[i+1]!=q[i+1])&&(q[i]!=q[i+1]))
				{
					e++;
					if(q[i+1]=='0')
					q[i+1]='1';
					else
					q[i+1]='0';
				}
				else
				e++;
			}
			else
			e++;
		}
	}
cout<<e;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,l,e=0;
	cin>>a;
	char p[a],q[a];
	cin.ignore();
	gets(p);
	gets(q);

	for(int i=0;i<=a;i++)
	{
		if(p[i]==q[i])
		continue;
		else
		{
		  if(i<a)
			{
				if((p[i+1]!=q[i+1])&&(q[i]!=q[i+1]))
				{
					e++;
					if(q[i+1]=='0')
					q[i+1]='1';
					else
					q[i+1]='0';
				}
				else
				e++;
			}
			else
			e++;
		}
	}
cout<<e;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,l,e=0;
	cin>>a;
	char p[a],q[a];
	cin.ignore();
	gets(p);
	gets(q);

	for(int i=0;i<a;i++)
	{
		if(p[i]==q[i])
		continue;
		else
		{
		  if(i<a-1)
			{
				if((p[i+1]!=q[i+1])&&(q[i]!=q[i+1]))
				{
					e++;
					if(q[i+1]=='1')
					q[i+1]='0';
					else
					q[i+1]='1';
				}
				else
				e++;
			}
			else
			e++;
		}
	}
cout<<e;
}


#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
	long long int a,i,l,e=0;
	string p,q;
	cin>>a>>p>>q;
	for(i=0;i<a;i++)
	{
		if(p[i]==q[i])
		continue;
		else
		{
		  if(i<a-1)
			{
				if((p[i+1]!=q[i+1])&&(q[i]!=q[i+1]))
				{
					e++;
					if(q[i+1]=='0')
			    {
						q[i+1]='1';
					}
					else
					q[i+1]='0';
				}
				else
				e++;
			}
			else
			e++;
		}
	}
cout<<e;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,l,e=0;
	cin>>a;
	char p[a],q[a];
	cin.ignore();
	gets(p);
	gets(q);

	for(int i=0;i<a;i++)
	{
		if(p[i]==q[i])
		continue;
		else
		{
		  if(i<a)
			{
				if((p[i+1]!=q[i+1])&&(q[i]!=q[i+1]))
				{
					e++;
					if(q[i+1]=='1')
					q[i+1]='0';
					else
					q[i+1]='1';
				}
				else
				e++;
			}
			else
			e++;
		}
	}
cout<<e;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,l,e=0;
	cin>>a;
	char p[a],q[a];
	cin.ignore();
	gets(p);
	gets(q);

	for(int i=0;i<=a;i++)
	{
		if(p[i]==q[i])
		continue;
		else
		{
		  if(i<a)
			{
				if((p[i+1]!=q[i+1])&&(q[i]!=q[i+1]))
				{
					e++;
					if(q[i+1]=='1')
					q[i+1]='0';
					else
					q[i+1]='1';
				}
				else
				e++;
			}
			else
			e++;
		}
	}
cout<<e;
}


						///****SaJib_ShaYan****///
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define pf push_front
#define mk make_pair
//const int MAX=200005;

//vector<ll>grap[MAX],vc;
//bool visit[MAX];

void solve()
{
	    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

		string ss,st,sp;
		cin>>n>>ss>>st;

		ll sum=0;
		c=0;
		for(i=0;i<n;i++)
		{
			if(ss[i]!=st[i])
			{
			   c++;
			   if(c==1)d=i+1;
			}
			if(c==2)
			{

				j=(i+1)-d;
				if(j==1)
				{
					swap(ss[d-1],ss[i]);
					if(ss[d-1]==st[d-1]&&ss[i]==st[i])sum++;
					else
					{
						swap(ss[d-1],ss[i]);
						sum++;
						i--;
						c=0;
					}
				}
				else
				{
					sum++;
					i--;
					c=0;
				}

				c=0;
			}
		}
		if(c>0)sum++;

		cout<<sum<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	  ll tc;
		  //cin>>tc;
		  ///while(tc--)
		///{
			   solve();
		  //}

    return 0;
}


						///****SaJib_ShaYan****///
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define pf push_front
#define mk make_pair
//const int MAX=200005;

//vector<ll>grap[MAX],vc;
//bool visit[MAX];

void solve()
{
	    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

		string ss,st,sp;
		cin>>n>>ss>>st;

		ll sum=0;
		c=0;
		for(i=0;i<n;i++)
		{
			if(ss[i]!=st[i])
			{
			   c++;
			   if(c==1)d=i+1;
			}
			if(c==2)
			{

				j=(i+1)-d;
				if(j==1)
				{
					swap(ss[d-1],ss[i]);
					if(ss[d-1]==st[d-1]&&ss[i]==st[i])sum++;
					else
					{
						sum++;
						i--;
						c=0;
					}
				}
				else sum+=2;

				c=0;
			}
		}
		if(c>0)sum++;

		cout<<sum<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	  ll tc;
		 // cin>>tc;
		 // while(tc--)
		 // {
			   solve();
		  //}

    return 0;
}


						///****SaJib_ShaYan****///
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define pf push_front
#define mk make_pair
//const int MAX=200005;

//vector<ll>grap[MAX],vc;
//bool visit[MAX];

void solve()
{
	    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

		string ss,st,sp;
		cin>>n>>ss>>st;

		ll sum=0;
		c=0;
		for(i=0;i<n;i++)
		{
			if(ss[i]!=st[i])
			{
			   c++;
			   if(c==1)d=i+1;
			}
			if(c==2)
			{

				j=(i+1)-d;
				if(j==1)
				{
					swap(ss[d-1],ss[i]);
					if(ss[d-1]==st[d-1]&&ss[i]==st[i])sum++;
					else
					{
						swap(ss[d-1],ss[i]);
						sum++;
						i--;
						c=0;
					}
				}
				else sum+=2;

				c=0;
			}
		}
		if(c>0)sum++;

		cout<<sum<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	  ll tc;
		 // cin>>tc;
		 // while(tc--)
		 // {
			   solve();
		  //}

    return 0;
}


						///****SaJib_ShaYan****///
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define pf push_front
#define mk make_pair
//const int MAX=200005;

//vector<ll>grap[MAX],vc;
//bool visit[MAX];

void solve()
{
	    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

		string ss,st,sp;
		cin>>n>>ss>>st;

		ll sum=0;
		for(i=0;i<st.size();i++)
		{
			if(ss[i]!=st[i])sum++;
		}
		//cout<<sum<<endl;
		c=0;
		for(i=0;i<st.size();i++)
		{
			if(ss[i]!=st[i])
			{
				c++;
				if(c==1)d=i;
			}
			if(c==2)
			{

				j=i-d;
				if(j<2)sum--;

				c=0;
			}
		}
		cout<<sum<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	  ll tc;

		  solve();

    return 0;
}


						///****SaJib_ShaYan****///
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define pf push_front
#define mk make_pair
//const int MAX=200005;

//vector<ll>grap[MAX],vc;
//bool visit[MAX];

void solve()
{
	    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

		string ss,st,sp;
		cin>>n>>ss>>st;

		ll sum=0;
		for(i=0;i<st.size();i++)
		{
			if(ss[i]!=st[i])sum++;
		}
		//cout<<sum<<endl;
		c=0;
		for(i=0;i<st.size();i++)
		{
			if(ss[i]!=st[i])
			{
				c++;
				if(c==1)d=i;
			}
			if(c==2)
			{

				j=i-d;
				if(j<2)
				{
					if(ss[d]==st[i]&&ss[i]==st[d])sum--;
				}

				c=0;
			}
		}
		cout<<sum<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	  ll tc;

		  solve();

    return 0;
}


						///****SaJib_ShaYan****///
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define pf push_front
#define mk make_pair
//const int MAX=200005;

//vector<ll>grap[MAX],vc;
//bool visit[MAX];

void solve()
{
	    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

		string ss,st,sp;
		cin>>n>>ss>>st;

		ll sum=0;
		for(i=0;i<st.size();i++)
		{
			if(ss[i]!=st[i])sum++;
		}
		//cout<<sum<<endl;
		c=0;
		for(i=0;i<st.size();i++)
		{
			if(ss[i]!=st[i])
			{
				c++;
				if(c==1)d=i;
			}
			if(c==2)
			{

				j=i-d;
				if(j==1)
				{
					if(ss[d]==st[i]&&ss[i]==st[d])sum--;
				}

				c=0;
			}
		}
		cout<<sum<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	  ll tc;

		  solve();

    return 0;
}


						///****SaJib_ShaYan****///
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define pb push_back
#define pf push_front
#define mk make_pair
//const int MAX=200005;

//vector<ll>grap[MAX],vc;
//bool visit[MAX];

void solve()
{
	    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

		string ss,st,sp;
		cin>>n>>ss>>st;

		ll sum=0;
		c=0;
		for(i=0;i<n;i++)
		{
			if(ss[i]!=st[i])
			{
			   c++;
			   if(c==1)d=i+1;
			}
			if(c==2)
			{

				j=(i+1)-d;
				if(j==1)
				{
					swap(ss[d-1],ss[i]);
					if(ss[d-1]==st[d-1]&&ss[i]==st[i])sum++;
					else
					{
						sum++;
						i--;
						c=0;
					}
				}
				else sum+=2;

				c=0;
			}
		}

		cout<<sum<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	  ll tc;

		  solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n,i,count=0,cost=0,j=0;
     cin>>n;
     vector<int>zero;
     vector<int>one;
     string s1,s2;
     cin>>s1>>s2;
     int a[n],b[n];
     for(i=0;i<n;i++)
     {
          a[i]=s1[i]-'0';
          b[i]=s2[i]-'0';
     }
     for(i=0;i<n;i++)
     {

          if(a[i]!=b[i])
          {
               if(a[i]==0)
                    zero.push_back(i);
               else
                    one.push_back(i);
          }
     }
     i=0;
     j=0;
     if(zero.size()==0)
     cost=one.size();
     else if(one.size()==0)
     cost=zero.size();
          while(i<zero.size() && j<one.size() )
          {

               if(abs(one[j]-zero[i])<2)
               {
                     cost=cost+abs(one[j]-zero[i]);
                      i++;
                      j++;
               }
               else if(one[j]>zero[i])
               {
                    cost=cost+1;
                    i++;
               }
               else
               {
                    cost+=1;
                    j++;
               }
          }
     if(i!=zero.size())
          cost=cost+zero.size()-i;
     if(j!=one.size())
          cost=cost+one.size()-j;
     cout<<cost<<endl;
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n,i,count=0,cost=0,j=0;
     cin>>n;
     vector<int>zero;
     vector<int>one;
     string s1,s2;
     cin>>s1>>s2;
     int a[n],b[n];
     for(i=0;i<n;i++)
     {
          a[i]=s1[i]-'0';
          b[i]=s2[i]-'0';
     }
     for(i=0;i<n;i++)
     {

          if(a[i]!=b[i])
          {
               if(a[i]==0)
                    zero.push_back(i);
               else
                    one.push_back(i);
          }
     }
     i=0;
     j=0;
     if(zero.size()==0)
     cost=one.size();
     else if(one.size()==0)
     cost=zero.size();
          while(i<zero.size() && j<one.size() )
          {

               if(abs(one[j]-zero[i])<=2)
               {
                     cost=cost+abs(one[j]-zero[i]);
                      i++;
                      j++;
               }
               else if(one[j]>zero[i])
               {
                    cost=cost+1;
                    i++;
               }
               else
               {
                    cost+=1;
                    j++;
               }
          }
     if(i!=zero.size())
          cost=cost+zero.size()-i;
     if(j!=one.size())
          cost=cost+one.size()-j;
     cout<<cost<<endl;
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n,i,count=0,cost=0,j=0;
     cin>>n;
     vector<int>zero;
     vector<int>one;
     string s1,s2;
     cin>>s1>>s2;
     int a[n],b[n];
     for(i=0;i<n;i++)
     {
          a[i]=s1[i]-'0';
          b[i]=s2[i]-'0';
     }
     for(i=0;i<n;i++)
     {

          if(a[i]!=b[i])
          {
               if(a[i]==0)
                    zero.push_back(i);
               else
                    one.push_back(i);
          }
     }
     i=0;
     j=0;
          while(i<zero.size() && j<one.size() )
          {
               if(abs(one[j]-zero[i])<=2)
               {
                     cost=cost+abs(one[j]-zero[i]);
                      i++;
                      j++;
               }
               else if(one[j]>zero[i])
               {
                    cost=cost+1;
                    i++;
               }
               else
               {
                    cost+=1;
                    j++;
               }
          }
     cout<<cost<<endl;
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n,i,count=0,cost=0;
     cin>>n;
     vector<int>zero;
     vector<int>one;
     string s1,s2;
     cin>>s1>>s2;
     int a[n],b[n];
     for(i=0;i<n;i++)
     {
          a[i]=s1[i]-'0';
          b[i]=s2[i]-'0';
     }
     for(i=0;i<n;i++)
     {

          if(a[i]!=b[i])
          {
               count++;
               if(a[i]==0)
                    zero.push_back(i);
               else
                    one.push_back(i);
          }
     }
     i=0;
     while(count--)
     {
          if(i<zero.size() && i<one.size() && abs(one[i]-zero[i])<=2)
          {
               cost=cost+abs(one[i]-zero[i]);
               i++;
               count--;
          }
          else if(i<zero.size()  && i<one.size() && abs(one[i]-zero[i])>2)
          {
               cost=cost+2;
               count--;
          }
          else
          cost=cost+1;
     }
     cout<<cost<<endl;
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n,i,count=0,cost=0;
     cin>>n;
     vector<int>zero;
     vector<int>one;
     string s1,s2;
     cin>>s1>>s2;
     int a[n],b[n];
     for(i=0;i<n;i++)
     {
          a[i]=s1[i]-'0';
          b[i]=s2[i]-'0';
     }
     for(i=0;i<n;i++)
     {

          if(a[i]!=b[i])
          {
               count++;
               if(a[i]==0)
                    zero.push_back(i);
               else
                    one.push_back(i);
          }
     }
     i=0;
     while(count--)
     {
          if(i<zero.size() && i<one.size() && abs(one[i]-zero[i])<=2)
          {
               cost=cost+abs(one[i]-zero[i]);
               i++;
               count--;
               cout<<count<<endl;
          }
          else if(i<zero.size()  && i<one.size() && abs(one[i]-zero[i])>2)
          {
               cost=cost+2;
               count--;
          }
          else
          cost=cost+1;
     }
     cout<<cost<<endl;
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n,i,count=0,cost=0,j=0;
     cin>>n;
     vector<int>zero;
     vector<int>one;
     string s1,s2;
     cin>>s1>>s2;
     int a[n],b[n];
     for(i=0;i<n;i++)
     {
          a[i]=s1[i]-'0';
          b[i]=s2[i]-'0';
     }
     for(i=0;i<n;i++)
     {

          if(a[i]!=b[i])
          {
               if(a[i]==0)
                    zero.push_back(i);
               else
                    one.push_back(i);
          }
     }
     i=0;
     j=0;
     if(zero.size()==0)
     cost=one.size();
     else if(one.size()==0)
     cost=zero.size();
          while(i<zero.size() && j<one.size() )
          {

               if(abs(one[j]-zero[i])<=2)
               {
                     cost=cost+abs(one[j]-zero[i]);
                      i++;
                      j++;
               }
               else if(one[j]>zero[i])
               {
                    cost=cost+1;
                    i++;
               }
               else
               {
                    cost+=1;
                    j++;
               }
          }
     cout<<cost<<endl;
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n,i,count=0,cost=0,j=0;
     cin>>n;
     vector<int>zero;
     vector<int>one;
     string s1,s2;
     cin>>s1>>s2;
     int a[n],b[n];
     for(i=0;i<n;i++)
     {
          a[i]=s1[i]-'0';
          b[i]=s2[i]-'0';
     }
     for(i=0;i<n;i++)
     {

          if(a[i]!=b[i])
          {
               if(a[i]==0)
                    zero.push_back(i);
               else
                    one.push_back(i);
          }
     }
     i=0;
     j=0;
     int flag=0;
     if(zero.size()==0)
     {
          cost=one.size();
          flag=1;
     }
     else if(one.size()==0)
     {
          cost=zero.size();
          flag=1;
     }
          while(i<zero.size() && j<one.size() )
          {

               if(abs(one[j]-zero[i])<2)
               {
                     cost=cost+abs(one[j]-zero[i]);
                      i++;
                      j++;
               }
               else if(one[j]>zero[i])
               {
                    cost=cost+1;
                    i++;
               }
               else
               {
                    cost+=1;
                    j++;
               }
          }
     if(i!=zero.size() && flag==0)
          cost=cost+zero.size()-i;
     if(j!=one.size() && flag==0)
          cost=cost+one.size()-j;
     cout<<cost<<endl;
     return 0;
}


#include<iostream>
using namespace std;
#include<vector>
int main()
{
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    vector<int>v;
    for(int i=0; i<n; i++) {
        if(a[i]!=b[i])
            v.push_back(i+1);
    }
    int y=v.size();
    int ans=0;
    for(int i=0; i<y; i++) {
        if(i==y-1)ans++;
        else {
            if(v[i+1]-v[i]<=2) {
                ans+=v[i+1]-v[i];
                i++;
            }
            else ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}


#include<iostream>
using namespace std;
#include<vector>
int main()
{
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    vector<int>v,c;
    for(int i=0; i<n; i++) {
        if(a[i]!=b[i]) {
            if(a[i]=='0')
                v.push_back(i+1);
            else
                c.push_back(i+1);
        }
    }
    int y=v.size();
    int x=c.size();
    int ans=0,i=0,j=0;
    while(i<y || j<x) {
        if(i==y) {
            j++;
            ans++;
        }
        else if(j==x) {
            i++;
            ans++;
        }
        else if(v[i]<c[j]) {
            if(c[j]-v[i]>2)
            {
                ans++;
                i++;
            }
            else {
                ans+=c[j]-v[i];
                i++;
                j++;
            }
        }

        else if(v[i]<c[j]) {
            if(c[j]-v[i]>2)
            {
                ans++;
                i++;
            }
            else {
                ans+=c[j]-v[i];
                i++;
                j++;
            }
        }
        else if(v[i]>c[j]) {
            if(v[i]-c[j]>2)
            {
                ans++;
                j++;
            }
            else {
                ans+=v[i]-c[j];
                i++;
                j++;
            }
        }

    }
    cout<<ans<<endl;

    return 0;
}


#include<iostream>
using namespace std;
#include<vector>
int main()
{
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    vector<int>v,c;
    for(int i=0; i<n; i++) {
        if(a[i]!=b[i]) {
            if(a[i]=='0')
                v.push_back(i+1);
            else
                c.push_back(i+1);
        }
    }
    int y=v.size();
    int x=c.size();
    int ans=0,i=0,j=0;
    while(i<y || j<x) {
        if(i==y) {
            j++;
            ans++;
        }
        else if(j==x) {
            i++;
            ans++;
        }
        else if(v[i]<c[j]) {
            if(c[j]-v[i]>2)
            {
                ans++;
                i++;
            }
            else if(c[j]-v[i]==2
                    && i<y-1 && v[i+1]<c[j])
            {
                ans++;
                i++;
            }

            else {
                ans+=c[j]-v[i];
                i++;
                j++;
            }
        }

        else if(v[i]>c[j]) {
            if(v[i]-c[j]>2)
            {
                ans++;
                j++;
            }
            else if(v[i]-c[j]==2
                    && j<x-1 && c[j+1]<v[i])
            {
                ans++;
                i++;
            }

            else {
                ans+=v[i]-c[j];
                i++;
                j++;
            }
        }

    }
    cout<<ans<<endl;

    return 0;
}


#include<iostream>
using namespace std;
#include<vector>
int main()
{
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    vector<int>v,c;
    for(int i=0; i<n; i++) {
        if(a[i]!=b[i]) {
            if(a[i]=='0')
                v.push_back(i+1);
            else
                c.push_back(i+1);
        }
    }
    int y=v.size();
    int x=c.size();
    int ans=0,i=0,j=0;
    while(i<y || j<x) {
        if(i==y) {
            j++;
            ans++;
        }
        else if(j==x) {
            i++;
            ans++;
        }
        else if(v[i]<c[j]) {
            if(c[j]-v[i]>=2)
            {
                ans++;
                i++;
            }

            else {
                ans+=c[j]-v[i];
                i++;
                j++;
            }
        }

        else if(v[i]>c[j]) {
            if(v[i]-c[j]>=2)
            {
                ans++;
                j++;
            }

            else {
                ans+=v[i]-c[j];
                i++;
                j++;
            }
        }

    }
    cout<<ans<<endl;

    return 0;
}


#include<iostream>
using namespace std;
#include<vector>
int main()
{
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    vector<int>v;
    for(int i=0; i<n; i++) {
        if(a[i]!=b[i])
            v.push_back(i+1);
    }
    int y=v.size();
    int ans=0;
    for(int i=0; i<y; i++) {
        if(i=y-1)ans++;
        else {
            if(v[i+1]-v[i]<=2) {
                ans+=v[i+1]-v[i];
                i++;
            }
            else ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int cost=0;
    cin>>n;
    string a;
    string b;
    cin>>a;
    cin>>b;
    for(int i=0; i<n; i++){
        if(a[i] != b[i]){
            if(a[i+1] != b[i+1] && a[i] != a[i+1] && i>=1 && (i+1)<=n){
                i=i+2;
            }
            cost++;
            if(i > n){
                break;
            }
            //cout<<i<<" ";
        }
    }
   cout<<cost;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int cost=0;
    cin>>n;
    string a;
    string b;
    cin>>a;
    cin>>b;
    for(int i=0; i<n; i++){
        if(a[i] != b[i]){
            if(a[i+1] != b[i+1] && a[i] != a[i+1] && (i+1)<n){
                i=i+2;
            }
            cost++;

        }
         if(i >= n){
                break;
        }
    }
   cout<<cost;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int cost=0;
    cin>>n;
    string a;
    string b;
    cin>>a;
    cin>>b;
    for(int i=1; i<=n; i++){
        if(a[i] != b[i]){
            if(a[i+1] != b[i+1] && a[i] != a[i+1]){
                i=i+2;
            }
            cost++;
            if(i > n){
                break;
            }
            //cout<<i<<" ";
        }
    }
   cout<<cost;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int cost=0;
    cin>>n;
    string a;
    string b;
    cin>>a;
    cin>>b;
    for(int i=0; i<n; i++){
        if(a[i] != b[i]){
            if(a[i+1] != b[i+1] && (i+1)<n){
                i=i+2;
            }
            cost++;
        }
    }
   cout<<cost;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int cost=0;
    cin>>n;
    string a;
    string b;
    cin>>a;
    cin>>b;
    for(int i=0; i<n; i++){
        if(a[i] != b[i]){
            if(a[i+1] != b[i+1] && a[i] != a[i+1] && (i+1)<n){
                i++;
            }
            cost++;
           // cout<<i<<" ";
        }
    }
   cout<<cost;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int cost=0;
    cin>>n;
    string a;
    string b;
    cin>>a;
    cin>>b;
    for(int i=0; i<n; i++){
        if(a[i] != b[i]){
            if(a[i+1] != b[i+1] && a[i] != a[i+1] && (i+1)<n){
                i=i+2;
            }
            cost++;
            if(i >= n){
                break;
            }
        }
    }
   cout<<cost;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int cost=0;
    cin>>n;
    string a;
    string b;
    cin>>a;
    cin>>b;
    for(int i=0; i<n; i++){
        if(a[i] != b[i]){
            if(a[i+1] != b[i+1] && a[i] != a[i+1] && (i+1)<n){
                i=i+2;
            }
            cost++;
            if(i > n){
                break;
            }
        }
    }
   cout<<cost;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int cost=0;
    cin>>n;
    string a;
    string b;
    cin>>a;
    cin>>b;
    for(int i=0; i<n; i++){
        if(a[i] != b[i]){
            if(a[i+1] != b[i+1]){
                i=i+2;
            }
            cost++;
            if(i >= n){
                break;
            }
            //cout<<i<<" "<<cost<<" ";
        }
    }
   cout<<cost;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int cost=0;
    cin>>n;
    string a;
    string b;
    cin>>a;
    cin>>b;
    for(int i=0; i<n; i++){
        if(a[i] != b[i]){
            if(a[i+1] != b[i+1] && a[i] != a[i+1] && i>=1 && (i+1)<=n){
                i=i+2;
            }
            cost++;
            if(i > n){
                break;
            }
            cout<<i<<" ";
        }
    }
   cout<<cost;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int cost=0;
    cin>>n;
    string a;
    string b;
    cin>>a;
    cin>>b;
    for(int i=0; i<n; i++){
        if(a[i] != b[i]){
            if(a[i+1] != b[i+1] && a[i] != a[i+1] && (i+1)<n){
                i=i+2;
            }
            cost++;
            if(i > n){
                break;
            }
            //cout<<i<<" ";
        }
    }
   cout<<cost;

}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int cost=0;
    cin>>n;
    string a;
    string b;
    cin>>a;
    cin>>b;
    for(int i=0; i<n; i++){
        if(a[i] != b[i] && a[i] != a[i+1]){
            if(a[i+1] != b[i+1]){
                i=i+2;
            }
            cost++;
            if(i >= n){
                break;
            }
            //cout<<i<<" "<<cost<<" ";
        }
    }
   cout<<cost;

}


///...................................*****.................................................///
///                  Mujahidul Islam ( mujahidulislam2923@gmail.com )                       ///
///                  Department of Ict                                                      ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

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

#define           CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define           ll               long long int
#define           ull              unsigned long long int
#define           pii              pair < int, int>
#define           pll              pair < ll, ll>
#define           MOD              1000000007
#define           vi               vector<int>
#define           vl               vector<ll>
#define           pb               push_back
#define           sc               scanf
#define           pf               printf
#define         scin(x)            scanf("%d",&(x))
#define        scin2(x,y)          scanf("%d %d",&(x),&(y))
#define         scln(x)            scanf("%lld",&(x))
#define        scln2(x,y)          scanf("%lld %lld",&(x),&(y))
#define       min3(a,b,c)          min(a,min(b,c))
#define       min4(a,b,c,d)        min(d,min(a,min(b,c)))
#define       max3(a,b,c)          max(a,max(b,c))
#define       max4(a,b,c,d)        max(d,max(a,max(b,c)))
#define         ms(a,b)            memset(a,b,sizeof(a))
#define           mp               make_pair
#define       gcd(a, b)            __gcd(a,b)
#define       lcm(a, b)            ((a)*(b)/gcd(a,b))
#define         input              freopen("input.txt","rt", stdin)
#define         output             freopen("output.txt","wt", stdout)
#define           PI               2*acos(0.0)
#define     rep( i , a , b )       for( i=a ; i<b ; i++)
#define     rev( i , a , b )       for( i=a ; i>=b ; i--)
#define     repx( i ,a,b, x)       for( i=a ; i<b ; i+=x)
#define       CASEL(t)             printf("Case %d:\n",t)
#define     RUN_CASE(t,T)          for(__typeof(t) t=1;t<=T;t++)

///priority_queue<int,vector<int>,greater<int> >pq;
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

int main()
{
    CIN;
    ll n,cnt=0,ck=0;
    cin>>n;
    string a,b;
    cin>>a>>b;
    a+='1';
    b+='1';

    for(int i=0; i<n; i++)
    {
        if(a[i]==b[i])
        {
            continue;
        }
        if(ck==1 && a[i]!=b[i])
        {
            ck=0;
            cnt++;
            continue;
        }

        if(a[i]!=b[i] && a[i+1]!=b[i+1])
        {
            if(a[i]==a[i+1])
            {
                if(i>=n-2 && a[i+2]!=b[i+2])
                {
                    cnt+=2;
                    i++;
                }
                else
                {
                    cnt+=2;
                }
            }
            else
                cnt++;
            i++;
        }
        else if(a[i]!=b[i] && a[i+1]==b[i+1])
        {
            cnt++;
            ck=1;
            i++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}


///...................................*****.................................................///
///                  Mujahidul Islam ( mujahidulislam2923@gmail.com )                       ///
///                  Department of Ict                                                      ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

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

#define           CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define           ll               long long int
#define           ull              unsigned long long int
#define           pii              pair < int, int>
#define           pll              pair < ll, ll>
#define           MOD              1000000007
#define           vi               vector<int>
#define           vl               vector<ll>
#define           pb               push_back
#define           sc               scanf
#define           pf               printf
#define         scin(x)            scanf("%d",&(x))
#define        scin2(x,y)          scanf("%d %d",&(x),&(y))
#define         scln(x)            scanf("%lld",&(x))
#define        scln2(x,y)          scanf("%lld %lld",&(x),&(y))
#define       min3(a,b,c)          min(a,min(b,c))
#define       min4(a,b,c,d)        min(d,min(a,min(b,c)))
#define       max3(a,b,c)          max(a,max(b,c))
#define       max4(a,b,c,d)        max(d,max(a,max(b,c)))
#define         ms(a,b)            memset(a,b,sizeof(a))
#define           mp               make_pair
#define       gcd(a, b)            __gcd(a,b)
#define       lcm(a, b)            ((a)*(b)/gcd(a,b))
#define         input              freopen("input.txt","rt", stdin)
#define         output             freopen("output.txt","wt", stdout)
#define           PI               2*acos(0.0)
#define     rep( i , a , b )       for( i=a ; i<b ; i++)
#define     rev( i , a , b )       for( i=a ; i>=b ; i--)
#define     repx( i ,a,b, x)       for( i=a ; i<b ; i+=x)
#define       CASEL(t)             printf("Case %d:\n",t)
#define     RUN_CASE(t,T)          for(__typeof(t) t=1;t<=T;t++)

///priority_queue<int,vector<int>,greater<int> >pq;
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

int main()
{
    CIN;
    ll n,cnt=0,ck=0;
    cin>>n;
    string a,b;
    cin>>a>>b;
    a+='1';
    b+='1';

    for(int i=0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            continue;
        }
        if(ck==1 && a[i]!=b[i])
        {
            ck=0;
            cnt++;
            continue;
        }
        if(a[i]!=b[i] && a[i+1]!=b[i+1])
        {
            cnt++;
            i++;
        }
        else if(a[i]!=b[i] && a[i+1]==b[i+1])
        {
            cnt++;
            ck=1;
            i++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}


///...................................*****.................................................///
///                  Mujahidul Islam ( mujahidulislam2923@gmail.com )                       ///
///                  Department of Ict                                                      ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

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

#define           CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define           ll               long long int
#define           ull              unsigned long long int
#define           pii              pair < int, int>
#define           pll              pair < ll, ll>
#define           MOD              1000000007
#define           vi               vector<int>
#define           vl               vector<ll>
#define           pb               push_back
#define           sc               scanf
#define           pf               printf
#define         scin(x)            scanf("%d",&(x))
#define        scin2(x,y)          scanf("%d %d",&(x),&(y))
#define         scln(x)            scanf("%lld",&(x))
#define        scln2(x,y)          scanf("%lld %lld",&(x),&(y))
#define       min3(a,b,c)          min(a,min(b,c))
#define       min4(a,b,c,d)        min(d,min(a,min(b,c)))
#define       max3(a,b,c)          max(a,max(b,c))
#define       max4(a,b,c,d)        max(d,max(a,max(b,c)))
#define         ms(a,b)            memset(a,b,sizeof(a))
#define           mp               make_pair
#define       gcd(a, b)            __gcd(a,b)
#define       lcm(a, b)            ((a)*(b)/gcd(a,b))
#define         input              freopen("input.txt","rt", stdin)
#define         output             freopen("output.txt","wt", stdout)
#define           PI               2*acos(0.0)
#define     rep( i , a , b )       for( i=a ; i<b ; i++)
#define     rev( i , a , b )       for( i=a ; i>=b ; i--)
#define     repx( i ,a,b, x)       for( i=a ; i<b ; i+=x)
#define       CASEL(t)             printf("Case %d:\n",t)
#define     RUN_CASE(t,T)          for(__typeof(t) t=1;t<=T;t++)

///priority_queue<int,vector<int>,greater<int> >pq;
///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

int main()
{
    CIN;
    ll n,cnt=0,ck=0;
    cin>>n;
    string a,b;
    cin>>a>>b;
    a+='1';
    b+='1';

    for(int i=0; i<n; i++)
    {
        if(a[i]==b[i])
        {
            continue;
        }
        if(ck==1 && a[i]!=b[i])
        {
            ck=0;
            cnt++;
            continue;
        }

        if(a[i]!=b[i] && a[i+1]!=b[i+1])
        {
            if(a[i]==a[i+1])
            {
                if(i<=n-2 && a[i+2]!=b[i+2])
                {
                    cnt+=2;
                    i++;
                }
                else
                {
                    cnt+=2;
                }
            }
            else
                cnt++;
            i++;
        }
        else if(a[i]!=b[i] && a[i+1]==b[i+1])
        {
            cnt++;
            ck=1;
            i++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}