#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
            x = link[x];
        return x;
    }

    void unite(int a, int b)
    {
        int pa = link[a];
        int pb = link[b];

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            ans++;
            place.emplace_back(i);
        }
    }
    cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
        {
            link[x] = link[link[x]];
            x = link[x];
        }
        return x;
    }

    void unite(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    //int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            //ans++;
            place.emplace_back(i);
        }
    }/*
    if(place.size() == 0)
        cout<<0<<'\n';
    else*/
    int ans = place.size();
    cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];
    vector<int>ss;
    dsu()
    {
        for(int i=1;i<n;i++)
            link[i] = i;
    }

    int find(int x);
    {
        while(x != link[x])
            x = link[x];
        return x;
    }

    void unite(int a, int b)
    {
        int pa = link[a];
        int pb = link[b];

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            ans++;
            place.emplace_back(i);
        }
    }
    cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<=n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
        {
            x = link[x];
        }
        return x;
    }

    void unite(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            ans++;
            place.emplace_back(i);
        }
    }
        cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


//https://codeforces.com/contest/25/problem/dsu
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<=n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
        {
            x = link[x];
        }
        return x;
    }

    void unite(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            ans++;
            place.emplace_back(i);
        }
    }
        cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<=n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
        {
            link[x] = link[link[x]];
            x = link[x];
        }
        return x;
    }

    void unite(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            ans++;
            place.emplace_back(i);
        }
    }
    if(place.size() == 0)
        cout<<0<<'\n';
    else
        cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


//https://codeforces.com/contest/25/problem/dsu
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<=n;i++)
        {
            link[i] = i;
            sz[i] = 1;
        }
    }

    int find(int x)
    {
        while(x != link[x])
        {
            x = link[x];
        }
        return x;
    }

    void unite(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            ans++;
            place.emplace_back(i);
        }
    }
        cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
            x = link[x];
        return x;
    }

    void unite(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            ans++;
            place.emplace_back(i);
        }
    }
    if(place.size() == 0)
        cout<<0<<'\n';
    else
        cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
        {
            link[x] = link[link[x]];
            x = link[x];
        }
        return x;
    }

    void unite(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            //ans++;
            place.emplace_back(i);
        }
    }
    if(place.size() == 0)
        cout<<0<<'\n';
    else
        cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
            x = link[x];
        return x;
    }

    void unite(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            ans++;
            place.emplace_back(i);
        }
    }/*
    if(place.size() == 0)
        cout<<0<<'\n';
    else*/
        cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
            x = link[x];
        return x;
    }

    void unite(int a, int b)
    {
        int pa = link[a];
        int pb = link[b];

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            ans++;
            place.emplace_back(i);
        }
    }
    if(place.size() == 0)
        cout<<0<<'\n';
    else
        cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
        {
            link[x] = link[link[x]];
            x = link[x];
        }
        return x;
    }

    void unite(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            //ans++;
            place.emplace_back(i);
        }
    }
    if(place.size() == 0)
        cout<<0<<'\n';
    else
        ans = place.size();
    cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
            x = link[x];
        return x;
    }

    void unite(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    //int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            //ans++;
            place.emplace_back(i);
        }
    }/*
    if(place.size() == 0)
        cout<<0<<'\n';
    else*/
    int ans = place.size();
    cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<=n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
        {
            link[x] = link[link[x]];
            x = link[x];
        }
        return x;
    }

    void unite(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            ans++;
            place.emplace_back(i);
        }
    }
        cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int N = 1005;
int n;

struct dsu
{
    int link[N], sz[N];

    dsu()
    {
        for(int i=1;i<n;i++)
            link[i] = i;
    }

    int find(int x)
    {
        while(x != link[x])
        {
            link[x] = link[link[x]];
            x = link[x];
        }
        return x;
    }

    void unite(int a, int b)
    {
        int pa = find(a);
        int pb = find(b);

        if(pa == pb)
            return;

        if(sz[pa] < sz[pb])
            swap(pa, pb);
        sz[pa]+=sz[pb];
        sz[pb] = 0;
        link[pb] = link[pa];
    }
};

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

    cin>>n;
    dsu uf;
    vector< pair<int, int> >rem;
    vector<int>place;
    for(int i=0;i<n-1;i++)
    {
        int a, b;
        cin>>a>>b;
        if(uf.find(a) == uf.find(b))
            rem.push_back({a, b});
        else
            uf.unite(a, b);
    }

    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(i == uf.find(i))
        {
            ans++;
            place.emplace_back(i);
        }
    }
    if(place.size() == 0)
        cout<<0<<'\n';
    else
        cout<<ans-1<<'\n';

    for(int i=0;i<ans-1;i++)
        cout<<rem[i].first<<' '<<rem[i].second<<' '<<place[i]<<' '<<place[i+1]<<'\n';

    return 0;
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int parent[1009] ,n, x, y  ,vis[1009];;
vector<pair<int, int> > v ,close;
vector<int> open;
void make_set(int v)
{
	parent[v] = v;
}
int find_set(int v)
{
	if(v == parent[v])
		return v ;
	return parent[v] = find_set(parent[v]);
}
void union_set(int a, int b)
{
    a = find_set(a), b = find_set(b);
	if(a != b)
		parent[b] = a;
}
int main()
{
	cin >> n;
	for(int i=1;i<=n;i++)
        make_set(i);
	for(int i = 0; i < n - 1; i++)
	{
		cin >> x >> y;
		v.push_back({x, y});
	}
    for(int i=0;i<n-1;i++)
    {
        int a=v[i].first , b=v[i].second;
        if(find_set(a)!=find_set(b))
            union_set(a,b);
        else
            close.push_back(v[i]);
    }
    for(int i=1;i<=n;i++)
        find_set(i);
    for(int i=1;i<=n;i++)
        if(vis[parent[i]]==0)
        open.push_back(i) , vis[parent[i]]++;
    cout<<open.size()-1<<endl;
    for(int i=1;i<open.size();i++)
    {
        cout<<close.back().first<<" "<<close.back().second<<" "<<open[0]<<" "<<open[i]<<endl;
        close.pop_back();
    }
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int parent[1009] ,n, x, y  ,vis[1009];;
vector<pair<int, int> > v ,close;
vector<int> open;
void make_set(int v)
{
	parent[v] = v;
}
int find_set(int v)
{
	if(v == parent[v])
		return v ;
	return parent[v] = find_set(parent[v]);
}
void union_set(int a, int b)
{
    a = find_set(a), b = find_set(b);
	if(a != b)
		parent[b] = a;
}
int main()
{
	cin >> n;
	for(int i=1;i<=n;i++)
        make_set(i);
	for(int i = 0; i < n - 1; i++)
	{
		cin >> x >> y;
		v.push_back({x, y});
	}
    for(int i=0;i<n-1;i++)
    {
        int a=v[i].first , b=v[i].second;
        if(find_set(a)!=find_set(b))
            union_set(a,b);
        else
            close.push_back(v[i]);
    }
    for(int i=1;i<=n;i++)
        find_set(i);
         for(int i=1;i<=6;i++) cout << parent[i] <<' ';
    cout<<endl;
    for(int i=1;i<=n;i++)
        if(vis[parent[i]]==0)
        open.push_back(i) , vis[parent[i]]++;
    cout<<open.size()-1<<endl;
    for(int i=1;i<open.size();i++)
    {
        cout<<close.back().first<<" "<<close.back().second<<" "<<open[0]<<" "<<open[i]<<endl;
        close.pop_back();
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int parent[1009] ,n, x, y  ,vis[1009];;
vector<pair<int, int> > v ,close;
vector<int> open;
void make_set(int v)
{
	parent[v] = v;
}
int find_set(int v)
{
	if(v == parent[v])
		return v ;
	return parent[v] = find_set(parent[v]);
}
void union_set(int a, int b)
{
    a = find_set(a), b = find_set(b);
	if(a != b)
		parent[b] = a;
}
int main()
{
	cin >> n;
	for(int i=1;i<=n;i++)
        make_set(i);
	for(int i = 0; i < n - 1; i++)
	{
		cin >> x >> y;
		v.push_back({x, y});
	}
    for(int i=0;i<n-1;i++)
    {
        int a=v[i].first , b=v[i].second;
        if(find_set(a)!=find_set(b))
            union_set(a,b);
        else
            close.push_back(v[i]);
    }
    for(int i=1;i<=n;i++)
        find_set(i);
    for(int i=1;i<=n;i++)
        if(vis[parent[i]]==0)
        open.push_back(i) , vis[parent[i]]++;
    cout<<open.size()-1<<endl;
    for(int i=1;i<open.size();i++)
    {
        cout<<close.back().first<<" "<<close.back().second<<" "<<open[0]<<" "<<open[i]<<endl;
        close.pop_back();
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int p[1010],n,a,b,vis[1010];
deque<pair<int, int> > v ,pre;
vector<int> nw;
void make_set(int a){  p[a]=a;  }
int find_set(int a){
    if(a==p[a]) return a;
    return p[a]=find_set(p[a]);
}
void union_set(int a ,int b){
    a=find_set(a); b=find_set(b);
    if(a!=b)
        p[a]=b;
}
int main(){
    cin >> n ;
    for(int i=1;i<=n;i++) make_set(i);
    for(int i=0;i<n-1;i++){
        cin >> a >> b ;
        v.push_back({a,b});
    }
    for(int i=0;i<v.size();i++){
        if(find_set(v[i].first) != find_set(v[i].second))
            union_set(v[i].first,v[i].second);
        else
            pre.push_back({v[i].first,v[i].second});
    }
    for(int i=1;i<=n;i++) find_set(i);
    for(int i=1;i<=n;i++){
        if(!vis[p[i]]){
            vis[p[i]]++; nw.push_back(i);
        }
    }
    cout << nw.size()-1 <<'\n';
    for(int i=0;i<nw.size()-1;i++){
        cout << pre.front().first <<' '<<pre.front().second <<' '<< nw[i]<<' '<<nw[i+1];
        pre.pop_front();
        cout << '\n';
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int parent[1009] ,n, x, y  ,vis[1009];;
vector<pair<int, int> > v ,close;
vector<int> open;
void make_set(int v)
{
	parent[v] = v;
}
int find_set(int v)
{
	if(v == parent[v])
		return v ;
	return parent[v] = find_set(parent[v]);
}
void union_set(int a, int b)
{
    a = find_set(a), b = find_set(b);
	if(a != b)
		parent[b] = a;
}
int main()
{
	cin >> n;
	for(int i=1;i<=n;i++)
        make_set(i);
	for(int i = 0; i < n - 1; i++)
	{
		cin >> x >> y;
		v.push_back({x, y});
	}
    for(int i=0;i<n-1;i++)
    {
        int a=v[i].first , b=v[i].second;
        if(find_set(a)!=find_set(b))
            union_set(a,b);
        else
            close.push_back(v[i]);
    }
    for(int i=1;i<=n;i++)
        find_set(i);
         for(int i=1;i<=6;i++) cout << parent[i] <<' ';
    cout<<endl;
    for(int i=1;i<=n;i++)
        if(vis[parent[i]]==0)
        open.push_back(i) , vis[parent[i]]++;
    cout<<open.size()-1<<endl;
    for(int i=1;i<open.size();i++)
    {
        cout<<close.back().first<<" "<<close.back().second<<" "<<open[0]<<" "<<open[i]<<endl;
        close.pop_back();
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int p[1010],n,a,b,vis[1010];
deque<pair<int, int> > v ,pre;
vector<int> nw;
void make_set(int a){  p[a]=a;  }
int find_set(int a){
    if(a==p[a]) return a;
    return p[a]=find_set(p[a]);
}
void union_set(int a ,int b){
    a=find_set(a); b=find_set(b);
    if(a!=b)
        p[a]=b;
}
int main(){
    cin >> n ;
    for(int i=1;i<=n;i++) make_set(i);
    for(int i=0;i<n-1;i++){
        cin >> a >> b ;
        v.push_back({a,b});
    }
    for(int i=0;i<v.size();i++){
        if(find_set(v[i].first) != find_set(v[i].second))
            union_set(v[i].first,v[i].second);
        else
            pre.push({v[i].first,v[i].second});
    }
    for(int i=1;i<=n;i++) find_set(i);
    for(int i=1;i<=n;i++){
        if(!vis[p[i]]){
            vis[p[i]]++; nw.push_back(i);
        }
    }
    cout << nw.size()-1 <<'\n';
    for(int i=0;i<nw.size()-1;i++){
        cout << pre.front().first <<' '<<pre.front().second << nw[i]<<' '<<nw[i+1];
        cout << '\n';
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int p[1010],n,a,b,vis[1010];
deque<pair<int, int> > v ,pre;
vector<int> nw;
void make_set(int a){  p[a]=a;  }
int find_set(int a){
    if(a==p[a]) return a;
    return p[a]=find_set(p[a]);
}
void union_set(int a ,int b){
    a=find_set(a); b=find_set(b);
    if(a!=b)
        p[a]=b;
}
int main(){
    cin >> n ;
    for(int i=1;i<=n;i++) make_set(i);
    for(int i=0;i<n-1;i++){
        cin >> a >> b ;
        v.push_back({a,b});
    }
    for(int i=0;i<v.size();i++){
        if(find_set(v[i].first) != find_set(v[i].second))
            union_set(v[i].first,v[i].second);
        else
            pre.push_back({v[i].first,v[i].second});
    }
    for(int i=1;i<=n;i++) find_set(i);
    for(int i=1;i<=n;i++){
        if(!vis[p[i]]){
            vis[p[i]]++; nw.push_back(i);
        }
    }
    cout << nw.size()-1 <<'\n';
    for(int i=0;i<nw.size()-1;i++){
        cout << pre.front().first <<' '<<pre.front().second << nw[i]<<' '<<nw[i+1];
        cout << '\n';
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int p[1010],n,a,b,vis[1010];
deque<pair<int, int> > v ,pre;
vector<int> nw;
void make_set(int a){  p[a]=a;  }
int find_set(int a){
    if(a==p[a]) return a;
    return p[a]=find_set(p[a]);
}
void union_set(int a ,int b){
    a=find_set(a); b=find_set(b);
    if(a!=b)
        p[a]=b;
}
int main(){
    cin >> n ;
    for(int i=1;i<=n;i++) make_set(i);
    for(int i=0;i<n-1;i++){
        cin >> a >> b ;
        v.push_back({a,b});
    }
    for(int i=0;i<v.size();i++){
        if(find_set(v[i].first) != find_set(v[i].second))
            union_set(v[i].first,v[i].second);
        else
            pre.push_back({v[i].first,v[i].second});
    }
    for(int i=1;i<=n;i++) find_set(i);
    for(int i=1;i<=n;i++){
        if(!vis[p[i]]){
            vis[p[i]]++; nw.push_back(i);
        }
    }
    cout << nw.size()-1 <<'\n';
    for(int i=0;i<nw.size()-1;i++){
        cout << pre.front().first <<' '<<pre.front().second <<' '<< nw[i]<<' '<<nw[i+1];
        cout << '\n';
    }
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<utility>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<limits>
#include <bitset>

#define LL long long
#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

int r[1005];
int siz[1005];
int rcmp1;

int root(int i){
     if(i == r[i]) return i;
     return (r[i] = root(r[i]));
    }

void union_(int u, int v){

        int ru, rv;
        ru = root(u);
        rv = root(v);

        if(ru != rv){
            if(siz[ru] < siz[rv]) swap(ru,rv);
            siz[ru] += siz[rv];
            r[rv] = ru;
          }
     }

int main(){

    int n;
    cin >> n;

    vector<pair<int,int> > a, b;

    for(int i = 1; i <= n; i++) r[i] = i, siz[i] = 1;

    for(int i = 0; i < n-1; i++){
          int x, y;
          cin >> x >> y;

         //if(!rcmp1) rcmp1 = x;

          if(root(x) != root(y)){
                union_(x,y);
             }
          else{
                a.pb(mp(x,y));
          }
       }

    // for(int i = 1; i <= n; i++){
    //      cout  << r[i] << endl;
    //   }

    // for(int i = 1; i <= n; i++){
    //       if(root(i) == i){
    //              rcmp1 = i;
    //              break;
    //           }
    //       }

      for(int i = 2; i <= n; i++){
          if(root(i) != 1){
                b.pb(mp(1,i));
                union_(1,i);
              }
          }

    // int z = max(a.size(), b.size());
    int x = min(a.size(), b.size());

    cout << x << endl;

    for(int j = 0; j < x; j++){
         cout << a[j].f << " " << a[j].s << " " << b[j].f << " " << b[j].s << endl;
      }

    return 0;

}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include<stdio.h>
#include <cstdlib>
#include<stdio.h>
#include<sstream>

using namespace std ;

/*
There's No Impossible
         Once You Start Trying :)
*/

int main(){
    long long int num , con = 0 , rn = 1 , room = 0;
    string rooms;
    char small;
    vector<char>keys;
    bool flag = false;
    cin >> num >> rooms;
    while(rn < num){
        if(islower(rooms[room])){
            keys.push_back(rooms[room]);
        }else{
            small = tolower(rooms[room]);
            for(int i = 0; i < keys.size(); i++){
                if(small == keys[i]){
                    flag = true;
                    keys[i] = '0';
                    sort(keys.rbegin(),keys.rend());
                    keys.pop_back();
                    break;
                }
            }
            if(flag == false){
                con++;
            }
            rn++;
        }
        room++;
        flag = false;
    }
    cout << con << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include<stdio.h>
#include <cstdlib>
#include<stdio.h>
#include<sstream>

using namespace std ;

/*
There's No Impossible
         Once You Start Trying :)
*/

int main(){
    int num , con = 0 , rn = 1 , room = 0;
    string rooms;
    char small;
    vector<char>keys;
    bool flag = false;
    cin >> num >> rooms;
    while(rn < num){
        if(islower(rooms[room])){
            keys.push_back(rooms[room]);
        }else{
            small = tolower(rooms[room]);
            for(int i = 0; i < keys.size(); i++){
                if(small == keys[i]){
                    flag = true;
                    keys[i] = '0';
                    break;
                }
            }
            if(flag == false){
                con++;
            }
            rn++;
        }
        room++;
        flag = false;
    }
    cout << con << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include<stdio.h>
#include <cstdlib>
#include<stdio.h>
#include<sstream>

using namespace std ;

/*
There's No Impossible
         Once You Start Trying :)
*/

int main(){
    int num , con = 0 , rn = 1 , room = 0;
    string rooms;
    char small;
    vector<char>keys;
    bool flag = false;
    cin >> num >> rooms;
    while(rn < num){
        if(islower(rooms[room])){
            keys.push_back(rooms[room]);
        }else{
            small = tolower(rooms[room]);
            for(int i = 0; i < keys.size(); i++){
                if(small == keys[i]){
                    flag = true;
                    keys[i] = '0';
                    sort(keys.rbegin(),keys.rend());
                    keys.pop_back();
                    break;
                }
            }
            if(flag == false){
                con++;
            }
            rn++;
        }
        room++;
        flag = false;
    }
    cout << con << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include<stdio.h>
#include <cstdlib>
#include<stdio.h>
#include<sstream>

using namespace std ;

/*
There's No Impossible
         Once You Start Trying :)
*/

int main(){
    int num , con = 0 , rn = 1 , room = 0;
    string rooms;
    char small;
    map<char,int>keys;
    cin >> num >> rooms;
    while(rn < num){
        if(islower(rooms[room])){
            keys[rooms[room]]++;
        }else{
            small = tolower(rooms[room]);
            if(keys[small] >= 1){
                keys[small]--;
            }else{
                con++;
            }
            rn++;
        }
        room++;
    }
    cout << con << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include<stdio.h>
#include <cstdlib>
#include<stdio.h>
#include<sstream>

using namespace std ;

/*
There's No Impossible
         Once You Start Trying :)
*/

int main(){
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    string alpha1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int num , con = 0 , n , z;
    string rooms;
    vector<int> keys;
    bool flag = false;
    cin >> num;
    cin >> rooms;
    for(int i = 0; i < rooms.size()-1; i+=2){
        for(int m = 0; m < alpha.size();m++){
            if(rooms[i] == alpha[m]){
                n = m;
            }
        }
        for(int y = 0; y < keys.size(); y++){
            if(n-1 == keys[y]){
                flag = true;
                keys[y] = -11;
            }
        }
        keys.push_back(n);
        if(rooms[i+1] != alpha1[n] && flag != true){
            con++;
        }
        flag = false;
    }
    cout << con << endl;
    return 0;
}


#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;
#define ll long long int
const int mod=1e9+7;

int d[333333], k[333333];

int main(){
#pragma comment(linker, "/STACK:268435456")
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif
    int n, i, j, m, l, x, s, r[111];
    char kk, dd, c[1111];
    scanf("%d",&n);
    gets(c);
    for(i=0;i<n-1;i++){
        kk=getchar();
        dd=getchar();
        k[i]=(int)(kk-'a');
        d[i]=(int)(dd-'A');
    }
    for(i=0;i<33;i++){
        r[i]=0;
    }
    s=0;
    for(i=0;i<n-1;i++){
        r[k[i]]++;
        if(r[d[i]]==0){
            s++;
        }
        else{
            r[d[i]]--;
        }
    }
    printf("%d",s);

    return 0;
}


#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;
#define ll long long int
const int mod=1e9+7;

char d[111111], k[111111];

int main(){
#pragma comment(linker, "/STACK:268435456")
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif
    int n, i, j, m, l, x, s;
    map<char,int> kk;
    scanf("%d",&n);
    gets(d);
    s=0;
    for(i=0;i<n-1;i++){
        scanf("%c%c",&k[i],&d[i]);
        k[i]=k[i]-'a'+'A';
    }
    for(i=0;i<n-1;i++){
        if(k[i]!=d[i]){
            if(kk[d[i]]==0){
                s++;
                kk[k[i]]=1;
            }
            else{
                kk[k[i]]--;
            }
        }
    }
    printf("%d",s);

    return 0;
}


#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;
#define ll long long int
const int mod=1e9+7;

int d[1111111], k[1111111];

int main(){
#pragma comment(linker, "/STACK:268435456")
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif
    int n, i, j, m, l, x, s, r[111];
    char kk, dd, c[1111];
    scanf("%d",&n);
    gets(c);
    s=0;
    for(i=0;i<n-1;i++){
        kk=getchar();
        dd=getchar();
        k[i]=(int)(kk-'a');
        d[i]=(int)(dd-'A');
    }
    for(i=0;i<33;i++){
        r[i]=0;
    }
    for(i=0;i<n-1;i++){
        if(k[i]!=d[i]){
            if(r[d[i]]==0){
                s++;
                r[k[i]]++;
            }
            else{
                r[d[i]]--;
            }
        }
    }
    printf("%d",s);

    return 0;
}


#include<cstdio>

using namespace std;

int main()
{
#ifdef D
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int n;
    scanf("%d\n", &n);
    n--;

    int arr[256];
    for (int i = 'A'; i <= 'Z'; i++)
    {
        arr[i] = i + (97 - 65);
    }

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        char c, C;
        scanf("%c%c", &c, &C);

        if (arr[C] != c)
            ans++;
    }

    printf("%d", ans);

    return 0;
}


#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
#ifdef D
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int n;
    scanf("%d\n", &n);
    n--;

    int arr[256];
    for (int i = 'A'; i <= 'Z'; i++)
    {
        arr[i] = i + (97 - 65);
    }

    int ans = 0;
    int cnt1[256];
    int cnt2[256];

    memset(cnt1, 0, sizeof cnt1);
    memset(cnt2, 0, sizeof cnt2);
    for (int i = 0; i < n; i++)
    {
        char c, C;
        scanf("%c%c", &c, &C);

        cnt1[c]++;
        cnt2[C + 97 - 65]++;
    }

    for (int i = 0; i < 256; i++)
    {
        if (cnt2[i]>cnt1[i])
            ans += (cnt2[i] - cnt1[i]);
    }

    printf("%d", ans);

    return 0;
}


#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
#ifdef D
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int n;
    scanf("%d\n", &n);
    n--;

    int arr[256];
    for (int i = 'A'; i <= 'Z'; i++)
    {
        arr[i] = i + (97 - 65);
    }

    int ans = 0;
    int cnt[256];

    memset(cnt, 0, sizeof cnt);
    for (int i = 0; i < n; i++)
    {
        char c, C;
        scanf("%c%c", &c, &C);

        cnt[c]++;

        if (cnt[C + 97 - 65] == 0)
            ans++;
        else
            cnt[C + 97 - 65]--;
    }

    printf("%d", ans);

    return 0;
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "Project1\Project1.vcxproj", "{F6E1D25E-BBB2-4922-8375-D6323DD9C80C}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Win32 = Debug|Win32
		Release|Win32 = Release|Win32
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{F6E1D25E-BBB2-4922-8375-D6323DD9C80C}.Debug|Win32.ActiveCfg = Debug|Win32
		{F6E1D25E-BBB2-4922-8375-D6323DD9C80C}.Debug|Win32.Build.0 = Debug|Win32
		{F6E1D25E-BBB2-4922-8375-D6323DD9C80C}.Release|Win32.ActiveCfg = Release|Win32
		{F6E1D25E-BBB2-4922-8375-D6323DD9C80C}.Release|Win32.Build.0 = Release|Win32
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal


#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

void main()
{
    int n,count=0,c=0;
    cin>>n;
    int arr[26];
    for(int i=0;i<26;i++)
        arr[i]=0;
    char s[1000000];

    cin>>s;
    for(int i=0;s[i];i++)
        c++;
    if(c==2*n-2)
    {

        for(int i=0;i<c;i++)
        {

            if(s[i]-s[i+1]!='a'-'A')
            {
                arr[s[i]-'a']++;
                if(arr[s[i+1]-'A'])
                    arr[s[i+1]-'A']--;
                else
                    count++;
            }
            i++;
        }
    }
    cout<<count;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iterator>
#include <set>

#define initi ifstream f
#define inito ofstream of
#define openi f.open("input.txt" )
#define openo of.open("output.txt" )
// #define cin f
// #define cout of

#define ii <int , int>
#define nInf -1000000000
#define pInf 1000000000
#define mod 1000000007

#define mp make_pair
#define all(v) v.begin(),v.end()
#define loop(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define sz(v) v.size()

using namespace std;

typedef long long ll;
typedef vector<int > vi;
typedef vector<vi> vii;
typedef pair ii pii;
typedef map ii mii;
typedef set <int > si;
typedef multiset <int > msi;
typedef multimap <int , int> mmi;
initi;
inito;

int main()
{
// 	openi;
// 	openo;

	int n;

	cin >> n;
	char *str = new char[2 * n + 100];
	cin >> str;
	char *rooms = new char[n + 100];
	char *keys = new char[n + 100];
	int l = strlen(str);
	for (int i = 0; i < l; i++)
	{
		if (i % 2 == 1)
		{
			rooms[i / 2] = str[i]- 'A' + 'a';
		}
		else
		{
			keys[i / 2] = str[i] ;
		}
	}
	int count = 0;
	si k;
//	k.insert(keys[0]);
	for (int i = 0; i < (l) / 2; i++)
	{
		k.insert(keys[i]);
		si::iterator it = k.find(rooms[i]);
		if (it == k.end())
		{
			count++;
//			k.insert(keys[i]);
		}
		else
		{
			k.erase(it);
		}
	}
	cout << count;
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iterator>
#include <set>

#define initi ifstream f
#define inito ofstream of
#define openi f.open("input.txt" )
#define openo of.open("output.txt" )
// #define cin f
// #define cout of

#define ii <int , int>
#define nInf -1000000000
#define pInf 1000000000
#define mod 1000000007

#define mp make_pair
#define all(v) v.begin(),v.end()
#define loop(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define sz(v) v.size()

using namespace std;

typedef long long ll;
typedef vector<int > vi;
typedef vector<vi> vii;
typedef pair ii pii;
typedef map ii mii;
typedef set <int > si;
typedef multiset <int > msi;
typedef multimap <int , int> mmi;
initi;
inito;

int main()
{
// 	openi;
// 	openo;

	int n;

	cin >> n;
	char *str = new char[2 * n + 100];
	cin >> str;
	char *rooms = new char[n + 100];
	char *keys = new char[n + 100];
	int l = strlen(str);
	for (int i = 0; i < l; i++)
	{
		if (i % 2 == 1)
		{
			rooms[i / 2] = str[i]- 'A' + 'a';
		}
		else
		{
			keys[i / 2] = str[i] ;
		}
	}
	int count = 0;
	msi k;
//	k.insert(keys[0]);
	for (int i = 0; i < (l) / 2; i++)
	{
		k.insert(keys[i]);
		msi::iterator it = k.find(rooms[i]);
		if (it == k.end())
		{
			count++;
//			k.insert(keys[i]);
		}
		else
		{
			k.erase(it);
		}
	}
	cout << count;
	return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <iterator>
#include <set>

#define initi ifstream f
#define inito ofstream of
#define openi f.open("input.txt" )
#define openo of.open("output.txt" )
// #define cin f
// #define cout of

#define ii <int , int>
#define nInf -1000000000
#define pInf 1000000000
#define mod 1000000007

#define mp make_pair
#define all(v) v.begin(),v.end()
#define loop(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define sz(v) v.size()

using namespace std;

typedef long long ll;
typedef vector<int > vi;
typedef vector<vi> vii;
typedef pair ii pii;
typedef map ii mii;
typedef set <int > si;
typedef multiset <int > msi;
typedef multimap <int , int> mmi;
initi;
inito;

int main()
{
// 	openi;
// 	openo;

	int n;

	cin >> n;
	char *str = new char[2 * n + 100];
	cin >> str;
	char *rooms = new char[n + 100];
	char *keys = new char[n + 100];
	int l = strlen(str);
	for (int i = 0; i < l; i++)
	{
		if (i % 2 == 0)
		{
			rooms[i / 2] = str[i];
		}
		else
		{
			keys[i / 2] = str[i] - 'A' + 'a';
		}
	}
	int count = 0;
	si k;
//	k.insert(keys[0]);
	for (int i = 0; i < (l) / 2; i++)
	{
		k.insert(keys[i]);
		si::iterator it = k.find(rooms[i]);
		if (it == k.end())
		{
			count++;
//			k.insert(keys[i]);
		}
		else
		{
			k.erase(it);
		}
	}
	cout << count;
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))

bool compar(pair<int, int> a, pair<int, int> b) {
	return (a.second < b.second) ? true : (a.second == b.second ? a.first > b.first :false);
}

int main() {
	const int s = 'z'-'a'+1;
	int k[s];
	int b[s];
	for (int i = 0; i < s; i++) {
		k[i] = b[i] = 0;
	}
	int n;
	scanf("%d\n", &n);
	vector<char> a(2*n-2);
	scanf("%s", &a[0]);
	int result = 0;
	for (int i = 0; i < 2*n-2; i+=2) {
		k[a[i]-'a']++;
		k[a[i+1]-'A']--;
		if (k[a[i+1]-'A'] < 0) {
			k[a[i+1]-'A'] = 0;
			result++;
		}
	}
	printf("%d", result);

	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))

bool compar(pair<int, int> a, pair<int, int> b) {
	return (a.second < b.second) ? true : (a.second == b.second ? a.first > b.first :false);
}

int main() {
	const int s = 'z'-'a'+1;
	int k[s];
	int b[s];
	for (int i = 0; i < s; i++) {
		k[i] = b[i] = 0;
	}
	int n;
	scanf("%d", &n);
	string a;
	getline(cin, a);
	getline(cin, a);
	int result = 0;
	for (int i = 0; i < 2*n-2; i+=2) {
		k[a[i]-'a']++;
		k[a[i+1]-'A']--;
		if (k[a[i+1]-'A'] < 0) {
			k[a[i+1]-'A'] = 0;
			result++;
		}
	}
	printf("%d", result);

	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))

bool compar(pair<int, int> a, pair<int, int> b) {
	return (a.second < b.second) ? true : (a.second == b.second ? a.first > b.first :false);
}

int main() {
	const int s = 'z'-'a'+1;
	int k[s];
	int b[s];
	for (int i = 0; i < s; i++) {
		k[i] = b[i] = 0;
	}
	int n;
	scanf("%d\n", &n);
	vector<char> a(2*n-2);
	scanf("%s", &a[0]);
	int result = 0;
	for (int i = 0; i < 2*n-2; i+=2) {
		k[a[i]-'a']++;
		k[a[i+1]-'A']--;
		if (k[a[i+1]-'A'] == 0) {
			k[a[i+1]-'A'] = 0;
			result++;
		}
	}
	printf("%d", result);

	return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
          int n = 0, m = 0, l = 0, k = 0;
          string s = "";
          char a = ' ', A = ' ';
          cin >> n;
          n--;
          n = 2 * n;
          for (int i = 0; i < n; i += 2)
          {
                    cin >> a >> A;
                    k = int(A) + 32;
                    if (int(a) != k)
                    {
                              l++;
                              s += a;
                              m = s.find(char(k));
                              if (m > -1)
                              {
                                        s.erase(m,1);
                                        l--;
                              }
                    }
          }
          cout << l;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
          int n = 0, m = 0, l = 0;
          string s = "";
          char a = ' ', A = ' ';
          cin >> n;
          for (int i = 0; i < n; i++)
          {
                    cin >> a >> A;
                    if (int(a) != int(A + 32))
                    {
                              m = s.find(a);
                              if (m == -1)
                              {
                                        s += a;
                                        l++;
                              }
                              else
                              {
                                        s[m] = '0';
                                        l--;
                              }
                    }
          }
          cout << l;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
          int n = 0, m = 0, l = 0, k = 0;
          string s = "";
          char a = ' ', A = ' ';
          cin >> n;
          n--;
          n = 2 * n;
          for (int i = 0; i < n; i += 2)
          {
                    cin >> a >> A;
                    k = int(A) + 32;
                    if (int(a) != k)
                    {
                              l++;
                              s += a;
                              m = s.find(char(k));
                              if (m > -1)
                              {
                                        s[m] = '0';
                                        l--;
                              }
                    }
          }
          cout << l;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	scanf("%d\n", &n);
	string s; getline(cin, s);

	int ans = 0;
	set<int> keys;
	for(int i=0; i<2*(n-1); i+=2){

		keys.insert(s[i]);
		s[i+1] -= 'A' - 'a';

		if( !keys.count(s[i+1]) ) ++ans;
		else keys.erase(s[i+1]);
	}

	printf("%d", ans);

	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	scanf("%d\n", &n);
	string s; getline(cin, s);

	int ans = 0;
	int keys[256];
	fill(keys, keys+256, 0);

	for(int i=0; i<2*(n-1); i+=2){

		++keys[s[i]];
		s[i+1] -= 'A' - 'a';

		if( !keys[s[i+1]] ) ++ans;
		else --keys[s[i+1]];
	}

	printf("%d", ans);

	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
const int maxn = 101111;
char s[2*maxn],x[2*maxn],d[2*maxn];
using namespace std;
int main ()
{
    int t,sum=0;;
    cin>>t;
    for(int i =1 ;i <= 2*(t-1);i++)
    {
        cin>>s[i];
        if(s[i] >= 'A' && s[i] <= 'Z')
        {
            sum++;
        }
    }
    for(int i =1;i <= 2*(t-1);i++)
    {
        for(int j =i+1;j<= 2*(t-1);j++)
        {
            if(s[i] - s[j] == 'a' - 'A')
            {
                sum--;
                break;
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
const int maxn = 101111;
char s[2*maxn];
int num[288];
using namespace std;
int main ()
{
    int t,sum=0;
    cin>>t;
    cin.ignore();
    gets(s);
    memset(num,0,sizeof(num));
    for(int i =0; s[i] !='\0';i++)
    {
        if(i % 2 == 0)
        {
            num[s[i]-32]++;
        }
        else
        {
            if(num[s[i]])
            {
                num[s[i]]--;
            }
            else
            {
                sum++;
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
const int maxn = 101111;
char s[2*maxn];
int num[28];
using namespace std;
int main ()
{
    int t,sum=0;
    cin>>t;
    scanf("%s",&s);
    memset(num,0,sizeof(num));
    for(int i =0; s[i] !='\0';i++)
    {
        if(i % 2 == 0)
        {
            num[s[i]-32]++;
        }
        else
        {
            if(s[i])
            {
                num[s[i]]--;
            }
            else
            {
                sum++;
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
const int maxn = 101111;
char s[2*maxn],x[2*maxn],d[2*maxn];
using namespace std;
int main ()
{
    int t,xd=0,dd=0;
    cin>>t;
    for(int i =1 ;i <= 2*(t-1);i++)
    {
        cin>>s[i];
        if(s[i] >= 'a' && s[i] <= 'z')
        {
            x[xd++]=s[i];
        }
        else if(s[i] >= 'A' && s[i] <= 'Z')
        {
            d[dd++]=s[i];
        }
    }
    int sum = dd;
    for(int i=0;i<dd;i++)
    {
        for(int j=0;j<xd;j++)
        {
            if(x[j] - d[i] == 'a' - 'A')
            {
                sum--;
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
const int maxn = 101111;
char s[2*maxn],x[2*maxn],d[2*maxn];
using namespace std;
int main ()
{
    int t,sum=0;;
    cin>>t;
    for(int i =1 ;i <= 2*(t-1);i++)
    {
        cin>>s[i];
        if(s[i] >= 'A' && s[i] <= 'Z')
        {
            sum++;
        }
    }
    for(int i =1;i < 2*(t-1);i++)
    {
        for(int j =i+1;j<= 2*(t-1);j++)
        {
            if(s[i] >='a' && s[i] <= 'z' && s[j] >='A' && s[j] <= 'Z' && s[i] - s[j] == 'a' - 'A')
            {
                sum--;
                break;
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
const int maxn = 101111;
char s[2*maxn];
int num[28];
using namespace std;
int main ()
{
    int t,sum=0;
    cin>>t;
    scanf("%s",&s);
    memset(num,0,sizeof(num));
    for(int i =0; s[i] !='\0';i++)
    {
        if(i % 2 == 0)
        {
            num[s[i]-32]++;
        }
        else
        {
            if(num[s[i]])
            {
                num[s[i]]--;
            }
            else
            {
                sum++;
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
const int maxn = 101111;
char s[2*maxn];
int num[28];
using namespace std;
int main ()
{
    int t,sum=0;
    cin>>t;
    cin.ignore();
    gets(s);
    memset(num,0,sizeof(num));
    for(int i =0; s[i] !='\0';i++)
    {
        if(i % 2 == 0)
        {
            num[s[i]-32]++;
        }
        else
        {
            if(num[s[i]])
            {
                num[s[i]]--;
            }
            else
            {
                sum++;
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include <stdio.h>
#include <string.h>

char str[200005];

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

    scanf("%s", str);

    int s = strlen(str);

    int K['z' + 3] = { 0 };

    int c = 0;
    int d = 'a' - 'A';
    for (int i = 1; i < s; i += 2){
        K[str[i - 1]]++;
        if (!K[str[i] + d])c++;
        else
            K[str[i] + d]--;
    }

    printf("%d\n", c);
}


#include <stdio.h>
#include <string.h>

char str[100003];

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

    scanf("%s", str);

    int s = strlen(str);

    int c = 1;
    int d = 'A' - 'a';

    int x = 0;

    for (int i = 0; i < s-2; i+=2){
        if (str[i] == str[i + 2] || str[i] + d == str[i + 2] || str[i] == str[i + 2] + d){
            c++;
        }
        else{
            x = x < c ? c : x;
            c = 1;
        }
    }

    x = x < c ? c : x;

    c = 1;

    for (int i = 1; i < s - 2; i += 2){
        if (str[i] == str[i + 2] || str[i] + d == str[i + 2] || str[i] == str[i + 2] + d){
            c++;
        }
        else{
            x = x < c ? c : x;
            c = 1;
        }
    }

    x = x < c ? c : x;

    if (x == 1)x = 0;

    printf("%d\n", x);
}


#include <stdio.h>
#include <string.h>

char str[100003];

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

    scanf("%s", str);

    int s = strlen(str);

    int c = 1;
    int d = 'A' - 'a';

    int x = 0;

    for (int i = 0; i < s-2; i+=2){
        if (str[i] == str[i + 2] || str[i] + d == str[i + 2] || str[i] == str[i + 2] + d){
            c++;
        }
        else{
            if (c > 1)x += c;
            c = 1;
        }
    }

    if (c > 1)x += c;

    c = 1;

    for (int i = 1; i < s - 2; i += 2){
        if (str[i] == str[i + 2] || str[i] + d == str[i + 2] || str[i] == str[i + 2] + d){
            c++;
        }
        else{
            if (c > 1)x += c;
            c = 1;
        }
    }

    if (c > 1)x += c;

    printf("%d\n", x);
}


#include <stdio.h>
#include <string.h>

char str[100003];

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

    scanf("%s", str);

    int s = strlen(str);

    int K['z' + 3] = { 0 };

    int c = 0;
    int d = 'a' - 'A';
    for (int i = 1; i < s; i += 2){
        K[str[i - 1]]++;
        if (!K[str[i] + d])c++;
        else
            K[str[i] + d]--;
    }

    printf("%d\n", c);
}


using namespace std;

#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define For(i,n) for(int i = 0; i < (n); i++)
const ll cnst = 1e9+7;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, cnt = 0;
    string s;
    cin >> n;
    cin >> s;
    string keys = "";
    string doors = "";
    For(i,n-1) {
        keys += s[2*i];
        if(keys.find(towlower(s[2*i+1]))!= string::npos) keys[keys.find(towlower(s[2*i+1]))] = 'A';
        else cnt++;
    }
    cout << cnt << endl;
    //system("pause");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <utility>
#include <math.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define For(i,n) for(int i = 0; i < (n); i++)
const ll cnst = 1e9+7;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, cnt = 0;
    string s;
    cin >> n;
    cin >> s;
    string keys = "";
    string doors = "";
    For(i,n-1) {
        keys += s[2*i];
        if(keys.find(towlower(s[2*i+1]))!= string::npos) keys[keys.find(towlower(s[2*i+1]))] = '#';
        else cnt++;
    }
    cout << cnt << endl;
    //system("pause");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <utility>
#include <math.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define For(i,n) for(int i = 0; i < (n); i++)
const ll cnst = 1e9+7;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, cnt = 0;
    string s;
    cin >> n;
    cin >> s;
    string keys = "";
    string doors = "";
    For(i,n-1) {
        keys += s[2*i];
        if(keys.find(towlower(s[2*i+1]))!= string::npos) keys.erase(keys.find(towlower(s[2*i+1])));
        else cnt++;
    }
    cout << cnt;
    //system("pause");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <utility>
#include <math.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define For(i,n) for(int i = 0; i < (n); i++)
const ll cnst = 1e9+7;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, cnt = 0;
    string s;
    cin >> n;
    cin >> s;
    string keys = "";
    string doors = "";
    For(i,n-1) {
        keys += s[2*i];
        if(keys.find(towlower(s[2*i+1]))!= string::npos) keys[keys.find(towlower(s[2*i+1]))] = 'A';
        else cnt++;
    }
    cout << cnt << endl;
    //system("pause");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <utility>
#include <math.h>
#include <map>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define For(i,n) for(int i = 0; i < (n); i++)
const ll cnst = 1e9+7;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, cnt = 0;
    map <int, int> m;
    string s;
    cin >> n;
    cin >> s;
    vector<int> keys(n), doors(n);
    For(i, n-1){
        keys[i] = s[2*i] - 'a';
        doors[i] = s[2*i+1] - 'A';
    }
    For(i, n-1) {
        m[keys[i]]++;
        if(m[doors[i]] > 0) m[doors[i]]--;
        else cnt++;
    }
    cout << cnt << endl;
    //system("pause");
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
#include <climits>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn = 500001;
int n;
string s;
int vis[26];

int main()
{

    #ifdef DoubleQ
    freopen("in.txt" , "r" , stdin);
    #endif
    while(cin >> n)
    {
        memset(vis , 0 , sizeof(vis));
        cin >> s;
        int len = s.length();
        int cnt = 0;
        for(int i = 0 ; i < len ; i ++)
        {
            if((i+1) % 2 != 0)
            {
                vis[s[i] - 'a'] ++;
            }
            else
            {
                if(vis[s[i] - 'A'])
                {
                    vis[s[i] - 'A'] --;
                }
                else
                {
                    cnt ++;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const int maxn = 500001;
int n;
string s;
int vis[26];

int main()
{

    #ifdef DoubleQ
    freopen("in.txt" , "r" , stdin);
    #endif
    while(cin >> n)
    {
        memset(vis , 0 , sizeof(vis));
        cin >> s;
        int len = s.length();
        int cnt = 0;
        for(int i = 0 ; i < len ; i ++)
        {
            if((i+1) % 2 != 0)
            {
                vis[s[i] - 'a'] ++;
            }
            else
            {
                if(vis[s[i] - 'A'])
                {
                    vis[s[i] - 'A'] --;
                }
                else
                {
                    cnt ++;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
#include <climits>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn = 500001;
int n;
string s;
int vis[26];

int main()
{
    cin>>n;
        memset(vis , 0 , sizeof(vis));
        cin >> s;
        int len = s.length();
        int cnt = 0;
        for(int i = 0 ; i < len ; i ++)
        {
            if((i+1) % 2 != 0)
            {
                vis[s[i] - 'a'] ++;
            }
            else
            {
                if(vis[s[i] - 'A'])
                {
                    vis[s[i] - 'A'] --;
                }
                else
                {
                    cnt ++;
                }
            }
        }
        cout << cnt << endl;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int n;
string str;
int keys[27]={0};
int cnt=0;

int main()
{
    int a,b;
    cin>>n;
    cin>>str;
    for(int i=0;i<2*n-2;i++)
    {
        if(i%2==0)
        {
            keys[str[i]-97+1]++;
        }else if(i%2==1)
        {
            if(keys[str[i]-65+1]==0)
            {
                cnt++;
            }else
            {
                keys[str[i]-65+1]--;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
map<char,int> mp;
int main()
{
    int N,t=0;
    char a,b;
    scanf("%d",&N);
    n--;
    for(int i=0;i<N;i++)
    {
        cin>>a>>b;
        if(a-32!=b)
        {
            mp[a-32]++;
            if(mp[b])
                mp[b]--;
            else
                t++;
        }
    }
    printf("%d",t);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<ctype.h>
char room[111111],key[111111],ss[222222];
int main(){
	int n,i,j,k=0,l=0;
	int len,num=0;
	scanf("%d",&n);
	scanf("%s",ss);
	len=strlen(ss);
	for(i=0;i<len;i++){
		if(ss[i]>='A'&&ss[i]<='Z') room[k++]=ss[i];
		else if(ss[i]>='a'&&ss[i]<='z') key[l++]=ss[i];
	}
	int book[111111]={0};
	for(i=0;i<l;i++){
		if(key[i]==tolower(room[i])) book[i]=1;
	}
	for(i=0;i<l;i++){
		if(i==0){
			if(key[i]==tolower(room[i]))  continue;
			else {
				num++;
				for(j=i+1;j<l;j++){
					if(book[j]==0&&key[i]==tolower(room[j])&&key[j]!=tolower(room[j])){
						book[j]=1;  break;
					}
				}
			}
		}
		//当不是第一把钥匙时；
		else{
			if(key[i]==tolower(room[i])) continue;
			else{
				if(book[i]==0)	num++;
				for(j=i+1;j<l;j++){
					if(key[i]==tolower(room[j])&&book[j]==0&&key[j]!=tolower(room[j])){
						book[j]=1; break;
					}
				}
			}
		}
	}
	printf("%d\n",num);
}


#include<stdio.h>
#include<string.h>
#include<ctype.h>
char room[111111],key[111111],ss[222222];
int main(){
	int n,i,j,k=0,l=0;
	int len,num=0;
	scanf("%d",&n);
	scanf("%s",ss);
	len=strlen(ss);
	for(i=0;i<len;i++){
		if(ss[i]>='A'&&ss[i]<='Z') room[k++]=ss[i];
		else if(ss[i]>='a'&&ss[i]<='z') key[l++]=ss[i];
	}
	//printf("%d %d\n",k,l);
	#if 1
	int book[111111]={0};
	for(i=0;i<l;i++){
		if(tolower(room[i])==key[i]) continue;
		else if(book[i]) continue;
		else if(key[i]!=tolower(room[i])){
			num++;
			for(j=i+1;j<l;j++){
				if(key[i]==tolower(room[j])&&book[j]==0) {book[j]=1; break;}
			}
		}
	}
	printf("%d\n",num);
	#endif
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<fstream>
#include<regex>
#include<stdlib.h>
#include<math.h>

using namespace std;

#define all(v)         v.begin(),v.end()
#define sz(v)        ((int)((v).size()))
#define psh(x)               push_back(x)
#define mk(x,y)           make_pair(x,y)
#define ck(a)               (a<1 || a>9)
#define lop(i,n)     for(ll i=0;i<n;i++)
#define loop(i,f,l)  for(ll i=f;i<l;i++)
#define READ(s)   freopen(s, "r", stdin)
#define WRITE(s) freopen(s, "w", stdout)
#define scl(n)          scanf("%lld",&n)
#define sc(n)             scanf("%d",&n)
#define INF                   1000000000
#define LINF               1000000000000
#define PI             3.141592653589793

typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef pair<char, int>  chi;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<string>    vs;
typedef vector<ll>       vll;
typedef vector<vii>     vvii;
typedef set<int>         sti;

const double EPS = (1e-7);

int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, -1, 1 };

int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return ((a*b) / gcd(a, b)); }
ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
int sd(ll x){ return x<10 ? x : x % 10 + sd(x / 10); }
ll sq(ll x){ lop(i, x)if ((ll)i*i > x) return (i - 1); return ll(1); }
//READ("input.txt");WRITE("output.txt");
int arr[26];
int main()
{
    int n,sum=0;    string s;   cin >> n >> s;
    lop(i, s.length())
        if (!(i % 2)) arr[s[i] - 'a']++;
        else
        {
            if (!arr[s[i] - 'A']) sum++;
            else arr[s[i] - 'A']--;
        }
    cout << sum;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<fstream>
#include<stdlib.h>
#include<math.h>

using namespace std;

#define all(v)         v.begin(),v.end()
#define sz(V)        ((int)((v).size()))
#define ck(a)               (a<1 || a>9)
#define lop(i,n)    for(int i=0;i<n;i++)
#define loop(i,f,l) for(int i=f;i<l;i++)
#define dlop(i,f,l) for(int i=f;i>l;i--)
#define READ(s)   freopen(s, "r", stdin)
#define WRITE(s) freopen(s, "w", stdout)
#define INF                   1000000000
#define PI             3.141592653589793

typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef pair<char, int>  chi;
typedef pair <ll, ll>    pll;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<string>    vs;
typedef vector<ll>       vll;
typedef vector<pll>     vpll;
typedef set<int>         sti;

int arr[26];

int main()
{
    int n,sum=0;    cin >> n;
    for (int i = 0; i < (2*n - 2); i++)
    {
        char x;
        cin >> x;
        if (!(i % 2))
        {
            arr[x - 'a']++;
        }
        else {
            arr[x - 'A']--;
            if (arr[x - 'A'] < 0)
                sum++;
        }
    }
    cout << sum;
    return 0;
}


#include<stdio.h>
#include<string.h>
#define N 100001
#define SIZE 26
char com[N];
int ache[SIZE];
int kinmu[SIZE];

void INIT(){
	for (int i = 0; i < SIZE; i++){
		ache[i] = 0;
		kinmu[i] = 0;
	}
}
int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int rooms,door,keyNeededToBuy;
	scanf("%d %s", &rooms, com);
	INIT();
	door = 1;
	keyNeededToBuy = 0;
	do
	{
		ache[com[door - 1] - 'a']+=1;
		char key = com[door] + ('a' - 'A');
		if (ache[key-'a'] == 0){
			kinmu[key - 'a'] += 1;
			keyNeededToBuy++;
		}
		else{
			ache[key - 'a']--;
		}
		door += 2;
	} while (door<=2*rooms-2);

	printf("%d\n", keyNeededToBuy);
	return 0;
}


#include<stdio.h>

#define N 200000
#define SIZE 26
char com[N];
int ache[SIZE];
int kinmu[SIZE];

void INIT(){
	for (int i = 0; i < SIZE; i++){
		ache[i] = 0;
		kinmu[i] = 0;
	}
}
int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int rooms,door,keyNeededToBuy;
	scanf("%d %s", &rooms, com);
	INIT();
	door = 1;
	keyNeededToBuy = 0;
	do
	{
		ache[com[door - 1] - 'a'] += 1;
		char key = com[door] + ('a' - 'A');
		if (ache[key-'a'] == 0){
			kinmu[key - 'a'] += 1;
			keyNeededToBuy++;
		}
		else{
			ache[key - 'a']--;
		}
		door += 2;
	} while (door<=2*rooms-3);

	printf("%d\n", keyNeededToBuy);
	return 0;
}


#include<stdio.h>
#include<string.h>
#define N 100001
#define SIZE 26
char com[N];
int ache[SIZE];
int kinmu[SIZE];

void INIT(){
	for (int i = 0; i < SIZE; i++){
		ache[i] = 0;
		kinmu[i] = 0;
	}
}
int main(){
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int rooms,door,keyNeededToBuy;
	scanf("%d %s", &rooms, com);
	int len = strlen(com);
	INIT();
	door = 1;
	keyNeededToBuy = 0;
	do
	{
		ache[com[door - 1] - 'a']+=1;
		char key = com[door] + ('a' - 'A');
		if (ache[key-'a'] == 0){
			kinmu[key - 'a'] += 1;
			keyNeededToBuy++;
		}
		else{
			ache[key - 'a']--;
		}
		door += 2;
	} while (door<=2*rooms-3);

	printf("%d\n", keyNeededToBuy);
	return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
char s[200005];
int key[30];
int main()
{
    int n;
    cin>>n;
    cin>>s;
    memset(key,0,sizeof(key));
    int ans=0;
    for(int i=0;i<strlen(s);i+=2)
    {
        char tmpkey,tmproom;
        tmpkey=s[i];
        tmproom=s[i+1];
        key[tmpkey-'a']++;
        if(key[tmproom-'A']==0)
            ans++;
        else
            key[tmproom-'A']--;
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<set>
using namespace std;
char s[200005];
multiset<char>key;
int main()
{
    int n;
    cin>>n;
    cin>>s;
    key.clear();
    int ans=0;
    for(int i=0;i<strlen(s);i+=2)
    {
        char tmpkey,tmproom;
        tmpkey=s[i];
        tmproom=s[i+1];
        key.insert(tmpkey);
        auto it=key.find((char)(tmproom-'A'+'a'));
        if(it==key.end())
            ans++;
        else
            key.erase(it);
    }
    cout<<ans<<endl;
}


#include<iostream>
using namespace std;
#define MX 300007
char in,inp;
int doors[26]={0};
int keys[26]={0};
int main(){
	long long int number, count = 0;
	cin>>number;
	for(long long i =0;i<(number*2-2);i++)
	{
		cin>> in;
		if(in>='A' && in<='Z')
		{
			int idx = in -'A';
			doors[idx] = doors[idx] + 1;
			if(doors[idx] > keys[idx])
			{
				count++;
				keys[idx] = keys[idx]+1;
			}
		}
		if(in>='a' && in<='z')
		{
			int idx = in -'a';
			keys[idx] = keys[idx] + 1;
		}
	}
	cout<<count;

	return 0;
}


#include<iostream>
using namespace std;
#define MX 300007
char in,inp;
int doors[26]={0};
int keys[26]={0};
int main(){
	long long int number, count = 0;
	cin>>number;
	for(long long i =0;i<(number*2-2);i++)
	{
		cin>> in;
		if(in>='A' && in<='Z')
		{
			int idx = in -'A';
			doors[idx] = doors[idx] + 1;
			if(doors[idx] > keys[idx])
			{
				count++;
			}
		}
		if(in>='a' && in<='z')
		{
			int idx = in -'a';
			keys[idx] = keys[idx] + 1;
		}
	}
	cout<<count;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>
#include <memory.h>
#include <string.h>
#include <time.h>
using namespace std;
#pragma comment(linker, "/STACK:100000000")

#define mp make_pair
#define pb push_back
#define ll long long
#define sz(x) (int)(x).size()

int cnt[26];

int main()
{
    //freopen("input.txt","rt",stdin);
    //freopen("output.txt","wt",stdout);
    //freopen("a.in","rt",stdin);
    //freopen("a.out","wt",stdout);

	int n;
	scanf("%d", &n);
	string s;
	cin >> s;
	int c = 0;
	for(int i = 0; i < 2 * n - 2; i++) {
		if(i % 2 == 0) {
			cnt[s[i]-'a']++;
		}
		else {
			int val = s[i] - 'A';
			if(cnt[val] == 0) c++;
else cnt[val]--;
		}
	}
	printf("%d", c);

    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>
#include <memory.h>
#include <string.h>
#include <time.h>
using namespace std;
#pragma comment(linker, "/STACK:100000000")

#define mp make_pair
#define pb push_back
#define ll long long
#define sz(x) (int)(x).size()

int main()
{
    //freopen("input.txt","rt",stdin);
    //freopen("output.txt","wt",stdout);
    //freopen("a.in","rt",stdin);
    //freopen("a.out","wt",stdout);

	int n;
	scanf("%d", &n);
	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < 2 * n - 2; i += 2) {
		if(s[i] != s[i+1]) cnt++;
	}
	printf("%d", cnt);

    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>
#include <memory.h>
#include <string.h>
#include <time.h>
using namespace std;
#pragma comment(linker, "/STACK:100000000")

#define mp make_pair
#define pb push_back
#define ll long long
#define sz(x) (int)(x).size()

int main()
{
    //freopen("input.txt","rt",stdin);
    //freopen("output.txt","wt",stdout);
    //freopen("a.in","rt",stdin);
    //freopen("a.out","wt",stdout);

	int n;
	scanf("%d", &n);
	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < 2 * n - 2; i += 2) {
		if(s[i] != s[i+1] + 'a' - 'A') cnt++;
	}
	printf("%d", cnt);

    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <stdlib.h>
#include <sstream>
#include <assert.h>
#include <memory.h>
#include <string.h>
#include <time.h>
using namespace std;
#pragma comment(linker, "/STACK:100000000")

#define mp make_pair
#define pb push_back
#define ll long long
#define sz(x) (int)(x).size()

int main()
{
    //freopen("input.txt","rt",stdin);
    //freopen("output.txt","wt",stdout);
    //freopen("a.in","rt",stdin);
    //freopen("a.out","wt",stdout);

	int n;
	scanf("%d", &n);
	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < 2 * n - 2; i += 2) {
		if(s[i] != s[i+1] + 'A' - 'a') cnt++;
	}
	printf("%d", cnt);

    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int arr[26];
int main()
{
	string s; int k;
	cin >> k; cin >> s;
	int keys=0;
	for (int i=0; i<2*k-2; i+=2)
	{
		arr[(int)(s[i])-97]++;
		if (arr[(int)(s[i+1])-65]>0)
			arr[(int)(s[i+1])-65]--;
		else
			keys++;
	}
	cout << keys;
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int arr[26];
int main() {
	string s; int k;
	cin >> k; cin >> s;
	int keys=0;
	for (int i=0; i<2*k-2; i+=2)
		if (arr[(int)(s[i+1])-65]>0)
			arr[(int)(s[i+1])-65]--;
		else
			if (((int)(s[i])!=(int)(s[i+1])+32))
			{
				keys++;
				arr[(int)(s[i])-97]++;
			}
	cout << keys;
	system("pause");
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int arr[26];
int main() {
	string s; int k;
	cin >> k; cin >> s;
	int keys=0;
	for (int i=0; i<2*k-2; i+=2)
		if (arr[(int)(s[i+1])-65]>0)
			arr[(int)(s[i+1])-65]--;
		else
			if (((int)(s[i])!=(int)(s[i+1])+32))
			{
				keys++;
				arr[(int)(s[i])-97]++;
			}
	cout << keys;
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int arr[26];
int main() {
	string s; int k;
	cin >> k; cin >> s;
	int keys=0;
	for (int i=0; i<2*k-2; i+=2)
		if (arr[(int)(s[i+1])-65]>0)
			arr[(int)(s[i+1])-65]--;
		else
		{
				keys++;
				arr[(int)(s[i+1])-65]++;
		}
	cout << keys;
	return 0;
}


// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

#ifndef DONLINE_JUDGE
int _tmain(int argc, _TCHAR* argv[])
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#elif
int main()
{
#endif
	int n;
	cin >> n;
	char k;
	char d;
	int keys = 0;
	string ks="";
	for (int i = 1; i < n; i++){
		cin >> k>>d;
		if (toupper(k) != d) {
			int f = ks.find(tolower(d));
			if (f == string::npos){
				keys++;
				ks += k;
			}
			else{
				ks[f] = ' ';
			}
		}
	}

	cout << keys<<endl;
	return 0;
}


#include <iostream>
#include <string>
#include <vector>

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int n, m, a[200010], sum[200010];
string s;
char res[200010];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> s;
	cin >> m;
	n = s.length();
	for (int i = 0; i < m; i++) {
		cin >> a[i];
		a[i]--;
		sum[a[i]]++;
		sum[n - a[i]]--;
	}
	int t = 0;
	for (int i = 0; i < n; i++) {
		t += sum[i];
		if (t % 2 == 1)
			res[n - i - 1] = s[i];
		else
			res[i] = s[i];
	}
	cout << res << endl;
	return 0;
}


// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <string>

using namespace std;

#ifndef DONLINE_JUDGE
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#elif
int main()
{
#endif
	int n;
	cin >> n;
	char k;
	char d;
	int keys = 0;
	string ks="";
	for (int i = 1; i < n; i++){
		cin >> k>>d;
		if (toupper(k) != d) {
			int f = ks.find(tolower(d));
			if (f == string::npos){
				keys++;
				ks += k;
			}
			else{
				ks[f] = ' ';
			}
		}
	}

	cout << keys;
	return 0;
}


// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

#ifndef DONLINE_JUDGE
int _tmain(int argc, _TCHAR* argv[])
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#elif
int main()
{
#endif
	int n;
	cin >> n;
	char k;
	char d;
	int keys = 0;
	string ks="";
	for (int i = 1; i < n; i++){
		cin >> k>>d;
		if (toupper(k) != d) {
			int f = ks.find(tolower(d));
			if (f == string::npos){
				keys++;
				ks += k;
			}
			else{
				ks[f] = ' ';
			}
		}
	}

	cout << keys<<endl;
	return 0;
}


// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <string>

using namespace std;

int main()
{

	int n;
	cin >> n;
	char k;
	char d;
	int keys = 0;
	string ks="";
	for (int i = 1; i < n; i++){
		cin >> k>>d;
		if (k != tolower(d)) {
			int f = ks.find(tolower(d));
			if (f == string::npos){
				keys++;
				ks += k;
			}
			else{
				ks[f] = ' ';
				ks += k;
			}
		}
	}

	cout << keys;
	return 0;
}


// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <string>

using namespace std;

#ifndef DONLINE_JUDGE
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
#ifdef DONLINE_JUDGE
int main()
{
#endif
	int n;
	cin >> n;
	char k;
	char d;
	int keys = 0;
	string ks="";
	for (int i = 1; i < n; i++){
		cin >> k>>d;
		if (toupper(k) != d) {
			int f = ks.find(tolower(d));
			if (f == string::npos){
				keys++;
				ks += k;
			}
			else{
				ks[f] = ' ';
			}
		}
	}

	cout << keys;
	return 0;
}


// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <string>

using namespace std;

int main()
{

	int n;
	cin >> n;
	char k;
	char d;
	int keys = 0;
	string ks="";
	for (int i = 1; i < n; i++){
		cin >> k>>d;
		if (toupper(k) != d) {
			int f = ks.find(tolower(d));
			if (f == string::npos){
				keys++;
				ks += k;
			}
			else{
				ks[f] = ' ';
			}
		}
	}

	cout << keys;
	return 0;
}


// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <string>

using namespace std;

#ifndef DONLINE_JUDGE
int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#elif
int main()
{
#endif
	int n;
	cin >> n;
	char k;
	char d;
	int keys = 0;
	string ks="";
	for (int i = 1; i < n; i++){
		cin >> k>>d;
		if (toupper(k) != d) {
			int f = ks.find(tolower(d));
			if (f == string::npos){
				keys++;
				ks += k;
			}
			else{
				ks[f] = ' ';
			}
		}
	}

	cout << keys<<endl;
	return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cctype>
#include<set>
#include<math.h>
using namespace std;
int main()
{
	int n, ans=0;
	string s;
	vector < int > b(35);
	cin >> n >> s;
	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i] >= 'a' && s[i] <= 'z')
		{
			b[s[i] - 'a']++;
		}
		else
		{
			if (b[s[i] - 'A'] == 0)
				ans++;
			else
				b[s[i] - 'A']--;
		}
	}
	cout << ans;
	return 0;
}
/*

*/


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cctype>
#include<set>
#include<math.h>
using namespace std;
int main()
{
	int n, ans=0;
	scanf("%d\n", &n);
	char c1;
	set < char> S;
	for (int i = 0; i < 2*n-2; ++i)
	{
		cin >> c1;
		if (islower(c1))
		{
			S.insert(c1);

		}
		else
		{
			c1 = (char)tolower(c1);
			if (S.count(c1) != 0)
			{
				S.erase(c1);
			}
			else ans++;
		}
	}
	cout << ans;
	return 0;
}
/*

*/


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cctype>
#include<set>
#include<math.h>
using namespace std;
int main()
{
	int n, ans=0;
	scanf("%d\n", &n);
	char c1, c2;
	set < char> S;
	for (int i = 0; i < n-1; ++i)
	{
		cin >> c1 >> c2;
		S.insert(c1);
		c2 = (char)tolower(c2);
		if (S.count(c2) != 0)
		{
			S.erase(c2);
		}
		else ans++;
	}
	cout << ans;
	return 0;
}
/*

*/


#include <iostream>
#include <stdlib.h>
#include <fstream>

using namespace std;

int main(){
	/*char a = 'a';
	char A = 'A';
	cout << int(A) <<' ' << int(a);*/
	//cout << 1 % 2;
	/*ifstream cin("input.txt");
	ofstream cout("output.txt");*/

	int arr[26] = {0};

	int n;
	cin >> n;
	char* str = new char[2*n - 1];
	cin >> str;

	int count = 0;
	for(int i = 0; i < strlen(str); i++){
		if(!(i % 2)){
			arr[str[i] - 97]++;
		}else{
			if(arr[str[i] - 65]){
				arr[str[i] - 65]--;
			}else{
				count++;
			}
		}
	}

	cout << count;

	/*cin.close();
	cout.close();*/
	delete[] str;
	return 0;
}


#include <iostream>
#include <stdlib.h>
#include <fstream>

using namespace std;

int main(){
	/*char a = 'a';
	char A = 'A';
	cout << int(A) <<' ' << int(a);*/
	//cout << 1 % 2;
	/*ifstream cin("input.txt");
	ofstream cout("output.txt");*/

	int arr[26] = {0};

	int n;
	cin >> n;
	int N = 2*n - 2;
	char* str = new char[N + 1];
	cin >> str;

	int count = 0;
	for(int i = 0; i < N; i++){
		if(!(i % 2)){
			arr[str[i] - 97]++;
		}else{
			if(arr[str[i] - 65]){
				arr[str[i] - 65]--;
			}else{
				count++;
			}
		}
	}

	cout << count;

	/*cin.close();
	cout.close();*/
	delete[] str;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>

using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define vi vector<int>
#define vLL vector<LL>
#define vs vector<string>
#define fori(n) for(int (i)=0; (i)<n; (i)++)
int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    string S;
    cin >> S;
    LL ans = 0;
    map<char, int> low, up;

    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] >= 'a' && S[i] <= 'z')
            low[S[i]]++;
        else
        {
            char tmp = S[i] - 'A' + 'a';
            if (low[tmp] > 0) low[tmp]--;
            else ans++;
        }
    }
    cout << ans;

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
	int n;
	string s;
	cin>>n;
	cin>>s;
	vector <char> keys(n-1);
	vector <char> flats(n-1);
	int nCount=n-1;
	for (int i=0; i<2*n-2; i++){
		if (i%2==0) keys[i/2]=s[i];

		if (i%2==1){
			flats[i/2]=s[i]-('A'-'a');
		}
	}

	for (int i=0; i<n-1; i++){
		for (int j=i; j<n-1; j++){
			if (keys[i]==flats[j]) {
				nCount--;
				break;
			}
		}
	}
	cout<<nCount;
	//system("PAUSE");

}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
	int n;
	string s;
	cin>>n;
	cin>>s;
	vector <char> keys(n-1);
	vector <char> flats(n-1);
	int nCount=n-1;
	for (int i=0; i<s.size(); i++){
		if (i%2==0) keys[i/2]=s[i];

		if (i%2==1){
			flats[i/2]=s[i]-('A'-'a');
		}
	}

	for (int i=0; i<n-1; i++){
		for (int j=i; j<n-1; j++){

			if (keys[i]==flats[j]) {
				nCount--;
				break;
			}
		}
	}
	cout<<nCount;
	//system("PAUSE");

}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
	int n;
	string s;
	cin>>n;
	cin>>s;
	vector <char> keys(n-1);
	vector <char> flats(n-1);
	int nCount=n-1;
	for (int i=0; i<s.size(); i++){
		if (i%2==0) keys[i/2]=s[i];

		if (i%2==1){
			flats[i/2]=s[i]-('A'-'a');
		}
	}

	for (int i=0; i<n-1; i++){
		for (int j=i; j<n-1; j++){

			if (keys[i]==flats[j]) {
				flats[j]=' ';
				nCount--;
				break;
			}
		}
	}
	cout<<nCount;
	//system("PAUSE");

}


#include<stdio.h>
#include<ctype.h>
int main()
{
    long int n,i,k,x,a[26]={0},count=0;
    char s[100110];
    scanf("%ld",&n);
    scanf("%s",s);
    for(i=0;s[i]!='\0';i++)
    {
        if(i%2==0)
        {
            if(toupper(s[i])==s[i+1]) {i+=1;continue;}
            else
            {
                x=s[i]-'a';
                a[x]++;
            }
        }
        else
        {
            x=s[i]-'A';
            if(a[x]>0) a[x]--;
            else count++;
        }
    }
    printf("%ld\n",count);
    return 0;
}


#include<stdio.h>
#include<ctype.h>
int main()
{
    int n,i,k,x,a[26]={0},count=0;
    char s[100010];
    scanf("%d%s",&n,s);
    for(i=0;s[i]!='\0';i++)
    {
        if(i%2==0)
        {
            if(toupper(s[i])==s[i+1]) {i+=1;continue;}
            else
            {
                x=s[i]-'a';
                a[x]++;
            }
        }
        else
        {
            x=s[i]-'A';
            if(a[x]>0) a[x]--;
            else count++;
        }
    }
    printf("%d\n",count);
    return 0;
}


#include<stdio.h>
#include<ctype.h>
int main()
{
    long int n,i,k,x,a[26]={0},count=0;
    char s[200110];
    scanf("%ld",&n);
    scanf("%s",s);
    for(i=0;s[i]!='\0';i++)
    {
        if(i%2==0)
        {
            x=s[i]-'a';
            a[x]++;
        }
        else
        {
            x=s[i]-'A';
            if(a[x]>0) a[x]--;
            else count++;
        }
    }
    printf("%ld\n",count);
    return 0;
}


#include<stdio.h>
#include<ctype.h>
int main()
{
    long int n,i,k,x,a[26]={0},count=0;
    char s[100010];
    scanf("%ld%s",&n,s);
    for(i=0;s[i]!='\0';i++)
    {
        if(i%2==0)
        {
            if(toupper(s[i])==s[i+1]) {i+=1;continue;}
            else
            {
                x=s[i]-'a';
                a[x]++;
            }
        }
        else
        {
            x=s[i]-'A';
            if(a[x]>0) a[x]--;
            else count++;
        }
    }
    printf("%ld\n",count);
    return 0;
}


#include<stdio.h>
#include<ctype.h>
int main()
{
    long int n,i,k,x,a[26]={0},count=0;
    char s[100110];
    scanf("%ld",&n);
    scanf("%s",s);
    for(i=0;s[i]!='\0';i++)
    {
        if(i%2==0)
        {
            x=s[i]-'a';
            a[x]++;
        }
        else
        {
            x=s[i]-'A';
            if(a[x]>0) a[x]--;
            else count++;
        }
    }
    printf("%ld\n",count);
    return 0;
}


# include<iostream>
# include<cstring>
using namespace std;
char str[10005];
int hs[1000];
int main()
{
    int n;
    cin>>n;
    cin>>str+1;
    int sum=0;
    memset(hs,0,sizeof(hs));
    for(int i=1;i<=strlen(str);i++)
    {
        if(str[i]<='z'&&str[i]>='a')
        {
            hs[str[i]-'a']++;
        }else{
        if(hs[str[i]-'A']==0)
            {sum++;   }
        else hs[str[i]-'A']--;
        }
    }
    cout<<sum<<endl;
    return 0;
}


# include<iostream>
using namespace std;
char str[10005];
int hs[1000];
int main()
{
    int n;
    cin>>n;
    cin>>str;
    int sum=0;
    for(int i=1;i<=2*n-2;i++)
    {
        if(str[i]<='z'&&str[i]>='a')
        {
            hs[str[i]-'a']++;
        }else{
        if(hs[str[i]-'A']==0)
            sum++;
        else hs[str[i]-'A']--;
        }
    }
    cout<<sum<<endl;
    return 0;
}


# include<iostream>
# include<cstring>
using namespace std;
char str[1000005];
int hs[1000];
int main()
{
    int n;
    cin>>n;
    cin>>str;
    int sum=0;
    for(int i=0;i<27;i++)
    {
     hs[i]=0;
    }
   // memset(hs,0,sizeof(hs));
    for(int i=0;i<strlen(str);i++)
    { //cout<<str[i]<<endl;
        if(str[i]<='z'&&str[i]>='a')
        {
            hs[str[i]-'a']++;
        }else{
        if(hs[str[i]-'A']==0)
            {sum++;   }
        else {
                //cout<<str[i]<<endl;
                hs[str[i]-'A']--;}
        }
    }
    cout<<sum<<endl;
    return 0;
}


# include<iostream>
# include<cstring>
using namespace std;
char str[10005];
int hs[1000];
int main()
{
    int n;
    cin>>n;
    cin>>str;
    int sum=0;
    for(int i=0;i<27;i++)
    {
     hs[i]=0;
    }
   // memset(hs,0,sizeof(hs));
    for(int i=0;i<strlen(str);i++)
    { //cout<<str[i]<<endl;
        if(str[i]<='z'&&str[i]>='a')
        {
            hs[str[i]-'a']++;
        }else{
        if(hs[str[i]-'A']==0)
            {sum++;   }
        else {
                //cout<<str[i]<<endl;
                hs[str[i]-'A']--;}
        }
    }
    cout<<sum<<endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>

using namespace std;

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

	int n;
	string s,s1;

	cin>>n>>s;
	int t=0,k=0;
	for (int i=1;i<n;i++){
		if (s[t]-s[t+1]!=32) {
			int f=s1.find(s[t+1]);
			if (f>=0) s1.erase(f,1);
			else k++;
			s1+=s[t]-32;
		}
		t=t+2;
	}

		cout<<k;
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>

using namespace std;

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

	int n;
	string s,s1;

	cin>>n>>s;
	int t=0,k=0;
	for (int i=1;i<n;i++){
		if (s[t]-s[t+1]!=32) {
			int f=s1.find(s[t+1]);
			if (f>=0) s1.erase(f,1);
			else k++;
			s1+=s[t]-32;
		}
		t=t+2;
	}

		cout<<k;
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>

using namespace std;

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

	int n;
	string s,s1;

	cin>>n>>s;
	int t=0,k=0;
	for (int i=1;i<n;i++){
		if (s[t]-s[t+1]!=32) {
			if (!s1.find(s[t+1])) s1.erase(s1.find(s[t+1]),1);
			else k++;
			s1+=s[t]-32;
		}
		t=t+2;
	}

		cout<<k;
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>

using namespace std;

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

	int n;
	string s,s1;

	cin>>n>>s;
	int t=0,k=0;
	for (int i=1;i<n;i++){
		if (s[t]-s[t+1]!=32) {
			if (!s1.find(s[t+1])) s1.erase(s1.find(s[t+1]),1);
			else k++;
			s1+=s[t]-32;
		}
		t=t+2;
	}

		cout<<k;
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>

using namespace std;

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

     string s;
     int n,t=0;

     cin>>n>>s;

     int m=s.length();
     int j=0;
     for (int i=1;i<n;i++){
            int k=s[t];
            int p=s[t+1];

           if (k-p==32) j++;

        t=t+2;

     }
     cout<<n-1-j;
		return 0;
}


#include <stdio.h>

int main(){

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

    int arr[27]={0};
    int sum=0;

    for(int i=0;i<n*2-1;i++){
        char tmp;
        scanf("%c",&tmp);

        if(i%2==0){//key
            arr[tmp-'a']++;

        }else{//room
            if(arr[tmp-'a']>0)//key exist
            {
                arr[tmp-'a']--;

            }else{
                sum++;
            }
        }

    }

    printf("%d\n",sum);

}


#include <stdio.h>

int main(){

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

    int arr[27]={0};
    int sum=0;

    for(int i=0;i<n*2-1;i++){
        char tmp;
        scanf("%c",&tmp);

        if(i%2==0){//key
            arr[tmp-'a']++;

        }else{//room
            if(arr[tmp]>0)//key exist
            {
                arr[tmp]--;

            }else{
                sum++;
            }
        }

    }

    printf("%d\n",sum);

}


#include <stdio.h>

int main(){

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

    int arr[27]={0};
    int sum=0;

    char str[100005]={0};
    scanf("%s",str);

    for(int i=0;i<n*2-1;i++){
        char tmp=str[i];

        if(i%2==0){//key
            arr[tmp-'a']+=1;

        }else{//room
            if(arr[tmp-'A']==0)//no key
            {
                sum+=1;
            }else{
                arr[tmp-'A']--;
            }
        }

    }

    printf("%d\n",sum);

}