<commit_before>#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

ll n, m;
ll a[100010];

ll imos[3][100010];

int main () {
  cin >> n >> m;
  for (auto i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll sum = 0;
  for (auto i = 0; i < n-1; ++i) {
    if (a[i+1] > a[i]) {
      sum += a[i+1] - a[i];
    } else {
      sum += m - a[i] + a[i+1];
    }
  }
  cerr << "sum = " << sum << endl;
  fill(&imos[0][0], &imos[0][0]+3*100010, 0);
  for (auto i = 0; i < n-1; ++i) {
    if (a[i] < a[i+1]) {
      imos[0][a[i]+2] += 1;
      imos[0][a[i+1]+1] -= 1;
      imos[2][a[i+1]+1] -= a[i+1] - (a[i] + 1);
    } else {
      imos[0][1] += 1;
      imos[0][a[i+1]+1] -= 1;
      imos[0][a[i]+2] += 1;
      imos[2][1] += m - (a[i] + 1);
      imos[2][a[i+1]+1] -= m - (a[i] + 1) + (a[i+1] + 1);
    }
  }
  for (auto k = 0; k < 3; ++k) {
    for (auto i = 1; i < m+10; ++i) {
      cerr << "imos[" << k << "][" << i << "] = " << imos[k][i] << endl;
    }
  }
  for (auto k = 0; k < 3; ++k) {
    for (auto i = 0; i < m+10; ++i) {
      imos[k][i+1] += imos[k][i];
    }
    if (k < 2) {
      for (auto i = 0; i <= m+10; ++i) {
        imos[k+1][i] += imos[k][i];
      }
    }
  }
  ll ans = 0;
  for (auto i = 1; i <= m; ++i) {
    ans = max(ans, imos[2][i]);
  }
  cout << sum - ans << endl;
}
<commit_msg>tried E.cpp to 'E'<commit_after>#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

ll n, m;
ll a[100010];

ll imos[3][100010];

int main () {
  cin >> n >> m;
  for (auto i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll sum = 0;
  for (auto i = 0; i < n-1; ++i) {
    if (a[i+1] > a[i]) {
      sum += a[i+1] - a[i];
    } else {
      sum += m - a[i] + a[i+1];
    }
  }
  cerr << "sum = " << sum << endl;
  fill(&imos[0][0], &imos[0][0]+3*100010, 0);
  for (auto i = 0; i < n-1; ++i) {
    if (a[i] < a[i+1]) {
      imos[0][a[i]+2] += 1;
      imos[0][a[i+1]+1] -= 1;
      imos[2][a[i+1]+1] -= a[i+1] - (a[i] + 1);
    } else {
      imos[0][1] += 1;
      imos[0][a[i+1]+1] -= 1;
      imos[0][a[i]+2] += 1;
      imos[2][1] += m - (a[i] + 1);
      imos[2][a[i+1]+1] -= m - (a[i] + 1) + (a[i+1] + 1);
    }
  }
  for (auto k = 0; k < 3; ++k) {
    for (auto i = 1; i < m+10; ++i) {
      cerr << "imos[" << k << "][" << i << "] = " << imos[k][i] << endl;
    }
  }
  for (auto k = 0; k < 3; ++k) {
    for (auto i = 0; i < m+10; ++i) {
      imos[k][i+1] += imos[k][i];
    }
    if (k < 2) {
      for (auto i = 0; i <= m+10; ++i) {
        imos[k+1][i] += imos[k][i];
      }
    }
  }
  for (auto i = 1; i < m+10; ++i) {
    cerr << "imos[" << 2 << "][" << i << "] = " << imos[2][i] << endl;
  }
  ll ans = 0;
  for (auto i = 1; i <= m; ++i) {
    ans = max(ans, imos[2][i]);
  }
  cout << sum - ans << endl;
}

{'fraction_non_alphanumeric': 0.27224435590969454, 'fraction_numerical': 0.05334218680832226, 'mean_word_length': 2.305779078273592, 'pattern_counts': {'":': 0, '<': 134, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2092995', 'n_tokens_mistral': 2252, 'n_tokens_neox': 2094, 'n_words': 542}