akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
/*
bool sw[1000001];
int i;
 
void sws(int k){
        if(k==1){
                sw[i]=true;
                return;
        }
        if(k%2==0) sws(k/2);
        else if(k%3==0) sws(k/3);
        else if(k%5==0) sws(k/5);
        return;
}
*/
// korenisuru
int dp[1000001];
int f(int n){
        if(~dp[n]) return dp[n];
        int ans = 0;
        if(n%2==0) ans |= f(n/2);
        else if(n%3==0) ans |= f(n/3);
        else if(n%5==0) ans |= f(n/5);
        return dp[n] = ans;
}
 
int main() {
        int k,m,n;
        for(int i = 0 ; i <= 1000000 ; i++) dp[i] = -1;
        dp[1] = 1;
        /*
        for(int j=0;j<1000001;j++) sw[j]=false;
        for(i=1;i<1000001;i++) sws(i);
        while(cin >> m,m){
                int ans=0;
                cin >> n;
                for(int j=m;j<=n;j++) if(sw[j]==true) ans++;
                cout << ans << endl;
        }*/
        while(cin >> m && m){
                cin >> n;
                int ans = 0;
                for(int i = m ; i <= n ; i++) ans += f(i);
                cout << ans << endl;
        }
        return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll num = min({a, b, c, d, e});
    cout << (ll)ceil((double)n / num) + 4 << endl;
}

Measured memory_bytes: 256
/**
 * @brief  Knuth, Morris, Prattによる線形時間の文字列照合アルゴリズムを扱う
 *
 * @note  このアルゴリズムは遷移関数δを一度に計算するのを避け、補助関数πだけを用いて照合時間Θ(n)を達成する
 *        ここでは、πは事前にパターンからΘ(m)時間をかけて計算し、配列π[0..m-1]に保存しておく
 *        遷移関数δは必要になった時点で"動的に"配列πから(ならし時間の意味で)効率よく計算する
 *        大雑把に言えば、任意の状態q = 0,1,...,mと任意の文字a ∈ Σに対して、値π[q]はδ(q, a)の計算に必要な
 *        すべての情報を含むが、この情報はaに依存しない. 配列πはm個の要素しか持たず、一方、δはΘ(m|Σ|)個の
 *        要素を持つから、δではなくπを計算することで、前処理時間を1/|Σ|に削減できる
 *
 * @date   2016/04/28
 */



//****************************************
// 必要なヘッダファイルのインクルード
//****************************************

#include <iostream>
#include <cstdint>
#include <cstring>
#include <vector>



//****************************************
// 型シノニム
//****************************************

using string_t  = const char*;
using strlen_t  = std::int32_t;

using radix_t   = std::int32_t;
using prime_t   = std::int32_t;

using state_t   = std::int32_t;
using states_t  = std::vector<state_t>;
using chridx_t  = std::int32_t;
using chrset_t  = std::vector<chridx_t>;
using delta_t   = std::vector<chrset_t>;



 //****************************************
// 関数の宣言
//****************************************

static states_t compute_prefix_function(string_t P);



//****************************************
// 関数の定義
//****************************************

/**
 * @brief  テキストTをPに対して照合する
 * @note   KMP-MATCHERの照合時間はΘ(n)となる
 *
 * @param  string_t T テキストT
 * @param  string_t P パターンP
 */
void kmp_matcher(string_t T, string_t P)
{
    strlen_t n = strlen(T);
    strlen_t m = strlen(P);

    states_t pi = compute_prefix_function(P);
    state_t  q = 0;  // 一致した文字数

    for (strlen_t i = 0; i < n; i++) {                      // 左から右にテキストを走査
        
        while (q > 0 && (P[q] != T[i])) { q = pi[q - 1]; }  // 次の文字が一致しない

        if (P[q] == T[i]) { q = q + 1; }                    // 次の文字が一致した

        if (q == m) {                                       // Pが完全に一致したか判定
            std::cout << i - m + 1 << std::endl;
            q = pi[q - 1];                                  // 次のシフトを探す
        }
    }
}


/**
 * @brief  COMPUTE-PREFIX-FUNCTIONはPをそれ自身に対して照合する
 * @note   COMPUTE-PREFIX-FUNCTIONの実行時間はΘ(m)である
 *
 * @param  string_t P パターンP
 * @return 接頭語関数(prefix function) π[q] = max { k : k < q かつ Pk ] Pq }
 */
states_t compute_prefix_function(string_t P)
{
    strlen_t m = strlen(P);
    states_t pi(m);

    pi[0] = 0;
    strlen_t k = 0;  // 一致した文字数

    for (state_t q = 1; q < m; q++) {                       // 左から右へテキストを走査

        while (k > 0 && (P[k] != P[q])) { k = pi[k - 1]; }  // 次の文字が一致しない
        
        if (P[k] == P[q]) { k = k + 1; }                    // 次の文字が一致した

        pi[q] = k;                                          // kとπ[q]は正しく設定される
    }

    return pi;
}



//****************************************
// エントリポイント
//****************************************

int main()
{
    using namespace std;

    string T, P;

    cin >> T >> P;

    kmp_matcher(T.c_str(), P.c_str());
    
    return 0;
}

Measured memory_bytes: 3136
#include <iostream>

using namespace std;

int main(void){
    int days, A, B, maxA, maxB;
	int* inputs[] = {&days, &A, &B, &maxA, &maxB};
	for (int i = 0; i < (sizeof inputs / sizeof inputs[0]); i++) {
		cin >> *inputs[i];
	}

	int dayA = (A % maxA == 0) ? (A / maxA) : (A / maxA + 1);
	int dayB = (B % maxB == 0) ? (B / maxB) : (B / maxB + 1);
	int dayHw = days - ((dayA >= dayB) ? dayA : dayB);

	cout << dayHw << endl;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n]; int[] G = new int[n];
		int[] GL = new int[n]; int[] GR = new int[n];

		for(int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		GL[0] = 0; GR[n-1] = 0;

		for(int i = 1; i < n; i++) {
			GL[i] = gcm(GL[i-1], a[i-1]);
			GR[n-i-1] = gcm(GR[n-i],a[n-i]);
		}

		for(int i =0; i < n; i++)
			G[i] = gcm(GR[i],GL[i]);

		Arrays.parallelSort(G);

		System.out.println(G[n-1]);

		sc.close();
	}

	public static int gcm(int a, int b) {
		if(a == 0 || b == 0) return Math.max(a, b);
		if(a < b)  {
			return gcm(b, a);
		}else {
			if(a%b == 0) {
				return b;
			}else {
				return gcm(b, a%b);
			}
		}
	}
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

typedef long long ll;

int main() { 
    ll n,m;
    cin >>n;
    m=n;
    if(n%2==1){
        cout<<0<<endl;
        return 0;
    }
    ll ans =0;
    m=10;
    while(1){
        ans += n/m;
        m*=5;
        if(n/m==0) break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
using namespace std;
int A, B;
char S[12];
bool correct = true;
int main() {
  scanf("%d %d", &A, &B);
  scanf("%s", S);
  int i = 0;
  while (i < A) {
    if (S[i] == '-') {
      correct = false;
    }
    i++;
  }
  if (S[i] != '-') {
    correct = false;
  }
  i++;
  while (i < A+B) {
    if (S[i] == '-') {
      correct = false;
    }
    i++;
  }
  if (correct) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
readnum(T::Type{<:Number} = Int) = parse.(T, split(readline()))
let
  _ = readline()
  A = sort(readnum())
  M = A[end]
  B = zeros(Int, M)
  for i in A
    B[i] += 1
    for j in 2i:i:M
      B[j] += 2
    end
  end
  print(sum(B .== 1))
end


Measured memory_bytes: 215160
#include<stdio.h>
int main(){
  int s,d,i;
  
  while(scanf("%d",&d)!=EOF){
    s=0;
    for(i=1;i*d<600;i++){
      s+=i*d*i*d*d;
    }
    printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int p, q, r;
    cin >> p >> q >> r;
    int qq = min(p + q, p + r);
    int e = min(qq, q + r);
    cout << e  << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
int main()
{
  ll N,X,Y,l;
  cin>>N>>X>>Y;
  vector<ll> D(N-1);
  rep(i,N){
    rep(j,N){
      if(i<j){
        l=min(min(j-i,max(j-X+1,X-j-1)+max(i+1-Y,Y-i-1)+1),max(j-Y+1,Y-j-1)+max(i+1-X,X-i-1)+1);
        D.at(l-1)++;
      }
    }
  }
  rep(i,N-1)cout<<D.at(i)<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	long a[5],n;
    scanf("%ld",&n);
    for (int i=0; i<5; i++) {
        scanf("%ld",&a[i]);
    }
    sort(a,a+5);
    if (n%a[0]==0){
        printf("%ld\n",n/a[0]+4);
    } else{
        printf("%ld\n",n/a[0]+5);
    }
}

Measured memory_bytes: 128
import sys
import itertools
import numpy as np

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

N, *A = map(int, read().split())
Anp = np.array(A)

L = np.maximum.accumulate(Anp)
R = np.maximum.accumulate(Anp[::-1])[::-1]

LL = [0] + L.tolist()[:-1]
RR = R.tolist()[1:] + [0]

for x, y in zip(LL, RR):
    print(x if x > y else y)


Measured memory_bytes: 43432
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define TEST int t = 1; while(t--) solve()

void solve(){
    vector<vector<int>> mat(3, vector<int>(3));
    for(int i=0;i<3;i++){
    	for(int j=0;j<3;j++)
    		cin>>mat[i][j];
    }
    int n; cin>>n;
    for(int k=0;k<n;k++){
    	int x; cin>>x;
    	for(int i=0;i<3;i++){
	    	for(int j=0;j<3;j++)
	    		if(mat[i][j] == x)
	    			mat[i][j] = 0;
	    }
    }
    if(mat[0][0]+mat[0][1]+mat[0][2] == 0 ||
       mat[1][0]+mat[1][1]+mat[1][2] == 0 ||
       mat[2][0]+mat[2][1]+mat[2][2] == 0 ||
       mat[0][0]+mat[1][0]+mat[2][0] == 0 ||
       mat[0][1]+mat[1][1]+mat[2][1] == 0 ||
       mat[0][2]+mat[1][2]+mat[2][2] == 0 ||
       mat[0][0]+mat[1][1]+mat[2][2] == 0 ||
       mat[0][2]+mat[1][1]+mat[2][0] == 0 )
    	cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); TEST; return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

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

const double Pi = acos(-1.0);

struct Point {
	double x, y;

	Point() = default;
	Point(double x_, double y_): x(x_), y(y_) {}

	Point operator+(const Point& rhs) const { return Point(x + rhs.x, y + rhs.y); }
	Point operator-(const Point& rhs) const { return Point(x - rhs.x, y - rhs.y); }
	Point operator/(double scalar) const { return Point(x / scalar, y / scalar); }

	double dot(const Point& rhs) const { return x * rhs.x + y * rhs.y; }
	double length() const { return std::sqrt(lengthSq()); }
	double lengthSq() const { return dot(*this); }
	double distanceFrom(const Point& rhs) const { return (*this - rhs).length(); }

	friend Point operator*(double scalar, const Point& rhs) { return Point(scalar * rhs.x, scalar * rhs.y); }
	friend std::istream& operator>>(std::istream& is, Point& rhs) { return is >> rhs.x >> rhs.y; }
};

struct Triangle {
	Point a, b, c;
	
	Triangle(const Point& a_, const Point& b_, const Point& c_) :a(a_), b(b_), c(c_) {}

	double getAngleA() const {
		double
			dist_a = b.distanceFrom(c),
			dist_b = c.distanceFrom(a),
			dist_c = a.distanceFrom(b);
		return acos((-dist_a * dist_a + dist_b * dist_b + dist_c * dist_c) / (2 * dist_b * dist_c));
	}
	
	double getAngleB() const {
		double
			dist_a = b.distanceFrom(c),
			dist_b = c.distanceFrom(a),
			dist_c = a.distanceFrom(b);
		return acos((dist_a * dist_a - dist_b * dist_b + dist_c * dist_c) / (2 * dist_c * dist_a));
	}

	double getAngleC() const { 
		return acos(-1.0) - getAngleA() - getAngleB(); 
	}

	//外心
	Point getCircumCenter() const {
		double
			sin2a = sin(2 * getAngleA()),
			sin2b = sin(2 * getAngleB()),
			sin2c = sin(2 * getAngleC());
		return (sin2a * a + sin2b * b + sin2c * c) / (sin2a + sin2b + sin2c);
	}
	
	friend std::istream& operator>>(std::istream& is, Triangle& rhs) { return is >> rhs.a >> rhs.b >> rhs.c; }
};

int main() {
	int n;
	cin >> n;
	vector<Point>p(n);
	for (Point& e : p) cin >> e;
	if (n == 2) {
		printf("%.12lf\n", 0.5 * p[0].distanceFrom(p[1]));
	}
	else {
		double ans = 1e4;
		rep(i, n - 2) {
			repn(j, i + 1, n - 1) {
				repn(k, j + 1, n) {
					Triangle tri(p[i], p[j], p[k]);
					Point center;
					double r;

					if (0.5 * Pi + 1e-12 < tri.getAngleA()) {
						center = 0.5 * (p[j] + p[k]);
						r = 0.5 * p[j].distanceFrom(p[k]);
					}
					else if (0.5 * Pi + 1e-12 < tri.getAngleB()) {
						center = 0.5 * (p[k] + p[i]);
						r = 0.5 * p[k].distanceFrom(p[i]);
					}
					else if (0.5 * Pi + 1e-12 < tri.getAngleC()) {
						center = 0.5 * (p[i] + p[j]);
						r = 0.5 * p[i].distanceFrom(p[j]);
					}
					else {
						center = tri.getCircumCenter();
						r = p[i].distanceFrom(center);
					}

					bool can = true;
					for (const Point& e : p) {
						if (r + 1e-12 < e.distanceFrom(center)) {
							can = false;
							break;
						}
					}
					if (can) ans = min(ans, r);
				}
			}
		}
		printf("%.12lf\n", ans);
	}
}


Measured memory_bytes: 4348
S = input()

if (S[0] == S[1] and S[2] == S[3] and S[0] != S[2]) or (S[0] == S[2] and S[1] == S[3] and S[0] != S[1]) or (S[0] == S[3] and S[2] == S[1] and S[0] != S[2]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9020
N, M = map(int, input().split())

A = []
for i in range(M):
  A.append(list(map(int, input().split())))

D1 = set(A[i][1] for i in range(M) if A[i][0] == 1)
D2 = set(A[i][0] for i in range(M) if A[i][1] == N)

if len(D1 & D2) != 0:
  print ("POSSIBLE")
else:
  print ("IMPOSSIBLE")

Measured memory_bytes: 59500
function setUp(input) {
  input = input.split("\n");
  A = Number(input[0].split(" ")[0]);
  B = Number(input[0].split(" ")[1]);
  main();
}
function main() {
  var count = 0;
  if (A > B) {
    count += A;
    A--
  } else {
    count += B;
    B--
  }
  if (A > B) {
    count += A;
    A--
  } else {
    count += B;
    B--
  }
  console.log(count);
}

setUp(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 25160
N = int(input())

ans_i = 1
ans = 0
for i in range(N + 1):
    j = i
    cnt = 0
    while j % 2 == 0 and j != 0:
        j = int(j / 2)
        cnt = cnt + 1
    if cnt > ans:
        ans_i = i
        ans = cnt
print(ans_i)


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

const int N=1e6;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

LL a[N],b[N];
LL f[N],g[N];
#define lc (i<<1)
#define rc (lc|1)
inline void modify(int i,int l,int r,int k) {
	if (l==r) f[i]=a[l],g[i]=b[l];
	else {
		int mid=(l+r)>>1;
		k<=mid?modify(lc,l,mid,k):modify(rc,mid+1,r,k);
		f[i]=max(f[lc]+f[rc],g[lc]+g[rc]);
		g[i]=max(f[lc]+g[rc],g[lc]+f[rc]);
	}
}
int main()
{
	int n=gi()*2,m=gi(),i,k;
	for (i=1;i<=n;i++) a[i]=gi();
	for (i=1;i<=n;i++) b[i]=gi();
	b[1]=b[n]=-OO;
	for (i=1;i<=n;i++) modify(1,1,n,i);
	while (m--) {
		k=gi(),a[k]=gi(),b[k]=gi();
		b[1]=b[n]=-OO;
		modify(1,1,n,k);
		printf("%lld\n",f[1]);
	}
	return 0;
}


Measured memory_bytes: 22144
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
using namespace std;
const int Maxn = 1e5;
const int INF = 0x3f3f3f3f;
struct Edge {
    int to,cost;
    Edge(int a,int b){to=a,cost=b;}
};
vector<Edge> G[8*Maxn+5];
void AddEdge(int u,int v,int w) {
    G[u].push_back(Edge(v,w));
    G[v].push_back(Edge(u,w));
}

int dist[8*Maxn+5];
bool vis[8*Maxn+5];
void SPFA(int s) {
    memset(dist,0x3f,sizeof dist);
    memset(vis,false,sizeof vis);
    queue<int> q;

    q.push(s);
    vis[s]=true,dist[s]=0;

    while(!q.empty()) {
        int u=q.front();
        q.pop();vis[u]=false;

        for(int i=0;i<G[u].size();i++) {
            int v=G[u][i].to,w=G[u][i].cost;
            if(dist[v]>dist[u]+w) {
                dist[v]=dist[u]+w;
                if(!vis[v]) {
                    vis[v]=true;
                    q.push(v);
                }
            }
        }
    }
}

map<pair<int,int>,int> P;
int cnt;
int Getid(int u,int c) {
    if(P.find(make_pair(u,c))!=P.end())
        return P[make_pair(u,c)];
    return P[make_pair(u,c)]=++cnt;
}

int N,M;
int main() 
{
    scanf("%d %d",&N,&M);
    cnt=N;
    for(int i=1;i<=M;i++) {
        int u,v,c;
        scanf("%d %d %d",&u,&v,&c);
        int t1=Getid(u,c);
        int t2=Getid(v,c);
        AddEdge(t1,t2,0);
        AddEdge(u,t1,1);
        AddEdge(v,t2,1);
    }
    SPFA(1);
    if(dist[N]==INF)puts("-1");
    else printf("%d\n",dist[N]/2);
    return 0;
}

Measured memory_bytes: 66432
N, M = map(int, input().split())

# 左パート
l, r = 1, N // 2
while M and l < r :
  print(l, r)
  l += 1
  r -= 1
  M -= 1
  
# 右パート
l, r = N // 2 + 2 - N % 2, N
while M :
  print(l, r)
  l += 1
  r -= 1
  M -= 1

Measured memory_bytes: 70180
#include<bits/stdc++.h>
#define Ms(a,b) memset(a,b,sizeof a)
#define db(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
using namespace std;
int n,f[100005],ans;
int main() {
	cin>>n;
	for(int i=1;i<=n;i++){
		f[i]=f[i/10]+1;
		if(f[i]&1)ans++;		
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<ll,pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    ll now1 = x % d, now2;
    if(now1 <= 0)now2 = now1 + d;
    else now2 = now1 - d;
    ll ans1 = inf, ans2 = inf;
    if(abs(x-now1)/d <= k){
        if(( k - abs(x-now1)/d ) % 2 == 0)ans1 = abs(now1);
    }
    if(abs(x-now2)/d <= k){
        if(( k - abs(x-now2)/d ) % 2 == 0)ans2 = abs(now2);
    }
    cout << min(min(ans1, ans2), min(abs(x+d*k), abs(x-d*k)));
}

Measured memory_bytes: 3632
#include <iostream>
//#include <math.h>
#include <set>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
#define pll pair<ll,ll>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main(){
    
    string s,t;
    
    cin >> s>>t;
    
    cout << t+s<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>


#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S,False(1,-1);
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

template<typename A,size_t N,typename T>
void Fill(A(&array)[N],const T &val){
    fill((T*)array,(T*)(array+N),val);
}

const ll INF = 1e10;
int main(){
    int h, w;
    cin >> h >> w;
    vector<string>field(h);
    rep(i, h)cin >> field[i];
    vector<bool> fh(h, false), fw(w, false);
    int cnt = 0;
    rep(i, h){
        rep(j, w){
            if(field[i][j] == '#'){
                fh[i] = true;
                fw[j] = true;
                cnt++;
            }
        }
    }
    bool alh = true, alw = true;
    rep(i, h)if(!fh[i])alh = false;
    rep(j, w)if(!fw[j])alw = false;
    cout << (alh && alw && cnt == h + w - 1 ? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>

using namespace std;

int main(){
    int a, b, c, x, y;

    cin >> a >> b >> c >> x >> y;

    int sum = a*x+b*y, m1, m2;

    m1 = c * (max(x, y) * 2);

    m2 = c * (min(x, y) * 2);
    if(x > y) m2 += a*(x-y);
    else m2 += b*(y-x);

    cout << min(sum, min(m1, m2)) << endl;
}

Measured memory_bytes: 256
n = int(input())
list = input().split()
max = int(list[0])
min = int(list[0])
total = 0
for i in list:
    if max < int(i):
        max = int(i)
    if min > int(i):
        min = int(i)
    total += int(i)
print(min, max, total)


Measured memory_bytes: 6328
import fractions

a,b,c,d = map(int,input().split())
lcm = c * d // fractions.gcd(c,d)

cde = b // c - (a - 1) // c
dde = b // d - (a - 1)  // d
lde = b // lcm - (a - 1)  // lcm

print(b - a + 1 - cde - dde + lde)

Measured memory_bytes: 5048
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<unordered_map>
using namespace std;
#define l long
#define ll long long
#define ull unsigned long long
int main()
{
   int n;cin>>n;
   int w;cin>>w;
   vector<pair<int,ll>>v(n);
   for(int i=0;i<n;i++)
   {cin>>v[i].first>>v[i].second;}
   
   ll dp[n][w+1];
   for(int i=0;i<n;i++)dp[i][0]=0;
  
  for(int i=0;i<=w;i++)
  {if(v[0].first>i)dp[0][i]=0;
    else dp[0][i]=v[0].second;
  }
  for(int i=1;i<n;i++)
  {for(int j=0;j<=w;j++)
  {
      if(v[i].first>j)dp[i][j]=dp[i-1][j];
      else {
          dp[i][j]=max(dp[i-1][j],v[i].second+dp[i-1][j-v[i].first]);
      }
  }
  }
  
 /* for(int i=0;i<n;i++)
  {for(int j=0;j<=w;j++)
  cout<<dp[i][j]<<" ";cout<<endl;}*/
  cout<<dp[n-1][w];
}
   

Measured memory_bytes: 78336
b = raw_input()
N = len(b)
#ACGT

score=0
tmp_score=0

for i in range(N):
	for c in range(N+1):
		if b[i:i+c].count('A')+b[i:i+c].count('C')+b[i:i+c].count('G')+b[i:i+c].count('T') == len(b[i:i+c]):
			tmp_score = len(b[i:i+c])

			if score<tmp_score:
				score=tmp_score
print score



Measured memory_bytes: 2568
#include <iostream>
using namespace std;
typedef long long  ll;

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

int main()
{
	char s[11]; cin >> s;
	char t[11] = {};
	ll p = 0;
	ll i = 0;
	while (s[i]) {
		if (s[i] == '0') {
			t[p++] = '0';
		}
		else if (s[i] == '1') {
			t[p++] = '1';
		}
		else if (s[i] == 'B') {
			if (p != 0) {
				t[--p] = '\0';
			}
		}
		i++;
	}
	cout << t << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a,b;
	
	scanf("%d %d", &a, &b);
	
	int d = a / b;
	int r = a % b;
	double f = 1.0* a / b;
	
	printf("%d %d %lf \n", d, r, f);
	
	return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;

int main() {
	int n, m;
	int a[10001];
	cin >> n >> m;
	FOR(i, 1, m) {
		cin >> a[i];
	}
	FOR(i, 1, m) {
		n -= a[i];
		if (n < 0) {
			ps(-1);
			return(0);
		}
	}
	pv(n);
	return(0);
}

Measured memory_bytes: 3624
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
 
using namespace std;

string s[8];

// ue migiue migi migishita shita hidarishita hidari hidariue
int dy[]={-1,-1,0,1,1,1,0,-1};
int dx[]={0,1,1,1,0,-1,-1,-1};

int cnt(int y,int x,char c){

	if( s[y][x]!='.' ) return 0;

	int res=0;
	for(int k=0;k<8;k++){
		for(int i=1;0<=y+dy[k]*i && y+dy[k]*i<8 && 0<=x+dx[k]*i && x+dx[k]*i<8;i++){
			if(s[y+dy[k]*i][x+dx[k]*i]==c){res+=i-1;break;}
			else if(s[y+dy[k]*i][x+dx[k]*i]=='.') break;
		}
	}

	return res;
}

void update(int y,int x,char c){
	
	s[y][x]=c;

	for(int k=0;k<8;k++){
		int pos=-1;
		for(int i=1;0<=y+dy[k]*i && y+dy[k]*i<8 && 0<=x+dx[k]*i && x+dx[k]*i<8;i++){
			if(s[y+dy[k]*i][x+dx[k]*i]==c){pos=i;break;}
			else if(s[y+dy[k]*i][x+dx[k]*i]=='.') break;
		}
		for(int i=1;i<pos;i++){
			s[y+dy[k]*i][x+dx[k]*i]=c;
		}
	}


}

int main(){

	for(int i=0;i<8;i++) cin>>s[i];

	while(true){
		int change=0;

		//mami o ue hidari
		int add=0;
		int y,x;
		for(int i=0;i<8;i++){
			for(int j=0;j<8;j++){
				int tmp=cnt(i,j,'o');
				if(add<tmp){
					add=tmp;
					y=i,x=j;
				}
			}
		}
		if(add!=0){
			change++;
			update(y,x,'o');

			//cout<<add<<endl;
			//for(int i=0;i<8;i++) cout<<s[i]<<endl;

		}


		//chokoreto x shita migi
		add=0;
		for(int i=7;i>=0;i--){
			for(int j=7;j>=0;j--){
				int tmp=cnt(i,j,'x');
				if(add<tmp){
					add=tmp;
					y=i,x=j;
				}
			}
		}
		if(add!=0){
			change++;
			update(y,x,'x');

			//cout<<add<<endl;
			//for(int i=0;i<8;i++) cout<<s[i]<<endl;
		}		

		if(change==0) break;
	}

	for(int i=0;i<8;i++) cout<<s[i]<<endl;

	return 0;
}

Measured memory_bytes: 3172
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
import time


#D, = map(int,readline().split())
D = 365
*c, = map(int,readline().split())
s = tuple(tuple(map(int,readline().split())) for _ in range(D))

def output(ans):
    for i in ans: print(i+1)

def score(ans,s,c): # ans: 0-indexed としたときのスコアの計算
    last = [-1]*26
    score = 0
    for i, ai in enumerate(ans):
        score += s[i][ai]
        last[ai] = i
        for ci,li in zip(c,last):
            score -= ci*(i-li)
        #print(score) # i日目のスコア
    return score


#ans = [max(range(26),key=lambda x: si[x]) for si in s]
ans = (list(range(26))*20)[:365]

"""
solution = 初期解(ランダム生成や、貪欲法など他の手法で求めたものを利用)
while 時間のある限り:
    solution を(ランダムに)少し変形
    if 変形前より解が悪化:
        solution を変形前の状態に戻す
"""

def main(ans,s,c):
    start = time.time()
    while time.time() - start < 0.5:
        pass
    return ans


#print(score(ans,s,c))
output(main(ans,s,c))







Measured memory_bytes: 9400
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>

#define ll long long int
#define loop(a, n) for(int a = 0; a < n; ++a)
#define INF 114514//1919810
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std

#define MAX_D 1234
#define MAX_N 1234

ll N, ans = 0, buf;


int main()
{
	
	IN >> N;

	loop(a, 9)
	{
		buf = 1;
		loop(b, a + 1) buf *= 10;
		
		ans += (N % buf) / (buf / 10);
	}


	if (N % ans == 0) puts("Yes");
	else puts("No");

	return 0;
}

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

#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

ll N, C;
vector<ll> h;
deque<pll> bag;

ll square(ll x) {
    return x * x;
}

ll cost(pll p, int i) {
    return p.F + square(h[i] - p.S) + C;
}

double intersect(pll p, pll q) {
    return (double) (q.F + square(q.S) - p.F - square(p.S)) / (2 * q.S - 2 * p.S);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> C;
    h.resize(N);
    for (int i = 0; i < N; i++)
        cin >> h[i];
    bag.push_back({0, h[0]});
    for (int i = 1; i < N; i++) {
        pll p, q;

        // Remove partial solutions that are no longer relevant
        p = bag.front();
        bag.pop_front();
        while (!bag.empty() && intersect(p, bag.front()) <= h[i]) {
            p = bag.front();
            bag.pop_front();
        }
        bag.push_front(p);
        q = {cost(p, i), h[i]};

        // Maintain invariant (strictly increasing intersections)
        p = bag.back();
        bag.pop_back();
        while (!bag.empty() && intersect(p, q) <= intersect(bag.back(), p)) {
            p = bag.back();
            bag.pop_back();
        }
        bag.push_back(p);
        bag.push_back(q);
    }
    cout << bag.back().F << endl;
}


Measured memory_bytes: 4096
def main():
    n , d = map(int, input().split())
    cordinate = 0
    for _ in range(n):
        x_i, y_i = map(int, input().split())
        ri = (x_i**2 + y_i**2)**(1/2)
        if ri <= d:
            cordinate += 1
    print(cordinate)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9636
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
D, X = MAP()
A = [INT() for _ in range(N)]

ans = X
for x in A:
	ans += (D-1)//x + 1
print(ans)


Measured memory_bytes: 3896
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    map<int, int> c;
    vector<int> x(N), y(N);
    rep(i, N) { cin >> x[i] >> y[i]; }
    double dist = 0;
    rep(i, N) {
        rep(j, i + 1, N) {
            dist +=
                sqrt(pow(1. * (x[i] - x[j]), 2) + pow(1. * (y[i] - y[j]), 2));
        }
    }
    dist *= 2;
    dist /= N;
    cout << fixed << setprecision(12) << dist << endl;
}


Measured memory_bytes: 3664
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

ll dp[3005][3005][4] = {0};
ll it[3005][3005] = {0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll r,c,k;
    cin >> r >> c >> k;
    rep(i,k){
        ll rr,cc,v;
        cin >> rr >> cc >> v;
        it[rr][cc] = v;
    }
    rep(i,r+1){
        rep(j,c+1){
            rep(s,4){
                if (i < r && it[i+1][j]){
                    chmax(dp[i+1][j][1],dp[i][j][s]+it[i+1][j]);
                }
                chmax(dp[i+1][j][0],dp[i][j][s]);
                if (j < c && s < 3 && it[i][j+1]){
                    chmax(dp[i][j+1][s+1],dp[i][j][s]+it[i][j+1]);
                }
                chmax(dp[i][j+1][s],dp[i][j][s]);
            }
        }
    }
    ll ans = 0;
    rep(i,4){
        chmax(ans,dp[r+1][c][i]);
        chmax(ans,dp[r][c+1][i]);
    }
    PRINT(ans);
}


Measured memory_bytes: 355716
import java.util.Scanner;
public class Main{
 public static void main(String[] args) {
  Scanner kbd = new Scanner(System.in);
   long h=kbd.nextLong();
   long w=kbd.nextLong();

   long x=h*w;
   if(h==1||w==1){
     System.out.println(1);
   }else if(x%2==0){
     System.out.println(x/2);
   }else{
     System.out.println((x+1)/2);
   }
}
}


Measured memory_bytes: 22868
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int k = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		Arrays.parallelSort(a);

		int mod = 1000000007;
		long[] p = new long[100001];
		long[] pi = new long[100001];
		p[0] = 1;
		pi[0] = 1;
		for (int i = 1; i < p.length; i++) {
			p[i] = p[i - 1] * i % mod;
			pi[i] = modinv(p[i], mod);
		}

		long sum1 = 0;
		long sum2 = 0;
		for (int i = 0; i < n; i++) {
			if (n - 1 - i >= k - 1) {
				long val = nCr(n - 1 - i, k - 1, mod, p, pi);
				sum1 += val * a[i];
				sum1 %= mod;
			}
			if (i >= k - 1) {
				long val = nCr(i, k - 1, mod, p, pi);
				sum2 += val * a[i];
				sum2 %= mod;
			}
		}
		long ans = sum2 - sum1;
		if (ans < 0) {
			ans += mod;
		}
		ans %= mod;
		System.out.println(ans);
	}

	static long nCr(int n, int r, int m, long[] p, long[] pi) {
		return p[n] * pi[r] % m * pi[n - r] % m;
	}

	static long modinv(long a, long m) {
		long b = m;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= m;
		if (u < 0) u += m;
		return u;
	}
}


Measured memory_bytes: 45268
#![allow(unused)]

use std::{cell, cmp, collections, fmt, io, iter, ops, str};

use cell::{Cell, RefCell};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use io::{Read, Write};

#[cfg(feature = "debug")]
macro_rules! debug {
    ($($args: tt)*) => { eprint!($($args)*) };
}

#[cfg(feature = "debug")]
macro_rules! debugln {
    ($($args: tt)*) => { eprintln!($($args)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! debug {
    ($($args:tt)*) => {};
}

#[cfg(not(feature = "debug"))]
macro_rules! debugln {
    ($($args:tt)*) => {};
}

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

fn main() {
    let n = parse_line::<usize>();
    let a = parse_vec::<i64>();

    let a = {
        let mut a = a.iter()
            .enumerate()
            .map(|(i, e)| *e - (i as i64 + 1))
            .collect::<Vec<_>>();
        a.sort();
        a
    };

    let ans = if n % 2 == 0 {
        cmp::min(sadness(&a, a[n / 2 - 1]), sadness(&a, a[n / 2]))
    } else {
        sadness(&a, a[n / 2])
    };

    println!("{}", ans);
}

fn sadness(a: &[i64], b: i64) -> i64 {
    a.iter().map(|a| (a - b).abs()).sum()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_owned()
}

fn read_word() -> String {
    const CAPACITY: usize = 16;

    let mut stdin = io::stdin();
    let mut byte: [u8; 1] = [0];

    loop {
        let mut buf = Vec::with_capacity(CAPACITY);

        loop {
            let res = stdin.read(&mut byte);

            if res.unwrap_or(0) == 0 || byte[0] <= b' ' {
                break;
            } else {
                buf.push(byte[0]);
            }
        }

        if !buf.is_empty() {
            return String::from_utf8(buf).unwrap();
        }
    }
}

fn parse_line<T: str::FromStr>() -> T {
    read_line().parse().ok().unwrap()
}

fn parse_word<T: str::FromStr>() -> T {
    read_word().parse().ok().unwrap()
}

fn parse_vec<T: str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn flush() {
    io::stdout().flush();
}


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

int main(){
        int h, w;
        int i, j;

        while(1){
                cin >> h >> w;
                if(h == 0 && w == 0) break;

                for(i=0; i<h; i++){
                        for(j=0; j<w;j++){
                                cout << "#";
                        }
                        cout << endl;
                }
                cout << endl;
        }

        return 0;
}

Measured memory_bytes: 3036
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// AtCoder_B
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		long max = a*c;
		if(max < a*d) {
			max = a*d;
		}
		if(max < b*c) {
			max = b*c;
		}
		if(max < b*d) {
			max = b*d;
		}

		System.out.println(max);

	    // Scannerクラスのインスタンスをクローズ
		sc.close();
	}
}


Measured memory_bytes: 35816
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	set<string> s;
	int N;
	
	cin>>N;
	
	for(int i = 0; i< N; i++){
		string S;
		
		cin>>S;
		
		s.insert(S);
	}
	
	cout<<s.size()<<endl;
	
	return 0;
}

Measured memory_bytes: 19244
n,m = map(int,input().split())

max_L = []
min_R = []

cnt = 0
for i in range(m):
    L,R = map(int,input().split())
    max_L.append(L)
    min_R.append(R)
if max(max_L) <= min(min_R):
    print(min(min_R)-max(max_L)+1)
else:
    print(0)

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

vector<int> g[15];

int main(){
    int N,M; cin >> N >> M;
    for(int i=0;i<M;i++){
        int a,b; cin >> a >> b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int array[N];
    for(int i=0;i<N;i++) array[i]=i;

    int ans=0;
    do{
        bool flag=true;
        for(int i=0;i<N-1;i++){
            bool now=false;
            if(array[0]!=0){
                flag=false;
                break;
            }
            for(auto j:g[array[i]]){
                if(j==array[i+1]){
                    now=true;
                    break;
                }
            }
            if(now==false){
                flag=false;
                break;
            }

        }
        if(flag) ans++;
    }while(next_permutation(array,array+N));
    cout << ans << endl;
}

Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    N=STR()
    if N[0]==N[2]:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    do()

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	for (int n; cin >> n&&n;) {
		bool l = false, r = false;
		char prev = 'd';
		int cnt = 0;
		rep(i, 0, n) {
			string s; cin >> s;
			if (s == "lu") {
				l = true;
			}
			if (s == "ru") {
				r = true;
			}
			if (s == "ld") {
				l = false;
			}
			if (s == "rd") {
				r = false;
			}
			if (prev == 'd' && l && r) {
				cnt++;
				prev = 'u';
			}
			if (prev == 'u' && !l && !r) {
				cnt++;
				prev = 'd';
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
template<class T>
inline T qread(T &IEE){
	register T x = 0, f = 1;
	register char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-'){
			f = -f;
		}
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return IEE = x * f;
}
template<class T>
inline void qwrite(T a){
	if(!a){
		putchar('0');
		return ;
	}
 	if(a < 0){
		putchar('-');
		a = -a;
	}
	if(a > 9) qwrite(a / 10);
	putchar(a % 10 + 48);
	return ;
}
template<class T>
inline T ab(T a){
	return (a > 0) ? a : -a;
}
template<class T>
inline void swa(T &a, T &b){
	a ^= b ^= a ^= b;
	return ;
}
ll ans, cnt, n, m, q;
ll a[maxn], x[maxn], y[maxn], z[maxn], u[maxn];
void dfs(ll now){
	if(now == n + 1){
		cnt = 0;
		for(int i = 1;i <= q;i++){
			if(a[y[i]] - a[x[i]] == z[i]){
				cnt += u[i];
			}
		}
		ans = max(ans, cnt);
		return ;
	}
	for(int i = a[now - 1];i <= m;i++){
		a[now] = i;
		dfs(now + 1);
	}
	return ;
}
int main(){
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	qread(n);
	qread(m);
	qread(q);
	for(int i = 1;i <= q;i++){
		qread(x[i]);
		qread(y[i]);
		qread(z[i]);
		qread(u[i]);
	}
	a[0] = 1;
	dfs(1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3660
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    int n, k;
    cin >> n >> k;
    vector<int> a(n), f(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> f[i];
    sort(all(a));
    sort(all(f));
    reverse(all(f));
    int l = -1, r = INF, m, cur;
    while (r - l > 1) {
        m = (l + r) / 2;
        cur = 0;
        for (int i = 0; i < n; i++) {
            cur += max(a[i] - m / f[i], 0LL);
        }
        if (cur <= k) r = m;
        else l = m;
    }
    cout << r;
}
/*

*/


Measured memory_bytes: 3328