akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

#include <iostream>
#include <vector>
using namespace std;

//重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start, const ll range_end)
{
    if (i == size) {
      // ここで所望の作業を行う
      for(ll itr:buf){
        cout << itr;
      }
    }
    else{
        for(ll j = range_start; j <= range_end; ++j){
            buf[i] = j;
            permutation(i + 1, size, range_start, range_end);
        }
    }
}

int main(void)
{
  ll ans=0,check;
  string n;
  cin >> n;
  RAP(i,(ll)(n.size())){
    check = n[i]-'0';
    //cout << check << endl;
    ans = (ans+check)%9;
  }
  if(ans%9==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


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

int main()
{
    long long int a=2,b=1,n,ans=2;
    cin>>n;
    if(n==1)
        cout<<1;
    else
    {
        while(--n)
        {
            ans=a+b;
            a=b;
            b=ans;
        }
        cout<<ans;
    }
    return 0;
}



Measured memory_bytes: 3604
n=int(input())

lis=[[[1,"a"]]]

for i in range(n-1):
    lisi=[]
    for j in lis[i]:
        for k in range(j[0]):
            lisi.append([j[0],j[1]+chr(ord("a")+k)])
        lisi.append([j[0]+1,j[1]+chr(ord("a")+j[0])])
    lis.append(lisi)

for i in lis[n-1]:
    print(i[1])

Measured memory_bytes: 28024
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    
    int ans = 0;
    for(int i=1;i<361;i++){
      if( i*n % 360 == 0 ){
        ans = i;
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 27060
N, K = map(int, input().split())
 
ans = set()

for i in range(K) :
  d = int(input())
  if d == 1 :
    ans.add(int(input()))
  else :
    A = list(map(int, input().split()))
    for j in A :
      ans.add(j)
      
print(N - len(ans))

Measured memory_bytes: 9184
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;

int n, A, B, C, l[8];
const int inf = 3000;
int dfs(int cur, int a, int b, int c) {
    if (cur == n) {
        if (min(min(a, b), c) > 0) return abs(a - A) + abs(b - B) + abs(c - C) - 30;
        //1個目 a, b, c +10されてる
        else return inf;
    }
    int ret0 = dfs(cur + 1, a, b, c);
    int ret1 = dfs(cur + 1, a + l[cur], b, c) + 10;
    int ret2 = dfs(cur + 1, a, b + l[cur], c) + 10;
    int ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10;
    return min(min(ret0, ret1), min(ret2, ret3));
}
int main() {
    cin >> n >> A >> B >> C;
    rep(i, n) cin >> l[i];
    cout << dfs(0, 0, 0, 0) << endl;
}


Measured memory_bytes: 256
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

const MOD: u64 = 1_000_000_000 + 7;

fn main() {
    let (n, k) = {
      let v: Vec<usize> = read_vec();
      (v[0], v[1])
    };

    let a: Vec<usize> = read_vec();
    // dp_table
    let mut dp: Vec<Vec<u64>> = vec![vec![0; k+1]; n+1];

    // init
    dp[0][0] = 1;


    for i in 0..n {
      let mut sum: Vec<u64> = vec![0; k+2];
      // i列目の累積和を作成
      for j in 0..k+1 {
        sum[j+1] = sum[j] + dp[i][j];
      }

      //
      for j in 0..k+1 {
        // dp[i+1][j] = SUM(dp[i][j - l]) (for l = 0 ~ a_i)
        // dp[i+1][j] = SUM(dp[i][m]) (for m = j - a_i ~ j)
        let m = max(0, j as i64 - a[i] as i64);
        dp[i+1][j] = sum[j+1] - sum[m as usize];
        dp[i+1][j] %= MOD;
      }

    }

    println!("{}", dp[n][k]);
}


Measured memory_bytes: 108796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const int inf = 1e9;
const int MAX = 1e5+5;
const ll MOD = 1e9+7;
#define REP(i, n) for (int i = 0; i < (n); ++i)

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int n, m; cin >> n >> m;
    priority_queue<ll, vector<ll>, greater<ll>> a;
    ll tmp;
    REP(i, n){
        cin >> tmp;
        a.push(tmp);
    }
    int b;
    ll c;
    multimap<ll, int, greater<ll>> cards;
    REP(i, m){
        cin >> b >> c;
        cards.insert(make_pair(c, b));
    }
    bool breaking = false;
    for(auto const& entry: cards){
        c = entry.first;
        b = entry.second;
        REP(j, b){
            tmp = a.top();
            if(c > tmp){
                a.pop();
                a.push(c);
            }else{
                breaking = true;
                break;
            }
        }
        if(breaking) break;
    }
    ll ans = 0;
    while(!a.empty()){
        ans += a.top();
        a.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7284
#include<bits/stdc++.h>
using namespace std;
vector<int>g[100009];
const long long mod=1000000007;
long long ans=1;
int n,k;
void dfs(int cur,int par,int dep,int num) {
	if(k<=num) {
		cout<<0<<endl;
		exit(0);
	}
	ans=ans*(k-num)%mod;
	if(dep>2) num=2;
	else num=dep;
	for(int i=0;i<g[cur].size();i++)
		if(g[cur][i]!=par) {
			dfs(g[cur][i],cur,dep+1,num);
			num++;
		}
}
int main() {
	cin>>n>>k;
	for(int i=0;i<n-1;i++) {
		int x,y;
		cin>>x>>y;
		g[x].push_back(y),g[y].push_back(x);
	}
	dfs(1,0,1,0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11520
l,s=input().split()
l=int(l)
m=0
for i in range(l):
    if s[i]!='W':continue
    j=i
    while j-1>=0 and s[j-1]=='B':
        j-=1
    t=0
    if j-1>=0 and s[j-1]=='.':
        t=i-j
        while j-1>0:
            if s[j-2]=='.':break
            if s[j-2]=='B':
                t=0
                break
            j-=1
    j=i
    while j+1<l and s[j+1]=='B':
        j+=1
    if j+1<l and s[j+1]=='.':
        td=j-i
        while j+2<l:
            if s[j+2]=='.':break
            if s[j+2]=='B':
                td=0
                break
            j+=1
        t+=td
    m=max(m,t)
    #print(t)
print(m)



Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
int h,n,a[1001],b[1001],i,j,f[20000],maxv; 
int main(){
	cin>>h>>n;
	for(i=1;i<=n;i++){
		cin>>a[i]>>b[i];
		if(maxv<a[i]) maxv=a[i];
	}
	f[0]=1;
	for(i=1;i<=n;i++)
		for(j=0;j<=h;j++){
			if(f[j]!=0){
				if(f[j+a[i]]==0)
					f[j+a[i]]=f[j]+b[i];
				else
					f[j+a[i]]=min(f[j+a[i]],f[j]+b[i]);
			}
		}
	int ans;
	j=h;
	while(f[j]==0){
		j++;
	}
	ans=f[j];
	for(i=j+1;i<=h+maxv;i++){
		if(ans>f[i] && f[i]!=0) ans=f[i];
	}
	cout<<ans-1;
	return 0;
} 

Measured memory_bytes: 256
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defun read-fixnum ()
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char *standard-input* nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte *standard-input* nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (return-from read-fixnum 0))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (the fixnum (* result 10))))
              (return (if minus (- result) result))))))))

(defmacro dbg (&rest forms)
  #+swank
  `(progn
     ,@(mapcar (lambda (form) `(format *error-output* "~A => ~A~%" ',form ,form))
               forms))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (table (make-array n :element-type 'boolean :initial-element nil))
         (res 0))
    (dotimes (i n)
      (when (= i (- (read-fixnum) 1))
        (setf (aref table i) t)))
    (loop for i below n
          do (when (and (aref table i)
                        (not (= i (- n 1)))
                        (aref table (+ i 1)))
               (incf res)
               (setf (aref table i) nil
                     (aref table (+ i 1)) nil)))
    (loop for i below n
          do (when (aref table i)
               (incf res)))
    (println res)))

#-swank(main)


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

using namespace std;

long long int n, W, w[100], v[100], dp[100][100001], ans, sum, mn[100][100001];

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> W;
	sum = 0;
	for (int i=0; i<n; ++i) {
		cin >> w[i] >> v[i];
		sum += v[i];
	}
	for (int i=0; i<n; ++i) {
		dp[i][0] = 0;
		for (int j=1; j<=sum; ++j) 
			dp[i][j] = 10*W;
	}
	dp[0][v[0]] = w[0];
	for (int i=0; i<=sum; ++i)
		mn[0][i] = dp[0][i];
	mn[0][v[0]] = w[0];

	for (int i=1; i<n; ++i)
		for (int j=0; j<=sum; ++j) {
			if (j >= v[i]) dp[i][j] = w[i] + mn[i-1][j-v[i]];
			mn[i][j] = min(dp[i][j], mn[i-1][j]);
		}

	for (int i=sum; i; i--) {
		bool f = 0;
		for (int j=0; j<n; ++j)
			if (dp[j][i] <= W) {
				f = 1;
				break;
			}
		if (f) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 156544
while True:
    
    #旅行費用を入力し0なら終わる
    num = int(input())
    if num == 0:break
    num_list = []
    
    #小遣いの差額をリストに追加していく
    for i in range(0,12):
        a,b = map(int,input().split())
        num_list.append(a - b)
        
    #12ヶ月ためても無理な場合は"NA"を出力する
    if num > sum(num_list):
        print("NA")
        continue
    
    #毎月減らしていき達成したらループを抜ける
    for i in range(0,12):
        num -= num_list[i]
        if num <= 0:break
    
    #リストに合わせるため変数を1減らしていたため1足して出力する
    print(i + 1)


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

ll MOD=1ll*1e9+7;

ll be(ll b, ll e, ll mod){
  ll r=1;
  while(e)if(e&1)r=(r*b)%mod,e^=1; else b=(b*b)%mod,e/=2;
  return r;
}

int main(){FIN;
	ll n; cin>>n;
	string s; cin>>s;
	sort(ALL(s));
	ll res=1,van=0;
	char va='?';
	fore(i,0,n){
		if(s[i]==va){
			van++;
		}else{
			res*=van+1;
			res%=MOD;
			van=1; va=s[i];
		}
	}
	res*=van+1;
	res%=MOD;
	res=(res+MOD-1)%MOD;
	cout<<res;
	
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

const int MAXV = 300;
const int MAXE = MAXV * MAXV;
const int MAXF = (1<<29);
typedef int F;

struct MaxFlow {
    F cap[MAXE], flow[MAXE];
    int V, E, level[MAXV], prev[MAXE], edge[MAXV], to[MAXE];
    MaxFlow(int n) : E(0), V(n) {
        memset(prev, -1, sizeof(prev));
        memset(edge, -1, sizeof(edge));
    }
    void add_edge(int s, int t, F f, F g = 0) {
        flow[E] = 0; cap[E] = f; to[E] = t; prev[E] = edge[s]; edge[s] = E; E++;
        flow[E] = 0; cap[E] = g; to[E] = s; prev[E] = edge[t]; edge[t] = E; E++;
    }
    void make_level(int s) { // make level graph (bfs)
        memset(level, -1, sizeof(level));
        queue<int> q; q.push(s); level[s] = 0;
        while(!q.empty()) {
            int v = q.front(); q.pop();
            for (int e = edge[v]; e != -1; e = prev[e]) {
                if (cap[e] - flow[e] > 0 && level[to[e]] == -1)
                    q.push(to[e]), level[to[e]] = level[v]+1;
            }
        }
    }
    int augment(int s, int t, F f) { // find augment path (dfs)
        if (s == t || f == 0) return f;
        for (int e = edge[s]; e != -1; e = prev[e]) {
            if (level[to[e]] > level[s] && cap[e] - flow[e] > 0) {
                F g = augment(to[e], t, min(f, cap[e] - flow[e]));
                if (g > 0) {
                    flow[e] += g, flow[e^1] -= g;
                    return g;
                }
            }
        }
        return 0;
    }
    int max_flow(int s, int t) {
        int f, ret = 0;
        for (bool cont = true; cont; ) {
            cont = false;
            make_level(s);
            while ((f = augment(s, t, MAXF)) > 0) {
                cont = true;
                ret += f;
            }
        }
        return ret;
    }
};

int main() {
    ios::sync_with_stdio(false);
    int x[MAXE], y[MAXE];
    int N,M,a,b;
    cin>>N>>M;
    MaxFlow mf(N);
    for (int i=0; i<M; ++i) {
        cin>>a>>b; a--, b--;
        mf.add_edge(a, b, 1, 1);
        x[i] = a, y[i] = b;
    }
    cin>>a>>b; a--, b--;
    cout<<mf.max_flow(a, b)<<endl;
    vector<int> rev;
    for (int i=0; i<M; ++i) {
        int e = mf.edge[y[i]];
        while(e != -1) {
            if (mf.to[e] == x[i] && mf.flow[e] > 0) rev.push_back(i);
            e = mf.prev[e];
        }
    }
    cout<<rev.size()<<endl;
    for (int i=0; i<rev.size(); ++i) cout<<rev[i]+1<<endl;
}

Measured memory_bytes: 3288
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}


int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        #if __cplusplus >= 201103L
        auto start = steady_clock::now();
        #endif
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    sf(n);
    vector<ll> v;
    rep(i, 1, n) {
        ll t;
        sf(t);
        v.push_back(t);
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            ans += 1ll * v[i] * v[j];
        }
    }
    cout << ans << endl;
    #ifdef LOCAL
        #if __cplusplus >= 201103L
        auto end = steady_clock::now();
        duration<double> time_span = duration_cast<duration<double>>(end - start);;
        printf("Total time: %.6fs\n", time_span.count());
        #endif
    #endif
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INF 100000000
using namespace std;

int n, t;
int dp[2][5001][2];

int main(){
	scanf("%d", &n);
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < 5001; j++){
			for(int k = 0; k < 2; k++){
				dp[i][j][k] = INF;
			}
		}
	}
	dp[0][1][0] = 0; dp[0][0][1] = 0;
	for(int i = 1; i < n; i++){
		scanf("%d", &t);
		/*
		for(int j = 0; j < 20; j++){
			for(int k = 0; k < 2; k++){
				printf("%d ", dp[0][i][k]);
			}
			printf("\n");
		}
		*/
		for(int j = 0; j <= n/2; j++){
			if(j != 0){
				dp[1][j][0] = min(dp[0][j-1][0],dp[0][j-1][1]+t);
				dp[1][j][1] = min(dp[0][j][1],dp[0][j][0]+t);
			} else{
				dp[1][j][1] = dp[0][j][1];
			}
		}
		for(int j = 0; j <= n/2; j++){
			for(int k = 0; k < 2; k++){
				dp[0][j][k] = dp[1][j][k];
			}
		}
	}
	printf("%d\n", min(dp[0][n/2][0],dp[0][n/2][1]));
}

Measured memory_bytes: 1100
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int gcd(int a, int b) {
  return b != 0 ? gcd(b, a % b) : a;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,x;
  cin >> n >> x;
  int a[100100];
  for(int i=0;i<n;i++){
    int b;
    cin >> b;
    a[i] = b-x;
  }
  int an = a[0];
  for(int i=1;i<n;i++){
    an = gcd(a[i],an);
  }
  cout << abs(an) << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
// scanf("%d %d %d %d",&w,&b,&d,&s); %lld
// printf("%d\n" ,points);
// const double PI=acos(-1);

const int L=105;
const int MAX=1e5+5;
const ll oo=1e18;
ll dp[L][MAX];
int w[L],v[L];
int n,W;

int main(){
    cin >> n >> W;
    ll aux;
    for(int i=0;i<n;i++){
        cin >> w[i] >> v[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=W;j++){
            if(j-w[i-1]<0) aux=-oo;
            else aux=dp[i-1][j-w[i-1]]+v[i-1];
            dp[i][j]=max(aux,dp[i-1][j]);
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}


Measured memory_bytes: 81688
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto n = readLong();
    auto g = new long[][](n,0);
    foreach(i; iota(n-1)) {
        long a, b;
        readlnTo(a, b);
        --a;
        --b;
        g[a] ~= b;
        g[b] ~= a;
    }
    Tuple!(long, long) dfs(long s, long t, long depth, ref bool[] used) {
        used[s] = true;
        if(s == t) {
            return tuple((depth+1)/2 + 1 == depth ? s: -1, depth);
        }
        foreach(v; g[s]) {
            if(used[v]) {
                continue;
            }
            auto tmp = dfs(v, t, depth+1, used);
            auto tDepth = tmp[1];
            if(tDepth != -1) {
                return tuple((tDepth+1)/2 + 1 == depth ? s: tmp[0], tDepth);
            }
        }
        return tuple(-1L, -1L);
    }
    long size(long x, ref bool[] used) {
        long ans = 1;
        used[x] = true;
        foreach(v; g[x]) {
            if(used[v]) {
                continue;
            }
            ans += size(v, used);
        }
        return ans;
    }

    auto used1 = new bool[](n);
    auto m = dfs(0, n-1, 1, used1)[0];
    auto used2 = new bool[](n);
    used2[m] = true;
    auto b = size(0, used2);
    writeln(b > n-b ? "Fennec": "Snuke");
}



Measured memory_bytes: 28028
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder strb = new StringBuilder();
        String[] data;
        int h = 0;
        int w = 0;
        while (true) {
            data = br.readLine().split(" ");
            h = Integer.parseInt(data[0]);
            w = Integer.parseInt(data[1]);
            if (h == 0 && w == 0) {
                break;
            }
            for (int i = 1; i <= h; i++) {
                for (int j = 1; j <= w; j++) {
                    if (i == 1 || i == h || j == 1 || j == w) {
                        strb.append("#");
                    } else {
                        strb.append(".");
                    }
                }
                strb.append("\n");
            }
            strb.append("\n");
        }
        System.out.print(strb);
    }
}

Measured memory_bytes: 25512
#include <bits/stdc++.h>
using namespace std;
int main () {
	int n; scanf("%d", &n);
	n %= 10;
	if (n == 3) printf("bon\n");
	else if (n == 0 || n == 1 || n == 6 || n == 8) printf("pon\n");
	else printf("hon\n");
	return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <algorithm>
using namespace std;

int main(void){
    int n, c;
    cin >> n >> c;
    
    bool record[31][100000] = {{false}};
    int recorder[100000] = {0};
    int s, t;
    int i, j;
    for(i = 0; i < n; i++){
        cin >> s >> t >> c;
        for(j = s; j <= t; j++){
            if(!record[c][j]){
                recorder[j]++;
            }
            record[c][j] = true;
        }
    }
    
    sort(recorder, recorder + 100000, greater<int>());
    cout << recorder[0] << endl;
    
    return 0;
}


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

int main() {
    int S, h, m, s;
    cin >> S;
    s = S % 60;
    m = S / 60 % 60;
    h = S / 60 / 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3104
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def b_ser(l,r)
  mid = (r+l)/2
  if(mid == l)
    return (j(mid))? mid : mid+1 
  end
  if(j(mid))
    b_ser(l,mid)
  else
    b_ser(mid,r)
  end
end
def j(d)
  c = @k
  @n.times do |i|
    sa = @a[i]* @b[i] - d
    if(sa > 0)
      c -= r_up(sa,@b[i])
    end
    return false if(c < 0)
  end
  return true
end
@n,@k = inp

@a = inp.sort
@b = inp.sort.reverse

p b_ser(0,10**12)


Measured memory_bytes: 36964
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n, red = 0, ans = 0;
  string s;
  cin >> n >> s;
  rep(i, n) if (s[i] == 'R') red++;
  rep(i, red) {
    if (s[i] == 'W') ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3748
//#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <climits>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <stdio.h>
//#define int long long
using namespace std;
#define loop(n) for(int i=0;i<n;i++)
#define endl '\n'
#define OnlineJudgec
#define F first
#define S second
#define  precision(n)  cout << fixed << setprecision(n)
#define clr(v,d ) memset(v, d, sizeof(v))
typedef long long ll;
typedef vector<int> vi;
void init()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    cout.tie(0);
    #ifdef OnlineJudge
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}
ll S(ll x){ll s = 0;while(x){s += x % 10;x /= 10;}return s;} /// sum of digits.
ll powe(ll a , ll n){if(n == 1)return a;return a * powe(a ,n-1);}
ll com(int n,int m){ll z = 1;for(int i = 0; i < m;i++){z = z * ( n - i) / (i + 1) ;}return z;}
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dr[] = {0,0,0,1,1,1,-1,-1,-1};
int dc[] ={-1,0,1,-1,0,1,-1,0,1};
/// <<------------------------------------------------------------------------------>>
const int mx = 100009;
int n , k;
int arr[mx][4];
int dp[mx][4];
int solve(int idx , int last)
{
     if(idx == n)return 0;
     int &ret = dp[idx][last];
     if(~ret) return ret;
     int A = 0 ,B = 0 ,C = 0;
     if(last != 0)
        A = solve(idx+1 , 0) + arr[idx][0];
     if(last != 1)
        B = solve(idx+1 , 1) + arr[idx][1];
     if(last != 2)
        C = solve(idx+1 , 2) + arr[idx][2];
     return ret = max(A,max(B,C));
}
/// <<------------------------------------------------------------------------------>>
int main()
{
    init();
    cin >> n;
    for(int i = 0 ;i < n;i++)
    {
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
    }
    clr(dp,-1);
    cout<<solve(0,3);
}


Measured memory_bytes: 9728
N = int(input())
Alist = list(map(int, input().split())) 

mina = min(Alist)
maxa = max(Alist)
costlist =list()

for i in range(mina,maxa+1):
    res = 0
    for j in Alist:
        temp = (j-i)**2
        res = res + temp
    costlist.append(res)

res = min(costlist)
print(res)

Measured memory_bytes: 3060
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import Data.List (sortBy)
import Data.Maybe (fromJust)

main :: IO ()
main = do
  [n, m] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  as <- sortBy (flip compare) . map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    table = V.constructN (succ n) rec :: V.Vector (Maybe (Int, [Int]))
      where
        rec :: V.Vector (Maybe (Int, [Int])) -> (Maybe (Int, [Int]))
        rec v | l == 0    = Just (0, [])
              | otherwise = maximum . map f $ as
          where
            l = V.length v :: Int
            f :: Int -> Maybe (Int, [Int])
            f d | l < k     = Nothing
                | otherwise = ((,) <$> succ . fst <*> (d :) . snd) <$> v V.! (l - k)
              where
                k = matchNums VU.! d :: Int
  mapM_ (putStr . show) . snd . fromJust $ table V.! n
  putStrLn ""

matchNums = VU.fromList [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] :: VU.Vector Int
{-# INLINE matchNums #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 3964
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();

    int[] X = new int[M];
    for (int i = 0; i < M; i++) {
      X[i] = sc.nextInt();
    }

    Arrays.sort(X);
    int[] diff = new int[M-1];
    Map<Integer, Integer> map = new HashMap<>();
    for (int i = 0; i < M-1; i++) {
      diff[i] = X[i+1] - X[i];
      map.put(diff[i], map.getOrDefault(diff[i],0)+1);
    }

    Arrays.sort(diff);

    for (int i = diff.length-1; i >= 0 && i > diff.length-N; i--) {
      map.put(diff[i], map.get(diff[i])-1);
    }
    
    int ans = 0;
    for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
      ans += (entry.getKey()*entry.getValue());
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 50820
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  string S;
  cin>>S;
  int mod=1e9+7;
  ll dp[2][S.size()];
  dp[0][0]=1;
  dp[1][0]=2;
  rep(i,S.size()-1){
    dp[0][i+1]=(dp[0][i]*3+dp[1][i]*(S[i+1]=='1'))%mod;
    dp[1][i+1]=(dp[1][i]+dp[1][i]*(S[i+1]=='1'))%mod;
  }
  cout<<(dp[0][S.size()-1]+dp[1][S.size()-1])%mod<<endl;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int rslt;
  if(a > b)
  {
    if( a-b > 1 ){rslt = a * 2 - 1;}
    else{rslt = a+b;}
  }
  else
  {
    if( b-a > 1 ){rslt = b * 2 - 1;}
    else{rslt = a+b;}
  }
  cout << rslt << endl;
}

Measured memory_bytes: 256
///***Bismillahir Rahmanir Rahim***///
///*********************************///
///******Ashraful Haque Toni********///
///********Dept. of CSE,JnU*********///
///email:ashrafulhaquetoni@gmail.com///
///*******contact:01640690531*******///
///*********************************///


#include<bits/stdc++.h>

using namespace std;

#define         ash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define         pb push_back
#define         mp make_pair
#define         sc(n) scanf("%d",&n);
#define         scl(n) scanf("%I64d",&n);
#define         sc2(m,n) scanf("%d%d",&m,&n);
#define         sc2l(m,n) scanf("%I64d%I64d",&m,&n);
#define         pf printf
#define         Big(x,y) max(x,y);
#define         Small(x,y) min(x,y);
#define         array_input(array,size) for(int i=0;i<size;i++)cin>>array[i];
#define         vector_input(v,size) for(int i=0;i<size;i++){ll n;cin>>n,v.pb(n);}
#define         newline pf("\n");
#define         f(i,n) for(ll i=0;i<(n);i++)
#define         f1(i,n) for(ll i=1;i<=(n);i++)
#define         Max INT_MAX
#define         Min INT_MIN
#define         pi acos(-1.0)
#define         Memset(a,val) memset(a,val,sizeof(a));


const int mod =1e9+7;
const int N =5e6+5;
typedef long long ll;



int main()
{

    ash;
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(b,a*n)<<endl;



    return 0;
}



Measured memory_bytes: 256
NN = 2020202
MOD = 10**9+7
INF = float("inf")

N = int(input())
X = list(map(int, input().split()))

vmin = float("inf")
for i in range(1, 101):
    vtmp = 0
    for j in X:
        vtmp += (i-j)**2
    vmin = min(vtmp, vmin)

print(vmin)



Measured memory_bytes: 38896
#include <iostream>
#include <string>

using namespace std;
typedef long long ll;

#define RPT(i, n) for (int i = 0; i < n; i++)

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

    ll K;
    cin >> K;

    // 最初の'1'以外の文字位置
    int index;
    bool only_one = true;
    RPT(i, S.size()) {
        if (S[i] != '1') {
            only_one = false;
            index = i;
            break;
        }
    }

    char ans = (only_one || K <= index) ? '1' : S[index];

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


Measured memory_bytes: 256
import sys


class Node:
    def __init__(self):
        self.parent = self.left = self.right = None


n = int(sys.stdin.readline())

nodes = [Node() for _ in range(n)]

for _ in range(n):
    id, left, right = map(int, sys.stdin.readline().split())
    if left != -1:
        nodes[id].left = left
        nodes[left].parent = id
    if right != -1:
        nodes[id].right = right
        nodes[right].parent = id


def preorder(id):
    node = nodes[id]
    yield id
    if node.left is not None:
        yield from preorder(node.left)
    if node.right is not None:
        yield from preorder(node.right)


def inorder(id):
    node = nodes[id]
    if node.left is not None:
        yield from inorder(node.left)
    yield id
    if node.right is not None:
        yield from inorder(node.right)


def postorder(id):
    node = nodes[id]
    if node.left is not None:
        yield from postorder(node.left)
    if node.right is not None:
        yield from postorder(node.right)
    yield id


root_id = next(i for i, node in enumerate(nodes) if node.parent is None)
print('Preorder')
print(' ' + ' '.join(map(str, preorder(root_id))))
print('Inorder')
print(' ' + ' '.join(map(str, inorder(root_id))))
print('Postorder')
print(' ' + ' '.join(map(str, postorder(root_id))))



Measured memory_bytes: 5624
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;



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

	int A, B;
	cin >> A >> B;

	cout << max(max(A + B, A - B), A*B) << endl;

	return 0;
}

Measured memory_bytes: 256
//
// Created by sark2 on 22-10-2019.
//

#include "bits/stdc++.h"

using namespace std;
#define PB push_back
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define CASES int t;cin>>t;while(t--)
#define MP make_pair

using ll = long long;
using ld = long double;

ll mod = 1e9 + 7;


ll gcd(ll a, ll b){
    ll r = a%b;
    while(r){
        a = b;
        b = r;
        r = a%b;
    }
    return b;
}

vector<ll>ma;
void fun(ll a){

    for(ll i = 2; i*i <= a; i++){
        if(a%i == 0)
            ma.PB(i);
        while(a%i == 0)
            a /= i;
    }
    if(a > 1)
        ma.PB(a);
}


int main() {
    IOS

    ll a,b;
    cin>>a>>b;

    ll n = gcd(a,b);


    fun(n);

    cout<<(int)ma.size()+1;


}


Measured memory_bytes: 256
N, A, B , *h = map(int, open(0).read().split())
C = A-B
l = -1
r = 10**12
while l+1<r:
  s = (l+r)//2
  cnt = sum((c-s*B+C-1)//C if c-s*B>0 else 0 for c in h)
  if cnt>s:
    l = s
  else:
    r = s
print(r)

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

int n, p[100005];
int main()
{
	std::cin >> n;
	for (int i = 0; i < n; ++i)
		std::cin >> p[i];

	long long ans = 0;
	bool before = false;
	for (int i = 0; i < n; ++i) {
		if (p[i] == i + 1) {
			if (!before)
				++ans;
			before = !before;
		}
		else
			before = false;
	}

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
//typedef  long double lld;
typedef pair<int,int> pii;
#define M 200005
lli a[M];
int main()
{
   string s,t;
   cin>>s;
   cin>>t;
   int ns,nt,i,j,mn=INT_MAX;
   ns=s.size();
   nt=t.size();
   for(i=0;i<=ns-nt;i++)
   {
       int c=0,k=0;
       for(j=i;j<i+nt;j++)
       {
           if(s[j]!=t[k])
           {
               c++;
           }
           k++;
       }
       mn=min(mn,c);
   }
   cout<<mn;
}


Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>

//エイリアス
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

constexpr ll MOD = 1000000007;

ll modpow(ll n, ll r, ll mod) {
    if(r == 0) return 1;
    if(n == 0) return 0;
    if(r % 2 == 0) {
        ll tmp = modpow(n, r / 2, mod);
        return tmp * tmp % mod;
    }
    else {
        return n * modpow(n, r - 1, mod) % mod;
    }
}

int main(){
    Stream io;

    int N;
    io.read(N);

    ll ans = 0;
    for(int i = 1; i <= N - 1; i++){
        ans += (N - 1) / i;
    }

    cout << ans;

    return 0;
}


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

int main() {
    ll n;
    ll a[200000+10];
    ll result = 0;
    std::cin >> n;
    std::unordered_map<ll, ll> v;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        v[a[i]]++;
    }
    sort(a,a+n,greater<>());
    // 二重取りしていることに気付く
    for (int i = 0; i < n; i++) {
        // std::cout << floor((ll)log2(a[i]))+1  << std::endl;
        ll pair = pow(2,floor((ll)log2(a[i]))+1)-a[i];
        if(v[pair]>0 && v[a[i]]>0){
            
            // 同じ数字だった場合
            if(a[i] == pair){
                // 2個以上あるならOK
                if(v[pair]>1){
                    v[pair]--;
                    v[a[i]]--;
                    result++;
                    
                    // 2回で一回を表すために
                    // i++;
                }
                continue;
            }
            v[a[i]]--;
            v[pair]--;
            result++;
        }else{
            
        }
    }
    std::cout << result << std::endl;
}


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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 200005
#define MOD 1000000007
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pi 3.14159265358979323846
#define Q ll _; cin >> _; while(_--)
#define endl "\n"
#define flush fflush(stdout);

int main(){

    fast;

    ll n,x,t;
    cin >> n >> x >> t;
    ll t1 = n/x;
    if(n%x){
        t1++;
    }
    cout << t1*t << endl;

}

//    cout << fixed << setprecision(12);


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vl a(n);
  rep(i,n){
    cin >> a[i];
    a[i] = (a[i]-(i+1));
  }

  sort(a.begin(), a.end());
  int b = (n % 2 == 0) ? a[n / 2 - 1] : a[(n + 1) / 2 - 1];
  ll ans =0;
  rep(i,n) ans+=abs(a[i]-b);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1792
using System;

class Program
{
    static void Main()
    {
        while(true)
        {
            string[] s = Console.ReadLine().Split(' ');
            int H = int.Parse(s[0]);
            int W = int.Parse(s[1]);
            if (H == 0 && W == 0)
                break;
            for(int i=0;i<H;i++)
            {
                string a = new string('#', W);
                Console.WriteLine(a);
            }
            Console.WriteLine("");
        }
    }
}

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

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

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct Point{
	double x,y;
	Point(){}
	Point(double x,double y):x(x),y(y){}
	Point& operator+=(Point p){
		x+=p.x,y+=p.y;
		return *this;
	}
	Point& operator-=(Point p){
		x-=p.x,y-=p.y;
		return *this;
	}
	Point& operator*=(double c){
		x*=c,y*=c;
		return *this;
	}
	Point& operator/=(double c){
		x/=c,y/=c;
		return *this;
	}
};
Point operator+(Point a,Point b){
	return a+=b;
}
Point operator-(Point a,Point b){
	return a-=b;
}
Point operator*(Point a,double c){
	return a*=c;
}
Point operator*(double c,Point a){
	return a*=c;
}
Point operator/(Point a,double c){
	return a/=c;
}
bool operator==(Point a,Point b){
	return abs(a.x-b.x)<EPS && abs(a.y-b.y)<EPS;
}
bool operator!=(Point a,Point b){
	return !(a==b);
}

double Cross(Point a,Point b){
	return a.x*b.y-a.y*b.x;
}

double Area(const vector<Point>& ps){
	double res=0;
	repi(i,2,ps.size())
		res+=Cross(ps[i-1]-ps[0],ps[i]-ps[0])/2;
	return res;
}

int main()
{
	for(int n;cin>>n && n;){
		vector<Point> ps(n);
		for(auto& p:ps) cin>>p.x>>p.y;
		printf("%.1f\n",Area(ps));
	}
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> img(h);
  
  for (int i = 0; i < h; i++)
      cin >> img.at(i);
  
  for (int i = 0; i < h*2; i++)
    cout << img.at(i/2) << endl;
}

Measured memory_bytes: 3576
using System;
using System.Linq;
using System.Collections;

namespace Ccs
{
    class Program
    {
        static void Main(string[] args)
        {
            var hw = Console.ReadLine().Split(' ')
                .Select(x => int.Parse(x)).ToArray();

            var h = hw[0];
            var w = hw[1];

//            Console.WriteLine("" + h + w);

            var tab  = new char[h, w];

            String s;
            for (int hi = 0; hi < h; ++hi) {
                s = Console.ReadLine();
                for (int wi = 0; wi < w; ++wi) {
                    tab[hi, wi] = s[wi]; 
                }
            }

            bool alone = false;
            for (int hi = 0; hi < h; ++hi)
            {
                if (alone) break;
                for (int wi = 0; wi < w; ++wi)
                {
                    if (tab[hi, wi] != '#')
                        continue;

                    if (hi - 1 >= 0)
                        if (tab[hi - 1, wi] == '#')
                            continue;
                    if (hi + 1 < h)
                        if (tab[hi + 1, wi] == '#')
                            continue;
                    if (wi - 1 >= 0)
                        if (tab[hi, wi - 1] == '#')
                            continue;
                    if (wi + 1 < w)
                        if (tab[hi, wi + 1] == '#')
                            continue;

                    alone = true;
                    break;
                }
            }

            Console.WriteLine(!alone?"Yes":"No");
        }
    }
}


Measured memory_bytes: 11348
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	int A, B, max;
	A = sc.nextInt();
	B = sc.nextInt();

	max = A + B;
	if (max < (A - B))
	    max = A - B;
	if (max < (A * B))
	    max = A * B;

	System.out.println(max);
    }
}

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

int main() {
  int64_t A,B,K,ansT,ansA;
  cin >> A;
  cin >> B;
  cin >> K;
  if (A < K) {
    ansT=0;
    ansA=A+B-K;
  }
  else {
    ansT=A-K;
    ansA=B;
  }
  if (ansA < 0) ansA=0;
    cout << ansT<<" "<< ansA << endl;
}

Measured memory_bytes: 256
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
ll mod = 1000000007LL;


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

	ll a[n];
	rep(i , n) {
		cin >> a[i];
	}

	ll c_max = 0;
	ll ans = 0;
	rep(i, n) {
		if (a[i] < c_max) {
			ans += c_max - a[i];
		} else {
			c_max = a[i];
		}
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 4724
#include <iostream>
#include <map>
using namespace std;


int main(void){
    int n;
    cin >> n;
    map<int,int> m;
    
    for(int i = 0; i < n; i++) {
        int a; cin >> a;
        m[a]++;
    }
    
    int ans = 0;
    for(auto p : m) {
        if (p.second % 2 == 1) ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
#define endl cout << "\n"
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll t, a, b, k=100, flag = 0, x, cnt=0;
    cin >> x;
     while(k<x){
     	k= k*1.01;
     	cnt++;
     }

    cout << cnt << "\n";
   bye;

}

//100


Measured memory_bytes: 3616
#include <stdio.h>

int A[100000];
int partition(int p,int r)
{
  int x,i,j,tmp;
  x = A[r];
  i=p-1;
  for(j=p;j<r;j++)
  {
    if(A[j]<=x)
    {
      i++;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
    tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp;

  return i+1;
}
int main()
{
  int n,i,q;
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    scanf("%d",&A[i]);
  }
  q=partition(0,n-1);
  for(i=0;i<n;i++)
  {
    if(i!=0)printf(" ");
    if(i==q)printf("[%d]",A[i]);
    else printf("%d",A[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2148