akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int n,l[51],t[51],r[51],b[51];
int area[300][300];
int nx[4]={-1,0,1,0};
int ny[4]={0,1,0,-1};
int h,w;

bool in(int a,int b){
  if(a<0 || b<0 || a>=h || b>=w)return false;
  return true;
}

void dfs(int a,int b,int num){
  for(int i=0;i<4;i++){
    int A=a+ny[i],B=b+nx[i];
    if(!in(A,B))continue;
    if(area[A][B]==0){
      area[A][B]=num;
      dfs(A,B,num);
    }
  }
  return;
}

int main()
{
  while(1){
    cin>>n;
    if(n==0)break;
    vector<int> x,y;
    for(int i=0;i<300;i++)for(int j=0;j<300;j++)area[i][j]=0;
    for(int i=0;i<n;i++){
      cin>>l[i]>>t[i]>>r[i]>>b[i];
      x.push_back(l[i]);
      x.push_back(r[i]);
      y.push_back(t[i]);
      y.push_back(b[i]);
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    map<int,int> X,Y;
    int num=1;
    for(int i=0;i<x.size();i++){
      if(X.find(x[i])==X.end()){
	X[x[i]]=num; 
	num+=2;
      }
    }
    num=1;
    for(int i=0;i<y.size();i++){
      if(Y.find(y[i])==Y.end()){
	Y[y[i]]=num;
	num+=2;
      }
    }
    w=X.size()*2+1;
    h=Y.size()*2+1;
    for(int k=0;k<n;k++){
      int L=X[l[k]],R=X[r[k]],T=Y[t[k]],B=Y[b[k]];
      for(int i=L;i<=R;i++){
	area[T][i]=-1;
	area[B][i]=-1;
      }
      for(int i=B;i<=T;i++){
	area[i][L]=-1;
	area[i][R]=-1;
      }
    } 
    
    int ans=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(area[i][j]==0){
	  ans++;
	  area[i][j]=ans;
	  dfs(i,j,ans);
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int x, y, z, k;
ll a[1111], b[1111], c[1111];

bool f(ll n) {
    int cnt = 0;
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            for (int l = 0; l < z; l++) {
                if (a[i] + b[j] + c[l] < n) break;
                cnt++;
                if (cnt >= k) return true;
            }
        }
    }
    return false;
}

int main() {
    cin >> x >> y >> z >> k;
    for (int i = 0; i < x; i++) cin >> a[i];
    for (int i = 0; i < y; i++) cin >> b[i];
    for (int i = 0; i < z; i++) cin >> c[i];
    sort(a, a + x, greater<ll>());
    sort(b, b + y, greater<ll>());
    sort(c, c + z, greater<ll>());
    ll lb = -1, ub = 1001001001001;
    while (ub - lb > 1) {
        ll md = (ub + lb) / 2;
        if (f(md)) lb = md;
        else ub = md;
    }
    priority_queue<ll> que;
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            for (int l = 0; l < z; l++) {
                if (a[i] + b[j] + c[l] < lb) break;
                if (a[i] + b[j] + c[l] > lb) que.push(a[i] + b[j] + c[l]);
            }
        }
    }
    for (int i = 0; i < k; i++) {
        if (que.empty()) {
            cout << lb << endl;
        } else {
            cout << que.top() << endl;
            que.pop();
        }
    }
}

Measured memory_bytes: 3632
import networkx as nx
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

G = nx.Graph()

n, m = map(int, readline().split())
if m == 0:
    print(1)
    sys.exit()
for i in range(m):
    a, b = map(int, readline().split())
    G.add_edge(a, b)

largest_cc = max(nx.connected_components(G), key=len)
print(len(largest_cc))



Measured memory_bytes: 255092
#include <bits/stdc++.h>
using namespace std;
#define maxn 100010
vector<int> v;
int a[maxn], cnt[maxn];
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        ++cnt[a[i]];
        ++cnt[a[i]+1];
        ++cnt[a[i]+2];
    }
    int p = 0;
    for (int i = 1; i < maxn; ++i) {
        if (cnt[i] > cnt[p]) p = i;
    }
    printf("%d\n", cnt[p]);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;



int main() {

    long long h;
    cin >> h;
    if(h==0)
    {
        cout << 0 << endl;
    }
    else if (h==1)
    {
        cout << 1 << endl;
    }
    else
    {
        int cnt=0;
        for (int i = 0; true;i++)
        {
            h /= 2;
            cnt += 1;
            if (h == 1)
                break;
        }
        long long ans = pow(2, cnt + 1) - 1;
        cout << ans << endl;


    }

    

    return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ll n,k;
cin>>n>>k;
ll cnt=0;
while(n){
    n/=k;
    cnt++;
}
cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int N = 0;
int a[N+5];

int32_t main()
{
    string s;
    cin>>s;

    for(int i=0; i<s.size()-2; i++){
        if(s[i]==s[i+1] and s[i+1]==s[i+2]){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;



    return 0;
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vii;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

// ────────────────────────────────────────────────────

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

	vd x(n);
	vd h(n);
	vd a(n);

	double ans = 0;

	rep(i, n) {
		cin >> x[i] >> h[i];
		a[i] = sqrt(x[i] * x[i] + h[i] * h[i]);
		a[i] *= t / x[i];

		a[i] = sqrt(a[i] * a[i] - t * t);
		ans = max(ans, a[i]);
	}
	cout << setprecision(10) << ans << endl;
}


Measured memory_bytes: 3320
#include <iostream>

using namespace std;

int main(void){
    int N;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    int ans=a[0];
    for(int i=1;i<N;i++){
        ans=ans^a[i];
    }
    if(ans==0){
        cout << "Yes" << endl;
    }else{
        
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define N_max 200000
#define AM    10000000

bool tst(unsigned long long l, unsigned long long r );

unsigned long long N;
vector<unsigned long long>  v(N_max);
vector< vector<unsigned long long> >  s_bit( N_max, vector<unsigned long long>(21,0));

int main(){
    cin >> N;

    FOR(i, 0, N){
        cin >> v[i];
        bitset<21> b(v[i]);
        if(i == 0){
            FOR(j, 0, 21){
                if( b[j] ) s_bit[i][j] += 1;             
            }
        }else{
            s_bit[i] = s_bit[i-1];
            FOR(j, 0, 21){
                if( b[j] ) s_bit[i][j] += 1;             
            }
        }
    }        
    /* 
      for(auto itr = vec.begin(); itr != vec.end(); ++itr){
          std::cout << *itr << "\n";        
          
      }
     */
    unsigned long long l,r = 0;
    unsigned long long ans = 0;
    FOR(i,0,N){
        l = i;
        while( tst(l,r) ) r++;
        ans += r-l;
    }

    cout << ans << endl;
    return 0;
}

bool tst( unsigned long long l, unsigned long long r ){
    if(r == N) return false;
    FOR(i,0,21){
        if(l == 0){ if(s_bit[r][i] > 1) return false;}
        else {if(s_bit[r][i] - s_bit[l-1][i] > 1) return false;}
    }

    return true;
}




Measured memory_bytes: 41088
import numpy as np

_,*_t=[list(map(int,i.split())) for i in open(0)]
n=_[0]
m=_[1]
x=_[2]
table=np.array(_t)
value=9000000


def boolAchieve(nums):
  for i in range(1,m+1):
    if nums[i]<x:
      return False
  return True


tmp=np.sum(table,axis=0)
if not boolAchieve(tmp):
  print(-1)
  exit()


for i in range(1,2 ** n):
  slist=np.right_shift(i,np.arange(n))
  blist=np.bitwise_and(slist,1).tolist()
  selects=list(map(bool,blist))
  #  selects=[bool((i >> j) & 1) for j in range(n)]
  picks=np.sum(table[selects,:],axis=0)
  if not boolAchieve(picks):
    continue
  value=min(value,picks[0])

  
print(value)

Measured memory_bytes: 27336
s = input().rstrip()[::-1]

r=0
while r < len(s):
    if s[r:r+3] == "mae":
        if s[r:r+5] == "maerd":
            r += 5
        else:
            print("NO")
            exit()
    elif s[r:r+3] == "rem":
        if s[r:r+7] == "remaerd":
            r += 7
        else:
            print("NO")
            exit()
    elif s[r:r+3] == "esa":
        if s[r:r+5] == "esare":
            r += 5
        else:
            print("NO")
            exit()
    elif s[r:r+3] == "res":
        if s[r:r+6] == "resare":
            r += 6
        else:
            print("NO")
            exit()
    else:
        print("NO")
        exit()

print("YES")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

ll gcd(ll a,ll b) {
  if (a < b) swap(a, b);
  if (a % b == 0) return b;
  return gcd(b, a%b);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int t;
  cin >> t;
  while (t--) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    if (a < b || b > d) {
      cout << "No" << '\n';
      continue;
    }
    if (b <= c + 1) {
      cout << "Yes" << '\n';
      continue;
    }
    a %= b;
    ll s = gcd(b, d), t = (b - 1 - a) / s, maxv = a + s * t;
    cout << (maxv <= c ? "Yes" : "No") << '\n';
  }


  
  return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
A=[-1]+A
still=[0]*(N+1)
still[1]=1
before=1
rS=-1
root=[1]
while True:
  dest=A[before]
  if still[dest]==1:
    rS=dest
    break
  else:
    still[dest]=1
    root.append(dest)
    before=dest
#print(root,rS)
num=0
for i in root:
  if i==rS:
    break
  num+=1
#print(num)
if K<=num:
  print(root[K])
else:
  K-=num
  root2=root[num:]
  print(root2[K%len(root2)])
  

Measured memory_bytes: 32376
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

  

int32_t main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int count=0,res=0;
    for(int i=0;i<n;i++)
    {
		if(s[i]=='R')
		count++;
	}
	
	for(int i=0;i<count;i++)
	{
		if(s[i]=='W')
		res++;
	}
	
	cout<<res;
 
   

		
	
		  
}


Measured memory_bytes: 3676
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    H=[0]+list(map(int,input().split()))
    ans=0
    for i in range(n):
        ans+=max(0,H[i+1]-H[i])
    print(ans)
resolve()

Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())
#define MOD 1000000007 
#define mx 100003

void dfs(int now, int lev, vector<int> &ve, vector<int> &level, vector<vector<int>> &g){
	level[now] = lev;
	for(int i : g[now]){
		if(!ve[i])
			dfs(i, lev + 1, ve, level, g);
	}
}

int main(){
	int n;
	cin >> n;
	vector<vector<int>> g(n);
	vector<int> p(n);
	for(int i = 0; i < n; i++){
		cin >> p[i];
		p[i] -= 1;
		g[p[i]].pb(i);
	}
	int mulai = 0;
	vector<int> ve(n, 0);
	while(!ve[mulai]){
		ve[mulai] = true;
		mulai = p[mulai];
	}	
	for(int i = 0; i < n; i++)
		ve[i] = false;
	while(!ve[mulai]){
		ve[mulai] = true;
		mulai = p[mulai];
	}
	vector<int> level(n);
	for(int i = 0; i < n; i++){
		if(ve[i])
			dfs(i, 0, ve, level, g);
	}
	vector<int> v(n), a(n);
	iota(ALL(v), 0);
	sort(ALL(v), [&](int x, int y){
		return level[x] > level[y];
	});
	vector<set<int>> ini(n);
	vector<int> ke(n, 0), tadi(n, 0);
	for(int i : v){
		if(ve[i]){
			for(int j : g[i]){
				if(ve[j]){
					ke[i] = j;
					tadi[j] = i;
					break;
				}
			}
		}
	}
	vector<int> val1(n, 0), val2(n, 0);
	for(int i : v){
		if(level[i] == 0){
			int mini = 0;
			while(1){
				if(!ini[i].count(mini))
					break;
				mini += 1;
			}
			val1[i] = mini;
			mini += 1;
			while(1){
				if(!ini[i].count(mini))
					break;
				mini += 1;
			}
			val2[i] = mini;
			mini += 1;
			continue;
		}
		int mini = 0;
		while(1){
			if(!ini[i].count(mini))
				break;
			mini += 1;
		}
		ini[p[i]].insert(mini);
	}
	int now = mulai;
	a[now] = val1[now];
	now = ke[now];
	while(now != mulai){
		if(val1[now] == a[tadi[now]])
			a[now] = val2[now];
		else a[now] = val1[now];
		now = ke[now];
	}
	if(a[now] != a[tadi[now]]){
		cout << "POSSIBLE\n";
		return 0;
	}
	now = mulai;
	a[now] = val2[now];
	now = ke[now];
	while(now != mulai){
		if(val1[now] == a[tadi[now]])
			a[now] = val2[now];
		else a[now] = val1[now];
		now = ke[now];
	}
	if(a[tadi[now]] == val1[now]){
		cout << "POSSIBLE\n";
		return 0;
	}
	cout << "IMPOSSIBLE\n";
}

Measured memory_bytes: 31616
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> v(n);
  rep(i,n){
    ll a;cin>>a;
    v[i]=a-i-1;
  }
  sort(ALL(v));
  ll ans1=0,ans2=0;
  rep(i,n){
    ans1+=abs(v[i]-v[n/2]);
    ans2+=abs(v[i]-v[n/2-1]);
  }
  cout<<min(ans1,ans2)<<endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

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

    int n, k; cin >> n >> k;
    int arr[n + 2]; arr[0] = arr[n + 1] = 0; for(int i = 1; i <= n; ++i) cin >> arr[i];

    long long ps[n + 2]; ps[0] = 0;
    for(int i = 1; i <= n + 1; ++i) ps[i] = max(0, arr[i] - arr[i - 1]);
    for(int i = 1; i <= n + 1; ++i) ps[i] += ps[i - 1];

    long long dis[n][n];
    for(int i = 0; i < n; ++i)
        for(int j = i; j < n; ++j)
            dis[i][j] = ps[j + 2] - ps[i] - max(0, arr[j + 2] - arr[i]);

    long long dp[n + 1][k + 1]{};
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= k; ++j)
        {
            if(i <= j) dp[i][j] = dis[0][i - 1];
            else for(int t = 1; t <= j; ++t)
                dp[i][j] = max(dp[i][j], dp[i - t - 1][j - t] + dis[i - t][i - 1]);
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        }
    }

    cout << ps[n + 1] - dp[n][k];
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;



int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall
	
	ins(morty);
	reverse(all(morty));
	map<ll,ll>tmp1;
	tmp1[0]++;
	int  dp = 0;
	int tmp  = 0;
	int pos = 1;
	FOR(i,0,morty.size()){
		dp = (ll)(tmp+(ll)(morty[i]-'0')*pos)%2019;
		(pos*=10)%=2019;
		tmp = dp;
		tmp1[dp]++;
	}
	int rick = 0;
	for(auto x:tmp1){
		rick+=x.second*(x.second-1)/2;
	}
	out(rick);
	













	return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;

int h[33] = { 0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

int main()
{
	ll a;
	cin >>a ;

 cout<<h[a]<<endl;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Text;
using static System.Math;
using static Scanner;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Solve();
        Console.Out.Flush();
    }
    static void Solve() {
        string S = Scan(), T = Scan();
        var answer = S.Length;
        for (int i = 0; i <= S.Length - T.Length; i++) {
            var count = 0;
            for (int j = 0; j < T.Length; j++) {
                if (S[i + j] != T[j]) count++;
            }
            answer = Min(answer, count);
        }
        Console.WriteLine(answer);
    }
}

public static class Scanner
{
    static readonly Stream stream = Console.OpenStandardInput();
    static readonly byte[] buffer = new byte[1024];
    static int length, p;
    static bool isEof;
    private static byte ConsoleIn() {
        if (isEof) return 0;
        if (p < length) return buffer[p++];
        p = 0;
        if ((length = stream.Read(buffer, 0, 1024)) > 0) return buffer[p++];
        isEof = true;
        return 0;
    }
    public static char GetChar() {
        var by = ConsoleIn();
        while ((by < '!' || '~' < by) && !isEof) by = ConsoleIn();
        return (char) by;
    }
    public static string Scan() {
        var sb = new StringBuilder();
        for (var ch = GetChar(); '!' <= ch && ch <= '~'; ch = (char) ConsoleIn()) {
            sb.Append(ch);
        }
        return sb.ToString();
    }
}

Measured memory_bytes: 23804
#include <iostream>
using namespace std;
int main(int argc, char* argv[]){
	int N;
  	string A, B, C;
  	cin >> N;
  	cin >> A;
    cin >> B;
  	cin >> C;
  	
  	int answer = 0;
  
  	for (int i = 0; i < N; i++) {
      	if (A[i] == B[i] && B[i] == C[i]){
          	continue;
        }
      	else if (A[i] == B[i] ||
                 B[i] == C[i] ||
                 C[i] == A[i]){
        	answer += 1;
        }
      	else {
        	answer += 2;
        }
    }
  	
  	cout << answer;
  	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 101
#define MIN 999999
int min(int m,int q){
  if(m>q)return q;
  else return m;
}

void matrixChainOrder(int *p,int n){
  int i,l,j=0,k,q,m[n][n];
  for(i=1;i<n;i++)
    m[i][i]=0;
  for(l=2;l<n;l++){
    for(i=1;i<(n-l+1);i++){
      j=i+l-1;
      m[i][j]=MIN;
      for(k=i;k<j;k++){
        q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
        m[i][j]=min(m[i][j],q);
      }
    }
  }
  if(j==0)printf("0\n");
  else printf("%d\n",m[i-1][j]);
}

int main(){
  int n,r,c,i,p[N];
  for(i=0;i<N;i++)
    p[i]=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&p[i],&p[i+1]); 
  }
  n++;
  matrixChainOrder(p,n);
  return 0;
}



Measured memory_bytes: 2048
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

struct uf {
private:
	vector<int> par, ran,sum;
public:
	void init(int n) {
		par.resize(n, 0);
		ran.resize(n, 0);
		sum.resize(n, 1);
		rep(i, n) {
			par[i] = i;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)return;
		if (ran[x] < ran[y]) {
			par[x] = y; sum[y] += sum[x];
		}
		else {
			par[y] = x; sum[x] += sum[y];
			if (ran[x] == ran[y])ran[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	ll calc(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return 0;
		else return (ll)sum[x] * sum[y];
	}
};
vector<ll> ans;
int n, m;
int u[1 << 17], v[1 << 17];
int main() {
	cin >> n >> m;
	uf us; us.init(n);
	ll s = (ll)n*(n - 1) / 2;
	rep(i, m) {
		cin >> u[i] >> v[i]; u[i]--; v[i]--;
	}
	per(i, m) {
		ans.push_back(s);
		int a = us.find(u[i]), b = us.find(v[i]);
		s -= us.calc(a, b); us.unite(a, b);
	}
	per(i, m) {
		cout << ans[i] << endl;
	}
	//stop
	return 0;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define bn(n) (n).begin(), (n).end()
#define FOR(n) for(int i = 0; i < (int)n; i++)
#define MX 1e5


void solve() {
    int n;
    cin >> n;
    vector<int> v(3201, 0);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a > 3199) {
            v[3200]++;
        } else if (a > 2799) {
            v[2800] = 1;
        } else if (a > 2399) {
            v[2400] = 1;
        } else if (a > 1999) {
            v[2000] = 1;
        } else if (a > 1599) {
            v[1600] = 1;
        } else if (a > 1199) {
            v[1200] = 1;
        } else if (a > 799) {
            v[800] = 1;
        } else if (a > 399) {
            v[400] = 1;
        } else if (a > 0 ) {
            v[0] = 1;
        }
    }
    int mx = accumulate(v.begin(), v.end(), 0);
    int cnt = 0;
    for (int i = 0; i < 3200; i+=400) {
        cnt += v[i];
    }
    if (v[3200] == n) {
        cout << cnt+1 << " " << n << "\n";
    } else {
        cout << cnt << " " << mx << "\n";
    }

}

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

    int t = 1, i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3568
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    deque<int> dq;
    string s;
    cin >> s;
    REP(i,0,s.size()){
        if(s[i] == '0'){
            dq.push_back(0);
        }
        if(s[i] == '1'){
            dq.push_back(1);
        }
        if(s[i] == 'B'){
            if(!dq.empty()){
                dq.pop_back();
            }
        }
    }
    for(int i = 0; i < dq.size(); i++){
        cout << dq[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm> // sort
#include <map>       // pair
#include <vector>
using namespace std;

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


const int INF = 100100100;
const int MOD = (int)1e9 +7;
const double EPS = 1e-9; 

typedef long long int ll;

//char in[120];
//ex. pair
//pair<pair<string,int>,int> p[110];

int main(){
    int n;cin>>n;
    vector<int> vec(n);
    int max=0, sec=0;
    FOR(n){
        int tmp;
        cin>>tmp;
        vec[i]=tmp;
        if (tmp > max){
            sec=max;
            max=tmp;
            continue;
        }
        if(tmp>sec){
            sec=tmp;
        }
    }
    for(int i=0;i<n;i++){
        //cout << "i is " << i<< "v[i] is " << vec[i] << endl;
        if(vec[i] < max){
            cout<<max<<endl;
            continue;
        }else{
            cout<<sec<<endl;
            continue;
        }
    }
    
    return 0;    
}

Measured memory_bytes: 2432
#include<stdio.h>
#include<stdlib.h>

int main(){

  int n, q, *time, i, tsam=0, cnt=0,j;
  char name[100000][10];

  scanf("%d%d",&n, &q);

  time = (int *)malloc(sizeof(int)*n);
  for(i=0; i<=n-1; i++){
  //  name[i] = (char *)malloc(sizeof(char)*n);
  }
  for(i=0; i<=n-1; i++){
    scanf("%s%d",name[i], &time[i]);
  }

  while(cnt != n){
    for(i=0; i<=n-1; i++){
        if(time[i] == 0) continue;
      if(time[i] <=q && time[i] > 0){
        tsam += time[i];
        time[i] = 0;
        printf("%s %d\n",name[i], tsam);
        cnt++;
      }
      else if(time[i] > q){
        time[i] = time[i] - q;
        tsam += q;
      }
    }
    }
  return 0;
}


Measured memory_bytes: 2384
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/














string S;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> S;
	sort(all(S));

	if (S[0] == S[1] and S[1] != S[2] and S[2] == S[3]) cout << "Yes" << endl;
	else cout << "No" << endl;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long double db;
typedef long long ll;
const int maxlogn=19;
const int maxn=(1<<maxlogn)|1;
const db tau=2*acosl(-1);
int n,m,rev[maxn];
struct comp
{
    db a,b;
    comp(db a=0,db b=0):a(a),b(b) {}
    inline comp operator +(const comp &x) const { return comp(a+x.a,b+x.b); }
    inline comp operator -(const comp &x) const { return comp(a-x.a,b-x.b); }
    inline comp operator *(const comp &x) const { return comp(a*x.a-b*x.b,a*x.b+b*x.a); }
}w[maxn];
inline void calcrev(int logn)
{
    int i;
    for(rev[0]=0,i=1;i<(1<<logn);i++)
        rev[i]=(rev[i>>1]>>1)|((i&1)<<(logn-1));
}
inline void init()
{
    int i;
    for(i=0;i<=(1<<maxlogn);i++)
        w[i]=comp(cosl(i*tau/(1<<maxlogn)),sinl(i*tau/(1<<maxlogn)));
}
inline void DFT(comp *a,int logn,bool flag)
{
    register int i,j,k,mid;
    comp x,y;
    for(i=0;i<(1<<logn);i++)
        if(rev[i]<i)
            swap(a[rev[i]],a[i]);
    for(i=1;i<=logn;i++)
        for(mid=1<<(i-1),j=0;j<(1<<logn);j+=1<<i)
            for(k=0;k<mid;k++)
            {
                x=a[j|k],y=a[j|k|mid]*w[flag?(1<<maxlogn)-(k<<(maxlogn-i)):(k<<(maxlogn-i))];
                a[j|k]=x+y,a[j|k|mid]=x-y;
            }
}
comp a[maxn];//b[maxn],c[maxn];
inline long long rnd(db x) { return (long long)(x+.5); }
inline void MTT(const ll *f,ll *h,int logn)
{
    int i;
    comp x,y,z;
    calcrev(logn);
    // for(i=0;i<(1<<logn);i++) a[i]=comp(f[i]>>16),b[i]=comp(f[i]&0xffff);//c[i]=comp(g[i]>>16),d[i]=comp(g[i]&0xffff);
    // DFT(a,logn,0),DFT(b,logn,0);//DFT(c,logn,0),DFT(d,logn,0);
    // for(i=0;i<(1<<logn);i++)
    //     x=a[i]*a[i],y=a[i]*b[i]*2,z=b[i]*b[i],a[i]=x,b[i]=y,c[i]=z;
    // DFT(a,logn,1),DFT(b,logn,1),DFT(c,logn,1);
    // for(i=0;i<(1<<logn);i++) a[i].a/=1<<logn,b[i].a/=1<<logn,c[i].a/=1<<logn;
    // for(i=0;i<(1<<logn);i++) h[i]=(((rnd(a[i].a))<<32)+((rnd(b[i].a))<<16)+rnd(c[i].a));
    for(i=0;i<(1<<logn);i++) a[i]=comp(f[i]);
    DFT(a,logn,0);
    for(i=0;i<(1<<logn);i++) a[i]=a[i]*a[i];
    DFT(a,logn,1);
    for(i=0;i<(1<<logn);i++) a[i].a/=1<<logn;
    for(i=0;i<(1<<logn);i++) h[i]=rnd(a[i].a);
}
const int kcz=200003;
ll cnt[kcz<<2],temp[kcz],ans[kcz<<2];
int logn;
int main()
{
    int a,n,i;
    init();
    ll t,s=0;
    for(temp[t=1]=i=0,i++;i<kcz-1;i++)
        t=t*2%kcz,assert(temp[t]==0),temp[t]=i;
    scanf("%d",&n);
    memset(cnt,0,sizeof(cnt));
    while(n--) { scanf("%d",&a); if(a) cnt[temp[a]]++; s-=a*(ll)a%kcz; }
    for(logn=0;(1<<logn)<(kcz<<1);logn++);
    MTT(cnt,ans,logn);
    for(t=1,i=0;i<kcz-1;t=t*2%kcz,i++)
        s+=(ans[i]+ans[i+kcz-1])*t;
    printf("%lld\n",s/2);
    return 0;
}

Measured memory_bytes: 50876
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = 1e9+7;
const double EPS = 1e-9;

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

  Graph edge(m, vi(2));
  rep(i,m) {
    rep(j,2) {
      cin >> edge[i][j];
      --edge[i][j];
    }
  }

  reverse(ALL(edge));

  vl convenience(m, 0);
  Graph group(n);
  rep(i,n) group[i].push_back(i);
  vi belong(n);
  rep(i,n) belong[i] = i;
  int a, b;

  rep(i,m-1) {
    a = belong[edge[i][0]];
    b = belong[edge[i][1]];
    
    if (a == b) {
      convenience[i+1] = convenience[i];
    }
    else {
      ll sz_a = group[a].size();
      ll sz_b = group[b].size();
      convenience[i+1] = convenience[i] + sz_a * sz_b;
      if (sz_a < sz_b) swap(a,b);
      group[a].insert(group[a].end(), ALL(group[b]));
      for (auto v : group[b]) belong[v] = a;
    }
  }

  reverse(ALL(convenience));

  ll x = (ll)n*(n-1)/2;
  rep(i,m) cout << x - convenience[i] << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> p(n),q(n);
  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];
  vector<int> a(n);
  rep(i,n) a[i]=i+1;//nまで並べたものを用意
  
  map<vector<int>, int> mp;
  do {
    mp[a]=mp.size();//keyに順列を代入。aが何番目かが書かれたmapが作れる。
  }
  while (next_permutation(a.begin(),a.end()));//次の順列が見つからなかったらfalseを返すからdo whileを使うとうまいこと書ける
  
  int ans = abs(mp[p]-mp[q]);
  cout << ans << endl;
  return 0; 
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int X = tx - sx, Y = ty - sy;
    
    rep(i, Y) cout << 'U';
    rep(i, X) cout << 'R';
    rep(i, Y) cout << 'D';
    rep(i, X) cout << 'L';
    
    cout << 'L';
    rep(i, Y+1) cout << 'U';
    rep(i, X+1) cout << 'R';
    cout << 'D';
    cout << 'R';
    rep(i, Y+1) cout << 'D';
    rep(i, X+1) cout << 'L';
    cout << 'U';

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n){
    cin >> a.at(i);
    a.at(i) -= (i+1);
  }
  sort(ALL(a));
  int m = a.at(n/2);
  int m2 = m;
  if(n % 2 == 0) m2--;
  ll a1 = 0, a2 = 0;
  rep(i, n){
    a1 += abs(a.at(i) - m);
    a2 += abs(a.at(i) - m2);
  }
  cout << min(a1, a2) << endl;
  return 0;
}

Measured memory_bytes: 3952
N, M = map(int, input().split())
if M == 0:
  if N == 1:
    print(0)
  elif N==2:
    print(10)
  else:
    print(100)
else:
  sc = [list(map(int, input().split())) for i in range(M)]
  sc.sort()
  pin = 0
  if N == 1:
    tmp = sc[0][1]
    for i in range(M):
      if tmp != sc[i][1]:
        print(-1)
        pin = 1
        break
    if pin == 0:
      print(tmp)
  else:
    pin = 0
    ans_lis = [0] * N
    tmp_s = sc[0][0]
    tmp_c = sc[0][1]
    for i in range(M):
      if sc[i][0] == 1 and sc[i][1] == 0:
        print(-1)
        pin = 1
        break
      if tmp_s == sc[i][0]:
        if tmp_c != sc[i][1]:
          print(-1)
          pin = 1
          break
      else:
        ans_lis[tmp_s -1] = tmp_c
        tmp_s = sc[i][0]
        tmp_c = sc[i][1]
    if pin == 0:
      ans_lis[tmp_s -1] = tmp_c
      if ans_lis[0] == 0:
        ans_lis[0] = 1
      lis = map(str, ans_lis)
      mojiretsu = ''
      for x in lis:
         mojiretsu += x
      print(mojiretsu)
      
      


Measured memory_bytes: 3064
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

M = int(input())
print(48 - M)

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int main() {
    string s;
    cin >> s;

    set<char> cs;
    rep(0, 3) cs.insert(s[i]);

    cout << (1 < cs.size() ? "Yes" : "No") << endl;

    return 0;
}


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

int main(){
	int n, x, y;
	cin >> n >> x >> y;
	vector <int> ans(n, 0);
	for (int i = 1; i < n; ++i) {
		for (int j = i+1; j <= n; ++j) {
			if (j <= x || i >= y) {
				ans[j-i]++;
			}else if (i >= x && j <= y){
				if(j-i <= 1+y-j+i-x) {
					ans[j-i]++;
				}else {
					ans[1+y-j+i-x]++;
				}
			}else {
				int sub = y-x-1;
				if (x >= i && y <= j) {
					ans[j-i-sub]++;
				}else if (i <= x) {
					if (j-x <= 1+y-j) {
						ans[j-i]++;
					}else {
						ans[1+y-j+x-i]++;
					}
				}else if (j >= y) {
					if (y-i <= 1+i-x) {
						ans[j-i]++;
					}else {
						ans[1+j-y+i-x]++;
					}
				}
			}
		}
	}
	for (int i = 1; i < n; ++i) {
		cout << ans[i] << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c=1;
	cin>>a>>b;
	for(int i=0;i< a;i++){
		if(c<b){
			c=c*2;
		}else{
			c=c+b;
		}
	}
	cout<<c;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;

int main() {
    int r;
    cin>>r;
    cout<<2*r*pi<<endl;
    

    return 0;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{

  ll n,div=pow(10,9)+7,ans=1;;
  cin>>n;

  reps(i,n+1){
    ans*=i;
    ans%=div;
  }

  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3584
#include <bitset>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>


int main() {
	using uint32 = std::uint_fast32_t;
	using int32 = std::int_fast32_t;
	constexpr uint32 SIZ = 17000;
	std::string s;
	int32 x, y;
	std::cin >> s >> x >> y;
	const uint32 len = s.length();
	std::vector<uint32> sp[2];
	uint32 it = 0;
	while (it < len)
		if (s[it] == 'F')
			--x, ++it;
		else
			break;
	for (bool f = 0;it < len;++it)
		if (s[it] == 'T')
			sp[f ^= 1].push_back(0);
		else
			++sp[f].back();
	std::bitset<SIZ> dpx, dpy;
	x += std::accumulate(sp[0].begin(), sp[0].end(), 0);
	y += std::accumulate(sp[1].begin(), sp[1].end(), 0);
	if (x < 0 || y < 0) {
		puts("No");
		return 0;
	}
	dpx.set(0);
	for (const auto d : sp[0])
		dpx |= dpx << (d << 1);
	dpy.set(0);
	for (const auto d : sp[1])
		dpy |= dpy << (d << 1);
	puts(dpx[x] && dpy[y] ? "Yes" : "No");
	return 0;
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n),b(n);
    unordered_map<int,int> mp;
    for (int i = 0;i < n;++i) {
        cin >> a[i];
        if (mp.find(a[i]) != mp.end()) b[mp[a[i]]] = i;
        mp[a[i]] = i;
    }
    for (int i = 0;i < n;++i) {
        b[mp[a[i]]] = i;
        mp[a[i]] = i;
    }
    int cnt = 1,f = 0;
    do {
        if (b[f] <= f) cnt++;
        f = (b[f]+1)%n;
    } while (f);
    k %= cnt;
    while (1) {
        if (k == 0) break;
        if (b[f] <= f) {
            k--;
            if (k == 0) {
                k++;
                break;
            }
        }
        f = (b[f]+1)%n;
    }
    vector<int> ans;
    if (k) {
        do {
            if (b[f] > f) {
                f = (b[f]+1)%n;
            } else {
                ans.push_back(a[f]);
                f++;
                f %= n;
            }
        } while (f);
    }
    int m = ans.size();
    for (int i = 0;i < m;++i) cout << ans[i] << " \n"[i == m-1];
    return 0;
}

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

const int INF = 1000000007;
const int MX = 200010;
int dp[MX];

int main(){
    int n, k;
    cin >> n >> k;
    int h[n];
    rep(i, n) cin >> h[i];
    rep(i, n) dp[i] = INF;
    dp[0] = 0;
    rep(i, n){
        rep(j, k){
            dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(h[i + j + 1] - h[i]));
        }
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int n, m;
ll M = 1000000007;
ll inv[10000000], fac[10000000], fiv[10000000];
ll combination(ll k) {
    return fac[n+k-1] * fiv[k] % M * fiv[n-1] % M;
}

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

    int i = 2;
    vector<int> divisor_count;
    while (m > 1) {
        if (m % i == 0) {
            int count = 0;
            while (m % i == 0) {
                count++;
                m /= i;
            }
            divisor_count.push_back(count);
        } else {
            i++;
        }
    }

    inv[1]=fac[1]=fiv[1]=inv[0]=fac[0]=fiv[0]=1;
    for (ll j = 2; j < 10000000; j++) {
        fac[j] = fac[j-1] * j % M; // n!
        inv[j] = inv[M%j] * (M-M/j) % M; // n^-1
        fiv[j] = fiv[j-1] * inv[j] % M; // (n!)^-1
    }

    ll ans = 1LL;
    for (i = 0; i < divisor_count.size(); i++) {
        ans = ans * combination((ll)(divisor_count.at(i))) % M;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 234624
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#define db double
#define LL long long
#define inf 0x3f3f3f3f
#define N 1000005
using namespace std;
int gi()
{
    int res=0,s=1; char ch;
    for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
    if(ch=='-') s=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) res=res*10+ch-48;
    return res*s;
}
const int mo=1000000007;
int n,jc[N],ny[N],f[N],ans;
LL qp(LL x,LL y) {
    LL res=1;
    for(;y;y>>=1,x=x*x%mo)
	if(y&1) res=res*x%mo;
    return res;
}
int C(int n,int m) {
    return n>=m ? 1ll*jc[n]*ny[m]%mo*ny[n-m]%mo : 0;
}
int main()
{
    n=gi();
    if(n==2) {printf("1\n");return 0;}
    jc[0]=1; for(int i=1;i<=n;++i) jc[i]=1ll*jc[i-1]*i%mo;
    ny[n]=qp(jc[n],mo-2);
    for(int i=n-1;i>=0;--i) ny[i]=1ll*ny[i+1]*(i+1)%mo;
    for(int i=2;i<=n-1;++i)
	f[i]=1ll*C(i-1,n-1-i)*jc[i]%mo*jc[n-1-i]%mo;
    for(int i=2;i<=n-1;++i)
	ans+=1ll*i*(f[i]-f[i-1]+mo)%mo,ans>=mo?ans-=mo:0;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 11904