akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
using namespace std;

int main(){
	int n;
	stack<int> stack;
	while(cin >> n){
		if(n == 0){
			cout << stack.top() << endl;
			stack.pop();
		}
		else {
			stack.push(n);
		}
	}
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int main() {
	int k,n,t;
	cin >> k >> n;
	V<int> v;

	int ma = 0;
	int prev = 0;
	REP(i,n) {
		cin >> t;
		v.push_back(t);
		ma = max(ma, t - prev);
		prev = t;
	}
	ma = max(ma, k-v[n-1] + v[0]);

	cout << k-ma << endl;
	return 0;

}



Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const ll mod = 1e9 + 7;

void mkay(ll& a){
	if(a >= mod)
		a -= mod;
}

int main(){
	int n, d; cin >> n >> d;
	int ans = 0;
	for(int i = 0; i < n; i++){
		double s, p, q;
		cin >> p >> q;
		s = sqrt(p * p + q * q);
		if(s <= d)
			ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3808
#include<bits/stdc++.h>
#define N 158
using namespace std;
int vi[N*2],d1[N],mo,dp[N][N][2],n,k,ans;
void add(int &x,int y){x+=y;if (x>=mo)x-=mo;}
void get1(int x,int y){
	d1[0]=1;
	for (int i=1;i<=x+1;i++)
		for (int j=max(0,i-y);j<i;j++)add(d1[i],d1[j]);
	cout<<1ll*d1[x/2+1]*d1[(x+1)/2+1]%mo<<endl;
}
int main(){
	cin>>n>>k>>mo;
	if (k%2==0)get1(n,k/2+1);
	else{
		for (int i=1;i<=n+k+1;i++)
			if(i%2==0){if(i<k+2)vi[i]=0;else vi[i]=1;}else{if(i>n)vi[i]=0;else vi[i]=1;}
		dp[0][0][0]=1;
		for (int i=1;i<=(n+k)/2+1;i++){
			for (int l=0;l<i;l++)
			for (int p=0;p<=k;p++)
			if (dp[l][p][0]){
				int nl,np;
				for (int t1=0;t1<=vi[i*2-1];t1++)
				for (int t2=0;t2<=vi[i*2];t2++){
					if (t2&&p==1)continue;
					if (t1==1)nl=l+1;else nl=0;
					if (t2==0)np=0;
					if (t1==1&&t2==1){if (l>=k)continue;if (p==0)np=k-l;else np=min(p-1,k-l);}
					if (t1==0&&t2==1){if (p==0)np=0;else np=p-1;}
					add(dp[nl][np][1],dp[l][p][0]);
				}
			}
			for (int l=0;l<=i;l++)
			for (int p=0;p<=k;p++){
				dp[l][p][0]=dp[l][p][1],dp[l][p][1]=0;
				if (i==(n+k)/2+1)add(ans,dp[l][p][0]);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y-1);(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
//template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int i,j,k;
  int n,m;
  cin>>n;
  vector<ll> p(n);
  rep(i,n)
    cin>>p[i];
  cin>>m;
  vector<ll> pro(m),pt(m),sum(n+1);
  rep(i,m)
    cin>>pro[i];
  rep(i,m)
    cin>>pt[i];
  
  sort(all(p));
  rep(i,n)
    sum[i+1]=sum[i]+p[i];
  rep(i,m){
    ll sc=sum[upper_bound(all(p),pro[i])-p.begin()];
    cout<<(sc>=pt[i]?"Yes":"No")<<endl;
  }
  return 0;
}

Measured memory_bytes: 10236
#include <bits/stdc++.h>
using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

bool dfs(VVI& G, int u, VI& parity, PLL& res){
  if(parity[u] > 0) res.FF++;
  else res.SS++;

  for(int to: G[u]){
	if(parity[to]){
	  if(parity[to] == parity[u])
		return false;
	}
	else{
	  parity[to] = -parity[u];
	  if(!dfs(G, to, parity, res))
		return false;
	}
  }
  return true;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int V, E; cin >> V >> E;
  VVI G(V);
  REP(i,E){
	int u, v; cin >> u >> v;
	--u;
	--v;
	G[u].PB(v);
	G[v].PB(u);
  }

  map<PLL,int> xs;
  VI parity(V);
  REP(i,V){
	if(!parity[i]){
	  parity[i] = 1;
	  PLL res;
	  if(!dfs(G, i, parity, res)){
		cout << -1 << endl;
		return 0;
	  }
	  if(res.FF < res.SS) swap(res.FF, res.SS);
	  xs[res]++;
	}
  }

  int crt = 0, nxt = 1;
  vector<vector<bool>> dp(2, vector<bool>(V+1));
  dp[crt][0] = true;
  for(auto&& p_: xs){
	int num = p_.SS;
	int b = 1;
	while(num){
	  fill(ALL(dp[nxt]), false);
	  if(num < b)
		b = num;
	  num -= b;

	  PLL p(p_.FF.FF * b, p_.FF.SS*b);
	  for(int i=V;i-p.FF>=0;--i)
		dp[nxt][i] = dp[nxt][i] || dp[crt][i-p.FF];
	  for(int i=V;i-p.SS>=0;--i)
		dp[nxt][i] = dp[nxt][i] || dp[crt][i-p.SS];
	  
	  b <<= 1;
	  swap(crt, nxt);
	}
  }

  LL ans = 0;
  REP(i,V+1) if(dp[crt][i]) maxi(ans, (LL)i*(V-i));
  cout << ans - E << endl;

  return 0;
}

Measured memory_bytes: 9452
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
struct node{
	char name[105];
	int s,len,p;
	bool operator <(const node &rhs) const{
		for(int i=1;i<=len;i++){
			if(rhs.name[i]!=name[i]) return rhs.name[i]>name[i];
		}
		if (len==rhs.len) return rhs.s<s;
		return len<rhs.len;
	}
};
node a[105];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		a[i].p=i,scanf("%s %d",a[i].name+1,&a[i].s),a[i].len=strlen(a[i].name+1);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++) printf("%d\n",a[i].p);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <utility>
#include <algorithm>
using namespace std;
 
typedef pair<int, int> pi;
typedef pair<pi, char> pic;
 
int N;
vector<pic> P;
set<int> Ry;
 
void input_data(void) {
	cin >> N;
	P.resize(2 * N);
	for (int i = 0; i < N; ++i) {
		cin >> P[i].first.first >> P[i].first.second;
		P[i].second = 'R';
	}
	for (int i = N; i < 2 * N; ++i) {
		cin >> P[i].first.first >> P[i].first.second;
		P[i].second = 'B';
	}
}
 
int solve(void) {
	int cnt = 0;
	for (int i = 0; i < 2 * N; ++i) {
		if (P[i].second == 'R')
			Ry.insert(P[i].first.second);
		else {
			set<int>::reverse_iterator itr;
			for (itr = Ry.rbegin(); itr != Ry.rend(); ++itr) {
				if (*itr < P[i].first.second) {
					Ry.erase(*itr);
					++cnt;
					break;
				}
			}
		}
	}
	return cnt;
}
 
int main(void) {
	input_data();
 
	sort(P.begin(), P.end());
	int ans = solve();
 
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>


using namespace std;
#define INF 1000000005
long long int sum = 0;
long long int pre = 0;
long long int ppre = 0;
//int bol = 1;
long long int gcd(long long int a,long long  int b) {
    if (b == 0)
        return a;
    ppre = pre;
    pre = a;
    //bol = bol * -1;
    return gcd(b, a % b);
}

int main()
{

long long int n, x;
std::cin >> n >> x;
long long int num = 0;
long long int g = gcd(n, std::min(n-x,x));
/*if(n % std::min(n-x,x)  != 0) {
    if(bol == 1){
        num = ((pre / g - 1)) * g;
    } else {
        num = ((long long int)(ppre / pre)) * pre;
    }
} */
sum = std::max(n- x,x);
std::cout << 3 * n - 3 * g <<std::endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

string s;

int solve();

int main() {
  cin >> s;

  cout << solve() << endl;
  return 0;
}

int solve() {
  int ans = 1000;
  for(int i = 0; i + 2 < s.size(); ++i) {
    int now = 0;
    now += s[i] - '0';
    now *= 10;
    now += s[i + 1] - '0';
    now *= 10;
    now += s[i + 2] - '0';
    ans = min(ans, max(now - 753, 753 - now));
  }
  return ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int long long
typedef long long ll;
typedef pair<int,int> P;

ll gcd(ll a, ll b) //最大公約数
{
    if(b==0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a, ll b) //最小公倍数、gcdとセット
{
    ll g = gcd(a,b);
    return a/g*b;
}

signed main(){
    int n,m;
    cin >> n >> m;
    vector<int> vec;
    vector<int>count;
    rep(i,n){
        int aa;
        cin >> aa;
        int ain=aa;
        int cc=0;
        while(1){
            if(aa%2==0){
                cc++;
                aa/=2;
            }
            else break;
        }
        vec.push_back(ain/2);
        count.push_back(cc);
    }

    int save=count[0];
    for(int i=0;i<count.size();i++){
        if(count[i]!=save){
            cout << 0 << endl;
            return 0;
        }
        save=count[i];
    }

    int l=1;
    for(auto x:vec){
        l=lcm(l,x);
        if(l>m){
            cout << 0 << endl;
            return 0;
        }
        //cout << l << endl;
    }
    

    int c=1;
    int ans=0;
    while(1){
        if(l*c>m) break;
        c+=2;
        ans++;
    }
    
    cout << ans << endl;
    rep(i,n){
        //cout << count[i] << endl;
    }
    //cout << l << endl;
    
}

Measured memory_bytes: 2036
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>

#define ll long long

using namespace std;

const long long mod = 1e9 + 7;

int main() {
	int a,b,c;
    cin >> a >> b >> c;
    if(a<=c && c<=b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <array>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll ans = 0;
    rep(i,n)ans += (ll)i*(n-i+1);
    rep(i,n-1){
        int a, b;
        cin >> a >> b;
        if(a > b)swap(a, b);
        ans -= (ll)(n-b+1)*a;
    }
    cout << ans + n << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, p;
    cin >> n >> p;
    int a[n];
    vector<int> odd;
    vector<int> even;
    int tmp;
    for (int i = 0; i < n; ++i) {
        cin >> tmp;
        if (tmp % 2 == 0) {
            even.push_back(tmp);
        } else {
            odd.push_back(tmp);
        }
    }
    long long even_ncr_sum = 0;
    int even_size = static_cast<int>(even.size());
    for (int i = 0; i <= even_size; ++i) {
        long long ncr = 1;
        for (int j = 1; j <= i; ++j) {
            ncr *= (even_size - j + 1);
            ncr /=  j;
        }
        even_ncr_sum += ncr;
    }

    long long odd_ncr_sum = 0;
    int odd_size = static_cast<int>(odd.size());
    for (int i = p; i <= odd_size; i += 2) {
        long long ncr = 1;
        for (int j = 1; j <= i; ++j) {
            ncr *= (odd_size - j + 1);
            ncr /= j;
        }
        odd_ncr_sum += ncr;
    }

    // int zero_check = !(p == 1 && odd_size == 0);
    
    cout << odd_ncr_sum * even_ncr_sum << '\n';
    // cout << odd_ncr_sum * even_ncr_sum * zero_check + (p == 0) << '\n';

    return 0;
}


Measured memory_bytes: 256
if __name__ == "__main__":
    N=int(input())
    work=[]

    for i in range(N):
        W=list(map(int,input().split()))
        work.append(W)
    
    work.sort(key=lambda x:x[1])
    result=0
    flg=0

    for i in range(N):
        result+=work[i][0]
        if result>work[i][1]:
            flg=1
            break
    
    if flg==1:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 88408
#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::cerr;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long int ll;
const int MOD = 1e9 + 7;

int main() {
    int n, t;
    cin >> n >> t;

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

    int m = a[0];
    for(int i = 0; i < n; i++){
        m = min(m, a[i]);
        a[i] = a[i] - m;
    }

    sort(a.begin(), a.end());

    int cnt = 0;
    for(int i = n - 1; i >= 0; i--){
        if(a[i] == a[n-1]){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>
using namespace std;
#define all(x) (x).begin(), (x).end()

const int N = 500000;
const long long MOD = 1e9 + 7;

long long n, m, k;

string s[5000];

long long inq(long long a, long long b)
{
    if (b == 0) return 1;
    long long l = inq(a, b / 2);
    if (b % 2) return l * l % MOD * a % MOD;
    return l * l % MOD;
}

struct Matrix{
    int n, m;
    long long a[50][50];
};

Matrix operator * (Matrix a, Matrix b)
{
    Matrix c;
    c.n = a.n, c.m = b.m;
    for (int k = 0; k < a.m; k++)
    {
        for (int i = 0; i < a.n; i++)
        {
            for (int j = 0; j < b.m; j++)
            {
                c.a[i][j] = (c.a[i][j] + a.a[i][k] * b.a[k][j]) % MOD;
            }
        }
    }
    return c;
}

Matrix inq(Matrix a, long long b)
{
    if (b == 0)
    {
        Matrix x;
        x.n = a.n, x.m = a.m;
        for (int i = 0; i < a.n; i++) x.a[i][i] = 1;
        return x;
    }
    Matrix l = inq(a, b / 2);
    if (b % 2) return l * l * a;
    return l * l;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) cin >> s[i];
    int c1 = 0, c2 = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i][0] == s[i][m - 1] && s[i][0] == '#') c1 = 1;
    }
    for (int j = 0; j < m; j++)
    {
        if (s[0][j] == s[n - 1][j] && s[0][j] == '#') c2 = 1;
    }
    if (!c1 && !c2)
    {
        long long cnt = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++) if (s[i][j] == '#') cnt++;
        }
        cout << inq(cnt, k - 1);
        return 0;
    }
    if (c1 && c2)
    {
        cout << 1;
        return 0;
    }
    if (c2 == 1)
    {
        string t[5000];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                t[j] += ".";
            }
        }
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                t[j][i] = s[i][j];
            }
        }
        for (int i = 0; i < 5000; i++) s[i] = t[i];
        swap(n, m);
    }
    Matrix xy;
    xy.n = 2, xy.m = 1;
    xy.a[0][0] = 1, xy.a[1][0] = 1;
    Matrix dp;
    dp.n = 2, dp.m = 2;
    int a = 0, b = 0, c = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (s[i][j] == '#') a++;
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j + 1 < m; j++)
        {
            if (s[i][j] == '#' && s[i][j + 1] == '#') b++;
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (s[i][0] == '#' && s[i][m - 1] == '#') c++;
    }
    dp.a[0][0] = a, dp.a[0][1] = MOD - b, dp.a[1][1] = c;
    dp = inq(dp, k - 1);
    Matrix ans = dp * xy;
    cout << ans.a[0][0];
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N, K, d, a;
    cin >> N >> K;
    int cnt = 0;
    vector<int> vec(N, 0);
    for (int i = 0; i < K; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            cin >> a;
            vec.at(a - 1) += 1;
        }
    }
    for (int i = 0; i < vec.size(); i++) {
        if (vec.at(i) == 0) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
	public static void Main()
	{
		var n = ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
		var s = ReadLine().ToCharArray();
		s[n[1]] = s[n[1]].ToString().ToLower().ToCharArray()[0];
		
		WriteLine(new string(s));
	}
}


Measured memory_bytes: 19148
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    vector<int> S = A;
    sort(S.begin(), S.end());

    map<int, int> m;
    REP(i, S.size()) {
        m[S[i]] = i % 2;
    }

    int ans = 0;
    REP(i, A.size()) {
        if (i % 2 != m[A[i]]) {
            ans++;
        }
    }

    cout << ans / 2 << endl;

    return 0;
}


Measured memory_bytes: 8064
x = input().split()
y = input().split()
a = [0, 1, 2]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        k = a[j]
        if {x[j], x[-j-1]} != {y[k], y[-k-1]}:
            break
        if x[j] == y[k]:
            order[j] = 1
            if x[j] == x[-j-1]:
                order[j] = 2
    else:
        if 2 in order or (i < 3) == sum(order) % 2:
            print('Yes')
            break
    a = [a[2], a[0], a[1]]
    if i == 2:
        a = [a[0], a[2], a[1]]
else:
    print('No')

Measured memory_bytes: 7532
using System;
using System.Text;
using static ConsoleReader;

class Program
{
    static void Main(string[] args)
    {
        var x = Read<int>();

        Console.WriteLine(x >= 30 ? "Yes" : "No");
    }
}

public static class IntExtentions
{
    public static void Times(this int n, Action<int> action)
    {
        for (var i = 0; i < n; i++)
        {
            action(i);
        }
    }

    public static void Times(this (int n, int m) dimensions, Action<int, int> action)
    {
        var (n, m) = dimensions;
        n.Times(i => m.Times(j => action(i, j)));
    }
}

public static class ConsoleReader
{
    public static T Read<T>()
        where T : IConvertible
    {
        var inputBuffer = new StringBuilder();
        int currChar;

        while ((currChar = Console.Read()) != -1)
        {
            if (!char.IsWhiteSpace((char)currChar))
            {
                inputBuffer.Append((char)currChar);
            }
            else if (inputBuffer.Length != 0)
            {
                break;
            }
        }

        return (T)Convert.ChangeType(inputBuffer.ToString(), typeof(T));
    }

    public static T[] ReadArray<T>(int count)
        where T : IConvertible
    {
        if (count < 0)
        {
            throw new ArgumentOutOfRangeException(nameof(count), $"'{nameof(count)}' must be >= 0");
        }

        var result = new T[count];

        for (var i = 0; i < count; i++)
        {
            result[i] = Read<T>();
        }

        return result;
    }
}

Measured memory_bytes: 27516
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

#[allow(dead_code)]
const M: i64 = 1_000_000_007;

#[derive(Debug, Clone)]
enum UF { Root(usize), Child(usize) }

#[derive(Debug)]
struct UnionFind { table: Vec<UF> }
impl UnionFind {

    fn new(n: usize) -> UnionFind {
        UnionFind { table: vec![UF::Root(1); n], }
    }

    fn root(&mut self, x: usize) -> usize {
        match self.table[x] {
            UF::Root(_) => x,
            UF::Child(parent) => {
                let root = self.root(parent);
                self.table[x] = UF::Child(root);
                root
            }
        }
    }

    fn is_same(&mut self, x: usize, y: usize) -> bool {
        self.root(x) == self.root(y)
    }

    fn size(&mut self, x: usize) -> usize {
        let r = self.root(x);
        match self.table[r] {
            UF::Root(size) => size,
            UF::Child(_) => 0
        }
    }

    fn merge(&mut self, x: usize, y: usize) {
        let root_x = self.root(x);
        let root_y = self.root(y);
        if root_x != root_y {
            let size_x = self.size(root_x);
            let size_y = self.size(root_y);
            let (i, j) = if size_x > size_y {
                (root_x, root_y)
            } else {
                (root_y, root_x)
            };
            self.table[i] = UF::Root(size_x + size_y);
            self.table[j] = UF::Child(i);
        }
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut uf = UnionFind::new(n);
    let m: usize = sc.cin();
    for _ in 0..m {
        let x: usize = sc.cin::<usize>() - 1;
        let y: usize = sc.cin::<usize>() - 1;
        let _: usize = sc.cin();
        uf.merge(x, y);
    }
    use std::collections::HashSet;
    let mut hs = HashSet::new();
    for i in 0..n {
        hs.insert( uf.root(i) );
    }
    put!(hs.len());
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    
    int N;
    cin >> N;
    vi B(N+1,0);
    
    reps(i,2,N+1){
        int a;
        cin >> a;
        
        B[a]++;
    }
    
    reps(i,1,N+1){
        cout << B[i] << endl;
    }
    

    return 0;
}


Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int a, b; cin >> a >> b;
  cout << (b - 1 + a - 2) / (a - 1) << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long i, j, k;

const long long FACT_MAX = 3000;
long long MOD;
long long famod[FACT_MAX+1];
long long simod[FACT_MAX+1];
long long fimod[FACT_MAX+1];

void create_fact_mod(int num){
    famod[0] = 1;
    famod[1] = 1;
    long long i;
    for(i=2; i<=num; i++){
        famod[i] = famod[i-1] * i % MOD;
    }
}

void create_seq_inv_mod(int num){
    simod[0] = 1;
    simod[1] = 1;
    long long i;
    for(i=2; i<=num; i++){
        simod[i] = (MOD - MOD/i) * simod[MOD%i] % MOD;
    }
}

void create_fact_inv_mod(int num){
    fimod[0] = 1;
    fimod[1] = 1;
    long long i;
    for(i=2; i<=num; i++){
        fimod[i] = fimod[i-1] * simod[i] % MOD;
    }
}

void create_mod_tables(int num){
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

long long comb_mod(int n, int k){
    return famod[n] * fimod[n-k] % MOD * fimod[k] % MOD;
}

long long perm_mod(int n, int k){
    return famod[n] * fimod[n-k] % MOD;
}

long long power_mod(long long num, long long power){
    long long prod = 1;
    num %= MOD;
    while(power > 0){
        if((power&1) == 1){
            prod = prod * num % MOD;
        }
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

long long N;
long long dp[3001][3001];
long long pmod[3001];

int main(){
    cin >> N >> MOD;
    create_mod_tables(N);
    dp[0][0] = 1;
    for(i=1; i<=N; i++){
        dp[i][0] = 1;
        for(j=1; j<=i; j++){
            dp[i][j] = (dp[i-1][j-1] + (j+1) * dp[i-1][j]) % MOD; 
        }
    }

    pmod[0] = 2;
    for(i=1; i<=N; i++){
        pmod[i] = pmod[i-1] * pmod[i-1] % MOD;
    }

    long long ans = 0;
    for(i=0; i<=N; i++){
        long long result = 0;
        for(j=0; j<=i; j++){
            result = (result + dp[i][j] * power_mod(2, (N-i)*j)) % MOD;
        }
        if((i%2) == 0){
            ans = (ans + result * pmod[N-i] % MOD * comb_mod(N, i)) % MOD;
        }else{
            ans = (ans - result * pmod[N-i] % MOD * comb_mod(N, i) % MOD + MOD) % MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 68992
N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))

ans = 0
for i in range(1 << N):
  for j in range(M):
    t = 0
    for k in range(1, ks[j][0] + 1):
      if i >> (ks[j][k] - 1) & 1:
        t += 1
    if t % 2 != p[j]:
      break
  else:
    ans += 1

print(ans)


Measured memory_bytes: 70592
#include <bits/stdc++.h>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	string n;
	cin >> n;
	for (int i = 9; i >= 0; --i)
	{
		string n1;
		n1.push_back('0' + i);
		for (int j = 0; j + 1 < n.size(); ++j)
			n1.push_back('9');
		if (n1 <= n)
		{
			cout << i + 9 * ((int)n.size() - 1) << '\n';
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
  int A, B;
  scanf("%d %d", &A, &B);

  int X = A + B;
  int Y = A - B;
  int Z = A * B;
  int ANS = MAX(X, MAX(Y, Z));
  printf("%d\n", ANS);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
using namespace std;

#define rep(i,n) for(ll i = 0;i < n; i++)

typedef long long ll;

int main(){
    ll N,M;
    ll ans = 0;
    ll A[100010];
    ll B[100010];
    ll C[100010];


    cin >> N >> M;

    rep(i,N) cin >> A[i];
    rep(i,M) cin >> B[i] >> C[i];
    
    vector<pair<ll,ll>> pairs;

    //sort(A,A + N);
    
    
    for(ll i = 0;i < N;i++){
        pairs.emplace_back(make_pair(A[i],1));
        //pairs[A[i]].first = A[i];
        //pairs[A[i]].second = 1;
        //cout << pairs[A[i]].first << " " << pairs[A[i]].second << endl;
    }
    for(ll i = 0;i < M;i++){
          pairs.emplace_back(make_pair(C[i],B[i]));
          //pairs[C[i]].first = C[i];
          //pairs[C[i]].second = B[i];
          //cout << pairs[C[i]].second << endl;
    }
    
    ll cnt = 0;
    //cout << pairs[5].first << endl;
    sort(pairs.begin(),pairs.end(),greater<pair<ll,ll>>());
    for(ll i = 0;;i++){
        if (pairs[i].second != 0){
            for(ll j = 0;j < pairs[i].second;j++){
                ans += pairs[i].first;
                //cout << pairs[i].second * pairs[i].first << endl;
                //cout << i << "!" << endl;
                cnt++;
                if (cnt == N) break;
              }
            if (cnt == N) break;
          }
    }
    cout << ans << endl;
}

Measured memory_bytes: 8560
#include <bits/stdc++.h>
using namespace std;

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque…双方向リスト
//stack…FILO, 深さ優先探索
//queue…FIFO, 幅優先探索
//priority_queue…格納された最大値から順に取り出す
//pair…二つの値を一組
//tuple…複数の値を一組

template<typename T>
void remove(std::vector<T>& vector, char index) {
    vector.erase(vector.begin() + index);
}

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}
template<class T>
T mi(std::vector<T> &v) {
    T mini = 0;
    for(auto &i:v) mini = min(mini, i);
    return mini;
}
template <class T>
T pow(T x, T y, T n = numeric_limits<T>::max()) {
    if(y == 0) return 1;
    if(y % 2 == 0) return pow((x * x) % n, y / 2);
    return (x * pow(x, y - 1)) % n;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    return !y ? x : gcd(x % y, y);
}

using Graph = vector<vector<int>>;

template <class T, class S>
class Edge {
  T to;  //辺の行き先
  S weight;  //辺の重み

public:
  Edge(T t, S w) : to(t), weight(w) {}
};

int ansi = 0;
ll ansl = 0;
double ansd = 0.0;

int main() {
  ull n;
  cin >> n;
  vector<int> d(n);
  rep(i, 0, n-1) cin >> d[i];
  sort(d.begin(), d.end());
  ull l = floor(n / 2) - 1;
  ull r = floor(n / 2);

  cout << d[r] - d[l] << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
    int n, l; cin >> n >> l;
    vector<string> s(n);
    for(int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    for(int i = 0; i < n; i++)
    {
        cout << s[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);




signed main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;
	int K;
	cin >> K;

	for (int cursor = 0; 1 <= K && cursor + 1 < s.size(); cursor++) {
		if (s[cursor] == 'a')continue;
		int need = 26 - (s[cursor] - 'a');
		if (need <= K) {
			s[cursor] = 'a';
			K -= need;
		}
	}
	if (1 <= K) {
		int a = s[s.size() - 1] - 'a';
		s[s.size() - 1] = char(((a + K) % 26) + 'a');
	}

	cout << s << endl;
}

Measured memory_bytes: 592
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int tp = 1;
	int cnt = 0;
	while (tp < b) {
		tp += a - 1;
		cnt++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
# 夏休みN日間
# 宿題はM個出されており、i番目の宿題をやるにはj日間かかる。
# この場合、宿題を全部終わらせるのに ...日かかる

n, m = map(int, input().split())
days = list(map(int, input().split()))

# 宿題が全てが終わる場合
if n - sum(days) >= 0:
    print(n - sum(days))
# 宿題終わらない場合
else:
    print(-1)

Measured memory_bytes: 10188
#include <bits/stdc++.h>
#define MAX (ll)(1e5 + 7)
#define INF (ll)(3e18)
#define MOD (ll)(998244353)

using namespace std;
using ll = long long;

int main () {
	double pi = 3.14159;
	double r;
	cin >> r;
	cout << setprecision (5) << (2.0 * pi * r) << "\n";
}


Measured memory_bytes: 3784
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
const int maxn=20+10;
const int INF=int(1e9)+10;
#define LL long long
char str[maxn][maxn];
int swaped[maxn];
bool used[maxn];
bool ans;
int n,m;
bool check() {
	memset(used,0,sizeof(used));
	for(int i=0; i<m; i++) {
		if(used[i])
			continue;
		for(int j=0; j<m; j++) {
			bool vis=true;
			if(i==j||used[j])
				continue;
			for(int k=0; k<n; k++) {
				if(str[k][i]==str[swaped[k]][j])
					continue;
				vis=false;
				break;
			}
			if(vis){
				used[i]=used[j]=true;
				break;
			}
		}
	}
	int cnt=0;
	int pos=-1;
	for(int i=0; i<m; i++)
		if(!used[i]) {
			cnt++;
			pos=i;
		}
	if(cnt>=2||(cnt&&(m%2==0)))
		return false;
	if(cnt==1) {
		for(int i=0; i<n; i++) {
			if(str[i][pos]!=str[swaped[i]][pos])
				return false;
		}
	}
	return true;
}
void dfs(int u,int falg) {
	if(u==(n+1)>>1) {
		if(check())
			ans=true;
		return ;
	}
	if(ans==true)
	return;
	for(int i=u; i<n; i++) {
		if(swaped[i]==-1) {
			for(int j=i+1; j<n; j++) {
				if(swaped[j]==-1) {
					swaped[i]=j;
					swaped[j]=i;
					dfs(u+1,falg);
					swaped[i]=-1;
					swaped[j]=-1;
				}
			}
			if(falg) {
				swaped[i]=i;
				dfs(u+1,false);
				swaped[i]=-1;
			}
		}
	}
}
void init() {
	memset(swaped,-1,sizeof(swaped));
	ans=false;
}
int main() {
	while(~scanf("%d %d",&n,&m)) {
		init();
		for(int i=0; i<n; i++)
			scanf("%s",str[i]);
		if(n&1)
			dfs(0,true);
		else
			dfs(0,false);
		printf("%s\n",ans?"YES":"NO");
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  
  int x = a+b;
  
  if(x%2 == 0){
    cout << x / 2 << endl;  
  }else{
    cout << x  / 2 + 1 << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

int n;
LL a,b;
int p[5000],inv[5000];
LL dp[5001][10001],mindp[5001][10002];

int main(){
  cin>>n>>a>>b;
  REP(i,n){cin>>p[i];p[i]--;}
  REP(i,n)inv[p[i]]=i;
  REP(i,n+1)mindp[i][0]=0LL;
  REP(i,2*n+1){dp[0][i]=0LL;mindp[0][i+1]=0LL;}
  
  FOR(i,1,n+1){
    REP(j,2*n+1){
      //cerr<<i<<" "<<j<<" "<<2*inv[i-1]+1<<" "<<mindp[i-1][j]<<endl;
      if(2*inv[i-1]+1==j)
	dp[i][j]=mindp[i-1][j];
      else if(2*inv[i-1]+1 < j)
	dp[i][j]=mindp[i-1][j]+a;
      else
	dp[i][j]=mindp[i-1][j]+b;
    }

    mindp[i][0]=dp[i][0];
    REP(j,2*n+1){
      if(j%2!=0)
	mindp[i][j+1] = min(dp[i][j],min(dp[i][j+1],mindp[i][j]));
      else
	mindp[i][j+1] = mindp[i][j];
    }
  }

  /*
  REP(i,n+1){
    REP(j,2*n+1)
      cerr<<dp[i][j]<<" ";
    cerr<<endl;
  }

  REP(i,n+1){
    REP(j,2*n+2)
      cerr<<mindp[i][j]<<" ";
    cerr<<endl;
  }
  */
  
  
  cout<<*min_element(dp[n],dp[n]+2*n+1)<<endl;
  return 0;
}


Measured memory_bytes: 781824
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define prique priority_queue
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

signed main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K, a[2000]; cin >> N >> K;
  REP(i, N) cin >> a[i];
  int ans = 0;
  REP(i, N) for(int j = i+1; j < N; j++){
    if(a[i] < a[j]) ans += (1+(K-1))*(K-1)/2 % MOD;
    else if(a[i] > a[j]) ans += (1+K)*K/2 % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($format:expr) => (write!(out,$format).unwrap());
        ($format:expr, $($args:expr),+) => (write!(out,$format,$($args),*).unwrap())
    }
    input! {
        h: usize,
        w: usize,
        n: usize,
        xy: [(usize1, usize1); n],
    }
    let mut occur = vec![Vec::new(); w];
    for (x, y) in xy {
        occur[y].push(x);
    }
    for i in 0 .. w { occur[i].sort(); }
    let mut cx = 0;
    let mut cy = 0;
    let mem = |x, y: usize| occur[y].binary_search(&x).is_ok();
    let mut ans = h;
    for _ in 0 .. h {
        let idx = occur[cy].binary_search(&cx).unwrap_err();
        ans = min(ans, if idx >= occur[cy].len() { h } else { occur[cy][idx] });
        if cx >= h - 1 || mem(cx + 1, cy) {
            break;
        }
        cx += 1;
        if cy < w - 1 && !mem(cx, cy + 1) { cy += 1; }
    }
    puts!("{}\n", ans);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 20732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int K, N;
int A[200005];

int main(void) {

	
	cin >> K >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	int ans = K;

	for (int i = 2; i <= N; i++) {
		int tmp = A[i] - A[i - 1];
		ans = min(ans, K - tmp);
	}

	int tmp = K - A[N] + A[1];

	ans = min(ans, K - tmp);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int shift;
   cin >> shift;
   string s;
   cin >> s;
   int n = s.length();
   for(int i = 0 ; i < n ; i++)
      cout << char('A' + (s[i] - 'A' + shift) % 26);
   return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;

int main(){
    int N,A,B,C,D;
    cin>>N>>A>>B>>C>>D;
    A--;B--;C--;D--;
    string S;
    cin>>S;
    if(C<D){
        while(B!=D){
            if(S[B+1]=='.'){
                B++;
                continue;
            }else if(B+2<=D&&S[B+2]=='.'){
                B+=2;
                continue;
            }else{
                cout<<"No"<<endl;
                return 0;
            }
        }
        while(A!=C){
            if(S[A+1]=='.'){
                A++;
                continue;
            }else if(A+2<=C&&S[A+2]=='.'){
                A+=2;
                continue;
            }else{
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
    }else{
        while(A!=C){
            if(S[A+1]=='.'&&A+1!=B){
                A++;
                continue;
            }else if(A+2<=C&&S[A+2]=='.'&&A+2!=B){
                A+=2;
                continue;
            }else{
                if(A+1==B||A+2==B){
                    if(B+1<=D&&S[B+1]=='.'){
                        B++;
                        continue;
                    }else if(B+2<=D&&S[B+2]=='.'){
                        B+=2;
                        continue;
                    }
                }
                cout<<"No"<<endl;
                return 0;
            }
        }
        while(B!=D){
            if(S[B+1]=='.'){
                B++;
                continue;
            }else if(B+2<=D&&S[B+2]=='.'){
                B+=2;
                continue;
            }else{
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 576
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main(){
    
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector <int> v;
    for (ll i=0;i<n;i++){
        if(s[i] == 'o') {
            v.push_back(1);
        }else{
            v.push_back(0);
        }
    }
    vector <int> ans;
    int flag = 0;
    for (int phase=1;phase<=4;phase++){
        ans.clear();
        if(phase == 1){
            ans.push_back(1); // sheep
            ans.push_back(1);
        }else if(phase == 2){
            ans.push_back(1);
            ans.push_back(0); // wolf
        }else if(phase == 3){
            ans.push_back(0);
            ans.push_back(1);
        }else{
            ans.push_back(0);
            ans.push_back(0);
        }
        for (ll i=1;i<n-1;i++){
            if(ans[i] == v[i]){
                ans.push_back(ans[i-1]);
            }else{
                if(ans[i-1] == 0) {
                    ans.push_back(1);
                }else{
                    ans.push_back(0);
                }
            }
        }
        if(ans[n-1] == v[n-1]){
            if(ans[n-2] == ans[0]){
                if(ans[0] == v[0]){
                    if(ans[1] == ans[n-1]){
                        flag = 1;
                    }
                }else{
                    if(ans[1] != ans[n-1]){
                        flag = 1;
                    }
                }
            }
        }else{
            if(ans[n-2] != ans[0]){
                if(ans[0] == v[0]){
                    if(ans[1] == ans[n-1]){
                        flag = 1;
                    }
                }else{
                    if(ans[1] != ans[n-1]){
                        flag = 1;
                    }
                }
            }
        }
        if(flag == 1){
//            cout << phase << endl;
            break;
        }
    }
    if(flag == 1){
        for (ll i=0;i<n;i++){
            if(ans[i] == 0){
                cout << "W";
            }else{
                cout << "S";
            }
        }
        cout << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 1528