Language: C++

#include<vector>
#include<iostream>
#include<fstream>
#include<string>
#include<cassert>
#include<algorithm>
#include<random>
#include<map>
#include<set>
#include <bitset>

using namespace std;

//int mod = 998244353;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int>vi;
typedef vector<ll>vl;
typedef vector<char>vc;
typedef vector<string>vs;
typedef vector<vector<int>>vvi;
typedef vector<vector<char>>vvc;
typedef vector<vector<ll>>vvl;
typedef vector< pair<ll, ll>>vpll;
typedef vector< pair<ld, ld>>vpld;
typedef vector< pair<int, int>>vpi;
typedef pair<ld, ld>pld;
#define mp make_pair
#define pb push_back

int mod=998244353;
int sum(int a, int b)
{
	int c = a + b;
	if (c >= mod)
	{
		c -= mod;
	}
	return c;
}
int dif(int a, int b)
{
	int c = a - b;
	if (c < 0)
	{
		c += mod;
	}
	return c;
}
int mlt(int a, int b)
{
	ll c = a * 1LL * b;
	return c % mod;
}
int ibit(int n, int i)
{
	return ((n >> i) & 1);
}
void outp(vvi &ou)
{
	for (int i = 0; i < ou.size(); i++)
	{
		for (int j = 0; j < ou[i].size(); j++)
		{
			cout << ou[i][j] << ' ';
		}
		cout << '\n';
	}
}
int bp(int x, int y)
{
	if (y == 0)
	{
		return 1;
	}
	int a = 0;
	if (!(y % 2))
	{
		a = bp(x, y / 2);
	}
	return (y % 2) ? mlt(bp(x, y - 1), x) : mlt(a, a);
}
int obr(int x)
{
	return bp(x, mod - 2);
}
const int maxn = 10000007;
int fact[maxn], ofact[maxn];
void prec()
{
	fact[0] = 1;
	ofact[0] = 1;
	for (int i = 1; i < maxn; i++)
	{
		fact[i] = mlt(fact[i - 1], i);
	}
	//cerr << "sdsds" << endl;
	ofact[maxn - 1] = obr(fact[maxn - 1]);
	for (int i = maxn - 2; i > 0; i--)
	{
		ofact[i] = mlt(ofact[i + 1], i + 1);
	}
}
int c(int a, int b)
{
	return ((a <= b) && (a >= 0)) ? mlt(fact[b], mlt(ofact[a], ofact[b - a])) : 0;
}
int dp3[maxn], dp2[maxn];
const int inf = 1000000007;
int recalc(int val, int cand, int mn, vi changes, int nxt, int last)
{
	if ((val < 0)||(val>nxt)||(cand<0)||(cand>last))
	{
		return inf; 
	}
	int res = mn;
	for (int i = 0; i < changes.size(); i++)
	{
		if (changes[i] <= cand)
		{
			res++;
		}
	}
	if (cand < val)
	{
		res++;
	}
	int bcand = last - cand, bval=nxt-val;
	if (bcand > bval)
	{
		res++;
	}
	return res;
}
int getdyn(int val, int mn, vi changes, int nxt, int last)
{
	vi cands;
	cands.pb(val);
	cands.pb(nxt);
	cands.pb(nxt -last+ val);
	cands.pb(last - nxt + val);
	cands.pb(0);
	cands.pb(last);
	for (int i = 0; i < changes.size(); i++)
	{
		int v = changes[i];
		cands.pb(v);
		cands.pb(last - nxt + v);
		cands.pb(nxt - last + v);
	}
	int cur = 1000000007;
	for (int i = 0; i < cands.size(); i++)
	{
		cur = min(cur, recalc(val, cands[i], mn, changes, nxt, last));
		//cerr << val << ' '<<cands[i]<<' ' << nxt << ' ' << last << ' ' << cur << endl;
	}
	cerr << val << ' '<<' ' << nxt << ' ' << last << ' ' << cur << endl;
	return cur;
}
void rec(int &mn, vi &changes, int nxt, int last)
{
	vi int_vals;
	for (int i = 0; i < 10; i++)
	{
		int_vals.pb(i);
	}
	for (int i = 0; i < changes.size(); i++)
	{
		int cur = changes[i];
		int_vals.pb(cur);
		int_vals.pb(cur-1);
		int_vals.pb(cur+1);
		int_vals.pb(last-cur);
		int_vals.pb(last-cur+1);
		int_vals.pb(last-cur-1);
	}
	int_vals.pb(0);
	int_vals.pb(nxt);
	int_vals.pb(1);
	int_vals.pb(nxt-1);
	int new_mn=1488228;
	vpi int_prs;
	for (int i = 0; i < int_vals.size(); i++)
	{
		int_prs.pb(mp(int_vals[i], getdyn(int_vals[i], mn, changes, nxt, last)));
	}
	sort(int_prs.begin(), int_prs.end());
	vi new_changes;
	for (int i = 1; i < int_prs.size(); i++)
	{
	//	cerr << i << ' ' << int_prs[i].first << ' ' << int_prs[i].second << endl;
		int zn = int_prs[i].first;
		if (zn == 0)
		{
			new_mn = int_prs[i].second;
		}
		if (int_prs[i - 1].second < int_prs[i].second)
		{
			//cerr << "Here" << endl;
			for (int j = int_prs[i - 1].second; j < int_prs[i].second; j++);
			{
			//	cerr << "Threr" << endl;
				if ((zn >= 0) && (zn <= nxt))
				{
			//		cerr << 228 << endl;
					new_changes.pb(int_prs[i].first);
				}
			}
		}
	}
	if (int_prs[0].first == 0)
	{
		new_mn = int_prs[0].second;
	}
	mn = new_mn;
	changes = new_changes;
}
void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;
	cin >> n;
	vi c(n+2);
	for (int i = 0; i < n; i++)
	{
		cin >> c[i+1];
	}
	n += 2;
	if (n == 1)cout << 1 << endl;
	else
	{
		int vala = 0, valb = 0;
		for (int i = 0; i < n - 1; i++)
		{
			if (c[i + 1] < c[i])
			{
				vala++;
			}
			if (c[i + 1] > c[i])
			{
				valb++;
			}
		}
		int cur = min(vala, valb);
		int mn = 0;
		vi changes;
		for (int i = 1; i < n; i++)
		{
			rec(mn, changes, c[i], c[i - 1]);
			//cerr << "Mn" << ' ' << mn << endl;
			for (int i = 0; i < changes.size(); i++)
			{
		..		cerr << changes[i] << ' ';
			}
	//		cerr << endl;
		}
		cout << min(mn, cur) << endl;
	}
}
int main()
{
	//prec();
	//cerr << "Here" << endl;
	solve();
	int n;
	cin >> n;
}

Compiler output:
a.cc: In function 'void solve(std::istream&, std::ostream&)':
a.cc:256:17: error: expected primary-expression before '.' token
  256 |                 ..              cerr << changes[i] << ' ';
      |                 ^
a.cc:256:18: error: expected unqualified-id before '.' token
  256 |                 ..              cerr << changes[i] << ' ';
      |                  ^