Link to this code:
https://cses.fi/paste/2ecb38a2d1c174c1d42893/
// add me on genshin impact! 607984574
// Problem: Water Containers Moves
// Attempted: 2025-07-29 08:29:20 EST
#pragma GCC optimize("O3, unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 0
#else
#include "/Users/envyaims/Documents/template/debug.cpp"
#endif
using namespace std;
using ll = long long;
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define pq priority_queue
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FORE(i,a,b) for(int i = (a); i <= (b); ++i)
#define ROF(i,a,b) for(int i = (a); i >= (b); --i)
#define trav(a,x) for(auto& a: x)
#define sz(x) (int)x.size()
#define make_unique(v) v.erase(unique(all(v)), v.end());
template<class T> using minpq = pq<T, vector<T>, greater<T>>;
template<class T> bool ckmin(T& a, const T& b){return b<a?a=b,1:0;}
template<class T> bool ckmax(T& a, const T& b){return a<b?a=b,1:0;}
template<int D, typename T>struct vt : public vector<vt<D - 1, T>> { template<typename... Args>
vt(int n = 0, Args... args) : vector<vt<D - 1, T>>(n, vt<D - 1, T>(args...)) {}};
template<typename T> struct vt<1, T> : public vector<T> {
vt(int n = 0, const T& val = T()) : vector<T>(n, val) {}};
template<typename T> istream& operator>>(istream& in, vector<T>& a) {for(auto &x : a) in >> x; return in;};
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {for(auto &x : a) out << x << ' '; return out;};
const int INF = 1e9;
void uwu(){
int A, B, x; cin >> A >> B >> x;
if(x > A){
cout << -1 << "\n";
return;
}
vt<2,int> dist(A+1,B+1,INF);
vt<2,pair<int,int>> from(A+1,B+1);
vt<2,string> move_name(A+1,B+1);
dist[0][0] = 0;
minpq<array<int, 3>> pq;
pq.push({0,0,0});
while(!pq.empty()){
int d = pq.top()[0], a = pq.top()[1], b = pq.top()[2];
pq.pop();
if(d > dist[a][b]) continue;
dist[a][b] = d;
auto test = [&](int nd, int na, int nb, string move) -> void{
if(ckmin(dist[na][nb], d + nd)){
pq.push({dist[na][nb], na, nb});
from[na][nb] = {a, b};
move_name[na][nb] = move;
}
};
test(A - a, A, b, "FILL A");
test(B - b, a, B, "FILL B");
test(a, 0, b, "EMPTY A");
test(b, a, 0, "EMPTY B");
int num_move = min(a, B - b);
test(num_move, a - num_move, b + num_move, "MOVE A B");
num_move = min(A - a, b);
test(num_move, a + num_move, b - num_move, "MOVE B A");
}
int num_water = INF, num_b = -1;
FOR(i,0,B+1){
if(ckmin(num_water, dist[x][i])){
num_b = i;
}
}
if(num_water == INF){
cout << -1 << "\n";
return;
}
pair<int, int> cur = {x, num_b};
vector<string> res;
while(cur != make_pair(0,0)){
res.pb(move_name[cur.F][cur.S]);
cur = from[cur.F][cur.S];
}
reverse(all(res));
cout << sz(res) << " " << num_water << "\n";
trav(i, res) cout << i << "\n";
}
signed main(){
cin.tie(0) -> sync_with_stdio(0);
int t = 1;
// cin>>t;
while(t--){
uwu();
}
}