Problem:
String Conversion
Problem
ジェニファーとマリアンはカーラに文字列
S
をプレゼントしました。
しかし、カーラは文字列
S
をもらっても嬉しくありません。
文字列
T
が欲しかったのです。
3人は協力して文字列
S
を文字列
T
に変えることにしました。
最初にジェニファーが文字を任意の順番に並び替えます。
次にマリアンが２種類のアルファベットの小文字を交換することを任意の回数行います。
この操作では、例えば以下のように、文字列中の同じ文字が全て交換されます。
aab
→
a
と
b
を交換 →
bba
aab
→
a
と
c
を交換 →
ccb
最後にカーラがある1文字を別の1文字に置換することを
T
になるまで繰り返します。
ジェニファーとマリアンはカーラの置換回数が少なくなるようにしてあげることにしました。
カーラが行う置換の回数の最小値を求めてください。
Input
n
S
T
1行目に文字列の長さ
n
が与えられる。
2行目に文字列
S
、3行目に文字列
T
が与えられる。
Constraints
1 ≤
n
≤ 10
5
S
,
T
は
'a'~'z'
のみを含む
|
S
| = |
T
| =
n
Output
カーラの最少の置換回数を1行に出力せよ。
Sample Input 1
3
abc
xyz
Sample Output 1
0
Sample Input 2
5
aaabb
xyxyz
Sample Output 2
1

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
int a[26],b[26],n,ans;
string s,t;

int main() {
  cin >> n >> s >> t;
  for(int i=0; i<n; i++) {
    a[s[i]-'a']++;
    b[t[i]-'a']++;
  }
  sort(a,a+26);
  sort(b,b+26);
  for(int i=0; i<26; i++) ans+=max(0,b[i]-a[i]);
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3332
final_rank: 13

code_snippet: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL

#define SIZE 100000

int main(){
    int n;
    int s_cc[26]={0},t_cc[26]={0};
    int ans = 0;
    string s,t;
    
    cin >> n >> s >> t;
    
    for(int i=0;i<n;i++){
        s_cc[s[i]-'a']++;
        t_cc[t[i]-'a']++;
    }
    
    sort(s_cc,s_cc+26);
    sort(t_cc,t_cc+26);
    
    for(int i=0;i<26;i++){
        ans += max(0,s_cc[i]-t_cc[i]);
    }
    
    cout << ans << endl;
    
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1524
final_rank: 3

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

const int INF = 1 << 28;

int main () {
    int n; cin >> n;
    string S, T;
    cin >> S >> T;

    vector<int> s(256), t(256);
    for (int i = 0; i < n; i++) {
        s[S[i]]++;
        t[T[i]]++;
    }

    sort(s.begin(), s.end(), greater<int>());
    sort(t.begin(), t.end(), greater<int>());

    int res = 0;
    for (int i = 0; i < t.size() && i < s.size(); i++) {
        res += abs(t[i] - s[i]);
    }

    cout << res / 2 << endl;

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1524
final_rank: 3

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
int main(){
  int n;
  string a,b;
  cin>>n>>a>>b;

  int cnt1[256]={0};
  rep(i,n)cnt1[(char)a[i]]++;
  int cnt2[256]={0};
  rep(i,n)cnt2[(char)b[i]]++;

  vector<int>A,B;
  rep(i,256)if(cnt1[i])A.push_back(cnt1[i]);
  rep(i,256)if(cnt2[i])B.push_back(cnt2[i]);

  n=max(A.size(),B.size());
  while(A.size()!=n)A.push_back(0);
  while(B.size()!=n)B.push_back(0);
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  ////////////////////////////
  /*rep(i,n){
    rep(j,n){
      if(B[i]==A[j]){
	A.erase(A.begin()+j);
	B.erase(B.begin()+i);
	i--;j--;
	break;
      }
    }
  }*/
  int out=0;
  rep(i,A.size()){
    if(B[i]>A[i]){
      out+=B[i]-A[i];
    }
  }
  cout<<out<<endl;
  /*
  rep(i,A.size())cout<<A[i]<<endl;
  cout<<endl;
  rep(i,B.size())cout<<B[i]<<endl;
  */
}
accuracy: 1
time_ms: 10
memory_kb: 1532
final_rank: 11

code_snippet: #include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

#define unless(c) if (!(c))
#define each(i, c) for (auto& i: c)

using namespace std;

const int inf = 1 << 29;
struct edge { int to, cap, cost, rev; };

const int MAX_V = ('z' - 'a') * 2 + 10;

int V = MAX_V;
vector<edge> g[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V], preve[MAX_V];

void add_edge(int from, int to, int cap, int cost)
{
  // cout << from << ' ' << to << endl;
  g[from].push_back((edge){to, cap, cost, g[to].size()});
  g[to].push_back((edge){from, 0, -cost, g[from].size() - 1});
}

typedef pair<int, int> P;

int min_cost_flow(int s, int t, int f)
{
  // cout << "st : " << s << " => " << t << endl;
  int res = 0;
  while(f > 0){
    fill(dist, dist + V, inf);
    dist[s] = 0;
    while (true) {
      bool flg = false;
      for (int v = 0; v < V; v++) {
        if (dist[v] == inf) continue;
        for (int i = 0; i < g[v].size(); i++) {
          edge &e = g[v][i];
          if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
            dist[e.to] = dist[v] + e.cost;
	    prevv[e.to] = v;
	    preve[e.to] = i;
	    flg = true;
          }
        }
      }
      if (!flg) break;
    }    
    // cout << __LINE__ << ": " << dist[t] << endl;
    if(dist[t] == inf){
      return res;
    }
    int d = f;
    for (int v = t; v != s; v = prevv[v]) {
      // cout << v << endl;
      d = min(d, g[prevv[v]][preve[v]].cap);
    }
    // cout << __LINE__ << ": " << endl;
    f -= d;
    res += d * dist[t];
    // cout << __LINE__ << ": " << endl;
    for (int v = t; v != s; v = prevv[v]) {
      edge &e = g[prevv[v]][preve[v]];
      e.cap -= d;
      g[v][e.rev].cap += d;
    }
    // cout << __LINE__ << ": " << endl;
  }
  return res;

  /*
    int res = 0;
    fill(h, h + V, inf);
    h[s] = 0;
    for (int loop = V; loop--; ) {
    for (int i = 0; i < V; ++i) {
    if (h[i] == inf) continue;
    for (int j = 0; j < g[i].size(); ++j) {
    edge& e = g[i][j];
    if (e.cap) {
    h[e.to] = min(h[e.to], h[i] + e.cost);
    }
    }
    }
    }
    for (int i = 0; i < V; ++i) {
    if (h[i] != inf) cout << i << ": " << h[i] << endl;
    }
    while (f > 0) {
    priority_queue<P, vector<P>, greater<P> > q;
    fill(dist, dist + V, inf);
    dist[s] = 0;
    q.push(P(0, s));
    while (q.size()) {
    const P p = q.top();
    q.pop();
    const int v = p.second;
    if (dist[v] < p.first) continue;
    for (int i = 0; i < g[v].size(); ++i) {
    const edge& e = g[v][i];
    if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
    prevv[e.to] = v;
    preve[e.to] = i;
    q.push(P(dist[e.to], e.to));
    }
    }
    }
    if (dist[t] >= inf) {
    return res;
    }
    for (int v = 0; v < V; ++v) {
    h[v] += dist[v];
    }
    int d = f;
    for (int v = t; v != s; v = prevv[v]) {
    d = min(d, g[prevv[v]][preve[v]].cap);
    }
    f -= d;
    res += d * h[t];
    for (int v = t; v != s; v = prevv[v]) {
    edge& e = g[prevv[v]][preve[v]];
    e.cap -= d;
    g[v][e.rev].cap += d;
    }
    }
    return res;
  */
}

int main(void)
{
  int n;
  while (cin >> n) {
    fill(g, g + V, vector<edge>());
    string s;
    string t;
    cin >> s >> t;
    int cnt_s[300];
    int cnt_t[300];
    set<char> cs(s.begin(), s.end());
    fill(cnt_s, cnt_s + 300, 0);
    fill(cnt_t, cnt_t + 300, 0);
    for (char c = 'a'; c <= 'z'; ++c) {
      cnt_s[c] = count(s.begin(), s.end(), c);
      cnt_t[c] = count(t.begin(), t.end(), c);
    }
    const int source = V - 1;
    const int sink = V - 2;
    const int base = V / 2;
    for (char c = 'a'; c <= 'z'; ++c) {
      for (char d = 'a'; d <= 'z'; ++d) {
	if (cnt_s[c] && cnt_t[d]) {
	  int a = c - 'a';
	  int b = d - 'a' + base;
	  add_edge(a, b, 1, -min(cnt_s[c], cnt_t[d]));
	}
      }
    }
    for (char c = 'a'; c <= 'z'; ++c) {
      if (cnt_s[c]) {
	add_edge(source, c - 'a', 1, 0);
	int n = c - 'a';
	// g[source].push_back((edge){n, 1, 0});
      }
      if (cnt_t[c]) {
	add_edge(c - 'a' + base, sink, 1, 0);
	int n = c - 'a' + base;
	// g[n].push_back((edge){sink, 1, 0});
      }
    }
    int tmp = min_cost_flow(source, sink, cs.size());
    // cout << "tmp: " << tmp << endl;
    cout << n + tmp << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1532
final_rank: 11

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

#define loop(i,a,b) for(int i=a;i<(int)(b);i++)
#define rep(i,b) loop(i,0,b)
#define show(x) cout << #x << " = " << x << endl
template<class T>
ostream& operator << (ostream& os, const vector<T> v){
    rep(i,v.size()) os << v[i] << " ";
    return os;
}

typedef long long ll;



typedef int Capacity;
typedef int Cost;
struct PrimalDual {
    struct Edge {
        int dst;
        Capacity cap, cap_orig;
        Cost cost;
        int revEdge; bool isRev;
        Edge(int dst, Capacity cap, Cost cost, int revEdge, bool isRev)
            :dst(dst), cap(cap), cap_orig(cap), cost(cost), revEdge(revEdge), isRev(isRev) {}
    };
    int n;
    vector<vector<Edge> > g;
    enum : Cost { inf = 1<<29 };
    enum : int { MAX_V = 1000 };

    PrimalDual(int n_) : n(n_), g(vector<vector<Edge> >(n_)){}

    void add_edge(int src, int dst, Capacity cap, Cost cost) {
        g[src].emplace_back(dst, cap, cost, g[dst].size(), false);
        g[dst].emplace_back(src, 0, -cost, g[src].size() - 1, true);
    }

    Cost solve(int s, int t, int f) {
        Cost res = 0;
        static Cost h[MAX_V], dist[MAX_V];
        static int prevv[MAX_V], preve[MAX_V];
        rep(i,n)h[i] = 0;
        while (f > 0) {
            typedef pair<Cost,int> pcv;
            priority_queue<pcv, vector<pcv>, greater<pcv> > q;
            rep(i,n) dist[i] = inf;
            dist[s] = 0;
            q.emplace(pcv(0, s));
            while (q.size()) {
                pcv p = q.top(); q.pop();
                int v = p.second;
                if (dist[v] < p.first) continue;
                rep(i,g[v].size()){
                    Edge &e = g[v][i];
                    if (e.cap > 0 && dist[e.dst] > dist[v] + e.cost + h[v] - h[e.dst]) {
                        dist[e.dst] = dist[v] + e.cost + h[v] - h[e.dst];
                        prevv[e.dst] = v;
                        preve[e.dst] = i;
                        q.emplace(pcv(dist[e.dst], e.dst));
                    }
                }
            }
            if (dist[t] == inf) {
                return -1;
            }
            rep(v,n) h[v] += dist[v];
            // s-t 間最短路に沿って目一杯流す
            int d = f;
            for (int v = t; v != s; v = prevv[v]) {
                d = min(d, g[prevv[v]][preve[v]].cap);
            }
            f -= d;
            res += d * h[t];
            for (int v = t; v != s; v = prevv[v]) {
                Edge &e = g[prevv[v]][preve[v]];
                e.cap -= d;
                g[v][e.revEdge].cap += d;
            }
        }
        return res;
    }

    void view(){
        rep(i,g.size()){
            rep(j,g[i].size())if(!g[i][j].isRev){
                Edge& e = g[i][j];
                if(e.cap_orig - e.cap==0) continue;
                printf("%3d->%3d (flow:%d cost:%d)\n", i, e.dst, e.cap_orig - e.cap, e.cost);
            }
        }
    }

};

int main(){
    int n;
    while(cin >> n){
        string s,t;
        cin >> s >> t;
        vector<int> cs(26),ct(26);
        rep(i,n){
            cs[s[i]-'a']++;
            ct[t[i]-'a']++;
        }
        PrimalDual g(102);
        const int S = 100;
        const int T = 101;
        // from, to, cap, cost
        rep(i,26){
            g.add_edge(S,    i, 1, 0);
            g.add_edge(50+i, T, 1, 0);
        }
        rep(i,26)rep(j,26){
            g.add_edge(i, j+50, 1, max(0, ct[j]-cs[i]));
        }
        int ans = g.solve(S,T,26);
        //g.view();
        //show(ans);
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 1524
final_rank: 3

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=1;i<n;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) REP(i,v.size())cout<<#v<<"["<<i<<"]: "<<v[i]<<endl
#define ALL(a) (a).begin(),(a).end()

int main(){
  int n;
  string S,T;
  cin >> n >> S >> T;
  int scnt[26],tcnt[26];
  REP(i,26)scnt[i]=tcnt[i]=0;
  REP(i,n){
    scnt[S[i]-'a']++;
    tcnt[T[i]-'a']++;
  }
  sort(scnt,scnt+26);
  sort(tcnt,tcnt+26);
  int rest = 0;
  int result = 0;
  REP(i,26){
    int sc = scnt[i], tc = tcnt[i];
    if(sc==tc)continue;
    if(sc>tc){
      result += (sc-tc);
    }
  }
  cout << result << endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1404
final_rank: 2

code_snippet: #include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int INF = INT_MAX / 2;

int main()
{
    int n;
    string s, t;
    cin >> n >> s >> t;

    vector<int> a(26, 0), b(26, 0);
    for(int i=0; i<n; ++i){
        ++ a[s[i]-'a'];
        ++ b[t[i]-'a'];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    vector<vector<int> > dp(27, vector<int>(27, INF));
    dp[0][0] = 0;
    for(int i=0; i<27; ++i){
        for(int j=0; j<27; ++j){
            if(i < 26)
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + a[i]);
            if(j < 26)
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + b[j]);
            if(i < 26 && j < 26)
                dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + abs(a[i] - b[j]));
        }
    }
    cout << (dp[26][26] / 2) << endl;

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1524
final_rank: 3

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int n;
	string s,t;
	cin >> n >> s >> t;
	int a[30] = {} , b[30] = {};
	rep(i,n){
		a[s[i]-'a'] ++;
		b[t[i]-'a'] ++;
	}
	
	vector<int> A,B;
	rep(i,26){
		A.pb(a[i]);
		B.pb(b[i]);
	}
	sor(A);
	sor(B);
	
	int ret = 0;
	rep(i,26){
		ret += abs(A[i]-B[i]);
	}
	
	cout << ret/2 << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 1528
final_rank: 9

code_snippet: #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <limits>
#include <ctime>
#include <cassert>
#include <map>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <stack>
#include <queue>
#include <numeric>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)

template<typename ...> static inline int getchar_unlocked(void) { return getchar(); }
template<typename ...> static inline void putchar_unlocked(int c) { putchar(c); }
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
void reader(ll& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
int reader(char c[]) { int i, s = 0; for (;;) { mygc(i); if (i != ' '&&i != '\n'&&i != '\r'&&i != '\t'&&i != EOF) break; }c[s++] = i; for (;;) { mygc(i); if (i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF) break; c[s++] = i; }c[s] = '\0'; return s; }
template <class T, class S> void reader(T& x, S& y) { reader(x); reader(y); }
template <class T, class S, class U> void reader(T& x, S& y, U& z) { reader(x); reader(y); reader(z); }
template <class T, class S, class U, class V> void reader(T& x, S& y, U& z, V & w) { reader(x); reader(y); reader(z); reader(w); }
void writer(int x, char c) { int s = 0, m = 0; char f[10]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
void writer(ll x, char c) { int s = 0, m = 0; char f[20]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
void writer(const char c[]) { int i; for (i = 0; c[i] != '\0'; i++)mypc(c[i]); }
void writer(const char x[], char c) { int i; for (i = 0; x[i] != '\0'; i++)mypc(x[i]); mypc(c); }
template<class T> void writerLn(T x) { writer(x, '\n'); }
template<class T, class S> void writerLn(T x, S y) { writer(x, ' '); writer(y, '\n'); }
template<class T, class S, class U> void writerLn(T x, S y, U z) { writer(x, ' '); writer(y, ' '); writer(z, '\n'); }
template<class T> void writerArr(T x[], int n) { if (!n) { mypc('\n'); return; }FOR(i, n - 1)writer(x[i], ' '); writer(x[n - 1], '\n'); }

ll mod_pow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
template<class T> T extgcd(T a, T b, T& x, T& y) { for (T u = y = 1, v = x = 0; a;) { T q = b / a; swap(x -= q * u, u); swap(y -= q * v, v); swap(b -= q * a, a); } return b; }
template<class T> T mod_inv(T a, T m) { T x, y; extgcd(a, m, x, y); return (m + x % m) % m; }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

vector<int> f(string& s) {
	vector<int> ret(26);
	for (auto c : s) ret[c - 'a']++;
	sort(ret.begin(), ret.end());
	return ret;
}

int main() {
	int n;
	string s, t;
	cin >> n >> s >> t;
	auto v1 = f(s), v2 = f(t);
	int ans = 0;
	FOR(i, 26) {
		int diff = v1[i] - v2[i];
		if (diff > 0) ans += diff;
	}
	writerLn(ans);
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1368
final_rank: 1

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int inf = 10000000;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
  Edge(int src, int dst) :
    src(src), dst(dst) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int hungarian(const Matrix &a) {
  int n = a.size(), p, q;
  Array fx(n, inf), fy(n, 0);
  vector<int> x(n, -1), y(n, -1);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      fx[i] = max(fx[i], a[i][j]);
  for (int i = 0; i < n; ) {
    vector<int> t(n, -1), s(n+1, i);
    for (p = q = 0; p <= q && x[i] < 0; ++p)
      for (int k = s[p], j = 0; j < n && x[i] < 0; ++j)
        if (fx[k] + fy[j] == a[k][j] && t[j] < 0) {
          s[++q] = y[j], t[j] = k;
          if (s[q] < 0)
            for (p = j; p >= 0; j = p)
              y[j] = k = t[j], p = x[k], x[k] = j;
        }
    if (x[i] < 0) {
      int d = inf;
      for (int k = 0; k <= q; ++k)
        for (int j = 0; j < n; ++j)
          if (t[j] < 0) d = min(d, fx[s[k]] + fy[j] - a[s[k]][j]);
      for (int j = 0; j < n; ++j) fy[j] += (t[j] < 0 ? 0 : d);
      for (int k = 0; k <= q; ++k) fx[s[k]] -= d;
    } else ++i;
  }
  int ret = 0;
  for (int i = 0; i < n; ++i){
 
	ret += a[i][x[i]];
  }
  return ret;
}


int main(){
	int n;
	cin >> n;
	string s,t;
	cin >> s >> t;
	map<char,int> dic1,dic2;
	for( auto c : s ) dic1[c]++;
	for( auto c : t ) dic2[c]++;
	

	Matrix mat(26,Array(26));
	for(int i = 0 ; i < 26 ; i++){
		for(int j = 0 ; j < 26 ; j++){
			mat[i][j] = min(dic1['a'+i],dic2['a'+j]);
		}
	}
	cout << n-hungarian(mat) << endl;
	
	
}
accuracy: 1
time_ms: 10
memory_kb: 1524
final_rank: 3

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

vector<int> tov(string s){
  vector<int> v(128);
  for(auto e:s){
    v[e]++;
  }
  sort(begin(v),end(v));
  return v;
}

int main(){
  int n;
  cin>>n;
  string S;
  cin>>S;
  string T;
  cin>>T;
  auto sv=tov(S);
  auto tv=tov(T);
  int ans=0;
  for(int i=0;i<sv.size();i++){
    ans+=abs(sv[i]-tv[i]);
  }
  cout<<ans/2<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 1528
final_rank: 9

code_snippet: #define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
int INF = INT_MAX / 2;
double EPS = 1e-10;

int main() {
	int n; cin >> n;
	string S, T; cin >> S >> T;
	vector<int> a(26), b(26);
	for (int i = 0; i < n; i++) {
		a[S[i] - 'a']++;
		b[T[i] - 'a']++;
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	int sum = 0;
	for (int k = 0; k < 26; k++)
		sum += abs(a[k] - b[k]);
	cout << sum / 2 << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 1524
final_rank: 3