akhauriyash/Code-Regression huggingface dataset:
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 100000
struct node {
	int value, add;
}A[MAXN + 5];
int Ans = 0;
bool cmp(node a, node b) {
	return a.value < b.value;
}
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		A[i].add = i;
		A[i].value = x;
	}
	sort(A + 1, A + n + 1, cmp);
	for (int i = 1; i <= n; i++)
		Ans += abs(A[i].add - i) % 2;
	printf("%d", Ans / 2);
	//getchar(); getchar(); getchar();
	return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<numeric>
#include<string>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const ll MOD = 1000000007;
 
using namespace std;

int main(){
    string S;   cin >> S;
    int l = S.length();
    int ans = 999;
    for(int i=0; i<l-2; i++){
        ans = min(ans,abs(stoi(S.substr(i,3)) - 753));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long
#define str string
#define fori(i,n) for(long long i=1;i<=n;i++)
#define forj(j,n) for(long long j=1;j<=n;j++)
#define fors(i,ssz) for(long long i=0;i<s.size();i++)
#define Need_for_Speed ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
ll n,dp[100001],h[100001],maxi;
int main(){
	Need_for_Speed
	cin>>n;
	fori(i,n)
	cin>>h[i];
	dp[1]=0;
	dp[2]=abs(h[1]-h[2]);
	for(int i=3;i<=n;i++){
		dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main()
{
    ll X;
    cin >> X;
    if(X >= 30){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int n,d,x;
  cin >> n >> d >> x;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  int ans = x;
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < 110; ++j){
      if(1+j*a[i]<=d) ++ans;
      else break;
    }
  }
  cout << ans << endl;
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if( A == B || A == C || B == C ){
        if ( A == B && A == C ){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

type Cards [][]int

func (c Cards) Len() int {
	return len(c)
}

func (c Cards) Less(i, j int) bool {
	return c[i][1] > c[j][1]
}

func (c Cards) Swap(i, j int) {
	c[i], c[j] = c[j], c[i]
}

func inputIntSlice(size int) []int {
	slice := make([]int, size)
	for i := range slice {
		fmt.Scan(&slice[i])
	}
	return slice
}

func sum(a []int) int64 {
	ret := int64(0)
	for _, v := range a {
		ret += int64(v)
	}
	return ret
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	a := inputIntSlice(n)
	cards := make(Cards, m)
	for i := 0; i < m; i++ {
		cards[i] = make([]int, 2)
		fmt.Scan(&cards[i][0], &cards[i][1])
	}
	// aを昇順に並べる
	sort.Sort(sort.IntSlice(a))
	// cardsはCの降順に並べる
	sort.Sort(cards)

	cNum := 0
	for i := range a {
		if cards[cNum][1] > a[i] {
			a[i] = cards[cNum][1]
			cards[cNum][0]--
		}
		if cards[cNum][0] == 0 {
			cNum++
		}
		if cNum == m {
			break
		}
	}
	fmt.Println(sum(a))
}


Measured memory_bytes: 9732
#include<iostream>
using namespace std;
int n(int a)
{
	return (a+11)%13;
}
int main()
{
	int a,b;
	cin>>a>>b;
	if(n(a)>n(b))
		cout<<"Alice"<<endl;
	else
		if(n(a)==n(b))
			cout<<"Draw"<<endl;
		else
			cout<<"Bob"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stdio.h>
using namespace std;
typedef long long ll;
double *dp;




void solve(){
	
	int  N;
	
	cin >> N;
	double ans;
	if (N % 2 == 0) {
		ans = (double)(N / 2) / (double)N;
	}
	else {
		ans = (double)((N /2)+1) / (double)N;
	}
	cout << ans << endl;
	string str;
	cin >> str;
}


int main() {
	solve();

}

Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args) { 
		Scanner scn = new Scanner(System.in);
		String s=scn.next();
		int ans=0;
		int nans=0;
		int i=0;
		while(i<s.length()) {
			if(s.charAt(i)=='A' || s.charAt(i)=='G' || s.charAt(i)=='C' || s.charAt(i)=='T') {
				nans++;
				i++;
			}else {
				ans=Math.max(nans, ans);
				nans=0;
				i++;
			}
		}ans=Math.max(nans, ans);
		System.out.println(ans);
    }
}

Measured memory_bytes: 26996
#include <bits/stdc++.h>
using namespace std;
const int MAXN=100005;
int n,a[MAXN],ans[MAXN];
struct discretization_node
{
    int num;
    int ki;
} disc[MAXN];
bool cmp(discretization_node x,discretization_node y)
{
    return x.num<y.num;
}
void discretization(int a[],int n,discretization_node disc[])
{
    for(int i=0; i<n; ++i)
    {
        disc[i].num=a[i];
        disc[i].ki=i;
    }
    sort(disc,disc+n,cmp);
    int cnt=0,pre;
    for(int i=0; i<n; ++i)
    {
        if(i==0||a[disc[i].ki]!=pre)++cnt;
        pre=a[disc[i].ki];
        a[disc[i].ki]=cnt;
    }
    return;
}
int main()
{
    scanf("%d",&n);
    for(int i=0; i<n; ++i)
    {
        scanf("%d",&a[i]);
    }
    discretization(a,n,disc);
    reverse(a,a+n);
    int pans = 1, j;
    ans[0] = a[0];
    for(int i = 1; i < n; i++)
    {
        if(a[i] >= ans[pans - 1])
            ans[pans ++] = a[i];
        else
        {
            j = upper_bound(ans, ans + pans, a[i]) - ans;
            ans[j] = a[i];
        }
    }
    printf("%d\n", pans);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(kbrni,n)cout<<" "<<a[kbrni];cout<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define svecp(v) cout<<#v<<":";each(kbrni,v)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;
const int m = 18;

ll dp[41][(1 << m)];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi a(3);
    rep(i,3){
        cin >> a[i];
    }
    a[1] += a[2],a[0] += a[1];
    int z = 0;
    rep(i,3){
        z |= (1 << (m-1-a[i]));
    }
    ll ans = 1;
    rep(i,n){
        ans = (ans*10) % MOD;
    }
    dp[0][(1 << (m-1))] = 1;
    rep(i,n){
        rep(j,(1 << m)){
            srep(k,1,11){
                int nj = ((j >> k)|(1 << (m-1)));
                if((nj&z) != z){
                    dp[i+1][nj] = (dp[i+1][nj] + dp[i][j]) % MOD;
                }
            }
        }
    }
    rep(i,(1 << m)){
        ans = (ans+MOD-dp[n][i]) % MOD;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 82176
def inpl(): return tuple(map(int, input().split()))

N, C = inpl()
P = sorted([inpl() for _ in range(N)])

R = [[[-1, 0, -1]] for _ in range(30)]
for s, t, c in P:
    i = 0
    # 連続録画を探す
    sr = [i for i in range(30) if R[i][-1][2] == c and R[i][-1][1] <= s]
    if sr:
        R[min(sr)].append([s, t, c])
    else:
        r = [i for i in range(30) if R[i][-1][1] <= s - 0.5]
        R[min(r)].append([s, t, c])

for i in range(30):
    if len(R[i]) == 1:
        print(i)
        break
else:
    print(30)

Measured memory_bytes: 27956
#include<cstdio>
#include<cstring>
char a[110];
int main() 
{
	bool c=false,f=false;
    scanf("%s",a);
    for(int i=0;i<strlen(a);i++) 
	{
        if(a[i]=='C')c=true;
        if(a[i]=='F'&&c==true)f=true;
    }
    if(f==true)printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

#define N 100012
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define all(cont) cont.begin(), cont.end()
#define sortcmp(n, cmpfunc) sort(all(n), cmpfunc)
#define fastio ios::sync_with_stdio(false); cin.tie(0)

ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
ll powm(ll a, ll b);
ll divm(ll a, ll b);
ll multm(ll a, ll b);
ll subm(ll a, ll b);
ll addm(ll a, ll b);

int main(){
	fastio;
	// #ifndef ONLINE_JUDGE
 //    	freopen("input.in", "r", stdin);
 //    	freopen("output.out", "w", stdout);
	// #endif
	
	int n;
	ll a[N];
	pair<ll, ll> dp[N][2];
    cin >> n;

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

    dp[0][0] = mp(a[0] + a[1], a[1]);
	dp[0][1] = mp((a[0] + a[1]) * -1, a[1] * -1);
	for(int i = 1 ; i < n-1 ; i++){
    	for(int j = 0 ; j < 2 ; j++){
			if(j == 0) dp[i][j] = mp(max(dp[i-1][0].first, dp[i-1][1].first) + a[i+1], a[i+1]);
    		else dp[i][j] = mp(max(dp[i-1][0].first + (dp[i-1][0].second*-2), dp[i-1][1].first+ (dp[i-1][1].second*-2)) + (a[i+1]*-1),a[i+1]*-1);
    	}
    }

    cout << max(dp[n-2][0].first, dp[n-2][1].first) << endl;

	return 0;
}

// template function
ll gcd(ll a, ll b) { 
	if (b == 0) return a; 
	return gcd(b, a % b);  
} 

ll lcm(ll a, ll b){
	return a*b/gcd(a, b);
}

ll powm(ll a, ll b){
	ll x=1, y=a; 
    while (b > 0) {
        if (b%2) x = (x*y) % mod;
        y = (y*y) % mod;
        b /= 2;
    }
    return x % mod;
}

ll multm(ll a, ll b){
	return ((a%mod) * (b%mod)) % mod;
}

ll divm(ll a, ll b){
	return (a * powm(b, mod - 2)); 
}

ll subm(ll a, ll b){
	a -= b;
  	if (a < 0) a += mod;
	return a;
}

ll addm(ll a, ll b){
	a += b;
  	if (a >= mod) a -= mod;
  	return a;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
typedef pair<ll,ll> pll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
void A() {
    int n;
    cin>>n;
    int res=max(0,(n+999)/1000*1000-n);
    cout<<res<<endl;
}
void B() {

}
void C() {

}
void D() {

}
void E(){

}
void F()
{

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    A();
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[200010],b[200010];
int main(int argc,char const *argv[]) {
    ll n,m;
    cin>>n>>m;
    vector<int> f,t;
    for(int i=1;i<=m;i++) {
        cin>>a[i]>>b[i];
        if(a[i]==1) {
            f.push_back(b[i]);
        }
        else if(b[i]==1) {
            f.push_back(a[i]);
        }
        else if(a[i]==n) {
            t.push_back(b[i]);
        }
        else if(b[i]==n) {
            t.push_back(a[i]);
        }
    }
    if(f.size()==0||t.size()==0) {
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    ll tot=f.size()+t.size();
    set<ll> S;
    for(int i=0;i<f.size();i++) {
        S.insert(f[i]);
    }
    for(int i=0;i<t.size();i++) {
        S.insert(t[i]);
    }
    if((int)(S.size())<tot) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}



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


long m, n;
char a[1003][1003];

void run()
{
    queue<pair<int,pair<int,int> > >q;
    long cnt = 0, b = 0, w = 0;
    long dx[4] = {0,0,1,-1};
    long dy[4] = {1,-1,0,0};
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> a[i][j];
            if (a[i][j] == '#'){
                q.push(make_pair(0,make_pair(i,j)));
                b++;
            }
            else w++;
        }
    }
    while(!q.empty())
    {
        pair<int,pair<int,int> > tmp = q.front();
        q.pop();
        for (int i = 0; i < 4; i++)
        {
            int xx = tmp.second.first+dx[i];
            int yy = tmp.second.second+dy[i];
            if (xx > 0 and xx <= n and yy > 0 and yy <= m and a[xx][yy] == '.')
            {
                // cout << xx << ' ' << yy << endl;
                q.push(make_pair(tmp.first+1,make_pair(xx,yy)));
                a[xx][yy] = '#';
                if (cnt <= tmp.first+1)
                    cnt = tmp.first+1;
            }
        }
    }
    cout << cnt;
}


int main()
{   
    run();
    
    return 0;
}

Measured memory_bytes: 13328
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

struct cust {
	int  m;
	int l;
	int k;
};
 
struct query {
	int type;
	int time;
	int id;
};
struct aa {
	int id;
	int time;
};
class Compare {
public:
	bool operator()(const query&l,const query&r) {
		return l.time==r.time?l.type==r.type?l.id>r.id:l.type>r.type:l.time > r.time;
	}
	bool operator()(const aa&l, aa&r) {
		return l.time > r.time;
	}
};

bool check(const int T, const vector<cust>&cus, const int n) {
	int waitnum = n;
	priority_queue<query,vector<query>,Compare>que;
	//vector<int>waits(cus.size());
	set<int>waits;
	for (int i = 0; i < cus.size(); ++i) {
		que.push(query{ 0,0,i });
	}
	while (!que.empty()) {
		query q(que.top());
		que.pop();
		if (q.type == 1) {
			auto it = waits.begin();
			if (it == waits.end()) {
				waitnum++;
			}
			else {
				const int cid = *it;
				const int nexttime = q.time + cus[cid].m;
				if (nexttime < T) {
					waits.erase(it);
					que.push(query{ 1,nexttime,0 });
				}
				else if (nexttime == T) {
					waits.erase(it);
				}
				else {
					return false;
				}
				
			}
		}
		else if (q.type == 0) {
			const int cid = q.id;
			if (waitnum) {
				waitnum--;
				const int nexttime = q.time + cus[cid].m;
				if (nexttime < T) {
					que.push(query{ 1,nexttime,0 });
				}
				else if (nexttime == T) {
				}
				else {
					return false;
				}
			}
			else {
				waits.emplace(cid);
				const int nexttime = q.time + cus[cid].l;
				que.push(query{ 2,nexttime,cid });
			}
		}
		else if (q.type == 2) {
			const int cid = q.id;
			auto it = waits.find(cid);
			if (it!=waits.end()) {
				waits.erase(it);
				const int nexttime = q.time + cus[cid].k;
				if (nexttime < T) {
					que.push(query{ 0,nexttime,cid });
				}
				else {
					return false;
				}
			}
			else {

			}
		}
	}
	return true;
}

int main() {
	while (1) {
		int N, T; cin >> N >> T;
		if (!N)break;
		vector<cust>cus;
		int totalm = 0;
		for (int i = 0; i < N; ++i) {
			int m, l, k; cin >> m >> l >> k;
			totalm += m;
			cus.push_back(cust{ m,l,k });
		}
		/*int amin = 0;
		int amax = N;
		while (amin + 1 != amax) {
			int amid = (amin + amax) / 2;
			if (check(T, cus, amid)) {
				amax = amid;
			}
			else {
				amin = amid;
			}
		}
		cout << amax << endl;*/
		int ans = 0;
		int amin = (totalm-1) / T + 1;
		for (int n = amin; n <= N; ++n) {
			if (check(T, cus, n)) {
				ans = n;
				break;
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3076
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>

using namespace std;

typedef long long ll;

int main() {
   int N;
   cin >> N;
   string S;
   cin >> S;
   int Q;
   cin >> Q;
   int k[Q];
   for (int i = 0; i < Q; i++) {
      cin >> k[i];
   }

   ll SD[N + 1], SM[N + 1], SDM[N + 1];
   SD[0] = 0;
   SM[0] = 0;
   SDM[0] = 0;
   vector<int> Cid;
   for (int i = 0; i < N; i++) {
      if (S[i] == 'D') {
         SD[i + 1] = SD[i] + 1; 
      } else {
         SD[i + 1] = SD[i];
      }
      if (S[i] == 'M') {
         SM[i + 1] = SM[i] + 1;
         SDM[i + 1] = SDM[i] + SD[i];
      } else {
         SM[i + 1] = SM[i];
         SDM[i + 1] = SDM[i];
      }
      if (S[i] == 'C') {
         Cid.push_back(i);
      }
   }
   
   for (int ktmp = 0; ktmp < Q; ktmp++) {
      ll count = 0;
      for (int c = 0; c < Cid.size(); c++) {
         int minid = Cid[c] - k[ktmp];
         if (minid < 0) count += SDM[Cid[c] + 1];
         else {
            count += SDM[Cid[c] + 1];
            count -= SDM[minid + 1];
            count -= SD[minid + 1] * (SM[Cid[c] + 1] - SM[minid + 1]);
         }
      }
      cout << count << endl;
   }

   return 0;
}


Measured memory_bytes: 29048
package main
 
import (
	"fmt"
  "sort"
)
 
func main() {
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)
  ints := []int{a,b,c}
  sort.Ints(ints)
  fmt.Println(ints[0]+ints[1])
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
  int N,M;
  scanf("%d %d",&N,&M);
  int a[M];
  int b[M];
  int i;
  int count[50]={0};
  for(i=0;i<M;i++){
    scanf("%d %d",&a[i],&b[i]);
    count[a[i]-1]++;
  }
  for(i=0;i<M;i++){
    count[b[i]-1]++;
  }
  for(i=0;i<N;i++){
    printf("%d\n",count[i]);
  }
  return 0;
}


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

int main() {
  string str;
  cin >> str;
  if((str.at(2)==str.at(3))&(str.at(4)==str.at(5))){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
// 単一始点最短経路 ( ダイクストラ法 : 優先度付きキュー )
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>

using namespace std;

static const int MAX_N = 10000;
static const int INFTY = (1 <<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

class q_element
{
    public:
        // 各頂点のNo.と経路の値
        int vertex_num;
        int vertex_val;

        // コンストラクタ
        q_element(int a, int b)
        {
            vertex_num = a;
            vertex_val = b;
        };
};

// ">" のオーバーロード [ receive_val ] を基準に大小比較を行う
bool operator > (const q_element &q_element_1, const q_element &q_element_2)
{
    return q_element_1.vertex_val > q_element_2.vertex_val;
};

// q_elementクラスのオブジェクトを昇順にするためのキューの定義
std::priority_queue< q_element,
                     std::vector<q_element>,
                     std::greater<q_element> > pqEle;

// 隣接リストを作成する ( 頂点と重みの情報を格納する )
vector<q_element> v_Link[MAX_N + 1];

int n;

// ダイクストラ法を実施するメソッド( 優先度付きキュー )
int Dijkstra_priority_queue(int start_v);

int main(void)
{

    cin >> n;

    int k, c, u, v;
    q_element q_entity(0, 0);

    for(int i = 0; i < n; i++)
    {
        cin >> u >> k;

        for(int j = 0; j < k; j++)
        {
            cin >> v >> c;

            // 隣接リストの作成 ( 頂点と重みを設定する )
            q_entity.vertex_num = v;
            q_entity.vertex_val = c;

            v_Link[u].push_back(q_entity);
        }
    }

    // 優先度付きキューを用いたダイクストラ法
    Dijkstra_priority_queue(0);

    return 0;

}

// 優先度付きキューを用いたダイクストラ法を実施するメソッド
// start_v : スタートする頂点のNo.
int Dijkstra_priority_queue(int start_v)
{
    int u, v, minv;
    int d[MAX_N], p[MAX_N], color[MAX_N];

    // 初期設定
    for(int i = 0; i < n; i++)
    {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }

    // 開始点の設定 ( 開始点の距離をゼロをとする)
    d[start_v] = 0;
    color[start_v] = GRAY;
    // キューに要素を入れる
    pqEle.push( q_element(start_v, 0) );

    while( !pqEle.empty() )
    {

        // 最小の値を持つ頂点を取り出す ( キューの先頭 )
        u = pqEle.top().vertex_num;
        minv = pqEle.top().vertex_val;
        pqEle.pop();

        // 訪問完了
        color[u] = BLACK;

        for(int v_num = 0; v_num < v_Link[u].size(); v_num++)
        {
            // 隣接リストから接続している要素を取得する
            v = v_Link[u][v_num].vertex_num;

            if( color[v] != BLACK )
            {
                // u → v の経路の中で, vのコストが最小のものが見つかれば更新する
                if( d[v] > d[u] + v_Link[u][v_num].vertex_val )
                {
                    // コストの記録
                    d[v] = d[u] + v_Link[u][v_num].vertex_val;
                    // 頂点 v の親を記録する
                    p[v] = u;
                    // 訪問状態の記録
                    color[v] = GRAY;

                    // キューに要素を入れる
                    pqEle.push( q_element(v, d[v]) );
                }
            }
        }
    }

    // 結果の表示
    for(int i = 0; i < n; i++)
    {
        cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
    }

    return 0;
}



Measured memory_bytes: 7816
import sys, heapq, bisect, math, fractions
from collections import deque

mod = 2019
L, R = map(int, input().split())

res = 10 ** 15
if R - L > 2030:
    res = 0
else:
    for l in range(L, R):
        for r in range(l + 1, R + 1):
            res = min(res, (l * r) % mod)

print(res)

Measured memory_bytes: 5076
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String str = sc.next();
			int len = str.length();
			List<String> numarr = new ArrayList<>();
			if (len == 1) {
				System.out.print(Integer.parseInt(str));
				return;
			}
			long ans = 0;
			Set<Integer> set = new HashSet<>();
			for (int bit = 0; bit < 1 << len - 1; bit++) {
				for (int i = 0; i < len - 1; i++) {
					if ((bit & 1 << i) != 0) {
						set.add(i);
					}
				}
				int last = 0;
				for (int i : set) {
					numarr.add(str.substring(last, i + 1));
					last = i + 1;
				}
				numarr.add(str.substring(last, len));
				for (String e : numarr) {
					ans += Long.parseLong(e);
				}
				set.clear();
				numarr.clear();
			}
			System.out.print(ans);
		}
	}
}

Measured memory_bytes: 36052
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

int main(){
    int N; cin >> N;
    vector<long long> a(N);

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

    map<long long, long long> delta_cnt;
    vector<long long> delta_array(N);

    for(int i=1; i<=N; ++i){
        long long delta = a[i-1] - i;
        delta_array[i-1] = a[i-1] - i;
        if(delta_cnt.count(delta)){
            delta_cnt[delta]++;
        }else{
            delta_cnt[delta] = 1;
        }
    }

    pair<long long, long long> mx = {0, 0};

    for( auto delta : delta_cnt ){
        if(mx.second < delta.second){
            mx = delta;
        }
    }
    long long ans = 0;


    // if(mx.second == 1){
        sort(delta_array.begin(), delta_array.end());
        long long mid_idx = delta_array.size()/2;
        long long mid = delta_array[mid_idx];

        for(auto delta : delta_cnt){
            ans += abs(delta.first - mid) * delta.second;
        }

    // }else{

    //     for(auto delta : delta_cnt){
    //         ans += abs(delta.first - mx.first) * delta.second;
    //     }
    // }

    cout << ans << endl;

}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int main() {

  for (int s; cin >> s, s;){
  rep (i, 9) {
    int x; cin >> x;
    s -= x;
  }
  cout << s << endl;}

  return 0;
}

Measured memory_bytes: 1160
#include <array>
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

class interpreter {
private:
	static constexpr int NUM = 128;
	array<int, NUM> length;
	array<unordered_map<int, int>, NUM> value;
	string::const_iterator it;

	void declaration(char array_name, int len) {
		length[array_name] = len;
	}

	void assignment(char array_name, int index) {
		if(index >= length[array_name]) throw "out of bounds";
		++it; // "="
		const int right_value = expression();
		value[array_name][index] = right_value;
	}

	int expression() {
		if(isdigit(*it)) return number();

		const char array_name = *it;
		it += 2; // "<array_name>["
		const int index = expression();
		++it; // "]"

		if(index >= length[array_name]) throw "out of bounds";
		if(!value[array_name].count(index)) throw "undefined value";

		return value[array_name].at(index);
	}

	int number() {
		int res = 0;
		while(isdigit(*it)) {
			res = res * 10 + (*it - '0');
			++it;
		}
		return res;
	}

public:

	bool evaluate(const string &s) {
		try {
			it = s.cbegin();
			const char array_name = *it;
			it += 2; // "<array_name>["
			const int tmp = expression();
			++it; // "]"

			if(it == s.cend()) {
				declaration(array_name, tmp);
			}
			else {
				assignment(array_name, tmp);
			}
		}
		catch(const char *c) {
			return false;
		}

		return true;
	}
};

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

	for(string statement; cin >> statement && statement != ".";) {
		vector<string> program(1, statement);
		while(cin >> statement && statement != ".") {
			program.emplace_back(statement);
		}

		interpreter ipt;
		int first_bug = 0;
		for(unsigned i = 0; i < program.size(); ++i) {
			if(!ipt.evaluate(program[i])) {
				first_bug = i + 1;
				break;
			}
		}

		cout << first_bug << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;

int main(){
  ll N;cin>>N;
  string S; 
  vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  while(N!=0){
    N--;
    S.push_back(alp[N%26]);
    N/=26;
  }
  reverse(all(S));
  cout<<S<<endl;

}


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

int main() {
  long N, M;
  cin >> N >> M;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);

  long sum = accumulate(A.begin(), A.end(), 0L);

  long cnt = 0;
  for (long i = 0; i < N; i++) {
    if (A.at(i) < sum * (1.0 / (4 * M))) continue;
    else cnt++;
  }
  cout << ((cnt >= M) ? "Yes" : "No") << "\n";
}

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

int main() {
  int n;ll k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i=0;i<n;i++){
      cin >> a.at(i);
  }

  vector<int> s;
  vector<int> ord(n+1,-1);
  int c = 1;
  int l=0;
  {
    int v = 1;
    while (ord[v] == -1) {
      ord[v] = s.size();
      s.push_back(v);
      v = a[v-1];
    }
    c = s.size() - ord[v];
    l = ord[v];
  }

  if (k < l) 
    cout << s[k] << endl;
  else {
    k -= l;
    k %= c;
    cout << s[l+k] << endl;
  }
  return 0;
}


Measured memory_bytes: 5796
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int c = sc.nextInt();
    int[]b = new int[m];
    int[][]a = new int[n][m];
    
    for(int i=0; i<m; i++) {
    	b[i] = sc.nextInt();
    }
    for(int i=0; i<n; i++) {
    	for(int j=0; j<m; j++) {
    		a[i][j] = sc.nextInt();
    	}
    }
    int cou = 0;
    for(int i=0; i<n; i++) {
    	int al = 0;
    	for(int j=0; j<m; j++) {
     		al += a[i][j]*b[j];
    	}
    	if(al + c > 0) {
    		cou++;
    	}
    }
    System.out.println(cou);
    }
}

Measured memory_bytes: 38268
#include<stdio.h>

int main(void)
{
  int N,i,s;
  int hito[200005]={0};
  
  scanf("%d", &N);
  
  for(i=1;i<N;i++){
    scanf("%d", &s);
    hito[s-1]++;
  }
  
  for(i=0;i<N;i++){
    printf("%d\n",hito[i]);
  }
  
  return 0;
}

Measured memory_bytes: 2504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> c(10, vector<ll>(10));
    rep(i, 10) rep(j, 10) cin >> c[i][j];
    rep(i, 10) rep(j, 10) rep(k, 10) c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
    ll ans = 0;
    rep(i, h) {
        rep(j, w) {
            ll a;
            cin >> a;
            if (a == -1) continue;
            ans += c[a][1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
S=input()
if S[0]!='A':
    print("WA")
    exit()
s=S[2:len(S)-1]
#print(s)
if s.count('C')!=1:
    print("WA")
    exit()
S1=list(S)
S1.remove('A')
S1.remove('C')
alpha="abcdefghijklmnopqrstuvwxyz"
for s in S1:
    if not('a'<=s<='z'):
    #if s not in alpha:
        #print(s)
        print("WA")
        exit()
print("AC")


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

int main() {
    const long long size = 1000000;
    vector<long long> memo(size, -1);
    vector<long long> odd(size, -1);
    memo[0] = 0; odd[0] = 0;

    for (int i=0; i<size; i++) {
        memo[i] = i; odd[i] = i;
    }

    for (long long i=2; i<200; i++) {
        const long long pNum = (i * (i+1) * (i+2)) / 6;
        for (long long j=0; j<size; j++) {
            if (j-pNum >= 0) {
                memo[j] = min(memo[j-pNum]+1, memo[j]);

                if (pNum % 2 == 1) {
                    odd[j] = min(odd[j-pNum]+1, odd[j]);
                }
            }
        }
    }

    long long n; while (cin >> n, n != 0) {
        cout << memo[n] << " " << odd[n] << endl;
    }

}


Measured memory_bytes: 18152
#include <iostream>
#include <stdio.h>
using namespace std;

const int M=2e5+5;
int a[M];
int mx1=0,mx2=0;

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]>mx1)
		{
			mx2=mx1;
			mx1=a[i];
		}
		else if(a[i]>mx2)
			mx2=a[i];
	}
	for(int i=0;i<n;i++)
		printf("%d\n",a[i]==mx1?mx2:mx1);
	return 0;
}

Measured memory_bytes: 2432
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M,V,P=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
s=[None]*N
t=0
for i in range(N):
    t+=A[i]
    s[i]=t
S=M*(N-V)
l=P
r=N
if P==1:
    a=0
else:
    a=s[P-2]
while l<r:
    m=(r - l) // 2 + l
    if A[P-1]-M>A[m]:
        r=m
        continue
    if s[m-1]-a-(m-P+1)*A[m]>S:
        r=m
        continue
    l=m+1
print(l)

Measured memory_bytes: 62576
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}

int vis[105];
void init()
{
    clr(vis,0);
    for(int i = 0; i <= 25; i++)
    {
        for(int j = 0; j <= 100/7; ++j)
        {
            int now = 4*i + 7*j;
            if(now <= 100)
            vis[now] = 1;
        }
    }
}
int main()
{
   int n;init();
   while(cin>>n)
   {
       if(vis[n])
        cout<<"Yes"<<endl;
       else
        cout<<"No"<<endl;
   }
}
















Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

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

  vector<ll> ans_cand;
  for (ll i = 1; i <= 9; i++) {
    for (ll j = 1; j <= 9; j++) {
      ans_cand.emplace_back(i * j);
    }
  }
  string ans = "No";
  for (const auto& x: ans_cand) {
    if (x == N) ans = "Yes";
  }

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


Measured memory_bytes: 256
#include<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
 
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {for(auto x : v) cout << x << ' '; cout << endl;}
#define printn(v, n) {for(int _i = 0; _i < n; _i++) cout << *(v + _i) << ' '; cout << endl;}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
 
const int MAXN = 1000 + 20;

int n, m;
double a[MAXN];

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

    cin >> n;
    for(int i = 0; i < n; i++)
    	cin >> a[i];
    sort(a, a + n);
    double tmp = a[0];
    for(int i = 1; i < n; i++)
    	tmp = (tmp + a[i]) / 2;
    cout << tmp << endl;

    return 0;
}











Measured memory_bytes: 384
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#define Debug 0
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int main(){
    int A, B; cin >> A >> B;
    cout << max({A+B, A+A-1, B+B-1}) << endl;
}




Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const double PI=3.1415926535;
ll l[200000];
ll r[200000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m;
    cin>>n>>m;
    ll zuo=-1;ll you=1e9;
    for(int i=1;i<=m;i++)
    {
        cin>>l[i]>>r[i];
    }
    for(int i=1;i<=m;i++)
    {
        zuo=max(zuo,l[i]);
        you=min(r[i],you);
    }
    ll ans=you-zuo+1;
    if(you<zuo)
    {
        ans=0;
    }
    cout<<ans<<'\n';












}



Measured memory_bytes: 1792
/*
TEMPLATE
by.YXH_XianYu
   2018.7.1
 */
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LLI long long
#define rep(i,j,k) for(LLI i=j,lim=k;i<=lim;i++)
#define MXN 200005

LLI n,
	a[MXN],
	t[MXN],
	b,c=1000000000000000000,
	md,
	ans1,
	ans2;

int main(){
	//freopen("TEMPLATE.in","r",stdin);
	//freopen("TEMPLATE.out","w",stdout);

	scanf("%lld",&n);
	rep(i,1,n)
		scanf("%lld",&a[i]),a[i]-=i,c=std::min(c,a[i]);
	if(c<0)
		rep(i,1,n)
			a[i]-=c;
	rep(i,1,n)
		t[i]=a[i];
	std::sort(t+1,t+n+1);
	md=t[n/2];
	rep(i,1,n)
		ans1+=std::abs(a[i]-md);
	md=t[n/2+1];
	rep(i,1,n)
		ans2+=std::abs(a[i]-md);
	printf("%lld\n",std::min(ans1,ans2));

	return 0;
}


Measured memory_bytes: 3328
import std.stdio : write;
import std.array;
import std.range;

void main(){
	while(hasNext){
		
		for(char* p = (next!string().dup ~ "\0").ptr; *p!='\0'; ++p){
			if(*p == '@'){
				int l = *(++p) - '0';
				++p;
				foreach(i; l.iota){
					(*p).to!string.write;
				}
			}else{
				(*p).to!string.write;
			}
		}
		"\n".write;
	}
}


import std.stdio : readln, chomp;
import std.conv : to;
import std.string : split;
shared string[] input;
shared string delim = " ";
T next(T)()
in
{
	assert(hasNext());
}
out
{
	input.popFront;
}
body
{
	return input.front.to!T;
}

void next(T)(ref T v){
	v = next!T();
}

bool hasNext(){
	if(input.length > 0){
		return true;
	}
	
	string str = readln;
	if(str.length > 0){
		input ~= str.chomp.split(delim);
		return true;
	}else{
		return false;
	}
}


void dbg(T...)(T vs)
{
	import std.stdio : stderr;
	foreach(v; vs)
		stderr.write(v.to!string ~ " ");
	stderr.write("\n");
}

T clone(T)(T v){
	T v_;
	static if(isInputRange!(T)){
		foreach(ite; v){
			v_ ~= ite.clone;
		}
	}else{
		v_ = v;
	}
	
	return v_;
}

Measured memory_bytes: 1000
n, k = map(int, input().split())
tele = list(map(int, input().split()))
reached = [-1 for _ in range(n + 1)]
now = 1
count = 0
reached[1] = 0
cycle = False
while cycle == False:
    now = tele[now - 1] #current town
    count += 1
    if count == k:
        print(now)
        exit()
    elif reached[now] == -1:
        reached[now] = count
    else:
        cycle = True
roop_long = count - reached[now]
from_roop_in_town = (k - reached[now]) % roop_long

#print(reached, now, roop_long, from_roop_in_town)

for i in range(from_roop_in_town):
    now = tele[now - 1]
print(now)

Measured memory_bytes: 32352
n, m = map(int,input().split())
ans = 0
a = [-1]*n
for i in range(m):
  s, c = map(int,input().split())
  if a[s-1] in [-1, c]:
    a[s-1] = c
  else:
    ans = -1
    break
if a[0] == 0 and n > 1:
  ans = -1
if ans == 0 and a != [0] and a != [-1]:
  ans += max(a[0],1)*10**(n-1)
  for i in range(1,n):
    ans += max(a[i],0)*10**(n-i-1)
print(ans)

Measured memory_bytes: 39952
#include<stdio.h>
int n,t,s;
int a,b;//a=楽しさ　b=時間
int i,j;
int dp[3010][3010];//dp[時刻]
int main(void){
	scanf("%d %d %d",&n,&t,&s);
	for(i=0;i<=n;i++){
		for(j=0;j<=t;j++){
			dp[i][j]=-1;
		}
	}
	for(i=0;i<=n;i++){
		dp[i][0]=0;
	}
	for(i=0;i<n;i++){
		scanf("%d %d",&a,&b);
		for(j=0;j<=t;j++){
			if(dp[i][j]!=-1){
				if(j+b<=s && dp[i+1][j+b]<dp[i][j]+a){
					if(dp[i+1][j+b]==-1){
						dp[i+1][j+b]=0;
					}
					dp[i+1][j+b]=dp[i][j]+a;
				}
				else if(j<s && j+b>s && s+b<=t && dp[i+1][s+b]<dp[i][j]+a){	//j<s j+b>s s+b<=t
					if(dp[i+1][s+b]==-1){
						dp[i+1][s+b]=0;
					}
					dp[i+1][s+b]=dp[i][j]+a;
				}
				else if(j>=s && j+b<=t && dp[i+1][j+b]<dp[i][j]+a){
					if(dp[i+1][j+b]==-1){
						dp[i+1][j+b]=0;
					}
					dp[i+1][j+b]=dp[i][j]+a;
				}
			}
		}
		for(j=0;j<=t;j++){
			if(dp[i+1][j]<dp[i][j]){
				dp[i+1][j]=dp[i][j];
			}
		}
	}
	/*for(i=0;i<=n;i++){
		for(j=0;j<=t;j++){
			printf("%d ",dp[i][j]);
		}
		printf("\n");
	}*/
	int max=0;
	for(i=0;i<=t;i++){
		if(max<dp[n][i]){
			max=dp[n][i];
		}
	}
	printf("%d\n",max);
	return 0;
}

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

int main(){
    while(1){
        int n=0;
        cin>>n;
        if(n==0)break;
        int p[45]={0};
        p[0]=1;
        p[1]=1;
        p[2]=2;
        for(int i=3;i<=30;i++){
            p[i]=p[i-1]+p[i-2]+p[i-3];
        }
        cout<<(p[n]/3650)+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include<math.h>
int main(){
    int i , flag=0, count=0,n,j,A;
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%d",&A);
        for(j=2; j<=sqrt(A); j++){
            if(A%j==0) flag=1;
        }
        if(flag==0) {
            count++;
            //printf("%d ",A);
        }
        flag=0;
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2056
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.abc120
{
  class b
  {
    static void Main(string[] args)
    {
      int[] ABK = GetIntArray();
      int N = 1 + (ABK[0] > ABK[1] ? ABK[1] : ABK[0]);
      while (ABK[2] != 0)
      {
        N--;
        if (ABK[0] % N == 0 && ABK[1] % N == 0) ABK[2]--;
      }
      Console.Write(N);
    }
    static int GetInt() => int.Parse(Console.ReadLine());
    static int[] GetIntArray()
    {
      string[] r = Console.ReadLine().Split(' ');
      int[] a = new int[r.Length];
      Parallel.For(0, r.Length, i => a[i] = int.Parse(r[i]));
      return a;
    }
  }
}


Measured memory_bytes: 15068
def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    
    for i in range(2, n+1):
        if is_prime[i]:
            j = 2 * i
            while j <= n:
                is_prime[j] = False
                j += i
    table = [ i for i in range(n+1) if is_prime[i]]
    return table, is_prime

N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]

prime, flag = sieve(10 ** 5)
number = [0 for i in range(10 ** 5+1)]

for i in range(2, 10 ** 5):
    if flag[i] and flag[(i+1)//2]:
        number[i] += 1
        
for i in range(1, 10 ** 5):
    number[i] += number[i-1]
        
result = []
            
for i in range(N):
    res = number[L[i][1]] - number[L[i][0]-1]
    result.append(res)

for res in result:
    print(res)

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

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

    ll count = 700;
    rep(i, 3){
        if(s[i] == 'o'){
            count += 100;
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#include<string>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
 
    ll n;
    cin >> n;
 
    if(n == 2)
    {
        ll x, y;
        cin >> x >> y;
 
        cout << max(x,y) << endl;
        return 0;
    }
 
    vector<ll> v(n);
 
    for(ll i = 0; i < n; i++)
    {
        cin >> v[i];
    }
 
    sort(v.begin(), v.end(), greater<ll>());
 
    ll counter = 0;
    ll j = 1;
 
    counter += v[0];
 
    for(ll i = 2; i < n; i++)
    {
        counter += v[j];
        i++;
        if(i < n)
        {
            counter += v[j];
        }
        j++;
    }
    cout << counter << endl;
}


Measured memory_bytes: 4768
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
using ll = long long;
const int M = 100010;

ll c(ll z){
	return z*(z-1)*(z-2);
}
ll d(ll z){
	return z*(z-1)*3;
}

ll box(ll y){
	if(y==1)return 1;
	else if(y==2)return 8;
	else return y+d(y)+c(y);
}


int main(void){
	ll x[2*M]={},ans=0;
	ll n,k;

	cin>>n>>k;
	rep(i,1,n+1)x[i%k]++;
	if(k%2)cout<<box(x[0])<<endl;
	else cout<<box(x[k/2])+box(x[0])<<endl;

}

Measured memory_bytes: 1792
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k == x:
                count += 1
print(count)


Measured memory_bytes: 3064
import math
from functools import reduce
from collections import deque

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,k = get_nums_l()
v = get_nums_l()

# 左側でpos回操作するときの最大得点
left = [0]*(k+1)
leftmark = [0]*(k+1)
# 右側
right = [0]*(k+1)

for i in range(1,k+1):
    score = max(left[i-1], sum(v[:i]))
    leftmark[i] = i
    for ii in range(i//2):
        ii += 1
        score_ = sum(sorted(v[:i-ii],reverse=True)[:i-(ii*2)])
        if score_ > score:
            score = score_
            leftmark[i] = i-ii
    left[i] = score

for i in range(1,k+1):
    score = max(right[i-1],sum(v[max(leftmark[k-i],(n-i)):]))
    for ii in range(i//2):
        ii += 1
        score = max(score, sum(sorted(v[max(leftmark[k-i],n-i+ii):],reverse=True)[:min(n-leftmark[k-i], i-(ii*2))]))
    right[i] = score

ans = 0

for i in range(k+1):
    ans = max(ans, left[i] + right[k-i])
print(ans)

Measured memory_bytes: 43500