#include <cassert>
#include <iostream>
#include <iterator>
#include <vector>
#include <tuple>

#define STRING_IMPL(...) #__VA_ARGS__
#define STRING(...) STRING_IMPL(__VA_ARGS__)

#ifdef DEBUG
#define debug(...) void(std::cerr << "[" __FILE__ ":" STRING(__LINE__)  "] " #__VA_ARGS__ " = " << (__VA_ARGS__) << '\n')
#else
#define debug(...) void()
#endif

template <typename... Ts>
std::ostream& operator<<(std::ostream &os, std::tuple<Ts...> const &theTuple) {
    os << '(';
    std::apply([&os](Ts const&... tupleArgs) {
            std::size_t n{0};
            ((os << tupleArgs << (++n != sizeof...(Ts) ? ", " : "")), ...);
        }, theTuple);
    return os << ')';
}

template <typename T>
std::ostream& operator<< (std::ostream &os, std::vector<T> const &v) {
	os << '[';
	std::copy(begin(v), end(v), std::ostream_iterator<T>(os, ", "));
	os << "\b\b]";
	return os;
}

constexpr size_t N = 3;

std::string merge_cat(std::string const &lhs, std::string const &rhs) {
	std::string cat = rhs + lhs;

	std::vector<size_t> Z;
	Z.reserve(cat.size());
	Z.push_back(0);

	size_t l = 0;
	size_t r = 0;
	for (size_t i = 1; i < cat.size(); ++i)
		if (i > r) {
			l = r = i;
			while (r < cat.size() && cat[r] == cat[r-l])
				++r;
			Z.push_back(r - l);
		} else if (Z[i - l] > r - i) {
			l = i;
			while (r < cat.size() && cat[r] == cat[r-l])
				++r;
			Z.push_back(r - l);
		} else {
			Z.push_back(Z[i - l]);
		}

	assert(Z.size() == cat.size());

	size_t overlapping = 0;
	for (size_t i = cat.size() - rhs.size(); i < cat.size(); ++i) {
		if (i + Z[i] == cat.size()) {
			overlapping = Z[i];
			break;
		}
	}

	debug(std::tuple{lhs, rhs, Z, overlapping});

	cat.clear();
	std::copy(begin(lhs), end(lhs), back_inserter(cat));
	std::copy(begin(rhs) + overlapping, end(rhs), back_inserter(cat));

	return cat;
}

size_t solve(std::array<std::string, N> const &S) {
	auto min = SIZE_MAX;

	debug(S[0].size() + S[1].size() + S[2].size());

	for (size_t i = 0; i < N; ++i)
		for (size_t j = 0; j < N; ++j)
			for (size_t k = 0; k < N; ++k)
				if (i != j && j != k && k != i) {
					min = std::min(min, merge_cat(merge_cat(S[i], S[j]), S[k]).size());
					min = std::min(min, merge_cat(S[i], merge_cat(S[j], S[k])).size());
				}

	return min;
}

int main() {
	std::array<std::string, N> S;
	for (auto &s : S)
		std::cin >> s;
	std::cout << solve(S) << '\n';
}


#include <cassert>
#include <iostream>
#include <iterator>
#include <vector>
#include <tuple>

#define STRING_IMPL(...) #__VA_ARGS__
#define STRING(...) STRING_IMPL(__VA_ARGS__)

#ifdef DEBUG
#define debug(...) void(std::cerr << "[" __FILE__ ":" STRING(__LINE__)  "] " #__VA_ARGS__ " = " << (__VA_ARGS__) << '\n')
#else
#define debug(...) void()
#endif

template <typename... Ts>
std::ostream& operator<<(std::ostream &os, std::tuple<Ts...> const &theTuple) {
    os << '(';
    std::apply([&os](Ts const&... tupleArgs) {
            std::size_t n{0};
            ((os << tupleArgs << (++n != sizeof...(Ts) ? ", " : "")), ...);
        }, theTuple);
    return os << ')';
}

template <typename T>
std::ostream& operator<< (std::ostream &os, std::vector<T> const &v) {
	os << '[';
	std::copy(begin(v), end(v), std::ostream_iterator<T>(os, ", "));
	os << "\b\b]";
	return os;
}

constexpr size_t N = 3;

void merge_cat(std::string &out, std::string const &rhs) {
	std::string cat = rhs + out;

	std::vector<size_t> Z;
	Z.reserve(cat.size());
	Z.push_back(0);

	size_t l = 0;
	size_t r = 0;
	for (size_t i = 1; i < cat.size(); ++i)
		if (i > r) {
			l = r = i;
			while (r < cat.size() && cat[r] == cat[r-l])
				++r;
			Z.push_back(r - l);
		} else if (Z[i - l] > r - i) {
			l = i;
			while (r < cat.size() && cat[r] == cat[r-l])
				++r;
			Z.push_back(r - l);
		} else {
			Z.push_back(Z[i - l]);
		}

	assert(Z.size() == cat.size());

	size_t overlapping = 0;
	for (size_t i = cat.size() - rhs.size(); i < cat.size(); ++i) {
		if (i + Z[i] == cat.size()) {
			overlapping = Z[i];
			break;
		}
	}

	debug(std::tuple{out, rhs, Z, overlapping});

	out.reserve(cat.size() - overlapping);
	for (size_t i = overlapping; i < rhs.size(); ++i)
		out.push_back(rhs[i]);
}

size_t solve(std::array<std::string, N> const &S) {
	auto min = SIZE_MAX;

	for (size_t i = 0; i < N; ++i)
		for (size_t j = 0; j < N; ++j)
			for (size_t k = 0; k < N; ++k)
				if (i != j && j != k && k != i) {
					std::string cat = S[i];
					merge_cat(cat, S[j]);
					merge_cat(cat, S[k]);
					min = std::min(min, cat.size());
				}

	return min;
}

int main() {
	std::array<std::string, N> S;
	for (auto &s : S)
		std::cin >> s;
	std::cout << solve(S) << '\n';
}


#include <cassert>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <tuple>
#include <vector>

#define STRING_IMPL(...) #__VA_ARGS__
#define STRING(...) STRING_IMPL(__VA_ARGS__)

#ifdef DEBUG
#define debug(...) void(std::cerr << "[" __FILE__ ":" STRING(__LINE__)  "] " #__VA_ARGS__ " = " << (__VA_ARGS__) << '\n')
#else
#define debug(...) void()
#endif

template <typename... Ts>
std::ostream& operator<<(std::ostream &os, std::tuple<Ts...> const &theTuple) {
    os << '(';
    std::apply([&os](Ts const&... tupleArgs) {
            std::size_t n{0};
            ((os << tupleArgs << (++n != sizeof...(Ts) ? ", " : "")), ...);
        }, theTuple);
    return os << ')';
}

template <typename T>
std::ostream& operator<< (std::ostream &os, std::vector<T> const &v) {
	os << '[';
	std::copy(begin(v), end(v), std::ostream_iterator<T>(os, ", "));
	os << "\b\b]";
	return os;
}

constexpr size_t N = 3;

std::vector<size_t> zalgo(std::string_view S) noexcept {
	size_t l = 0, r = 0;
	std::vector<size_t> Z;
	Z.reserve(S.size());
	Z.push_back(Z.size());

	for (size_t i = 1; i < S.size(); ++i)
		if (i > r) {
			l = r = i;
			while (r < S.size() && S[r] == S[r-l])
				++r;
			Z.push_back(r - l);
		} else if (Z[i - l] > r - i) {
			l = i;
			while (r < S.size() && S[r] == S[r-l])
				++r;
			Z.push_back(r - l);
		} else {
			Z.push_back(Z[i - l]);
		}

	assert(Z.size() == S.size());
	return Z;
}

std::string merge_cat(std::string const &lhs, std::string const &rhs) {
	auto cat = rhs + lhs;
	auto const Z = zalgo(cat);

	size_t overlapping = 0;
	for (size_t i = cat.size() - std::min(lhs.size(), rhs.size()); i < cat.size(); ++i) {
		assert(i + Z[i] <= cat.size());
		if (i + Z[i] == cat.size()) {
			overlapping = Z[i];
			break;
		}
	}

	cat.resize(cat.size() - overlapping);
	auto it = copy(begin(lhs), end(lhs), begin(cat));
	copy(begin(rhs) + overlapping, end(rhs), it);
	return cat;
}

bool contains(std::string const &a, std::string const &b) noexcept {
	auto const Z = zalgo(b + a);

	for (size_t i = b.size(); i < Z.size(); ++i)
		if (Z[i] >= b.size())
			return true;

	return false;
}

size_t solve(std::vector<std::string> &S) {
	auto const l = [](std::string const &a, std::string const &b) { return a.size() != b.size() ? a.size() < b.size() : a < b; };

	sort(begin(S), end(S), l);
	for (size_t i = S.size() - 1; i < S.size(); --i)
		for (size_t j = i+1; j < S.size(); ++j)
			if (contains(S[j], S[i])) {
				S.erase(begin(S) + i);
				break;
			}

	auto min = SIZE_MAX;

	do {
		std::string cat = "";
		for (auto const &s : S)
			cat = merge_cat(cat, s);
		min = std::min(min, cat.size());
	} while (next_permutation(begin(S), end(S), l));

	return min;
}

int main() {
	std::vector<std::string> S;
	for (size_t i = 0; i < N; ++i) {
		std::string x;
		std::cin >> x;
		S.push_back(std::move(x));
	}
	std::cout << solve(S) << '\n';
}


#include <cassert>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <tuple>
#include <vector>

#define STRING_IMPL(...) #__VA_ARGS__
#define STRING(...) STRING_IMPL(__VA_ARGS__)

#ifdef DEBUG
#define debug(...) void(std::cerr << "[" __FILE__ ":" STRING(__LINE__)  "] " #__VA_ARGS__ " = " << (__VA_ARGS__) << '\n')
#else
#define debug(...) void()
#endif

template <typename... Ts>
std::ostream& operator<<(std::ostream &os, std::tuple<Ts...> const &theTuple) {
    os << '(';
    std::apply([&os](Ts const&... tupleArgs) {
            std::size_t n{0};
            ((os << tupleArgs << (++n != sizeof...(Ts) ? ", " : "")), ...);
        }, theTuple);
    return os << ')';
}

template <typename T>
std::ostream& operator<< (std::ostream &os, std::vector<T> const &v) {
	os << '[';
	std::copy(begin(v), end(v), std::ostream_iterator<T>(os, ", "));
	os << "\b\b]";
	return os;
}

constexpr size_t N = 3;

std::string add(std::string_view a, std::string_view b) {
	std::string ret(a.size() + b.size(), 0);
	auto it = copy(begin(a), end(a), begin(ret));
	copy(begin(b), end(b), it);
	return ret;
}

std::vector<size_t> zalgo(std::string_view S) noexcept {
	size_t l = 0, r = 0;
	std::vector<size_t> Z(S.size(), S.size());

	for (size_t i = 1; i < S.size(); ++i)
		if (i > r) {
			l = r = i;
			while (r < S.size() && S[r] == S[r-l])
				++r;
			Z[i] = r - l;
		} else if (Z[i - l] >= r - i) {
			l = i;
			while (r < S.size() && S[r] == S[r-l])
				++r;
			Z[i] = r - l;
		} else {
			Z[i] = Z[i - l];
		}

	return Z;
}

std::string merge_cat(std::string_view lhs, std::string_view rhs) {
	auto cat = add(rhs, lhs);
	auto const Z = zalgo(cat);

	size_t overlapping = 0;
	for (size_t i = cat.size() - std::min(lhs.size(), rhs.size()); i < cat.size(); ++i) {
		assert(i + Z[i] <= cat.size());
		if (i + Z[i] == cat.size()) {
			overlapping = Z[i];
			break;
		}
	}

	cat.resize(cat.size() - overlapping);
	auto it = copy(begin(lhs), end(lhs), begin(cat));
	copy(begin(rhs) + overlapping, end(rhs), it);
	return cat;
}

bool contains(std::string_view a, std::string_view b) noexcept {
	auto const Z = zalgo(add(b, a));

	for (size_t i = b.size(); i < Z.size(); ++i)
		if (Z[i] >= b.size())
			return true;

	return false;
}

size_t solve(std::vector<std::string> &S) {
	auto const l = [](std::string const &a, std::string const &b) { return a.size() != b.size() ? a.size() < b.size() : a < b; };

	sort(begin(S), end(S), l);
	for (size_t i = S.size() - 1; i < S.size(); --i)
		for (size_t j = i+1; j < S.size(); ++j)
			if (contains(S[j], S[i])) {
				S.erase(begin(S) + i);
				break;
			}

	auto min = SIZE_MAX;

	do {
		std::string cat = "";
		for (auto const &s : S)
			cat = merge_cat(cat, s);
		min = std::min(min, cat.size());
	} while (next_permutation(begin(S), end(S), l));

	return min;
}

int main() {
	std::vector<std::string> S(N);
	for (auto &x : S)
		std::cin >> x;
	std::cout << solve(S) << '\n';
}


#include <cassert>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <tuple>
#include <vector>

#define STRING_IMPL(...) #__VA_ARGS__
#define STRING(...) STRING_IMPL(__VA_ARGS__)

#ifdef DEBUG
#define debug(...) void(std::cerr << "[" __FILE__ ":" STRING(__LINE__)  "] " #__VA_ARGS__ " = " << (__VA_ARGS__) << '\n')
#else
#define debug(...) void()
#endif

template <typename... Ts>
std::ostream& operator<<(std::ostream &os, std::tuple<Ts...> const &theTuple) {
    os << '(';
    std::apply([&os](Ts const&... tupleArgs) {
            std::size_t n{0};
            ((os << tupleArgs << (++n != sizeof...(Ts) ? ", " : "")), ...);
        }, theTuple);
    return os << ')';
}

template <typename T>
std::ostream& operator<< (std::ostream &os, std::vector<T> const &v) {
	os << '[';
	std::copy(begin(v), end(v), std::ostream_iterator<T>(os, ", "));
	os << "\b\b]";
	return os;
}

constexpr size_t N = 3;

std::vector<size_t> zalgo(std::string const &S) noexcept {
	std::vector<size_t> Z;
	Z.reserve(S.size());
	Z.push_back(0);

	size_t l = 0, r = 0;
	for (size_t i = 1; i < S.size(); ++i)
		if (i > r) {
			l = r = i;
			while (r < S.size() && S[r] == S[r-l])
				++r;
			Z.push_back(r - l);
		} else if (Z[i - l] > r - i) {
			l = i;
			while (r < S.size() && S[r] == S[r-l])
				++r;
			Z.push_back(r - l);
		} else {
			Z.push_back(Z[i - l]);
		}

	return Z;
}

std::string merge_cat(std::string const &lhs, std::string const &rhs) {
	std::string cat = rhs + lhs;
	auto const Z = zalgo(cat);
	assert(Z.size() == cat.size());

	size_t overlapping = 0;
	for (size_t i = cat.size() - std::min(lhs.size(), rhs.size()); i < cat.size(); ++i) {
		if (i + Z[i] == cat.size()) {
			overlapping = Z[i];
			break;
		}
	}

	cat.clear();
	std::copy(begin(lhs), end(lhs), back_inserter(cat));
	std::copy(begin(rhs) + overlapping, end(rhs), back_inserter(cat));

	return cat;
}

bool contains(std::string const &a, std::string const &b) noexcept {
	auto const Z = zalgo(b + a);

	for (size_t i = b.size(); i < Z.size(); ++i)
		if (Z[i] == b.size())
			return true;

	return false;
}

size_t solve(std::vector<std::string> &S) {
	auto min = SIZE_MAX;

	sort(begin(S), end(S), [](std::string const &a, std::string const &b) { return a.size() < b.size(); });
	for (size_t i = 0; i < S.size(); ++i)
		for (size_t j = i+1; j < S.size(); ++j)
			if (contains(S[j], S[i])) {
				S.erase(begin(S) + i);
				break;
			}

	sort(begin(S), end(S));

	do {
		std::string cat = "";
		for (auto const &s : S)
			cat = merge_cat(cat, s);
		min = std::min(min, cat.size());
	} while (next_permutation(begin(S), end(S)));

	return min;
}

int main() {
	std::vector<std::string> S;
	for (size_t i = 0; i < N; ++i) {
		std::string x;
		std::cin >> x;
		S.emplace_back(std::move(x));
	}
	std::cout << solve(S) << '\n';
}


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

int kmp(string t, string p, bool b) {
    int m = (int)p.size();
    vector<int> v(100005);
    int i = 0, j = -1; v[0] = -1;
    while (i < m) {
        while (j >= 0 && p[i] != p[j]) j = v[j];
        i++; j++;
        v[i] = j;
    }
    i = 0, j = 0;
    int n = (int)t.size();
    while (i < n) {
        while (j >= 0 && t[i] != p[j]) j = v[j];
        i++; j++;
        if (b && j == m)
            return 1;
        if (!b && i == n)
            return j;
    }
    return 0;
}

void solve() {
    vector<string> v(3);
    for (int i = 0; i < 3; i++)
        cin >> v[i];
    sort(v.begin(), v.end());
    int ans = 3 * 100005;
    do {
        string a = v[0], b = v[1], c = v[2];
        if (!kmp(a, b, 1))
            a += b.substr(kmp(a, b, 0));
        if (!kmp(a, c, 1))
            a += c.substr(kmp(a, c, 0));
        ans = min(ans, (int)a.size());
    } while (next_permutation(v.begin(), v.end()));
    cout << ans << '\n';
}

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

    solve();
    return 0;
}


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

bool kmp(string T, string P) {
    int m = (int)P.size();
    vector<int> bP(m + 10);
    int i = 0, j = -1; bP[0] = -1;
    while (i < m) {
        while (j >= 0 && P[i] != P[j]) j = bP[j];
        i++; j++;
        bP[i] = j;
    }
    i = 0, j = 0;
    int n = (int)T.size();
    while (i < n) {
        while (j >= 0 && T[i] != P[j]) j = bP[j];
        i++; j++;
        if (j == m) {
            return true;
            j = bP[j];
        }
    }
    return false;
}

int f(string T, string P) {
    int m = (int)P.size();
    vector<int> bP(m + 10);
    int i = 0, j = -1; bP[0] = -1;
    while (i < m) {
        while (j >= 0 && P[i] != P[j]) j = bP[j];
        i++; j++;
        bP[i] = j;
    }
    i = 0, j = 0;
    int n = (int)T.size();
    while (i < n) {
        while (j >= 0 && T[i] != P[j]) j = bP[j];
        i++; j++;
        if (i == n)
            return j;
    }
    return -1;
}

void solve() {
    vector<string> v(3);
    for (string& s : v)
        cin >> s;
    sort(v.begin(), v.end());
    if (kmp(v[1], v[0]) || kmp(v[2], v[0])) {
        if (kmp(v[2], v[1])) {
            cout << v[2].size() << '\n';
        } else {
            cout << (int)v[1].size() + (int)v[2].size() - max(f(v[1], v[2]), f(v[2], v[1])) << '\n';
        }
    } else if (kmp(v[2], v[1])) {
        cout << (int)v[0].size() + (int)v[2].size() - max(f(v[0], v[2]), f(v[2], v[0])) << '\n';
    } else {
        int ans = 3 * 100005;
        do {
            string a = v[0], b = v[1], c = v[2];
            // if (kmp(a + c, b)) {
            //     ans = min(ans, (int)a.size() + (int)c.size() - f(a, c));
            // } else {
                a += b.substr(f(a, b));
                // ans = min(ans,
                //     (int)a.size() + (int)b.size() + (int)c.size() -
                //     max(f(a, b) - f(b, c), (int))
                // );
                ans = min(ans, (int)a.size() + (int)c.size() - f(a, c));
            // }
        } while (next_permutation(v.begin(), v.end()));
        cout << ans << '\n';
    }
}

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

    solve();
    return 0;
}


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

bool kmp(string T, string P) {
    int m = (int)P.size();
    vector<int> bP(m + 10);
    int i = 0, j = -1; bP[0] = -1;
    while (i < m) {
        while (j >= 0 && P[i] != P[j]) j = bP[j];
        i++; j++;
        bP[i] = j;
    }
    i = 0, j = 0;
    int n = (int)T.size();
    while (i < n) {
        while (j >= 0 && T[i] != P[j]) j = bP[j];
        i++; j++;
        if (j == m) {
            return true;
            j = bP[j];
        }
    }
    return false;
}

int f(string T, string P) {
    int m = (int)P.size();
    vector<int> bP(m + 10);
    int i = 0, j = -1; bP[0] = -1;
    while (i < m) {
        while (j >= 0 && P[i] != P[j]) j = bP[j];
        i++; j++;
        bP[i] = j;
    }
    i = 0, j = 0;
    int n = (int)T.size();
    while (i < n) {
        while (j >= 0 && T[i] != P[j]) j = bP[j];
        i++; j++;
        if (i == n)
            return j;
    }
    return -1;
}

void solve() {
    vector<string> v(3);
    for (string& s : v)
        cin >> s;
    sort(v.begin(), v.end());
    if (kmp(v[1], v[0]) || kmp(v[2], v[0])) {
        if (kmp(v[2], v[1])) {
            cout << v[2].size() << '\n';
        } else {
            cout << (int)v[1].size() + (int)v[2].size() - max(f(v[1], v[2]), f(v[2], v[1])) << '\n';
        }
    } else if (kmp(v[2], v[1])) {
        cout << (int)v[0].size() + (int)v[2].size() - max(f(v[0], v[2]), f(v[2], v[0])) << '\n';
    } else {
        int ans = 3 * 100005;
        do {
            string a = v[0], b = v[1], c = v[2];
            if (kmp(a + c, b)) {
                ans = min(ans, (int)a.size() + (int)c.size() - f(a, c));
            } else {
                a += b.substr(f(a, b));
                // ans = min(ans,
                //     (int)a.size() + (int)b.size() + (int)c.size() -
                //     max(f(a, b) - f(b, c), (int))
                // );
                ans = min(ans, (int)a.size() + (int)c.size() - f(a, c));
            }
        } while (next_permutation(v.begin(), v.end()));
        cout << ans << '\n';
    }
}

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

    solve();
    return 0;
}


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

bool kmp(string T, string P) {
    int m = (int)P.size();
    vector<int> bP(m + 10);
    int i = 0, j = -1; bP[0] = -1;
    while (i < m) {
        while (j >= 0 && P[i] != P[j]) j = bP[j];
        i++; j++;
        bP[i] = j;
    }
    i = 0, j = 0;
    int n = (int)T.size();
    while (i < n) {
        while (j >= 0 && T[i] != P[j]) j = bP[j];
        i++; j++;
        if (j == m) {
            return true;
            j = bP[j];
        }
    }
    return false;
}

int f(string T, string P) {
    // cout << T << '\n';
    // cout << P << '\n';
    int m = (int)P.size();
    vector<int> bP(m + 10);
    int i = 0, j = -1; bP[0] = -1;
    while (i < m) {
        while (j >= 0 && P[i] != P[j]) j = bP[j];
        i++; j++;
        bP[i] = j;
    }
    i = 0, j = 0;
    int n = (int)T.size();
    while (i < n) {
        // if (j >= 0)
        //     cout << T[i] << " " << P[j] << '\n';
        while (j >= 0 && T[i] != P[j]) j = bP[j];
        i++; j++;
        if (i == n)
            return j;
        // j = bP[j];
    }
    return -1;
}

void solve() {
    vector<string> v(3);
    for (string& s : v)
        cin >> s;
    sort(v.begin(), v.end());
    if (kmp(v[1], v[0]) || kmp(v[2], v[0])) {
        if (kmp(v[2], v[1])) {
            cout << v[2].size() << '\n';
        } else {
            cout << (int)v[1].size() + (int)v[2].size() - max(f(v[1], v[2]), f(v[2], v[1])) << '\n';
        }
    } else if (kmp(v[2], v[1])) {
        cout << (int)v[0].size() + (int)v[2].size() - max(f(v[0], v[2]), f(v[2], v[0])) << '\n';
    } else {
        int ans = 3 * 100005;
        do {
            string a = v[0], b = v[1], c = v[2];
            if (kmp(a + c, b)) {
                ans = min(ans, (int)a.size() + (int)c.size() - f(a, c));
            } else {
                // cout << f(a, b) << " " <<  f(b, c) << '\n';
                ans = min(ans,
                    (int)a.size() + (int)b.size() + (int)c.size() -
                    f(a, b) - f(b, c)
                );
            }
        } while (next_permutation(v.begin(), v.end()));
        cout << ans << '\n';
    }
}

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

    solve();
    // string a, b, c;
    // cin >> a >> b >> c;
    // cout <<f(b, c)<<'\n';
    return 0;
}


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

bool kmp(string T, string P) {
    int m = (int)P.size();
    vector<int> bP(m + 10);
    int i = 0, j = -1; bP[0] = -1;
    while (i < m) {
        while (j >= 0 && P[i] != P[j]) j = bP[j];
        i++; j++;
        bP[i] = j;
    }
    i = 0, j = 0;
    int n = (int)T.size();
    vector<int> ans;
    while (i < n) {
        while (j >= 0 && T[i] != P[j]) j = bP[j];
        i++; j++;
        if (j == m) {
            return true;
            j = bP[j];
        }
    }
    return false;
}

int f(string a, string b) {
    int sz_a = (int)a.size();
    int sz_b = (int)b.size();
    int i = sz_a - 1, j = 0, x = 0;
    while (i >= 0 && j < sz_b && a[i] == b[j]) {
        x++; i--; j++;
    }
    return x;
}

void solve() {
    vector<string> v(3);
    for (string& s : v)
        cin >> s;
    sort(v.begin(), v.end());
    if (kmp(v[1], v[0]) || kmp(v[2], v[0])) {
        if (kmp(v[2], v[1])) {
            cout << v[2].size() << '\n';
        } else {
            cout << (int)v[1].size() + (int)v[2].size() - max(f(v[1], v[2]), f(v[2], v[1])) << '\n';
        }
    } else if (kmp(v[2], v[1])) {
        cout << (int)v[0].size() + (int)v[2].size() - max(f(v[0], v[2]), f(v[2], v[0])) << '\n';
    } else {
        int ans = 3 * 100005;
        do {
            string a = v[0], b = v[1], c = v[2];
            if (kmp(a + c, b)) {
                ans = min(ans, (int)a.size() + (int)c.size() - f(a, c));
            } else {
                ans = min(ans,
                    (int)a.size() + (int)b.size() + (int)c.size() -
                    f(a, b) - f(b, c)
                );
            }
        } while (next_permutation(v.begin(), v.end()));
        cout << ans << '\n';
    }
}

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

    solve();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
// #define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll

auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}

int modpow(int a,int n,int m=1e9+7)
{
	int ans=1;
	while(n)
	{
		if(n%2)
			ans=(ans*a)%m;
		a*=a;
		a%=m;
		n/=2;
	}
	return ans;
}

int f(string a,string b,string c)
{
	const int mod=1e9+7;
	const int fac=43;
	int n1=a.size(),n2=b.size();
	int pre[n1+1];
	pre[0]=0;
	int po=1;
	for(int i=1;i<=n1;i++)
	{
		pre[i]=(pre[i-1]+po*(a[i-1]-'a'))%mod;
		po=(po*fac)%mod;
	}
	int pre1[n2+1];
	pre1[0]=0;
	po=1;
	for(int i=1;i<=n2;i++)
	{
		pre1[i]=(pre1[i-1]+(b[i-1]-'a')*po)%mod;
		po=(po*fac)%mod;
	}
	int comm=0;
	for(int i=min(n1,n2);i>0;i--)
	{
		int v1=pre[n1]-pre[n1-i];
		int v2=pre1[i]-pre1[0];
		v2*=modpow(fac,n1-i);
		v2%=mod;
		if(v1==v2)
		{
			comm=i;break;
		}
	}
	for(int i=comm;i<n2;i++)
	{
		a+=b[i];
	}
	b=c;
	n1=a.size(),n2=b.size();
	int pre2[n1+1];
	pre2[0]=0;
	po=1;
	for(int i=1;i<=n1;i++)
	{
		pre2[i]=(pre2[i-1]+po*(a[i-1]-'a'))%mod;
		po=(po*fac)%mod;
	}
	int pre22[n2+1];
	pre22[0]=0;
	po=1;
	for(int i=1;i<=n2;i++)
	{
		pre22[i]=(pre22[i-1]+po*(b[i-1]-'a'))%mod;
		po=(po*fac)%mod;
	}
	comm=0;
	for(int i=min(n1,n2);i>0;i--)
	{
		int v1=pre2[n1]-pre2[n1-i];
		int v2=pre22[i]-pre22[0];
		v2*=modpow(fac,n1-i);
		v2%=mod;
		if(v1==v2)
		{
			comm=i;break;
		}
	}
	for(int i=comm;i<n2;i++)
	{
		a+=b[i];
	}
	return a.size();
}

signed main()
{
	fio
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	cout<<min({f(s1,s2,s3),f(s1,s3,s2),f(s2,s1,s3),f(s2,s3,s1),f(s3,s1,s2),f(s3,s2,s1)});
	printclock;
}


#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
// #define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll

auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}

int modpow(int a,int n,int m=1e9+7)
{
	int ans=1;
	while(n)
	{
		if(n%2)
			ans=(ans*a)%m;
		a*=a;
		a%=m;
		n/=2;
	}
	return ans;
}

int f(string a,string b,string c)
{
	const int mod=1e9+7;
	const int fac=43;
	int n1=a.size(),n2=b.size();
	int pre[n1+1];
	pre[0]=0;
	int po=1;
	for(int i=1;i<=n1;i++)
	{
		pre[i]=(pre[i-1]+po*(a[i-1]-'a'))%mod;
		po=(po*fac)%mod;
	}
	int pre1[n2+1];
	pre1[0]=0;
	po=1;
	for(int i=1;i<=n2;i++)
	{
		pre1[i]=(pre1[i-1]+(b[i-1]-'a')*po)%mod;
		po=(po*fac)%mod;
	}
	int comm=0;
	for(int i=min(n1,n2);i>0;i--)
	{
		int v1=pre[n1]-pre[n1-i];
		v1+=mod;
		v1%=mod;
		int v2=pre1[i]-pre1[0];
		v2+=mod;
		v2%=mod;
		v2*=modpow(fac,n1-i);
		v2%=mod;
		if(v1==v2)
		{
			comm=i;break;
		}
	}
	for(int i=0;i+n2<n1;i++)
	{
		int v1=pre[i+n2]-pre[i];
		v1+=mod;
		v1%=mod;
		int v2=pre1[n2];
		v2*=modpow(fac,i);
		v2%=mod;
		if(v1==v2)
		{
			comm=max(comm,n2);
			break;
		}
	}
	for(int i=0;i+n1<n2;i++)
	{
		int v1=pre[n1];
		int v2=pre1[i+n1]-pre1[i];
		v2+=mod;
		v2%=mod;
		v1*=modpow(fac,i);
		v1%=mod;
		if(v1==v2)
		{
			comm=max(comm,n1);
			break;
		}
	}
	if(comm==a.size())
	{
		a=b;
	}
	else
	{
		for(int i=comm;i<n2;i++)
		{
			a+=b[i];
		}
	}
	b=c;
	n1=a.size(),n2=b.size();
	int pre2[n1+1];
	pre2[0]=0;
	po=1;
	for(int i=1;i<=n1;i++)
	{
		pre2[i]=(pre2[i-1]+po*(a[i-1]-'a'))%mod;
		po=(po*fac)%mod;
	}
	int pre22[n2+1];
	pre22[0]=0;
	po=1;
	for(int i=1;i<=n2;i++)
	{
		pre22[i]=(pre22[i-1]+po*(b[i-1]-'a'))%mod;
		po=(po*fac)%mod;
	}
	comm=0;
	for(int i=min(n1,n2);i>0;i--)
	{
		int v1=pre2[n1]-pre2[n1-i];
		v1+=mod;
		v1%=mod;
		int v2=pre22[i];
		v2*=modpow(fac,n1-i);
		v2%=mod;
		if(v1==v2)
		{
			comm=i;break;
		}
	}
	for(int i=0;i+n2<n1;i++)
	{
		int v1=pre2[i+n2]-pre2[i];
		v1+=mod;
		v1%=mod;
		int v2=pre22[n2];
		v2*=modpow(fac,i);
		v2%=mod;
		if(v1==v2)
		{
			comm=n2;
			break;
		}
	}
	for(int i=0;i+n1<n2;i++)
	{
		int v1=pre2[n1];
		int v2=pre22[i+n1]-pre22[i];
		v2+=mod;
		v2%=mod;
		v1*=modpow(fac,i);
		v1%=mod;
	//	cout<<v1<<','<<v2<<endl;
		if(v1==v2)
		{
			comm=max(comm,n1);
			break;
		}
	}
	//cout<<a<<','<<b<<endl;
	//cout<<comm<<endl;
	if(comm==a.size())
	{
		a=b;
	}
	else
	{
		for(int i=comm;i<n2;i++)
		{
			a+=b[i];
		}
	}
	//cout<<a<<endl;
	return a.size();
}

signed main()
{
	fio
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	//cout<<s1.size()<<' '<<s2.size()<<' '<<s3.size()<<endl;
	//cout<<f(s1,s2,s3)<<endl;return 0;
	cout<<min({f(s1,s2,s3),f(s1,s3,s2),f(s2,s1,s3),f(s2,s3,s1),f(s3,s1,s2),f(s3,s2,s1)});
	printclock;
}


#include <bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vL vector<ll>
#define pi pair<int,int>
#define pL pair<ll,ll>
#define pii pair<int,pi>
#define pLL pair<ll,pL>
#define vp vector<pi>
const int MX=100000;
const ll mod=998244353;
const ll inf=1e18;
const ll pm=999983;

ll pw[MX+10],sz[3],inv[MX+10];
ll hh[3][MX+10],rh[3][MX+10];
int is[3][3];
ll bigmod(ll a, ll b)
{
    if(!b)  return 1;
    if(b&1) return (a*bigmod(a,b-1))%mod;
    else
    {
        ll r=bigmod(a,b/2); return (r*r)%mod;
    }
}
int ck(int a, int b)
{
    if(a>b) swap(a,b);
    if(hh[a][sz[a]]==hh[b][sz[a]]) return 1;
    for(int i=sz[a]+1;i<=sz[b];i++)
    {
        ll H=(hh[b][i]-hh[b][i-sz[a]-1]+mod)%mod;
        H=(H*inv[i-sz[a]])%mod;
        if(H==hh[a][sz[a]]) return 1;
    }
    return 0;
}
int MXC(int a, int b, int c)
{
    int com=0;
    if(is[a][b]) com+=min(sz[a]+1,sz[b]+1);
    else
    {
        for(int i=min(sz[a],sz[b]);i>=0;i--)
        {
            if(rh[a][sz[a]-i]==hh[b][i])
            {
                com+=i+1; break;
            }
        }
    }
    if(is[b][c]) com+=min(sz[b]+1,sz[c]+1);
    else
    {
        for(int i=min(sz[b],sz[c]);i>=0;i--)
        {
            if(rh[b][sz[b]-i]==hh[c][i])
            {
                com+=i+1; break;
            }
        }
    }
    return com;
}
int main()
{
    FasterIO;
    ll tc,cs=1,i,j,n,m,x,q;

    ll base=29; pw[0]=inv[0]=1;
    ll INV=bigmod(base,mod-2);
    for(i=1;i<=MX; i++)
    {
        pw[i]=(pw[i-1]*base)%mod;
        inv[i]=(inv[i-1]*INV)%mod;
    }

    string a,b,c;

    cin>>a>>b>>c;
    sz[0]=a.size()-1; sz[1]=b.size()-1; sz[2]=c.size()-1;
    for(ll H=0,i=0;i<a.size();i++)
    {
        H=(H+a[i]*pw[i])%mod;
        hh[0][i]=H;
    }
    for(ll H=0,i=0;i<b.size();i++)
    {
        H=(H+b[i]*pw[i])%mod;
        hh[1][i]=H;
    }
    for(ll H=0,i=0;i<c.size();i++)
    {
        H=(H+c[i]*pw[i])%mod;
        hh[2][i]=H;
    }
    for(ll H=0,n=a.size()-1,i=n;i>=0;i--)
    {
        H=(H*base+a[i])%mod;
        rh[0][i]=H;
    }
    for(ll H=0,n=b.size()-1,i=n;i>=0;i--)
    {
        H=(H*base+b[i])%mod;
        rh[1][i]=H;
    }
    for(ll H=0,n=c.size()-1,i=n;i>=0;i--)
    {
        H=(H*base+c[i])%mod;
        rh[2][i]=H;
    }
    is[0][1]=is[1][0]=ck(0,1);
    is[1][2]=is[2][1]=ck(1,2);
    is[0][2]=is[2][0]=ck(0,2);
    int com=MXC(0,1,2);
    com=max(com,MXC(0,2,1));
    com=max(com,MXC(1,0,2));
    com=max(com,MXC(1,2,0));
    com=max(com,MXC(2,0,1));
    com=max(com,MXC(2,1,0));
    cout<<a.size()+b.size()+c.size()-com<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vL vector<ll>
#define pi pair<int,int>
#define pL pair<ll,ll>
#define pii pair<int,pi>
#define pLL pair<ll,pL>
#define vp vector<pi>
const int MX=100000;
const ll mod=998244353;
const ll inf=1e18;
const ll pm=999983;

ll pw[MX+10],sz[3];
ll hh[3][MX+10],rh[3][MX+10];
int MXC(int a, int b, int c)
{
    int com=0;
    for(int i=min(sz[a],sz[b]);i>=0;i--)
    {
        if(rh[a][sz[a]-i]==hh[b][i])
        {
            com+=i+1; break;
        }
    }
    for(int i=min(sz[b],sz[c]);i>=0;i--)
    {
        if(rh[b][sz[b]-i]==hh[c][i])
        {
            com+=i+1; break;
        }
    }
    return com;
}
int main()
{
    FasterIO;
    ll tc,cs=1,i,j,n,m,x,q;

    ll base=29; pw[0]=1;
    for(i=1;i<=MX; i++)
    {
        pw[i]=(pw[i-1]*base)%mod;
    }

    string a,b,c;

    cin>>a>>b>>c;
    sz[0]=a.size()-1; sz[1]=b.size()-1; sz[2]=c.size()-1;

    for(ll H=0,i=0;i<a.size();i++)
    {
        H=(H+a[i]*pw[i])%mod;
        hh[0][i]=H;
    }
    for(ll H=0,i=0;i<b.size();i++)
    {
        H=(H+b[i]*pw[i])%mod;
        hh[1][i]=H;
    }
    for(ll H=0,i=0;i<c.size();i++)
    {
        H=(H+c[i]*pw[i])%mod;
        hh[2][i]=H;
    }
    for(ll H=0,n=a.size()-1,i=n;i>=0;i--)
    {
        H=(H*base+a[i])%mod;
        rh[0][i]=H;
    }
    for(ll H=0,n=b.size()-1,i=n;i>=0;i--)
    {
        H=(H*base+b[i])%mod;
        rh[1][i]=H;
    }
    for(ll H=0,n=c.size()-1,i=n;i>=0;i--)
    {
        H=(H*base+c[i])%mod;
        rh[2][i]=H;
    }
    int com=MXC(0,1,2);
    com=max(com,MXC(0,2,1));
    com=max(com,MXC(1,0,2));
    com=max(com,MXC(1,2,0));
    com=max(com,MXC(2,0,1));
    com=max(com,MXC(2,1,0));
    cout<<a.size()+b.size()+c.size()-com<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vL vector<ll>
#define pi pair<int,int>
#define pL pair<ll,ll>
#define pii pair<int,pi>
#define pLL pair<ll,pL>
#define vp vector<pi>
const int MX=100000;
const ll mod=998244353;
const ll inf=1e18;
const ll pm=999983;

ll pw[MX+10],sz[3],inv[MX+10];
ll hh[3][MX+10],rh[3][MX+10];
int is[3][3];
ll bigmod(ll a, ll b)
{
    if(!b)  return 1;
    if(b&1) return (a*bigmod(a,b-1))%mod;
    else
    {
        ll r=bigmod(a,b/2); return (r*r)%mod;
    }
}
int ck(int a, int b)
{
    if(sz[a]>sz[b]) swap(a,b);
    if(hh[a][sz[a]]==hh[b][sz[a]]) return 1;
    for(int i=sz[a]+1;i<=sz[b];i++)
    {
        ll H=(hh[b][i]-hh[b][i-sz[a]-1]+mod)%mod;
        H=(H*inv[i-sz[a]])%mod;
        if(H==hh[a][sz[a]]) return 1;
    }
    return 0;
}
int MXC(int a, int b, int c)
{
    int com=0;
    if(is[a][b]) com+=min(sz[a]+1,sz[b]+1);
    else
    {
        for(int i=min(sz[a],sz[b]);i>=0;i--)
        {
            if(rh[a][sz[a]-i]==hh[b][i])
            {
                com+=i+1; break;
            }
        }
    }
    if(is[b][c]) com+=min(sz[b]+1,sz[c]+1);
    else
    {
        for(int i=min(sz[b],sz[c]);i>=0;i--)
        {
            if(rh[b][sz[b]-i]==hh[c][i])
            {
                com+=i+1; break;
            }
        }
    }
    return com;
}
int main()
{
    FasterIO;
    ll tc,cs=1,i,j,n,m,x,q;

    ll base=29; pw[0]=inv[0]=1;
    ll INV=bigmod(base,mod-2);
    for(i=1;i<=MX; i++)
    {
        pw[i]=(pw[i-1]*base)%mod;
        inv[i]=(inv[i-1]*INV)%mod;
    }

    string a,b,c;

    cin>>a>>b>>c;
    sz[0]=a.size()-1; sz[1]=b.size()-1; sz[2]=c.size()-1;
    for(ll H=0,i=0;i<a.size();i++)
    {
        H=(H+a[i]*pw[i])%mod;
        hh[0][i]=H;
    }
    for(ll H=0,i=0;i<b.size();i++)
    {
        H=(H+b[i]*pw[i])%mod;
        hh[1][i]=H;
    }
    for(ll H=0,i=0;i<c.size();i++)
    {
        H=(H+c[i]*pw[i])%mod;
        hh[2][i]=H;
    }
    for(ll H=0,n=a.size()-1,i=n;i>=0;i--)
    {
        H=(H*base+a[i])%mod;
        rh[0][i]=H;
    }
    for(ll H=0,n=b.size()-1,i=n;i>=0;i--)
    {
        H=(H*base+b[i])%mod;
        rh[1][i]=H;
    }
    for(ll H=0,n=c.size()-1,i=n;i>=0;i--)
    {
        H=(H*base+c[i])%mod;
        rh[2][i]=H;
    }
    is[0][1]=is[1][0]=ck(0,1);
    is[1][2]=is[2][1]=ck(1,2);
    is[0][2]=is[2][0]=ck(0,2);
//    cout<<is[0][1]<<" "<<is[1][2]<<" "<<is[0][2]<<endl;
    int com=MXC(0,1,2);
    com=max(com,MXC(0,2,1));
    com=max(com,MXC(1,0,2));
    com=max(com,MXC(1,2,0));
    com=max(com,MXC(2,0,1));
    com=max(com,MXC(2,1,0));
    cout<<a.size()+b.size()+c.size()-com<<endl;
    return 0;
}


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

const int64_t B = 101;
const int64_t MOD = 1000000007;
bool contain(const string &a, const string &b) { // a in b ?
    int al = a.length(), bl = b.length();
    if (al > bl)
        return false;

    int64_t ah = 0, bh = 0;
    int64_t t = 1;

    for ( int i=0; i<al; i++ ) {
        ah = (ah * B + (a[i] - 'a')) % MOD;
        bh = (bh * B + (b[i] - 'a')) % MOD;
        t = (t * B) % MOD;
    }
    if (ah == bh)
        return true;

    for (int i = al; i < bl; ++i) {
        bh = (bh * B + (b[i] - 'a') - (b[i - al] - 'a') * t) % MOD;
        if ( bh < 0 ) bh += MOD;
        if (ah == bh)
            return true;
    }

    return false;
}

int overlap(const string &a, const string &b) {
    int al = a.length(), bl = b.length();
    int iub = min(al, bl);

    int res = 0;

    int64_t ah = 0, bh = 0;
    int64_t t = 1;
    for (int i = 0; i < iub; ++i) {
        ah = (ah + (a[al - i - 1] - 'a') * t) % MOD;
        bh = (bh * B + (b[i] - 'a')) % MOD;
        t = (t * B) % MOD;
        if (ah == bh)
            res = i + 1;
    }

    return res;
}

int main() {
    string s[3];
    vector<int> perm(3);
    for ( int i=0; i<3; i++ ) cin >> s[i];
    for ( int i=0; i<3; i++ ) perm[i] = i;
    int ans = 1e9;
    do {
        string s1 = s[perm[0]], s2 = s[perm[1]], s3 = s[perm[2]];
        if ( !contain(s2, s1) ) {
            int x = overlap(s1, s2);
            s1 += s2.substr(x);
        }
        if  ( !contain(s3, s1) ) {
            int y = overlap(s1, s3);
            s1 += s3.substr(y);
        }
        ans = min(ans, (int) s1.size());
    } while ( next_permutation(perm.begin(), perm.end()) );
    cout << ans << '\n';
    return 0;
}


#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

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

int main() {
  vector<string> s(3);
  REP(i,3) cin >> s[i];
  sort(ALL(s));
  int ans=100100100;
  do {
    string t=s[0];
    {
      int l=min(SZ(t), SZ(s[1]));
      while ( t.substr(SZ(t)-l)!=s[1].substr(0,l) ) l--;
      t+=s[1].substr(l);
    }
    {
      int l = min(SZ(t), SZ(s[2]));
      while (t.substr(SZ(t) - l) != s[2].substr(0, l)) l--;
      t += s[2].substr(l);
    }
    chmin(ans, SZ(t));
  } while ( next_permutation(ALL(s)) );
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

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

int main() {
  vector<string> s(3);
  REP(i,3) cin >> s[i];
  sort(ALL(s));
  int ans=100100100;
  do {
    int res=SZ(s[0]);
    {
      int l=min(SZ(s[0]), SZ(s[1]));
      while ( s[0].substr(SZ(s[0])-l)!=s[1].substr(0,l) ) l--;
      res+=SZ(s[1])-l;
    }
    {
      int l = min(SZ(s[1]), SZ(s[2]));
      while (s[1].substr(SZ(s[1]) - l) != s[2].substr(0, l)) l--;
      res += SZ(s[2])-l;
    }
    chmin(ans, res);
  } while ( next_permutation(ALL(s)) );
  cout << ans << '\n';
  return 0;
}


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

const int64_t B = 101;
const int64_t MOD = 1000000007;
bool contain(const string &a, const string &b) { // a in b ?
    int al = a.length(), bl = b.length();
    if (al > bl)
        return false;

    int64_t ah = 0, bh = 0;
    int64_t t = 1;

    for ( int i=0; i<al; i++ ) {
        ah = (ah * B + (a[i] - 'a')) % MOD;
        bh = (bh * B + (b[i] - 'a')) % MOD;
        t *= B;
    }
    if (ah == bh)
        return true;

    for (int i = al; i < bl; ++i) {
        bh = (bh * B + (b[i] - 'a') - (b[i - al] - 'a') * t) % MOD;
        if ( bh < 0 ) bh += MOD;
        if (ah == bh)
            return true;
    }

    return false;
}

int overlap(const string &a, const string &b) {
    int al = a.length(), bl = b.length();
    int iub = min(al, bl);

    int res = 0;

    int64_t ah = 0, bh = 0;
    int64_t t = 1;
    for (int i = 0; i < iub; ++i) {
        ah = (ah + (a[al - i - 1] - 'a') * t) % MOD;
        bh = (bh * B + (b[i] - 'a')) % MOD;
        t *= B;
        if (ah == bh)
            res = i + 1;
    }

    return res;
}

int main() {
    string s[3];
    vector<int> perm(3);
    for ( int i=0; i<3; i++ ) cin >> s[i];
    for ( int i=0; i<3; i++ ) perm[i] = i;
    int ans = 1e9;
    do {
        string s1 = s[perm[0]], s2 = s[perm[1]], s3 = s[perm[2]];
        if ( !contain(s2, s1) ) {
            int x = overlap(s1, s2);
            s1 += s2.substr(x);
        }
        if  ( !contain(s3, s1) ) {
            int y = overlap(s1, s3);
            s1 += s3.substr(y);
        }
        ans = min(ans, (int) s1.size());
    } while ( next_permutation(perm.begin(), perm.end()) );
    cout << ans << '\n';
    return 0;
}


#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

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

int compute_z( string &a, string &b ) {
  string s=b+"#"+a;
  int n=SZ(s);
  vector<int> z(n);
  int x = 0, y = 0;
  for (int i = 1; i < n; i++) {
    z[i] = max(0, min(z[i - x], y - i + 1));
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
      x = i; y = i + z[i]; z[i]++;
    }
  }
  int mx=0;
  for ( int i=SZ(b)+1; i<n; i++ ) {
    chmax(mx,z[i]);
  }
  return mx;
}

int main() {
  vector<string> s(3);
  REP(i,3) cin >> s[i];
  sort(ALL(s));
  int ans=100100100;
  do {
    string t=s[0];
    {
      int l=compute_z(t,s[1]);
      if ( l!=SZ(s[1]) ) {
        t+=s[1].substr(l);
      }
    }
    {
      int l = compute_z(t, s[2]);
      if (l != SZ(s[2])) {
        t += s[2].substr(l);
      }
    }
    chmin(ans, SZ(t));
  } while ( next_permutation(ALL(s)) );
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

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

int compute_z( string &a, string &b ) {
  string s=b+"#"+a;
  int n=SZ(s);
  vector<int> z(n);
  int x = 0, y = 0;
  for (int i = 1; i < n; i++) {
    z[i] = max(0, min(z[i - x], y - i + 1));
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
      x = i; y = i + z[i]; z[i]++;
    }
  }
  int mx=0;
  for ( int i=SZ(b)+1; i<n; i++ ) {
    if ( z[i]==SZ(b) ) return z[i];
    if ( n-i==z[i] ) {
      chmax(mx, z[i]);
    }
  }
  return mx;
}

int main() {
  vector<string> s(3);
  REP(i,3) cin >> s[i];
  sort(ALL(s));
  int ans=100100100;
  do {
    string t=s[0];
    {
      int l=compute_z(t,s[1]);
      if ( l!=SZ(s[1]) ) {
        t+=s[1].substr(l);
      }
    }
    {
      int l = compute_z(t, s[2]);
      if (l != SZ(s[2])) {
        t += s[2].substr(l);
      }
    }
    chmin(ans, SZ(t));
  } while ( next_permutation(ALL(s)) );
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

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

int main() {
  vector<string> s(3);
  REP(i,3) cin >> s[i];
  sort(ALL(s));
  int ans=100100100;
  do {
    string t=s[0];
    if ( t.find(s[1])==string::npos ) {
      int l=min(SZ(t), SZ(s[1]));
      while ( t.substr(SZ(t)-l)!=s[1].substr(0,l) ) l--;
      t+=s[1].substr(l);
    }
    if (t.find(s[2])==string::npos) {
      int l = min(SZ(t), SZ(s[2]));
      while (t.substr(SZ(t) - l) != s[2].substr(0, l)) l--;
      t += s[2].substr(l);
    }
    chmin(ans, SZ(t));
  } while ( next_permutation(ALL(s)) );
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 1e6 + 5, MOD = 1e9 + 7, p = 31;
const ll INF = 1e18 + 17;

/*  stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?), set tle
	* do smth instead of nothing and stay organized
*/

void solve() {
	string s[4];
	cin >> s[0] >> s[1] >> s[2];
	vector <vector <ll> > h(4, vector <ll> (s[0].size() + s[1].size() + s[2].size(), 0));
	for (int i = 0; i < 3; ++i) {
		h[i][0] = s[i][0];
		for (int j = 1; j < s[i].size(); ++j) {
			h[i][j] = ((h[i][j - 1] * p) + s[i][j]) % MOD;
		}
	}
	auto pw = [&] (ll a, int n) {
		ll res = 1;
		while (n) {
			if (n & 1) res = res * a % MOD;
			a = a * a % MOD;
			n >>= 1;
		}
		return res;
	};
	auto get = [&] (int i, int L, int R) {
		if (!L) {
			return h[i][R];
		}
		return (h[i][R] - (h[i][L - 1] * pw(p, R - L + 1) % MOD) + MOD) % MOD;
	};
	vector <int> perm = {0, 1, 2};
	int ans = s[0].size() + s[1].size() + s[2].size();
	do {
		s[3] = "";
		bool was = 0;
		for (int L = 0; L < s[perm[0]].size(); ++L) {
			int R = s[perm[0]].size() - 1;
			if (s[perm[1]].size() >= R - L + 1) {
				if (get(perm[0], L, R) == get(perm[1], 0, R - L)) {
					s[3] += s[perm[1]];
					was = 1;
					break;
				}
			}
			s[3] += s[perm[0]][L];
		}
		if (!was) {
			s[3] += s[perm[1]];
		}
		h[3][0] = s[3][0];
		for (int j = 1; j < s[3].size(); ++j) {
			h[3][j] = ((h[3][j - 1] * p) + s[3][j]) % MOD;
		}
		string final;
		was = 0;
		for (int L = 0; L < s[3].size(); ++L) {
			int R = s[3].size() - 1;
			if (s[perm[2]].size() >= R - L + 1) {
				if (get(3, L, R) == get(perm[2], 0, R - L)) {
					final += s[perm[2]];
					was = 1;
					break;
				}
			}
			final += s[3][L];
		}
		if (!was) {
			final += s[perm[2]];
		}
		ans = min(ans, (int)final.size());
	}while (next_permutation(perm.begin(), perm.end()));
	cout << ans;
}

main(/*|^_^|*/) {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	int tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
		cout << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 1e6 + 5, MOD = 1e9 + 7, p = 31;
const ll INF = 1e18 + 17;

/*  stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?), set tle
	* do smth instead of nothing and stay organized
*/

void solve() {
	string s[4];
	cin >> s[0] >> s[1] >> s[2];
	vector <vector <ll> > h(4, vector <ll> (s[0].size() + s[1].size() + s[2].size(), 0));
	for (int i = 0; i < 3; ++i) {
		h[i][0] = s[i][0];
		for (int j = 1; j < s[i].size(); ++j) {
			h[i][j] = ((h[i][j - 1] * p) + s[i][j]) % MOD;
		}
	}
	auto pw = [&] (ll a, int n) {
		ll res = 1;
		while (n) {
			if (n & 1) res = res * a % MOD;
			a = a * a % MOD;
			n >>= 1;
		}
		return res;
	};
	auto get = [&] (int i, int L, int R) {
		if (R < L) return 0LL;
		if (!L) {
			return h[i][R];
		}
		return (h[i][R] - (h[i][L - 1] * pw(p, R - L + 1) % MOD) + MOD) % MOD;
	};
	vector <int> perm = {0, 1, 2};
	int ans = s[0].size() + s[1].size() + s[2].size();
	do {
		s[3] = "";
		bool was = 0;
		for (int L = 0; L < s[perm[0]].size(); ++L) {
			if (L + s[perm[1]].size() - 1 < s[perm[0]].size()) {
				if (get(perm[0], L, L + s[perm[1]].size() - 1) == get(perm[1], 0, s[perm[1]].size() - 1)) {
					s[3] = s[perm[0]];
					was = 1;
					break;
				}
			}
		}
		if (!was) {
			for (int L = 0; L < s[perm[0]].size(); ++L) {
				int R = s[perm[0]].size() - 1;
				if (s[perm[1]].size() >= R - L + 1) {
					if (get(perm[0], L, R) == get(perm[1], 0, R - L)) {
						s[3] += s[perm[1]];
						was = 1;
						break;
					}
				}
				s[3] += s[perm[0]][L];
			}
			if (!was) {
				s[3] += s[perm[1]];
			}
		}
		h[3][0] = s[3][0];
		for (int j = 1; j < s[3].size(); ++j) {
			h[3][j] = ((h[3][j - 1] * p) + s[3][j]) % MOD;
		}
		string final;
		was = 0;
		for (int L = 0; L < s[3].size(); ++L) {
			if (L + s[perm[2]].size() - 1 < s[3].size()) {
				if (get(3, L, L + s[perm[2]].size() - 1) == get(perm[2], 0, s[perm[2]].size() - 1)) {
					final = s[3];
					was = 1;
					break;
				}
			}
		}
		if (!was) {
			for (int L = 0; L < s[3].size(); ++L) {
				int R = s[3].size() - 1;
				if (s[perm[2]].size() >= R - L + 1) {
					if (get(3, L, R) == get(perm[2], 0, R - L)) {
						final += s[perm[2]];
						was = 1;
						break;
					}
				}
				final += s[3][L];
			}
			if (!was) {
				final += s[perm[2]];
			}
		}
		ans = min(ans, (int)final.size());
	}while (next_permutation(perm.begin(), perm.end()));
	cout << ans;
}

main(/*|^_^|*/) {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	int tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
		cout << '\n';
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc (o<<1)
#define rc (o<<1|1)
typedef long long ll;
typedef unsigned long long ull;
int mod=1e9+7;
const ll INF=1ll<<60;
const int maxn=3e5+10;
const int maxl=300+10;
const double pi=acos(-1.0);
const double eps=1e-8;
string s[3];
int d[3][3];
vector<int> zfunction(vector<int> s) {
    int n = (int) s.size();
    vector<int> z (n);
    for (int i=1, l=0, r=0; i<n; ++i) {
        if (i <= r)
            z[i] = min (r-i+1, z[i-l]);
        while (i+z[i] < n && s[z[i]] == s[i+z[i]])
            ++z[i];
        if (i+z[i]-1 > r)
            l = i,  r = i+z[i]-1;
    }
    z[0]=s.size();
    return z;
}
vector<int>v;
void f(int i,int j)
{
	string&a=s[i],&b=s[j];
	v.clear();
	for(auto&c:b)v.pb(c);
	v.pb(1<<30);
	for(auto&c:a)v.pb(c);
	auto z=zfunction(v);
	int n=min(a.size(),b.size());
	int ans=0;
	int sz=v.size();
	_for(i,1,n+1)
	{
		int u=z[sz-i];
		if(u==i)ans=i;
	}
	d[i][j]=ans;
}
int main()
{
	fast;_for(t,0,3)cin>>s[t];
	_for(i,0,3)_for(j,0,3)f(i,j);
	int a[3]={0,1,2};
	int ans=1<<30;
	do
	{
		int t=0;
		_for(i,0,3)t+=s[i].size();
		t-=(d[a[0]][a[1]]+d[a[1]][a[2]]);
		ans=min(ans,t);
	}while(next_permutation(a,a+3));
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc (o<<1)
#define rc (o<<1|1)
typedef long long ll;
typedef unsigned long long ull;
int mod=1e9+7;
const ll INF=1ll<<60;
const int maxn=3e5+10;
const int maxl=300+10;
const double pi=acos(-1.0);
const double eps=1e-8;
string s[3];
int d[3][3];
vector<int> zfunction(vector<int> s) {
    int n = (int) s.size();
    vector<int> z (n);
    for (int i=1, l=0, r=0; i<n; ++i) {
        if (i <= r)
            z[i] = min (r-i+1, z[i-l]);
        while (i+z[i] < n && s[z[i]] == s[i+z[i]])
            ++z[i];
        if (i+z[i]-1 > r)
            l = i,  r = i+z[i]-1;
    }
    z[0]=s.size();
    return z;
}
vector<int>v;
int f(string&a,string&b)
{
	v.clear();
	for(auto&c:b)v.pb(c);
	v.pb(1<<30);
	for(auto&c:a)v.pb(c);
	auto z=zfunction(v);
	int n=min(a.size(),b.size());
	int ans=0;
	int sz=v.size();
	_for(i,1,n+1)
	{
		int u=z[sz-i];
		if(u==i)ans=i;
	}
	return ans;
}
bool ch(string&a,string&b)
{
	if(a.size()>b.size())return 0;
	v.clear();
	for(auto&c:a)v.pb(c);
	v.pb(1<<30);
	for(auto&c:b)v.pb(c);
	auto z=zfunction(v);
	int n=min(a.size(),b.size());
	int sz=z.size();
	for(int i=a.size();i<=b.size();++i)
	{
		if(z[sz-i]==a.size())return 1;
	}
	return 0;
}
int main()
{
	fast;_for(t,0,3)cin>>s[t];
	set<string>se;_for(t,0,3)se.insert(s[t]);
	vector<string>v;
	for(auto&w:se)v.pb(w);
	bool ok=0;
	do
	{
		v.clear();
		for(auto&w:se)v.pb(w);
		se.clear();
		int n=v.size();
		for(auto&w:v)se.insert(w);
		bool fo=0;
		_for(i,0,n)_for(j,0,n)
		{
//			cout<<v[i]<<" "<<v[j]<<"\n";
			if(i!=j&&ch(v[i],v[j]))
			{
				fo=1;se.erase(v[i]);
			}
		}
		if(!fo)ok=1;
	}while(!ok);
	int n=v.size();_for(i,0,n)s[i]=v[i];
	int a[n];_for(i,0,n)a[i]=i;
	int ans=1<<30;
	do
	{
		string cur=s[0];
		_for(i,1,n)
		{
			int cl=f(cur,s[i]);
			cur+=s[i].substr(cl);
		}
		ans=min(ans,(int)cur.size());
	}while(next_permutation(a,a+n));
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc (o<<1)
#define rc (o<<1|1)
typedef long long ll;
typedef unsigned long long ull;
int mod=1e9+7;
const ll INF=1ll<<60;
const int maxn=3e5+10;
const int maxl=300+10;
const double pi=acos(-1.0);
const double eps=1e-8;
string s[3];
int d[3][3];
vector<int> zfunction(vector<int> s) {
    int n = (int) s.size();
    vector<int> z (n);
    for (int i=1, l=0, r=0; i<n; ++i) {
        if (i <= r)
            z[i] = min (r-i+1, z[i-l]);
        while (i+z[i] < n && s[z[i]] == s[i+z[i]])
            ++z[i];
        if (i+z[i]-1 > r)
            l = i,  r = i+z[i]-1;
    }
    z[0]=s.size();
    return z;
}
vector<int>v;
int f(string&a,string&b)
{
	v.clear();
	for(auto&c:b)v.pb(c);
	v.pb(1<<30);
	for(auto&c:a)v.pb(c);
	auto z=zfunction(v);
	int n=min(a.size(),b.size());
	int ans=0;
	int sz=v.size();
	_for(i,1,n+1)
	{
		int u=z[sz-i];
		if(u==i)ans=i;
	}
	return ans;
}
bool ch(string&a,string&b)
{
	if(a.size()>b.size())return 0;
	v.clear();
	for(auto&c:a)v.pb(c);
	v.pb(1<<30);
	for(auto&c:b)v.pb(c);
	auto z=zfunction(v);
	int n=min(a.size(),b.size());
	int sz=z.size();
	for(int i=a.size();i<=b.size();++i)
	{
		if(z[sz-i]==a.size())return 1;
	}
	return 0;
}
int main()
{
	fast;_for(t,0,3)cin>>s[t];
	set<string>se;_for(t,0,3)se.insert(s[t]);
	vector<string>v;
	for(auto&w:se)v.pb(w);
	bool ok=0;
	do
	{
		v.clear();
		for(auto&w:se)v.pb(w);
		se.clear();
		int n=v.size();
		for(auto&w:v)se.insert(w);
		bool fo=0;
		_for(i,0,n)_for(j,0,n)
		{
//			cout<<v[i]<<" "<<v[j]<<"\n";
			if(i!=j&&ch(v[i],v[j]))
			{
				fo=1;se.erase(v[i]);
			}
		}
		if(!fo)ok=1;
	}while(!ok);
	int n=v.size();_for(i,0,n)s[i]=v[i];
	int a[n];_for(i,0,n)a[i]=i;
	int ans=1<<30;
	do
	{
		string cur=s[a[0]];
		_for(i,1,n)
		{
			int cl=f(cur,s[a[i]]);
			cur+=s[a[i]].substr(cl);
		}
		ans=min(ans,(int)cur.size());
	}while(next_permutation(a,a+n));
	cout<<ans;
}


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

#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define eb emplace_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const int INF = 0x3f3f3f3f;

const int T = 1e5 + 3;
int pi[T];
string a[3];
string t,p;
int h;

void pre() {
    p += '#';
    pi[0] = pi[1] = 0;
    for(int i = 2; i < (int)p.size(); i++) {
        pi[i] = pi[i-1];
        while(pi[i] > 0 and p[pi[i]] != p[i-1]) pi[i] = pi[pi[i]];
        if(p[pi[i]] == p[i-1]) pi[i]++;
    }
}

int kmp() {
    pre();
    int k = 0;
    int m = p.size()-1;

    for(int i = 0; i < (int)t.size(); i++) {
        while(k > 0 and p[k] != t[i]) k = pi[k];
        if(p[k] == t[i]) k++;
        if(k == m) return k;
    }
    return k;
}

int calc(string x, string y, string z) {
    int hh = h;
    t = x;
    p = y;
    int s = kmp();
    hh -= s;
    for(int i = s; i < (int)y.size(); i++) t += y[i];
    p = z;
    hh -= kmp();
    return hh;
}

int solve() {
    string x = "012";
    int ans = INF;
    do {
        ans = min(ans, calc(a[x[0]-'0'], a[x[1]-'0'], a[x[2]-'0']));
    } while(next_permutation(x.begin(), x.end()));

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    while(cin >> a[0]) {
        cin >> a[1] >> a[2];
        h = a[0].size() + a[1].size() + a[2].size();
        cout << solve() << endl;
    }
    return 0;
}


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

#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define eb emplace_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const int INF = 0x3f3f3f3f;

const int T = 1e5 + 3;
int pi[T];
string a[3];
string t,p;
int h;

void pre() {
    p += '#';
    pi[0] = pi[1] = 0;
    for(int i = 2; i < (int)p.size(); i++) {
        pi[i] = pi[i-1];
        while(pi[i] > 0 and p[pi[i]] != p[i-1]) pi[i] = pi[pi[i]];
        if(p[pi[i]] == p[i-1]) pi[i]++;
    }
}

int kmp() {
    pre();
    int k = 0;

    for(int i = 0; i < (int)t.size(); i++) {
        while(k > 0 and p[k] != t[i]) k = pi[k];
        if(p[k] == t[i]) k++;
    }
    return k;
}

int calc(string x, string y, string z) {
    int hh = h;
    t = x;
    p = y;
    int s = kmp();
    hh -= s;
    t = x;
    for(int i = s; i < (int)y.size(); i++) t += y[i];
    p = z;
    hh -= kmp();
    return hh;
}

int solve() {
    string x = "012";
    int ans = INF;
    do {
        ans = min(ans, calc(a[x[0]-'0'], a[x[1]-'0'], a[x[2]-'0']));
    } while(next_permutation(x.begin(), x.end()));

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    while(cin >> a[0]) {
        cin >> a[1] >> a[2];
        h = a[0].size() + a[1].size() + a[2].size();
        cout << solve() << endl;
    }
    return 0;
}


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

#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define eb emplace_back

typedef long long ll;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const int INF = 0x3f3f3f3f;

const int T = 1e5 + 3;
int pi[T];
string a[3];
string t,p;
int h;

void pre() {
    p += '#';
    pi[0] = pi[1] = 0;
    for(int i = 2; i < (int)p.size(); i++) {
        pi[i] = pi[i-1];
        while(pi[i] > 0 and p[pi[i]] != p[i-1]) pi[i] = pi[pi[i]];
        if(p[pi[i]] == p[i-1]) pi[i]++;
    }
}

int kmp() {
    pre();
    int k = 0;

    for(int i = 0; i < (int)t.size(); i++) {
        while(k > 0 and p[k] != t[i]) k = pi[k];
        if(p[k] == t[i]) k++;
    }
    return k;
}

int calc(string x, string y, string z) {
    int hh = h;
    t = x;
    p = y;
    hh -= kmp();
    t = x+y;
    p = z;
    hh -= kmp();
    return hh;
}

int solve() {
    string x = "012";
    int ans = INF;
    do {
        ans = min(ans, calc(a[x[0]-'0'], a[x[1]-'0'], a[x[2]-'0']));
    } while(next_permutation(x.begin(), x.end()));

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    while(cin >> a[0]) {
        cin >> a[1] >> a[2];
        h = a[0].size() + a[1].size() + a[2].size();
        cout << solve() << endl;
    }
    return 0;
}


#ifdef DEBUG
#define trace(x) cerr << "DEBUG: " << (#x) << " = " << (x) << endl
#else
#pragma GCC optimize("Ofast")
#define trace(x)
#endif

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
using ll = long long;

const ll MOD = 1'000'000'007;
const ll B = 600'005;

int match(string const& a, string const& b) {
    int n = min(a.length(), b.length());
    int ans = 0;

    ll hash_a = 0;
    ll hash_b = 0;

    ll M = 1;
    for (int i = 1; i <= n; ++i) {
        hash_a = (hash_a * B + a[a.length() - i]) % MOD;
        hash_b = (hash_b + M * b[i - 1]) % MOD;
        M = (M * B) % MOD;
        if (hash_a == hash_b) ans = i;
    }

    return ans;
}

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

    vector<string> s;
    int len = 0;
    {
        vector<string> t(3);
        for (int i = 0; i < 3; ++i) {
            cin >> t[i];
        }
        for (int i = 0; i < 3; ++i) {
            bool b = true;
            for (int j = 0; j < 3; ++j) {
                if (t[i].length() < t[j].length() &&
                    t[j].find(t[i]) != string::npos) {
                    b = false;
                    break;
                }
            }
            if (b) {
                s.push_back(t[i]);
                len += t[i].length();
            }
        }
    }

    sort(s.begin(), s.end());

    int ans = INT_MAX;
    do {
        int k = 0;
        for (int i = 1; i < s.size(); ++i) {
            k += match(s[i - 1], s[i]);
        }
        ans = min(ans, len - k);
    } while (next_permutation(s.begin(), s.end()));

    cout << ans << endl;

    return 0;
}


#ifdef DEBUG
#define trace(x) cerr << "DEBUG: " << (#x) << " = " << (x) << endl
#else
#pragma GCC optimize("Ofast")
#define trace(x)
#endif

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;
using ll = long long;

const ll MOD = 1'000'000'007;
const ll B = 600'005;

int match(string const& a, string const& b) {
    int n = min(a.length(), b.length());
    int ans = 0;

    ll hash_a = 0;
    ll hash_b = 0;

    ll M = 1;
    for (int i = 1; i <= n; ++i) {
        hash_a = (hash_a * B + a[a.length() - i]) % MOD;
        hash_b = (hash_b + M * b[i - 1]) % MOD;
        M = (M * B) % MOD;
        if (hash_a == hash_b) ans = i;
    }

    return ans;
}

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

    vector<string> s(3);
    int len = 0;
    for (int i = 0; i < 3; ++i) {
        cin >> s[i];
        len += s[i].length();
    }

    sort(s.begin(), s.end());

    int ans = INT_MAX;
    do {
        ans = min(ans, len - match(s[0], s[1]) - match(s[1], s[2]));
    } while (next_permutation(s.begin(), s.end()));

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
#define li 400005
#define inf 1000000000
using namespace std;
int f[li],hh=inf;
string a,b,c;
int create(string gg){
    memset(f,0,sizeof(f));
    f[0]=0;
    int tam=(int)gg.size();
    for(int i=1;i<tam;i++){
        int j=f[i-1];
        while(j>0 && gg[i]!=gg[j]) j=f[j-1];
        if(gg[j]==gg[i]) j++;
        f[i]=j;
    }
    return f[tam-1];
}
int solve(string x,string y,string z){
    string q=y+'$'+x;
    int bul=create(q);
    string geveze=x;
    for(int i=bul;i<(int)y.size();i++) geveze=geveze+y[i];
    q=z+'$'+geveze;
    bul=create(q);
    int hty=(int)z.size()-bul;
    return (int)geveze.size()+hty;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>a>>b>>c;
    hh=min(hh,solve(a,b,c));
    hh=min(hh,solve(a,c,b));
    hh=min(hh,solve(b,a,c));
    hh=min(hh,solve(b,c,a));
    hh=min(hh,solve(c,b,a));
    hh=min(hh,solve(c,a,b));
    cout<<hh;
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
using namespace std;
string pi(string x,string y)
{
    int mx=0,c=0;
    string s=y+"#"+x;
    vector<int>pi(s.length());
    for(int i=1,j=0;i<s.length();i++)
    {
        while(j&&s[i]!=s[j])j=pi[j-1];
        if(s[i]==s[j])j++;
        pi[i]=j;
        if(j==(int)y.size())return x;
    }
    return x.substr(0,x.size()-pi.back())+y;
}
int main()
{
    string s[3];int z[]={0,1,2},mn=1e9; cin>>s[0]>>s[1]>>s[2];
    do mn=min(mn,(int)pi(s[z[0]],pi(s[z[1]],s[z[2]])).size());while(next_permutation(z,z+3));
    cout<<mn;
return 0;
}


#include <bits/stdc++.h>
#define li 400005
#define inf 1000000000
using namespace std;
int f[li],hh=inf;
string a,b,c;
int create(string gg,int sayma){
    memset(f,0,sizeof(f));
    f[0]=0;
    int tam=(int)gg.size();
    for(int i=1;i<tam;i++){
        int j=f[i-1];
        while(j>0 && gg[i]!=gg[j]) j=f[j-1];
        if(gg[j]==gg[i]) j++;
        f[i]=j;
        if(f[i]==sayma) return sayma;
    }
    return f[tam-1];
}
int solve(string x,string y,string z){
    int abc2=(int)y.size();
    string q=y+'$'+x;
    int bul=create(q,abc2);
    string geveze=x;
    for(int i=bul;i<(int)y.size();i++) geveze=geveze+y[i];
    q=z+'$'+geveze;
    bul=create(q,(int)q.size());
    int hty=(int)z.size()-bul;
    return (int)geveze.size()+hty;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>a>>b>>c;
    hh=min(hh,solve(a,b,c));
    hh=min(hh,solve(a,c,b));
    hh=min(hh,solve(b,a,c));
    hh=min(hh,solve(b,c,a));
    hh=min(hh,solve(c,b,a));
    hh=min(hh,solve(c,a,b));
    cout<<hh;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define    pf               printf
#define    PF(a)            printf("%d\n",(a))
#define    PF2(a,b)         printf("%d %d\n",(a), (b))
#define    PF3(a,b,c)       printf("%d %d %d\n",(a), (b), (c))
#define    PFL(a)           printf("%lld\n",(a))
#define    PFL2(a,b)        printf("%lld %lld\n",(a), (b))
#define    PFL3(a,b,c)      printf("%lld %lld %lld\n",(a), (b), (c))
#define    get(a)           cin>>a
#define    sf               scanf
#define    SF(a)            scanf("%d",&a)
#define    SF2(a,b)         scanf("%d %d",&a, &b)
#define    SF3(a,b,c)       scanf("%d %d %d",&a, &b, &c)
#define    SFL(a)           scanf("%lld",&a)
#define    SFL2(a,b)        scanf("%lld %lld",&a, &b)
#define    SFL3(a,b,c)      scanf("%lld %lld %lld",&a, &b, &c)
#define    gl(a)            getline(cin,(a))
#define    gc()             getchar()
#define    pb               push_back
#define    m_p              make_pair
#define    pc()             printf("Case %d: ",tt++)
#define    tc()             cout<<"Case "<<tt++<<": "
#define    dbg(x)           cout << #x << " -> " << x << endl;
#define    SZ(a)            (int)(a).size()
#define    all(a)           a.begin(),a.end()
#define    FF               first
#define    SS               second
#define    MAX              2134567891
#define    MOD              1000000007
#define    MM               100005
#define    PI               2*acos(0.0)
#define    cond(n,m)        (xx>=0 && xx<(n) && yy>=0 && yy<(m))

#define    mem(a)           memset((a),0,sizeof (a))
#define    SET(a)           memset((a),-1,sizeof (a))
#define    output           freopen("output.txt","w",stdout);
#define    input            freopen("input.txt","r",stdin);
#define    I_O              ios_base::sync_with_stdio(0); cin.tie(0)
#define    rep(a)           for(int i=0;i<(a);i++)
#define    FOR(a,b)         for(int i=(a);i<(b);i++)
#define    REP(a)           for(int j=0;j<(a);j++)
#define    rev(a)           for(int i=(a);i>=0;i--)
#define    fr(i,n)          for(i=0;i<n;i++)
#define    fr1(i,n,m)       for(i=n;i<m;i++)

int dx[]  = {0, 0, 1, -1};
int dy[]  = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};

typedef long long ll;
typedef unsigned long long llu;
typedef priority_queue < int > PQ;
typedef pair < int , int > pi;
typedef pair < int , pi > pii;
typedef vector < int > vi;
typedef vector < ll > vl;
typedef vector < string > vs;

ll bigmod(ll a, ll b, ll c){
    if(b==0)return 1%c;ll x=bigmod(a,b/2,c);x=(x*x)%c;
    if(b%2==1)x=(x*a)%c;return x;
}
ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}

/*
//FUNCTION//
ll poww(ll a, ll b){
    if(b==0)return 1;ll x=poww(a,b/2);x=x*x;if(b%2==1)x=(x*a);return x;
}

ll LCM(ll a, ll b){ return a*b/ __gcd(a,b);}

int pr = 50000;
vi primelist;
bool a[MM*100];
void seive( )
{
    int i,j,k=sqrt(pr);
    a[1]=1;
    primelist.pb(2);
    for(i=4;i<=pr;i+=2)a[i]=1;
    for(i=3;i<=k;i+=2)if(!a[i])for(j=i*i;j<=pr;j+=2*i)a[j]=1;
    for(i=3;i<=pr;i+=2)if(!a[i])primelist.pb(i);
}
int phi[MM];
void calculatePhi() {
  for (int i = 1; i < M; i++) {
    phi[i] = i;
  }
  for (int p = 2; p < M; p++) {
    if (phi[p] == p) { // p is a prime
      for (int k = p; k < M; k += p) {
        phi[k] -= phi[k] / p;
      }
    }
  }
}

ll fact_divs( ll n, ll p)
{
    ll cnt=0;while(p<=n){cnt += n/p;n /= p;}return cnt;
}
struct point{double x, y;};
double area( point A, point B, point C){
return 0.5*(A.x*(B.y-C.y) - A.y*(B.x-C.x) + B.x*C.y - C.x*B.y);
}

int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}

//*/
///AUTOMATA
const int M = 3*MM;
struct state{
    int len, link,fpos;
    bool isclone;
    int next[26];
} st[2*M];
int sz, last;
bool terminal[2*M];
void initialize(){
    rep(sz+1){
        REP(26){
            st[i].next[j] = 0;
        }
    }
    sz = last = 0; st[0].len = 0; st[0].link = -1;
}
void build_automata(char c){
    int cur = ++sz;
    st[cur].len = st[last].len + 1;
    st[cur].isclone = 0;
    st[cur].fpos = st[cur].len;
    int p;
    for(p=last;p!=-1 && !st[p].next[c]; p=st[p].link){
        st[p].next[c] = cur;
    }
    if(p==-1){
        st[cur].link = 0;
    }
    else{
        int q = st[p].next[c];
        if(st[p].len+1==st[q].len){
            st[cur].link = q;
        }
        else{
            int clone = ++sz;
            st[clone] = st[q];
            st[clone].len = st[p].len+1;
            st[clone].isclone = 1;
            for(;p!=-1 && st[p].next[c]==q;p=st[p].link){
                st[p].next[c] = clone;
            }
            st[q].link = st[cur].link = clone;
        }
    }
    last = cur;
}

void cal_terminal(){
    int now = last;
    while(now!=-1){
        terminal[now] = 1;
        now = st[now].link;
    }
}
string a[4];
int main() {
    I_O;
    rep(3)cin>>a[i];
    int p[] = {0,1,2};
    int mn = MAX;
    do{
        initialize();
        rep(3){
            for(int ii=0;ii<=sz;ii++) terminal[ii] = 0;
            cal_terminal();
            int len = a[p[i]].size();
            int lst = -1;
            int now = 0;
            bool flg = 0;
            REP(len){
                int x = a[p[i]][j]-'a';
                if(st[now].next[x]==0){
                    flg = 1;
                    break;
                }
                now = st[now].next[x];
                if(terminal[now])lst = j;
            }
            if(!flg)continue;
            for(int j=lst+1;j<len;j++){
                int x = a[p[i]][j]-'a';
                build_automata(x);
            }
        }
        mn = min(mn, st[last].len);
    }while(next_permutation(p,p+3));
    cout<<mn<<endl;
    return 0;
}
/*

*/


#include<bits/stdc++.h>

using namespace std;

#define    pf               printf
#define    PF(a)            printf("%d\n",(a))
#define    PF2(a,b)         printf("%d %d\n",(a), (b))
#define    PF3(a,b,c)       printf("%d %d %d\n",(a), (b), (c))
#define    PFL(a)           printf("%lld\n",(a))
#define    PFL2(a,b)        printf("%lld %lld\n",(a), (b))
#define    PFL3(a,b,c)      printf("%lld %lld %lld\n",(a), (b), (c))
#define    get(a)           cin>>a
#define    sf               scanf
#define    SF(a)            scanf("%d",&a)
#define    SF2(a,b)         scanf("%d %d",&a, &b)
#define    SF3(a,b,c)       scanf("%d %d %d",&a, &b, &c)
#define    SFL(a)           scanf("%lld",&a)
#define    SFL2(a,b)        scanf("%lld %lld",&a, &b)
#define    SFL3(a,b,c)      scanf("%lld %lld %lld",&a, &b, &c)
#define    gl(a)            getline(cin,(a))
#define    gc()             getchar()
#define    pb               push_back
#define    m_p              make_pair
#define    pc()             printf("Case %d: ",tt++)
#define    tc()             cout<<"Case "<<tt++<<": "
#define    dbg(x)           cout << #x << " -> " << x << endl;
#define    SZ(a)            (int)(a).size()
#define    all(a)           a.begin(),a.end()
#define    FF               first
#define    SS               second
#define    MAX              2134567891
#define    MOD              1000000007
#define    MM               100005
#define    PI               2*acos(0.0)
#define    cond(n,m)        (xx>=0 && xx<(n) && yy>=0 && yy<(m))

#define    mem(a)           memset((a),0,sizeof (a))
#define    SET(a)           memset((a),-1,sizeof (a))
#define    output           freopen("output.txt","w",stdout);
#define    input            freopen("input.txt","r",stdin);
#define    I_O              ios_base::sync_with_stdio(0); cin.tie(0)
#define    rep(a)           for(int i=0;i<(a);i++)
#define    FOR(a,b)         for(int i=(a);i<(b);i++)
#define    REP(a)           for(int j=0;j<(a);j++)
#define    rev(a)           for(int i=(a);i>=0;i--)
#define    fr(i,n)          for(i=0;i<n;i++)
#define    fr1(i,n,m)       for(i=n;i<m;i++)

int dx[]  = {0, 0, 1, -1};
int dy[]  = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};

typedef long long ll;
typedef unsigned long long llu;
typedef priority_queue < int > PQ;
typedef pair < int , int > pi;
typedef pair < int , pi > pii;
typedef vector < int > vi;
typedef vector < ll > vl;
typedef vector < string > vs;

ll bigmod(ll a, ll b, ll c){
    if(b==0)return 1%c;ll x=bigmod(a,b/2,c);x=(x*x)%c;
    if(b%2==1)x=(x*a)%c;return x;
}
ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}

/*
//FUNCTION//
ll poww(ll a, ll b){
    if(b==0)return 1;ll x=poww(a,b/2);x=x*x;if(b%2==1)x=(x*a);return x;
}

ll LCM(ll a, ll b){ return a*b/ __gcd(a,b);}

int pr = 50000;
vi primelist;
bool a[MM*100];
void seive( )
{
    int i,j,k=sqrt(pr);
    a[1]=1;
    primelist.pb(2);
    for(i=4;i<=pr;i+=2)a[i]=1;
    for(i=3;i<=k;i+=2)if(!a[i])for(j=i*i;j<=pr;j+=2*i)a[j]=1;
    for(i=3;i<=pr;i+=2)if(!a[i])primelist.pb(i);
}
int phi[MM];
void calculatePhi() {
  for (int i = 1; i < M; i++) {
    phi[i] = i;
  }
  for (int p = 2; p < M; p++) {
    if (phi[p] == p) { // p is a prime
      for (int k = p; k < M; k += p) {
        phi[k] -= phi[k] / p;
      }
    }
  }
}

ll fact_divs( ll n, ll p)
{
    ll cnt=0;while(p<=n){cnt += n/p;n /= p;}return cnt;
}
struct point{double x, y;};
double area( point A, point B, point C){
return 0.5*(A.x*(B.y-C.y) - A.y*(B.x-C.x) + B.x*C.y - C.x*B.y);
}

int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}

//*/
///AUTOMATA
const int M = 3*MM;
struct state{
    int len, link,fpos;
    bool isclone;
    map < char , int > next;
} st[2*M];
int sz, last;
int cnt[2*M];
bool terminal[2*M];
void initialize(){
    rep(sz+1){
        st[i].next.clear();
    }
    sz = last = 0; st[0].len = 0; st[0].link = -1;
}
void build_automata(char c){
    int cur = ++sz;
    cnt[cur] = 1;
    st[cur].len = st[last].len + 1;
    st[cur].isclone = 0;
    st[cur].fpos = st[cur].len;
    int p;
    for(p=last;p!=-1 && !st[p].next[c]; p=st[p].link){
        st[p].next[c] = cur;
    }
    if(p==-1){
        st[cur].link = 0;
    }
    else{
        int q = st[p].next[c];
        if(st[p].len+1==st[q].len){
            st[cur].link = q;
        }
        else{
            int clone = ++sz;
            cnt[clone] = 0;
            st[clone] = st[q];
            st[clone].len = st[p].len+1;
            st[clone].isclone = 1;
            for(;p!=-1 && st[p].next[c]==q;p=st[p].link){
                st[p].next[c] = clone;
            }
            st[q].link = st[cur].link = clone;
        }
    }
    last = cur;
}

void cal_terminal(){
    int now = last;
    while(now!=-1){
        terminal[now] = 1;
        now = st[now].link;
    }
}
string a[4];
int main() {
    rep(3)cin>>a[i];
    int p[] = {0,1,2};
    int mn = MAX;
    do{
        initialize();
        rep(3){
            mem(terminal);
            cal_terminal();
            int len = a[p[i]].size();
            int lst = -1;
            int now = 0;
            bool flg = 0;
            REP(len){
                int x = a[p[i]][j]-'a';
                if(st[now].next[x]==0){
                    flg = 1;
                    break;
                }
                now = st[now].next[x];
                if(terminal[now])lst = j;
            }
            if(!flg)continue;
            for(int j=lst+1;j<len;j++){
                int x = a[p[i]][j]-'a';
                build_automata(x);
            }
        }
        mn = min(mn, st[last].len);
    }while(next_permutation(p,p+3));
    cout<<mn<<endl;
    return 0;
}
/*

*/


#include<bits/stdc++.h>

using namespace std;

#define    pf               printf
#define    PF(a)            printf("%d\n",(a))
#define    PF2(a,b)         printf("%d %d\n",(a), (b))
#define    PF3(a,b,c)       printf("%d %d %d\n",(a), (b), (c))
#define    PFL(a)           printf("%lld\n",(a))
#define    PFL2(a,b)        printf("%lld %lld\n",(a), (b))
#define    PFL3(a,b,c)      printf("%lld %lld %lld\n",(a), (b), (c))
#define    get(a)           cin>>a
#define    sf               scanf
#define    SF(a)            scanf("%d",&a)
#define    SF2(a,b)         scanf("%d %d",&a, &b)
#define    SF3(a,b,c)       scanf("%d %d %d",&a, &b, &c)
#define    SFL(a)           scanf("%lld",&a)
#define    SFL2(a,b)        scanf("%lld %lld",&a, &b)
#define    SFL3(a,b,c)      scanf("%lld %lld %lld",&a, &b, &c)
#define    gl(a)            getline(cin,(a))
#define    gc()             getchar()
#define    pb               push_back
#define    m_p              make_pair
#define    pc()             printf("Case %d: ",tt++)
#define    tc()             cout<<"Case "<<tt++<<": "
#define    dbg(x)           cout << #x << " -> " << x << endl;
#define    SZ(a)            (int)(a).size()
#define    all(a)           a.begin(),a.end()
#define    FF               first
#define    SS               second
#define    MAX              2134567891
#define    MOD              1000000007
#define    MM               100005
#define    PI               2*acos(0.0)
#define    cond(n,m)        (xx>=0 && xx<(n) && yy>=0 && yy<(m))

#define    mem(a)           memset((a),0,sizeof (a))
#define    SET(a)           memset((a),-1,sizeof (a))
#define    output           freopen("output.txt","w",stdout);
#define    input            freopen("input.txt","r",stdin);
#define    I_O              ios_base::sync_with_stdio(0); cin.tie(0)
#define    rep(a)           for(int i=0;i<(a);i++)
#define    FOR(a,b)         for(int i=(a);i<(b);i++)
#define    REP(a)           for(int j=0;j<(a);j++)
#define    rev(a)           for(int i=(a);i>=0;i--)
#define    fr(i,n)          for(i=0;i<n;i++)
#define    fr1(i,n,m)       for(i=n;i<m;i++)

int dx[]  = {0, 0, 1, -1};
int dy[]  = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1};

typedef long long ll;
typedef unsigned long long llu;
typedef priority_queue < int > PQ;
typedef pair < int , int > pi;
typedef pair < int , pi > pii;
typedef vector < int > vi;
typedef vector < ll > vl;
typedef vector < string > vs;

ll bigmod(ll a, ll b, ll c){
    if(b==0)return 1%c;ll x=bigmod(a,b/2,c);x=(x*x)%c;
    if(b%2==1)x=(x*a)%c;return x;
}
ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}

/*
//FUNCTION//
ll poww(ll a, ll b){
    if(b==0)return 1;ll x=poww(a,b/2);x=x*x;if(b%2==1)x=(x*a);return x;
}

ll LCM(ll a, ll b){ return a*b/ __gcd(a,b);}

int pr = 50000;
vi primelist;
bool a[MM*100];
void seive( )
{
    int i,j,k=sqrt(pr);
    a[1]=1;
    primelist.pb(2);
    for(i=4;i<=pr;i+=2)a[i]=1;
    for(i=3;i<=k;i+=2)if(!a[i])for(j=i*i;j<=pr;j+=2*i)a[j]=1;
    for(i=3;i<=pr;i+=2)if(!a[i])primelist.pb(i);
}
int phi[MM];
void calculatePhi() {
  for (int i = 1; i < M; i++) {
    phi[i] = i;
  }
  for (int p = 2; p < M; p++) {
    if (phi[p] == p) { // p is a prime
      for (int k = p; k < M; k += p) {
        phi[k] -= phi[k] / p;
      }
    }
  }
}

ll fact_divs( ll n, ll p)
{
    ll cnt=0;while(p<=n){cnt += n/p;n /= p;}return cnt;
}
struct point{double x, y;};
double area( point A, point B, point C){
return 0.5*(A.x*(B.y-C.y) - A.y*(B.x-C.x) + B.x*C.y - C.x*B.y);
}

int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}

//*/
///AUTOMATA
const int M = 3*MM;
struct state{
    int len, link,fpos;
    bool isclone;
    map < char , int > next;
} st[2*M];
int sz, last;
bool terminal[2*M];
void initialize(){
    rep(sz+1){
        st[i].next.clear();
    }
    sz = last = 0; st[0].len = 0; st[0].link = -1;
}
void build_automata(char c){
    int cur = ++sz;
    st[cur].len = st[last].len + 1;
    st[cur].isclone = 0;
    st[cur].fpos = st[cur].len;
    int p;
    for(p=last;p!=-1 && !st[p].next.count(c); p=st[p].link){
        st[p].next[c] = cur;
    }
    if(p==-1){
        st[cur].link = 0;
    }
    else{
        int q = st[p].next[c];
        if(st[p].len+1==st[q].len){
            st[cur].link = q;
        }
        else{
            int clone = ++sz;;
            st[clone] = st[q];
            st[clone].len = st[p].len+1;
            st[clone].isclone = 1;
            for(;p!=-1 && st[p].next[c]==q;p=st[p].link){
                st[p].next[c] = clone;
            }
            st[q].link = st[cur].link = clone;
        }
    }
    last = cur;
}

void cal_terminal(){
    int now = last;
    while(now!=-1){
        terminal[now] = 1;
        now = st[now].link;
    }
}
string a[4];
int main() {
    I_O;
    rep(3)cin>>a[i];
    int p[] = {0,1,2};
    int mn = MAX;
    do{
        initialize();
        rep(3){
            for(int ii=0;ii<=sz;ii++) terminal[ii] = 0;
            cal_terminal();
            int len = a[p[i]].size();
            int lst = -1;
            int now = 0;
            bool flg = 0;
            REP(len){
                int x = a[p[i]][j]-'a';
                if(st[now].next.count(x)==0){
                    flg = 1;
                    break;
                }
                now = st[now].next[x];
                if(terminal[now])lst = j;
            }
            if(!flg)continue;
            for(int j=lst+1;j<len;j++){
                int x = a[p[i]][j]-'a';
                build_automata(x);
            }
        }
        mn = min(mn, st[last].len);
    }while(next_permutation(p,p+3));
    cout<<mn<<endl;
    return 0;
}
/*

*/


#include<iostream>
#include<string>
#include<stdio.h>
#include<math.h>
#include<sstream>
#include<memory.h>
#include<algorithm>
#include<vector>
#include<map>
#include <unordered_map>
#include <set>

#define ll long long
#define mod  1000000007LL
#define lmod 1000000000039LL
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()

using namespace std;

const int N = 100100;

vector<int> f;

void build(const string &p){

    int j = 0;
    f.assign(p.size(), 0);
    for(int i = 1; i < p.size(); ++i){

        while(j > 0 and p[i] != p[j]) j = f[j-1];
        if(p[i] == p[j]) ++j;
        f[i] = j;
    }
}

int search(const string &s, const string &p){

    int j = 0; build(p);
    for(int i = 0; i < s.size(); ++i){
        while(j > 0 and s[i] != p[j]) j = f[j-1];
        if(s[i] == p[j]) ++j;

        if(j == p.size())
            return -1;
    }

    return j;
}

string s[3];

int main(){

#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    string x;
    int mn = 0x3f3f3f3f;
    for(int i = 0; i < 3; ++i)
        cin >> s[i];

    sort(s, s+3);

    do {
        x = s[0];
        for(int i = 1; i < 3; ++i){
            int len = search(x, s[i]);
            if(len != -1) x += s[i].substr(len);
        }

        mn = min(mn, (int)x.size());
    } while(next_permutation(s, s+3));

    cout << mn << '\n';

    return 0;
}


#include<iostream>
#include<string>
#include<stdio.h>
#include<math.h>
#include<sstream>
#include<memory.h>
#include<algorithm>
#include<vector>
#include<map>
#include <unordered_map>
#include <set>

#define ll long long
#define mod  1000000007LL
#define lmod 1000000000039LL
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()

using namespace std;

const int N = 100100;

vector<int> f;

void build(const string &p){

    int j = 0;
    f.assign(p.size(), 0);
    for(int i = 1; i < p.size(); ++i){

        while(j > 0 and p[i] != p[j]) j = f[j-1];
        if(p[i] == p[j]) ++j;
        f[i] = j;
    }
}

int search(const string &s, const string &p){

    int j = 0; build(p);
    for(int i = 0; i < s.size(); ++i){
        while(j > 0 and s[i] != p[j]) j = f[j-1];
        if(s[i] == p[j]) ++j;
    }

    return j;
}

int main(){

#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    string x, a, b, c;

    cin >> a >> b >> c;
    x = a;
    int len = search(x, b);
    x += b.substr(len);
    len = search(x, c);
    x += c.substr(len);

    cout << x.size() << '\n';

    return 0;
}


#include<iostream>
#include<string>
#include<stdio.h>
#include<math.h>
#include<sstream>
#include<memory.h>
#include<algorithm>
#include<vector>
#include<map>
#include <unordered_map>
#include <set>

#define ll long long
#define mod  1000000007LL
#define lmod 1000000000039LL
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()

using namespace std;

const int N = 100100;

vector<int> f;

void build(const string &p){

    int j = 0;
    f.assign(p.size(), 0);
    for(int i = 1; i < p.size(); ++i){

        while(j > 0 and p[i] != p[j]) j = f[j-1];
        if(p[i] == p[j]) ++j;
        f[i] = j;
    }
}

int search(const string &s, const string &p){

    int j = 0; build(p);
    for(int i = 0; i < s.size(); ++i){
        while(j > 0 and s[i] != p[j]) j = f[j-1];
        if(s[i] == p[j]) ++j;
    }

    return j;
}

string s[3];
vector<string> v;

int main(){

#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    string x;
    int mn = 0x3f3f3f3f;
    for(int i = 0; i < 3; ++i)
        cin >> s[i];

    sort(s, s+3, [](string &a, string &b){
        return a.size() > b.size();
    });

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

        bool issub = false;
        for(auto str : v)
            if(str.find(s[i]) != string::npos) issub = true;

        if(!issub) v.push_back(s[i]);
    }

    sort(all(v));

    do {
        x = v[0];
        for(int i = 1; i < v.size(); ++i){
            int len = search(x, v[i]);
            x += v[i].substr(len);
        }

        mn = min(mn, (int)x.size());

    } while(next_permutation(all(v)));

    cout << mn << '\n';

    return 0;
}


#include<iostream>
#include<string>
#include<stdio.h>
#include<math.h>
#include<sstream>
#include<memory.h>
#include<algorithm>
#include<vector>
#include<map>
#include <unordered_map>
#include <set>

#define ll long long
#define mod  1000000007LL
#define lmod 1000000000039LL
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()

using namespace std;

const int N = 100100;

vector<int> f;

void build(const string &p){

    int j = 0;
    f.assign(p.size(), 0);
    for(int i = 1; i < p.size(); ++i){

        while(j > 0 and p[i] != p[j]) j = f[j-1];
        if(p[i] == p[j]) ++j;
        f[i] = j;
    }
}

int search(const string &s, const string &p){

    int j = 0; build(p);
    for(int i = 0; i < s.size(); ++i){
        while(j > 0 and s[i] != p[j]) j = f[j-1];
        if(s[i] == p[j]) ++j;
    }

    return j;
}

vector<string> v;

int main(){

#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    string x;
    int mn = 0x3f3f3f3f;
    for(int i = 0; i < 3; ++i){
        cin >> x;

        bool issub = false;
        for(auto str : v)
            if(str.find(x) != string::npos) issub = true;

        if(!issub) v.push_back(x);
    }

    sort(all(v));

    do {
        x = v[0];
        for(int i = 1; i < v.size(); ++i){
            int len = search(x, v[i]);
            x += v[i].substr(len);
        }

        mn = min(mn, (int)x.size());

    } while(next_permutation(all(v)));

    cout << mn << '\n';

    return 0;
}


#include<iostream>
#include<string>
#include<stdio.h>
#include<math.h>
#include<sstream>
#include<memory.h>
#include<algorithm>
#include<vector>
#include<map>
#include <unordered_map>
#include <set>

#define ll long long
#define mod  1000000007LL
#define lmod 1000000000039LL
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()

using namespace std;

const int N = 100100;

vector<int> f;

void build(const string &p){

    int j = 0;
    f.assign(p.size(), 0);
    for(int i = 1; i < p.size(); ++i){

        while(j > 0 and p[i] != p[j]) j = f[j-1];
        if(p[i] == p[j]) ++j;
        f[i] = j;
    }
}

int search(const string &s, const string &p){

    int j = 0; build(p);
    for(int i = 0; i < s.size(); ++i){
        while(j > 0 and s[i] != p[j]) j = f[j-1];
        if(s[i] == p[j]) ++j;
    }

    return j;
}

int per[] = {0, 1, 2};

int main(){

#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    string x, s[3];
    int mn = 0x3f3f3f3f;
    cin >> s[0] >> s[1] >> s[2];

    do {
        x = s[per[0]];
        int len = search(x, s[per[1]]);
        x += s[per[1]].substr(len);
        len = search(x, s[per[2]]);
        x += s[per[2]].substr(len);

        mn = min(mn, (int)x.size());

    } while(next_permutation(per, per+3));

    cout << mn << '\n';

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
double inff=1.0/0.0;
#define ll                       long long int
#define inf                      1e18
#define MOD                      998244353
#define pb                       push_back
#define sz(x)                    (ll)x.size()
#define mp                       make_pair
#define lbd                      lower_bound
#define ubd                      upper_bound
#define ipair                    pair<ll,ll>
#define all(v)                   v.begin(),v.end()
#define rep(a,b,c)               for(a=(ll)b;a<(ll)c;a++)
#define rep2(a,b,c)              for(a=(ll)b;a<(ll)c;a+=2)
#define bac(a,b,c)               for(a=(ll)b;a>=(ll)c;a--)
#define se                       second
#define f                        first
#define ios                      ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
#define mem(a,val)               memset(a,val,sizeof a)
#define endl                     "\n"
#define mxn                      200030
#define vi                       vector<ll>
#define vii                      vector<ipair>
#define si                       set<ll>
#define trace1(x)                cerr << #x << ": " << x << "\n";
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*Variables Start*/
ll x,y,n,i,z,j,k,w,u,q,m,d,t,g;
unordered_map<string,ll> m1;
ll pi[mxn];
/*Variables End*/
void prefix_function(string str)
{
  pi[0]=0;
  ll n=str.size();
  for(int i=1;i<n;i++)
  {
    int j=pi[i-1];
    while(j>0 and str[i]!=str[j])
    {
      j=pi[j-1];
    }
    if(str[i]==str[j])
      j++;
    pi[i]=j;
  }
}
void solve()
{
  vector<string> v;
  string str;
  ll tot=0;
  w=inf;
  rep(i,0,3)
  {
    cin>>str;
    v.pb(str);
    tot+=sz(str);
  }
  rep(i,0,3)
  {
    rep(j,0,3)
    {
      if(i==j) continue;
      str=v[i]+v[j];
      prefix_function(str);
      m1[str]=min({pi[str.size()-1],sz(v[i]),sz(v[j])});
    }
  }
  vi perm({0,1,2});
  do
  {
    string str1=v[perm[1]]+v[perm[0]];
    string str2=v[perm[2]]+v[perm[1]];
    x=m1[str1];
    y=m1[str2];
    w=min(w,tot-x-y);
  }while(next_permutation(all(perm)));
  cout<<w<<endl;
}
int main()
{
  int TESTS=1;
  ios;
  // cin>>TESTS;
  while(TESTS--)
  {
    solve();
  }
}


#include <bits/stdc++.h>
using namespace std;
double inff=1.0/0.0;
#define ll                       long long int
#define inf                      1e18
#define MOD                      998244353
#define pb                       push_back
#define sz(x)                    (ll)x.size()
#define mp                       make_pair
#define lbd                      lower_bound
#define ubd                      upper_bound
#define ipair                    pair<ll,ll>
#define all(v)                   v.begin(),v.end()
#define rep(a,b,c)               for(a=(ll)b;a<(ll)c;a++)
#define rep2(a,b,c)              for(a=(ll)b;a<(ll)c;a+=2)
#define bac(a,b,c)               for(a=(ll)b;a>=(ll)c;a--)
#define se                       second
#define f                        first
#define ios                      ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
#define mem(a,val)               memset(a,val,sizeof a)
#define endl                     "\n"
#define mxn                      200030
#define vi                       vector<ll>
#define vii                      vector<ipair>
#define si                       set<ll>
#define trace1(x)                cerr << #x << ": " << x << "\n";
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*Variables Start*/
ll x,y,n,i,z,j,k,w,u,q,m,d,t,g;
unordered_map<string,ll> m1;
ll pi[mxn];
/*Variables End*/
string conc(string str1,string str2)
{
  string str=str1+'#'+str2;
  n=str.size();
  ll n1=str1.size(),n2=str2.size();
  for(int i=1;i<n;i++)
  {
    int j=pi[i-1];
    while(j>0 and str[i]!=str[j])
    {
      j=pi[j-1];
    }
    if(str[i]==str[j])
      j++;
    pi[i]=j;
  }
  rep(i,n1+1,n) if(pi[i]==n1) return str2;
  return str2+str1.substr(pi[n-1],n1-pi[n-1]);
}
void solve()
{
  vector<string> v;
  string str,str1;
  ll tot=0;
  w=inf;
  rep(i,0,3)
  {
    cin>>str;
    v.pb(str);
  }
  vi perm({0,1,2});
  do
  {
    string res=conc(conc(v[perm[0]],v[perm[1]]),v[perm[2]]);
    w=min(sz(res),w);
  }while(next_permutation(all(perm)));
  cout<<w<<endl;
}
int main()
{
  int TESTS=1;
  ios;
  // cin>>TESTS;
  while(TESTS--)
  {
    solve();
  }
}


#include <bits/stdc++.h>
using namespace std;
double inff=1.0/0.0;
#define ll                       long long int
#define inf                      1e18
#define MOD                      998244353
#define pb                       push_back
#define sz(x)                    (ll)x.size()
#define mp                       make_pair
#define lbd                      lower_bound
#define ubd                      upper_bound
#define ipair                    pair<ll,ll>
#define all(v)                   v.begin(),v.end()
#define rep(a,b,c)               for(a=(ll)b;a<(ll)c;a++)
#define rep2(a,b,c)              for(a=(ll)b;a<(ll)c;a+=2)
#define bac(a,b,c)               for(a=(ll)b;a>=(ll)c;a--)
#define se                       second
#define f                        first
#define ios                      ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
#define mem(a,val)               memset(a,val,sizeof a)
#define endl                     "\n"
#define mxn                      300030
#define vi                       vector<ll>
#define vii                      vector<ipair>
#define si                       set<ll>
#define trace1(x)                cerr << #x << ": " << x << "\n";
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*Variables Start*/
ll x,y,n,i,z,j,k,w,u,q,m,d,t,g;
unordered_map<string,ll> m1;
ll pi[mxn];
/*Variables End*/
string conc(string str1,string str2)
{
  string str=str1+'#'+str2;
  n=str.size();
  ll n1=str1.size(),n2=str2.size();
  for(int i=1;i<n;i++)
  {
    int j=pi[i-1];
    while(j>0 and str[i]!=str[j])
    {
      j=pi[j-1];
    }
    if(str[i]==str[j])
      j++;
    pi[i]=j;
  }
  rep(i,n1+1,n) if(pi[i]==n1) return str2;
  return str2+str1.substr(pi[n-1],n1-pi[n-1]);
}
void solve()
{
  vector<string> v;
  string str,str1;
  ll tot=0;
  w=inf;
  rep(i,0,3)
  {
    cin>>str;
    v.pb(str);
  }
  vi perm({0,1,2});
  do
  {
    string res=conc(conc(v[perm[0]],v[perm[1]]),v[perm[2]]);
    w=min(sz(res),w);
  }while(next_permutation(all(perm)));
  cout<<w<<endl;
}
int main()
{
  int TESTS=1;
  ios;
  // cin>>TESTS;
  while(TESTS--)
  {
    solve();
  }
}


#include <bits/stdc++.h>

using namespace std;
string s[3];
int z[]={0,1,2};

string kmp(string x,string y)
{
    string s=y+"#"+x;
    vector<int>merg(s.length());
    for(int i=1,j=0;i<s.length();i++)
    {
        while(j&&s[i]!=s[j])j=merg[j-1];
        if(s[i]==s[j])j++;
        merg[i]=j;
        if(j==(int)y.size())return x;
    }
    return x.substr(0,x.size()-merg.back())+y;
}

int main()
{
    int res=1e9;
    cin>>s[0]>>s[1]>>s[2];
    do
    {
        res=min(res,(int)kmp(s[z[0]],kmp(s[z[1]],s[z[2]])).size());
    }
    while(next_permutation(z,z+3));
    cout<<res;
}


#include <bits/stdc++.h>

using namespace std;
string s[3];
int z[]={0,1,2};

string kmp(string x,string y)
{
    int mx=0,c=0;
    string s=y+"#"+x;
    vector<int>merg(s.length());
    for(int i=1,j=0;i<s.length();i++)
    {
        while(j&&s[i]!=s[j])j=merg[j-1];
        if(s[i]==s[j])j++;
        merg[i]=j;
        if(j==(int)y.size())return x;
    }
    return x.substr(0,x.size()-merg.back())+y;
}

int main()
{
    int res=1e9;
    cin>>s[0]>>s[1]>>s[2];
    do
    {
        res=min(res,(int)kmp(s[z[0]],kmp(s[z[1]],s[z[2]])).size());
    }
    while(next_permutation(z,z+3));
    cout<<res;
}