Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <cstdint>
#include <string>
#include <algorithm>
#include <memory>
#include <vector>
#include <iostream>
#include <functional>
#include <set>
#include <deque>
#include <chrono>
#include <ranges>
#include <random>
#include <numeric>
#include <map>
#include <cassert>
#include <queue>
#include <tuple>
#include <sstream>
#include <fstream>
#include <coroutine>
#include <array>
#include <bitset>
#include <forward_list>
#include <bit>
#include <stack>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
long TEST = 0;
long TEST_TOTAL = 0;
namespace _IOBase {
	int hook_test = 0;
	int min_tot = 0;
	std::stringstream hook_str;
	template<class T> T read() {
		T val;
		std::cin >> val;
		if (hook_test) {
			if (TEST == hook_test&&TEST_TOTAL >= std::max(min_tot, hook_test)) {
				hook_str << val;
				hook_str << " ";
			}
		}
		return val;
	}
	template<class T> void put(const T& v) {
		if (hook_test) {
			if (TEST_TOTAL >= std::max(min_tot, hook_test)) {
				if (TEST == hook_test) {
					std::cout << hook_str.str();
					hook_str = std::stringstream();
				}
				return;
			}
		}
		std::cout << v;
	}
	bool AutoFlash = false;
}
void Solve();
struct ProblemData {
	bool HasTestcase = true;
	bool AutoFlash = false;
};
class Timer {
	using sc = std::chrono::steady_clock;
	sc::time_point start;
public:
	Timer() :start(sc::now()) {}
	long long elapsedMs() {
		return std::chrono::duration_cast<std::chrono::milliseconds>(sc::now() - start).count();
	}
};
class Starter {
	void Solve2() {
		TEST++;
		try { Solve(); }
		catch (int) {}
	}
	void _Start(const ProblemData& pd) {
		TEST_TOTAL = pd.HasTestcase ? _IOBase::read<int>() : 1;
		for (int t = 0; t < TEST_TOTAL; t++) {
			Solve2();
		}
	}
public:
	Starter(const ProblemData& pd) {
		std::cout.precision(17);
		std::cin.tie(nullptr);
		std::cout.tie(nullptr);
		std::ios_base::sync_with_stdio(false);
		_Start(pd);
	}
};
void initialize(ProblemData& pd);
int main(int argc, char** argv) {
	ProblemData pd;
	initialize(pd);
	_IOBase::AutoFlash = pd.AutoFlash;
	Starter starter(pd);
	return 0;
}
#define TT template<class T>
#define TTs template<class ... T>
#define TC template<class
#define TCT TC T
#define TT2 TCT, class T2>
static const bool _IS_VSCPP=
#ifdef _MSC_VER
true
#else
false
#endif
;
using Long = int64_t;
#ifdef __SIZEOF_INT128__
using longw = __int128;
#else
using longw = std::ranges::range_difference_t<std::ranges::iota_view<long long, long long>>;
#endif
using ld = long double;
using ulong = uint64_t;
using uint = uint32_t;
constexpr Long operator""v(unsigned long long a) { return (Long)a; }
constexpr ld operator""v(long double a) { return a; }
#define long Long
TT concept Invoke0 = true;
TT concept Invoke1 = true;
TT concept Invoke2 = true;
TT concept TEnumerable = requires(T a) { a.begin();	a.end(); };
TT concept TEnumerableSized = requires(T a) { a.size(); } && TEnumerable<T>;
#define FORWARD_BY(item, item_by) std::is_rvalue_reference_v<decltype(item_by)> ? std::move(item) : item
#define FORWARD(x) std::forward<decltype(x)>(x)
#define DECLTYPE(x) std::decay_t<decltype(x)>
TT using TElemFromType = DECLTYPE(*std::declval<T&>().begin());
#define TElemFromInst(v) DECLTYPE(*v.begin())
#define _DEDUCT(t_name) \
template <TEnumerableSized T> t_name(T) -> t_name<TElemFromType<T>>; \
template <TEnumerable T> t_name(T) -> t_name<TElemFromType<T>>; \
template <class ...T> t_name(T...) -> t_name<Long>;
#define ALL_TH this->begin(),this->end()
#define ALL(x) x.begin(),x.end()
#define _OPER_FROM(op) TThis operator op(const TThis& b) const { TThis a(*this); a op ## = b; return a; }
struct Empty {};
#define var auto&&
constexpr Long inf = std::numeric_limits<Long>::max() / 4;
constexpr int inf_int = std::numeric_limits<int>::max() - 10;
auto geti() { return _IOBase::read<Long>(); }
auto getc() { return _IOBase::read<char>(); }
auto get_c() { return getc(); }
auto getd() { return _IOBase::read<ld>(); }
TT void put_raw(const T& v) { _IOBase::put(v); }
void _print_endl() { _IOBase::put('\n');  if (_IOBase::AutoFlash) std::cout.flush(); }
void put_raw(const std::string& v) { _IOBase::put(v); }
void put_raw(const TEnumerable auto& v) {
	bool init = false;
	for (const auto& e : v) {
		if (!init) init = true; else put_raw(' ');
		put_raw(e);
	}
}
void put_raw_nosp(const auto& v) { put_raw(v); }
void put_raw_nosp(const TEnumerable auto& v) { for (const auto& e : v) { put_raw(e); } }
TTs void put_nosp(const T&...v) { (put_raw_nosp(v), ...); }
TTs void put(const T&...v) {
	int cnt = 0;
	((put_raw(v), (++cnt != (sizeof...(v)) ? _IOBase::put(' ') : ([]() {})())), ...);
}
TTs void print(const T&...v) { put(v...); _print_endl(); }
TTs void print_nosp(const T&...v) { put_nosp(v...); _print_endl(); }
void done() { throw 1; }
TTs void done(const T&...v) { print(v...); done(); }
TTs void print_sp(const T&...v) { put(v...); put_raw(' '); }
void print_yes(bool cond) { print(cond ? "Yes" : "No"); }
void done_yes(bool cond) { print(cond ? "Yes" : "No"); done(); }
TTs void __READ(T&... v) { ((v = _IOBase::read<T>()), ...); }
#define __read_cmn(x, ...) x __VA_ARGS__ ; __READ(__VA_ARGS__);
#define readi(...) __read_cmn(Long, __VA_ARGS__)
Long Sum1n(Long n) { if (n <= 0) return 0; return (n * n + n) / 2; }
Long Sumkn(Long k, Long n) { if (k > n) return 0;  return Sum1n(n) - Sum1n(k - 1); }
auto Iota(Long l, Long r) { return std::ranges::iota_view(l, r + 1); }
auto Iota0(Long r) { return Iota(0, r); }
auto Iota1(Long r) { return Iota(1, r); }
auto Abs(const auto& a) { return std::abs(a); }
auto Min(const auto& a, const auto& b) { return a < b ? a : b; }
auto Max(const auto& a, const auto& b) { return a > b ? a : b; }
bool Max2(var a, const auto& b) { if (b > a) { a = b; return true; } return false; }
bool Min2(var a, const auto& b) { if (b < a) { a = b; return true; } return false; }
auto Max(var a, var b, var c, var... v) { auto res = Max(a, b); Max2(res, c); (Max2(res, v), ...); return res; }
auto Min(var a, var b, var c, var... v) { auto res = Min(a, b); Min2(res, c); (Min2(res, v), ...); return res; }
TT2 auto Swap(T& a, T2& b) { return std::swap(a, b); }
TT2 auto Sort(T& a, T2& b) { if (b < a) Swap(a, b); }
auto GCD(long a, long b) { return std::gcd(a, b); }
auto LCM(long a, long b) { return std::lcm(a, b); }
auto Log(var val, long k) {
	if (k <= 1) return DECLTYPE(val) {};
	DECLTYPE(val) test = 1;
	DECLTYPE(val) cnt = 0;
	while (test < val) { test *= k; ++cnt; }
	if (test != val) { cnt--; }
	return cnt;
}
auto Log_up(var val, long k) {
	if (k <= 1) return DECLTYPE(val) {};
	DECLTYPE(val) test = 1;
	DECLTYPE(val) cnt = 0;
	while (test < val) { test *= k; ++cnt; }
	return cnt;
}
auto Pow(auto base, long exp) {
	assert(exp >= 0);
	decltype(base) result = 1;
	for (; exp > 0; exp >>= 1) {
		if (exp & 1)
			result *= base;
		base *= base;
	}
	return result;
}
auto Max(TEnumerable var v) { return *std::max_element(ALL(v)); }
auto Min(TEnumerable var t) { return *std::min_element(ALL(t)); }
auto Max(TEnumerable auto&& v, Invoke1 var f) {
	auto it = v.begin();
	auto res = f(*it);
	it++;
	for (; it != v.end(); it++) { Max2(res, f(*it)); }
	return res;
}
auto Min(TEnumerable var v, Invoke1 var f) {
	auto it = v.begin();
	auto res = f(*it);
	it++;
	for (; it != v.end(); it++) { Min2(res, f(*it)); }
	return res;
}
TC T = long > T Fact(long n) {
	static std::vector<T> stor = { 1,1 };
	if (n < stor.size()) return stor[n];
	T res = stor.back();
	long from = stor.size();
	if (n >= 400000) {
		for (; from <= n; from++) { res *= from; }
	} else {
		for (; from <= n; from++) {
			res *= from;
			stor.push_back(res);
		}
	}
	return res;
}
TC T = long> T Acomb(long k, long n) {
	assert(k <= n);
	return Fact<T>(n) / Fact<T>(n - k);
}
TC T = long > T Ccomb(long k, long n) {
	assert(k <= n);
	return Acomb<T>(k, n) / Fact<T>(k);
}
TT class _BaseCont : public T {
	using TBase = T;
public:
	using value_type = TBase::value_type;
	using reference = TBase::reference;
	using TBase::TBase;
	_BaseCont(TBase&& s)noexcept : TBase(s)  {}
	Long size() const { return TBase::size(); }
	value_type min() const { return *std::min_element(ALL_TH); }
	value_type max() const { return *std::max_element(ALL_TH); }
	value_type sum() const { return std::accumulate(ALL_TH, value_type{}); }
};
TT class _BaseContList : public _BaseCont<T> {
	using TBase = _BaseCont<T>;
public:
	using value_type = TBase::value_type;
	using reference = TBase::reference;
	using TBase::TBase;
	_BaseContList(TEnumerableSized var v) {
		TBase::resize(v.size());
		int i = 0;
		for (auto&& item : v) {
			(*this)[i++] = FORWARD_BY(item, v);
		}
	}
	_BaseContList(TEnumerable var v) {
		for (auto&& item : v) { this->push_back(FORWARD_BY(item, v)); }
	}
	void reversy() { std::reverse(ALL_TH); }
	bool contains(const value_type& v) { return std::find(ALL_TH, v) != this->end(); }
	void replace(value_type a, value_type b) { std::replace(ALL_TH, a, b); }
	void insert_at(Long i, const value_type& v) { TBase::insert(this->begin() + i, v); }
	void fill(const value_type& v) { std::fill(ALL_TH, v); }
	void remove_at(Long i) { if(i < this->size()) this->erase(this->begin() + i); }
	bool remove_first(const value_type& val) { auto itr = std::find(ALL_TH, val); if (itr != this->end()) { this->erase(itr); return true; } return false; }
	Long remove_all(const value_type& val) {
		auto newEnd = std::remove(ALL_TH, val);
		auto cnt = this->end() - newEnd;
		this->erase(newEnd, this->end());
		return cnt;
	}
	value_type pop_back() {
		auto res = std::move(TBase::back());
		TBase::pop_back();
		return res;
	}
	value_type pop_front() {
		auto res = std::move(TBase::front());
		remove_at(0);
		return res;
	}
	void push_front(const value_type& v) {
		this->insert_at(0, v);
	}
	bool is_sorted() { return std::is_sorted(ALL_TH); }
	void sort() { std::stable_sort(ALL_TH); }
	void sort(Invoke2 var f) { std::stable_sort(ALL_TH, f); }
	void sort_rev() {
		std::stable_sort(ALL_TH, std::greater{});
	}
	void set(int l, int r, const value_type& v) {
		for (int i = l; i <= r; i++) { get(i) = v; }
	}
	reference operator[](int i) { return TBase::operator[](i); }
	auto& operator[](int i) const { return TBase::operator[](i); }
	value_type& get_rev(int i) { return get(this->size()-1-i); }
	value_type& get(int i) { return (*this)[i]; }
	value_type get_def(int i, value_type def = {}) { return i < this->size() && i >= 0 ? get(i) : def; }
	void swap(int i, int j) { std::swap(get(i), get(j)); }
private:
};
TCT = Long > class Vec : public _BaseContList<std::vector<T>> {
	using TBase = _BaseContList<std::vector<T>>;
public:
	using reference = TBase::reference;
	using TBase::TBase;
	using value_type = TBase::value_type;
};
_DEDUCT(Vec);
TCT = Long > class Deque : public _BaseContList < std::deque<T>> {
	using TBase = _BaseContList < std::deque<T>>;
public:
	using TBase::TBase;
	T pop_front() {
		auto res = std::move(TBase::front());
		TBase::pop_front();
		return res;
	}
};
_DEDUCT(Deque);
TCT = long > class Cont : public Vec<T> {
	using TBase = Vec<T>;
public:
	using reference = TBase::reference;
	using TBase::TBase;
public:
	reference operator[](int i) {
		if (i >= this->size()) { this->resize(i + 1); }
		return TBase::operator[](i);
	}
};
_DEDUCT(Cont);
TCT = long > class Cont2 : public Cont<T> {
	using TBase = Cont<T>;
public:
	using TBase::TBase;
	using reference = TBase::reference;
public:
	reference operator[](int i) {
		if (i < 0) {
			return minus[-i];
		}
		return TBase::operator[](i);
	}
private:
	Cont<T> minus;
};
_DEDUCT(Cont2);
auto getv(int n, Invoke0 var getter) {
	Vec<DECLTYPE(getter())> res(n);
	for (auto i = 0; i < n; i++) {
		res[i] = getter();
	}
	return res;
}
auto getv(int n) { return getv(n, geti); }
auto gets_digit(int n = -1) {
	if (n != -1) {
		Vec res(n);
		for(int i = 0; i < n; i++) {
			res[i] = get_c() - '0';
		}
		return res;
	}
	auto s = _IOBase::read<std::string>();
	Vec res(s.size());
	for(int i = 0; i < s.size(); i++) {
		res[i] = s[i] - '0';
	}
	return res;
}
class Str : public _BaseContList<std::string> {
	using TBaseStr = std::string;
	using TBase = _BaseContList<std::string>;
	using reference = TBase::reference;
public:
	using TBase::TBase;
	using value_type = TBase::value_type;
	Str get(int l, int r) const {
		if (l > r) return "";
		if (r >= size()) r = size() - 1;
		return substr(l, r - l + 1);
	}
	void tolower() {
		std::transform(begin(), end(), begin(), [](unsigned char c) { return std::tolower(c); }
		);
	}
};
Str operator"" s(const char* _Str, size_t _Len) {
	return Str{ _Str, _Len };
}
Str gets(int n = -1) {
	if (n != -1) {
		Str res;
		res.resize(n);
		for (int i = 0; i < n; i++) {
			res[i] = get_c();
		}
		return res;
	}
	return _IOBase::read<std::string>();
}
void put_raw(const Str& v) { for (char c : v) put_raw(c); }
namespace _For_impl {
	template<class T> struct ForIter {
		using Iter = decltype(std::begin(std::declval<T&>()));
		using Iter_end = decltype(std::end(std::declval<T&>()));
		using IterRef = decltype(*std::declval<Iter&>());
		Long i = 0; Iter iter; Iter_end iter_end;
		ForIter(T& cont) :iter(std::begin(cont)), iter_end(std::end(cont)) {  }
		auto&& begin() { return std::move(*this); }
		int end() { return 0; }
		void operator++() { ++iter; ++i; }
		bool operator!=(int) { return iter != iter_end; }
		std::tuple<IterRef, Long> operator*() { return { *iter, i }; }
	};
	template<class T> struct ForIterRev {
		using Iter = decltype(std::rbegin(std::declval<T&>()));
		using Iter_end = decltype(std::rend(std::declval<T&>()));
		using IterRef = decltype(*std::declval<Iter&>());
		Long i; Iter iter; Iter_end iter_end;
		ForIterRev(T& cont) :i(cont.size()-1), iter(cont.rbegin()), iter_end(cont.rend()) {  }
		auto&& begin() { return std::move(*this); }
		int end() { return 0; }
		void operator++() { ++iter; --i; }
		bool operator!=(int) { return iter != iter_end; }
		std::tuple<IterRef, Long> operator*() { return { *iter, i }; }
	};
	template<> struct ForIter<Long> {
		Long i; Long n;
		ForIter(Long c) :n(c) { i = 0; }
		auto&& begin() { return std::move(*this); }
		int end() { return 0; }
		void operator++() { ++i; }
		bool operator!=(int) { return i != n; }
		std::tuple<Long, Long> operator*() { return { i, i }; }
	};
	template<TEnumerable T> auto Get_For_Handler_rev(T& v) {
		return ForIterRev(v);
	}
	auto Get_For_Handler(Long v) {
		return ForIter<Long>(v);
	}
	template<TEnumerable T> auto Get_For_Handler(T& v) {
		return ForIter(v);
	}
}
#define __GET_MACRO(_0,_1,_2,_3,_4,_5,X,...) X
#define __EXPAND( x ) x
#define _fe2(e,cont) for(auto&& __cont = cont; auto&& [e, e ## i] : ::_For_impl::Get_For_Handler (__cont))
#define _fer2(e,cont) for(auto&& __cont = cont; auto&& [e, e ## i] : ::_For_impl::Get_For_Handler_rev (__cont))
#define _fe1(cont) _fe2(_, cont)
#define _fer1(cont) _fer2(_, cont)
#define fe(...) __EXPAND(__GET_MACRO(_0, __VA_ARGS__, _5, _4, _3, _fe2, _fe1, _0)(__VA_ARGS__))
#define re(...) __EXPAND(__GET_MACRO(_0, __VA_ARGS__, _5, _4, _3, _fer2, _fer1, _0)(__VA_ARGS__))
void Solve() {
	auto aa = gets();
	auto bb = gets();
	auto cc = gets();
	Vec dp(2010);
	fe(e, cc) {
		auto dp2 = dp;
		for (long cnt_a = 0; cnt_a <= 2005; cnt_a++) {
			auto cnt_b = ei - cnt_a;
			long ia = cnt_a;
			long ib = cnt_b;
			if (ib >= 0 && ib < bb.size()) {
				auto cur = bb[ib];
				long res = cur == e ? 1 : 0;
				Max2(dp2[cnt_a], dp[cnt_a] + res);
			}
			if (ia >= 0 && ia < aa.size()) {
				auto cur = aa[ia];
				long res = cur == e ? 1 : 0;
				Max2(dp2[cnt_a + 1], dp[cnt_a] + res);
			}
		}
		dp = dp2;
	}
	long max = dp.max();
	print(cc.size() - max);
}
void initialize(ProblemData& pd){
	pd.HasTestcase = true;
	pd.AutoFlash = false;
}