Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
typedef LL long long;

using namespace std;

int main(){

    LL n,m;
    cin>>n>>m;
    LL sum[m];
    LL ad[m];

    fill_n(sum,m,0);
    fill_n(ad,m,0);
    LL a[n];
    REP(i,n){
        cin>>a[i];
        a[i]--;
    }
    REP(i,n-1){
        sum[(a[i]+1)%m]--;
        sum[a[i+1]]++;
    }


    LL maxn=sum[0];
    REP(i,m-1){
        sum[i+1]+=sum[i];
        maxn =max(maxn,sum[i+1]);
    }
    REP(i,m){
        sum[i]-=maxn;
    }


    REP(i,n-1){
        ad[a[i+1]]+=(a[i+1]-a[i]+m)%m-1;
    }

    LL cnt[m];
    fill_n(cnt,m,0);
    REP(i,n-1){
        if(a[i]>a[i+1]){
            cnt[0]+=a[i+1]+1;
        }else{
            cnt[0]+=a[i+1]-a[i];
        }
    }
    LL minn = cnt[0];
    for(int i=1;i<m;i++){
        cnt[i]=cnt[i-1]+ad[i-1]+sum[i-1];
        minn = min(minn,cnt[i]);
    }
    cout<<minn<<endl;
//    REP(i,m){
//        cout<<ad[i]<<" "<<sum[i]<<endl;
//    }


    return 0;
}

Compiler output:
a.cc:4:9: error: 'LL' does not name a type; did you mean 'ALL'?
    4 | typedef LL long long;
      |         ^~
      |         ALL
a.cc: In function 'int main()':
a.cc:10:5: error: 'LL' was not declared in this scope; did you mean 'ALL'?
   10 |     LL n,m;
      |     ^~
      |     ALL
a.cc:11:10: error: 'n' was not declared in this scope; did you mean 'yn'?
   11 |     cin>>n>>m;
      |          ^
      |          yn
a.cc:11:13: error: 'm' was not declared in this scope; did you mean 'tm'?
   11 |     cin>>n>>m;
      |             ^
      |             tm
a.cc:12:7: error: expected ';' before 'sum'
   12 |     LL sum[m];
      |       ^~~~
      |       ;
a.cc:13:7: error: expected ';' before 'ad'
   13 |     LL ad[m];
      |       ^~~
      |       ;
a.cc:15:12: error: 'sum' was not declared in this scope
   15 |     fill_n(sum,m,0);
      |            ^~~
a.cc:16:12: error: 'ad' was not declared in this scope
   16 |     fill_n(ad,m,0);
      |            ^~
a.cc:17:7: error: expected ';' before 'a'
   17 |     LL a[n];
      |       ^~
      |       ;
a.cc:19:14: error: 'a' was not declared in this scope
   19 |         cin>>a[i];
      |              ^
a.cc:23:14: error: 'a' was not declared in this scope
   23 |         sum[(a[i]+1)%m]--;
      |              ^
a.cc:28:7: error: expected ';' before 'maxn'
   28 |     LL maxn=sum[0];
      |       ^~~~~
      |       ;
a.cc:31:9: error: 'maxn' was not declared in this scope; did you mean 'main'?
   31 |         maxn =max(maxn,sum[i+1]);
      |         ^~~~
      |         main
a.cc:34:17: error: 'maxn' was not declared in this scope; did you mean 'main'?
   34 |         sum[i]-=maxn;
      |                 ^~~~
      |                 main
a.cc:39:12: error: 'a' was not declared in this scope
   39 |         ad[a[i+1]]+=(a[i+1]-a[i]+m)%m-1;
      |            ^
a.cc:42:7: error: expected ';' before 'cnt'
   42 |     LL cnt[m];
      |       ^~~~
      |       ;
a.cc:43:12: error: 'cnt' was not declared in this scope; did you mean 'int'?
   43 |     fill_n(cnt,m,0);
      |            ^~~
      |            int
a.cc:45:12: error: 'a' was not declared in this scope
   45 |         if(a[i]>a[i+1]){
      |            ^
a.cc:51:7: error: expected ';' before 'minn'
   51 |     LL minn = cnt[0];
      |       ^~~~~
      |       ;
a.cc:54:9: error: 'minn' was not declared in this scope
   54 |         minn = min(minn,cnt[i]);
      |         ^~~~
a.cc:56:11: error: 'minn' was not declared in this scope
   56 |     cout<<minn<<endl;
      |           ^~~~