Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll
#define int ll;


int m,n;
int a[100010];



struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;
 
public:
    LazySegmentTree(const vector<ll>& v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);
 
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }
 
    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }
 
    void add_inter(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add_inter(a, b, x, 2*k+1, l, (l+r)/2);
            add_inter(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }
 
    ll get_inter(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = get_inter(a, b, 2*k+1, l, (l+r)/2);
        ll vr = get_inter(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

signed main()
{
	cin >> n >> m;

	for(int i = 0;i < n;i++)
	{
		cin >> a[i];
		a[i]--;
	}

	int sum = 0;

	LazySegmentTree seg(vector<ll>(3 * m,0LL));

	for(int i = 1;i < n;i++)
	{
		int from = a[i - 1];
		int to = a[i];
		if(from > to) to += m;
		//from < to
			

		int dist = (to - from)% m;

		sum += dist;
		
		to = a[i] + 1;
		from =  a[i] - (dist - 1) + 1;

		if(from < 0)
		{
		}
		else
		{

			seg.add_inter(from , to,1);
			seg.add_inter(to,to + 1,-(dist - 1));
		}

		from += m;
		to += m;
			

		seg.add_inter(from , to,1);
		seg.add_inter(to,to + 1,-(dist - 1));

	}

	ll minus = 0;

	for(int i = 0;i < 2 * m;i++)
	{
		minus = max(minus , seg.get_inter(0,i));
	}

	cout << sum - minus << endl;
}



Compiler output:
a.cc:8:13: error: expected initializer before 'll'
    8 | #define int ll;
      |             ^~
a.cc:11:1: note: in expansion of macro 'int'
   11 | int m,n;
      | ^~~
a.cc:11:5: error: 'm' does not name a type; did you mean 'tm'?
   11 | int m,n;
      |     ^
      |     tm
a.cc:8:13: error: 'll' does not name a type
    8 | #define int ll;
      |             ^~
a.cc:12:1: note: in expansion of macro 'int'
   12 | int a[100010];
      | ^~~
a.cc:12:5: error: 'a' does not name a type
   12 | int a[100010];
      |     ^
a.cc:8:13: error: 'll' does not name a type
    8 | #define int ll;
      |             ^~
a.cc:18:5: note: in expansion of macro 'int'
   18 |     int n;
      |     ^~~
a.cc:18:9: error: 'n' does not name a type
   18 |     int n;
      |         ^
a.cc:19:12: error: 'll' was not declared in this scope
   19 |     vector<ll> node, lazy;
      |            ^~
a.cc:19:14: error: template argument 1 is invalid
   19 |     vector<ll> node, lazy;
      |              ^
a.cc:19:14: error: template argument 2 is invalid
a.cc:22:34: error: 'll' was not declared in this scope
   22 |     LazySegmentTree(const vector<ll>& v) {
      |                                  ^~
a.cc:22:36: error: template argument 1 is invalid
   22 |     LazySegmentTree(const vector<ll>& v) {
      |                                    ^
a.cc:22:36: error: template argument 2 is invalid
a.cc:8:13: error: 'll' has not been declared
    8 | #define int ll;
      |             ^~
a.cc:32:15: note: in expansion of macro 'int'
   32 |     void eval(int k, int l, int r) {
      |               ^~~
a.cc:8:15: error: expected ')' before ';' token
    8 | #define int ll;
      |               ^
a.cc:32:15: note: in expansion of macro 'int'
   32 |     void eval(int k, int l, int r) {
      |               ^~~
a.cc:32:14: note: to match this '('
   32 |     void eval(int k, int l, int r) {
      |              ^
a.cc:32:19: error: 'k' does not name a type
   32 |     void eval(int k, int l, int r) {
      |                   ^
a.cc:32:26: error: 'l' does not name a type
   32 |     void eval(int k, int l, int r) {
      |                          ^
a.cc:32:33: error: 'r' does not name a type
   32 |     void eval(int k, int l, int r) {
      |                                 ^
a.cc:8:13: error: 'll' has not been declared
    8 | #define int ll;
      |             ^~
a.cc:43:20: note: in expansion of macro 'int'
   43 |     void add_inter(int a, int b, ll x, int k=0, int l=0, int r=-1) {
      |                    ^~~
a.cc:8:15: error: expected ')' before ';' token
    8 | #define int ll;
      |               ^
a.cc:43:20: note: in expansion of macro 'int'
   43 |     void add_inter(int a, int b, ll x, int k=0, int l=0, int r=-1) {
      |                    ^~~
a.cc:43:19: note: to match this '('
   43 |     void add_inter(int a, int b, ll x, int k=0, int l=0, int r=-1) {
      |                   ^
a.cc:43:24: error: 'a' does not name a type
   43 |     void add_inter(int a, int b, ll x, int k=0, int l=0, int r=-1) {
      |                        ^
a.cc:43:31: error: 'b' does not name a type
   43 |     void add_inter(int a, int b, ll x, int k=0, int l=0, int r=-1) {
      |                               ^
a.cc:43:44: error: 'k' does not name a type
   43 |     void add_inter(int a, int b, ll x, int k=0, int l=0, int r=-1) {
      |                                            ^
a.cc:43:53: error: 'l' does not name a type
   43 |     void add_inter(int a, int b, ll x, int k=0, int l=0, int r=-1) {
      |                                                     ^
a.cc:43:62: error: 'r' does not name a type
   43 |     void add_inter(int a, int b, ll x, int k=0, int l=0, int r=-1) {
      |                                                              ^
a.cc:58:5: error: 'll' does not name a type
   58 |     ll get_inter(int a, int b, int k=0, int l=0, int r=-1) {
      |     ^~
a.cc:58:22: error: 'a' does not name a type
   58 |     ll get_inter(int a, int b, int k=0, int l=0, int r=-1) {
      |                      ^
a.cc:58:29: error: 'b' does not name a type
   58 |     ll get_inter(int a, int b, int k=0, int l=0, int r=-1) {
      |                             ^
a.cc:58:36: error: 'k' does not name a type
   58 |     ll get_inter(int a, int b, int k=0, int l=0, int r=-1) {
      |                                    ^
a.cc:58:45: error: 'l' does not name a type
   58 |     ll get_inter(int a, int b, int k=0, int l=0, int r=-1) {
      |                                             ^
a.cc:58:54: error: 'r' does not name a type
   58 |     ll get_inter(int a, int b, int k=0, int l=0, int r=-1) {
      |                                                      ^
a.cc: In constructor 'LazySegmentTree::LazySegmentTree(const int&)':
a.cc:8:13: error: 'll' was not declared in this scope
    8 | #define int ll;
      |             ^~
a.cc:23:9: note: in expansion of macro 'int'
   23 |         int sz = (int)v.size();
      |         ^~~
a.cc:23:13: error: 'sz' was not declared in this scope
   23 |         int sz = (int)v.size();
      |             ^~
a.cc:8:15: error: expected ')' before ';' token
    8 | #define int ll;
      |               ^
a.cc:23:19: note: in expansion of macro 'int'
   23 |         int sz = (int)v.size();
      |                   ^~~
a.cc:23:18: note: to match this '('
   23 |         int sz = (int)v.size();
      |                  ^
a.cc:23:22: error: expected primary-expression before ')' token
   23 |         int sz = (int)v.size();
      |                      ^
a.cc:24:9: error: 'n' was not declared in this scope
   24 |         n = 1; while(n < sz) n *= 2;
      |         ^
a.cc:25:14: error: request for member 'resize' in '((LazySegmentTree*)this)->LazySegmentTree::node', which is of non-class type 'int'
   25 |         node.resize(2*n-1);
      |              ^~~~~~
a.cc:26:14: error: request for member 'resize' in '((LazySegmentTree*)this)->LazySegmentTree::lazy', which is of non-class type 'int'
   26 |         lazy.resize(2*n-1, 0);
      |              ^~~~~~
a.cc:28:17: error: 'i' was not declared in this scope
   28 |         for(int i=0; i<sz; i++) node[i+n-1] = v[i];
      |                 ^
a.cc:28:26: error: expected ')' before ';' token
   28 |         for(int i=0; i<sz; i++) node[i+n-1] = v[i];
      |                          ^
a.cc:28:12: note: to match this '('
   28 |         for(int i=0; i<sz; i++) node[i+n-1] = v[i];
      |            ^
a.cc:28:28: error: 'i' was not declared in this scope
   28 |         for(int i=0; i<sz; i++) node[i+n-1] = v[i];
      |                            ^
a.cc:29:28: error: expected ')' before ';' token
   29 |         for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
      |                            ^
a.cc:29:12: note: to match this '('
   29 |         for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
      |            ^
a.cc: In function 'int main()':
a.cc:71:16: error: 'n' was not declared in this scope
   71 |         cin >> n >> m;
      |                ^
a.cc:71:21: error: 'm' was not declared in this scope; did you mean 'tm'?
   71 |         cin >> n >> m;
      |                     ^
      |                     tm
a.cc:8:13: error: 'll' was not declared in this scope
    8 | #define int ll;
      |             ^~
a.cc:73:13: note: in expansion of macro 'int'
   73 |         for(int i = 0;i < n;i++)
      |             ^~~
a.cc:73:17: error: 'i' was not declared in this scope
   73 |         for(int i = 0;i < n;i++)
      |                 ^
a.cc:73:28: error: expected ')' before ';' token
   73 |         for(int i = 0;i < n;i++)
      |            ~               ^
      |                            )
a.cc:73:29: error: 'i' was not declared in this scope
   73 |         for(int i = 0;i < n;i++)
      |                             ^
a.cc:8:13: error: 'll' was not declared in this scope
    8 | #define int ll;
      |             ^~
a.cc:79:9: note: in expansion of macro 'int'
   79 |         int sum = 0;
      |         ^~~
a.cc:79:13: error: 'sum' was not declared in this scope
   79 |         int sum = 0;
      |             ^~~
a.cc:81:38: error: template argument 2 is invalid
   81 |         LazySegmentTree seg(vector<ll>(3 * m,0LL));
      |                                      ^
a.cc:83:28: error: expected ')' before ';' token
   83 |         for(int i = 1;i < n;i++)
      |            ~               ^
      |                            )
a.cc:117:11: error: expected ';' before 'minus'
  117 |         ll minus = 0;
      |           ^~~~~~
      |           ;
a.cc:119:32: error: expected ')' before ';' token
  119 |         for(int i = 0;i < 2 * m;i++)
      |            ~                   ^
      |                                )
a.cc:124:29: error: missing template arguments before '<<' token
  124 |         cout << sum - minus << endl;
      |                             ^~