akhauriyash/Code-Regression huggingface dataset:
from math import hypot

def half_point(p1,p2):
    x = (p1[0] + p2[0]) / 2
    y = (p1[1] + p2[1]) / 2
    r = hypot(p1[0] - p2[0], p1[1] - p2[1]) / 2
    return (x, y, r)

def three_points_on_a_line(p1,p2,p3):
    dx1 = p1[0] - p2[0]
    dy1 = p1[1] - p2[1]
    dx2 = p1[0] - p3[0]
    dy2 = p1[1] - p3[1]

    return dx1 * dy2 == dx2 * dy1

def same_point(p1,p2,p3):
    return p1 == p2 or p1 == p3 or p2 == p3

def gaisin(p1,p2,p3):
    a = p1[0]
    b = p1[1]
    c = p2[0]
    d = p2[1]
    e = p3[0]
    f = p3[1]

    aa = a * a
    bb = b * b
    cc = c * c
    dd = d * d
    ee = e * e
    ff = f * f

    py = ((e - a) * (aa + bb - cc - dd) - (c - a) * (aa + bb - ee- ff)) / (2 * (e - a)*(b - d) - 2 * (c - a) * (b - f))

    px = (2 * (b - f) * py - aa - bb + ee + ff) / (2 * (e - a)) \
        if (c == a) else (2 * (b - d) * py - aa - bb + cc + dd) / (2 * (c - a))

    r = hypot(px - a, py - b)

    return (px,py,r)

def in_c(x,y,r,px,py):

    if hypot(x-px,y-py) > r+10**(-6):
        return False
 
    return True

def main():
    
    N = int(input())
    X = []
    for _ in range(N):
        x, y = map(int, input().split())
        X.append((x,y))
    
    cand = []
    for i in range(N):
        for j in range(i+1,N):
            # 直線の中点を候補に追加する
            cand.append(half_point(X[i],X[j]))

            # 三点から外心を求める
            for k in range(j+1,N):
                if same_point(X[i],X[j],X[k]) or three_points_on_a_line(X[i],X[j],X[k]):
                    continue
                cand.append(gaisin(X[i],X[j],X[k]))

    ans = float('inf')
    for px, py, r in cand:
        flag = True
        for x, y in X:
            if not in_c(x,y,r,px,py):
                flag = False
                break 
        if flag:
            ans = min(ans, r)

    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 50540
# coding: utf-8
# Your code here!
N,W=map(int,input().split())

dp=[-1]*(W+1)
dp[0]=0

for _ in range(N):
    w,v=map(int,input().split())
    for i in range(W+1)[::-1]:
        if dp[i]!=-1 and i+w<=W:
            dp[i+w]=max(dp[i+w],dp[i]+v)

print(max(dp))    

Measured memory_bytes: 68552
using System.Linq;
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        var lst = new LinkedList<int>();

        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var cmd = line[0];
            switch(cmd)
            {
                case "insert":
                    lst.AddFirst(int.Parse(line[1]));
                    break;
                case "delete":
                    lst.Remove(int.Parse(line[1]));
                    break;
                case "deleteFirst":
                    lst.RemoveFirst();
                    break;
                case "deleteLast":
                    lst.RemoveLast();
                    break;
            }
        }
        var count = 1;
        foreach (var x in lst)
        {
            Console.Write(x);
            if (count == lst.Count()) Console.WriteLine();
            else Console.Write(" ");
            count++;
        }
    }
}

Measured memory_bytes: 83176
H,W=map(int, input().split())
S=[[] for _ in range(H)]
for i in range(H):
    S[i]=list(input())

for i in range(H):
    for j in range(W):
        if S[i][j]=='#':
            isOK=False
            if i-1 >= 0 and S[i-1][j]=='#':
                isOK=True
            if j-1 >= 0 and S[i][j-1]=='#':
                isOK=True
            if i+1 <= H-1 and S[i+1][j]=='#':
                isOK=True
            if j+1 <= W-1 and S[i][j+1]=='#':
                isOK=True
            
            if isOK==False:
                print("No")
                exit()

print("Yes")

Measured memory_bytes: 39408
x = int(input())
coins = [500, 5]
happy = [0] * 2
for coin in coins:
    if coin == 500:
        happy[0] = x // coin
    elif coin == 5:
        happy[1] = x // coin
    x = x % coin

print(1000 * happy[0] + 5 * happy[1])

Measured memory_bytes: 38256
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

#define for0(i,n) for(ll i = 0;i < (n);i++)
#define for1(i,n) for(ll i = 1;i<=(n);i++)
#define for2(i,n) for(ll i = 2;i<=(n);i++)
#define fastio cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define rep(i,st,en,cnt) for(ll i = st;i <= en;i+=cnt)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define bit(x,n) (x & (1<<(n)))
#define EPS 1e-8
#define all(x) (x).begin(),(x).end()
#define INF 0x3f3f3f3f3f3f3f
#define NEGINF -INF
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define inp_arr(a,n) for0(i,n) {cin>>a[i];}
#define out_arr(a,n) for0(i,n) {cout<<a[i]<<" ";}cout<<endl;
#define deb1(a) cout<<(a)<<endl;
#define deb2(a,b) cout<<(a)<<" "<<(b)<<endl;
#define deb3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl;

using namespace std;

typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<pair<long long, long long> > vll;
typedef long double LD;

ii DR8[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
ii DR4[] = {{-1,0},{0,-1},{0,1},{1,0}};

const ll mod = 1e9+7;

// ll nop = 2;
// vi primes(nop+1,1);

// void sieve(){
//     primes[1] = primes[0] = 0;
//     for(ll i = 2;i * i <= nop;i++){
//         if(primes[i]){
//             for(ll j = i*i; j <= nop;j+=i){
//                 primes[j] = 0;
//             }
//         }
//     }
// }

// ll phi(ll n) {
//     ll tot = n;
//     for(ll i = 2;i*i <= n;i++) {
//         if(n%i == 0) {
//             tot -= tot/i;
//         }
//         while(n%i == 0) {
//             n /= i;
//         }
//     }
//     if(n > 1) {
//         tot -= tot/n;
//     }
//     return tot;
// }

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

void extgcd(ll a,ll b,ll& x,ll& y){  //a smaller b larger
    if(a==0) {
        x = a;y = b;
        return;
    }
    extgcd(b%a,a,x,y);
    ll y1 = y,x1 = x;
    x = y1 - (b/a)*x1;
    y = x1;
}

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

ll bexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans *= num;
        }
        num *= num;
        e>>= 1;
    }
    return ans;
}

ll mexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans = (ans *num)%mod;
        }
        num *= num;
        num %= mod;
        e>>=1;
    }
    return ans%mod;
}

ll modinv(ll a){
    a %= mod;
    return mexp(a,mod-2);
}

void solve() {
    string s;
    cin>>s;
    if(s[s.length()-1] == 's') deb1(s+"es")
    else deb1(s+"s")
}


int main() {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t = 1;
    //cin>>t;
    for1(T,t){
        //cout<<fixed<<setprecision(8);
        //cout<<"Case #"<<T<<": ";
        solve();
    }
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif */
    return 0;
}


Measured memory_bytes: 3652
from math import ceil
N,K = map(int, input().split())
A = list(map(int, input().split()))

def is_ok(arg):
  # 条件を満たすかどうか？問題ごとに定義
  # arg以下になるように各々の木をきる。回数を足し合わせて、K以下かどうか判定する
  cnt = 0
  for a in A:
    cnt += ceil(a / arg) - 1
  return cnt <= K

def meguru_bisect(ng, ok):
  '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
  '''
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

ng = 0
ok = 10**9 + 1

ans = meguru_bisect(ng,ok)
print(ceil(ans))

Measured memory_bytes: 93780
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


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


int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N), B(N);
  vector<ll> v;
  ll asum = 0;
  REP(i, N) {
    cin >> A[i];
    asum += A[i];
  }

  ll ans = 0, hituyo = 0;
  ll bsum = 0;
  REP(i, N) {
    cin >> B[i];
    bsum += B[i];
    if (A[i] - B[i] < 0) {
      ans++;
      hituyo += B[i] - A[i];
    }
    v.PB(A[i] - B[i]);
  }
  if (asum < bsum) {
    cout << -1 << endl;
    return 0;
  }

  sort(ALL(v), greater<ll>());
  ll sum = 0, cnt = -1;
  for (ll i = 0; i < v.size(); i++) {
    if (sum >= hituyo) {
      cnt = i;
      break;
    }
    sum += v[i];
  }
  ans += cnt;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2936
#__author__ = "tatuo"
#__date__ = "$Mar 3, 2018 12:34:20 PM$"

import math
import re
import sys


def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result




arr_data = getinputdata()

n=int(arr_data[0][0])


print(n//3)

Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>
int main()
{
  char s[19];
  char *p;
  
  scanf("%s",s);
  p = strtok(s, ",");
  printf("%s", p);
  
  while(p!= NULL) {
    p = strtok(NULL, ",");
    if(p!= NULL) {
      printf(" %s", p);
    }
  }
   
  return 0;
}

Measured memory_bytes: 128
s = input()
n = len(s)
m = 2019
a = 0
r = [0 for _ in range(m+1)]
r[0] = 1
z = 0
for i in range(0,n):
    z = (int(s[n-i-1])*pow(10,i,m) + z)%m
    a += r[z]
    r[z] += 1
print(a)


Measured memory_bytes: 9220
import sys
import numpy as np
read = sys.stdin.read


class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if self.root[x] < 0:
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if x == y:
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


N, *xy = map(int, read().split())
xy = np.array(xy, np.int64).reshape(N, 2)
x = xy[:, 0]
y = xy[:, 1]

arg_x = np.argsort(x)
arg_y = np.argsort(y)

edges_x = x[arg_x[1:]] - x[arg_x[:-1]]
edges_y = y[arg_y[1:]] - y[arg_y[:-1]]

edges = np.concatenate([edges_x, edges_y])
towns_1 = np.concatenate([arg_x[:-1], arg_y[:-1]])
towns_2 = np.concatenate([arg_x[1:], arg_y[1:]])

arg_edges = np.argsort(edges)
graph = zip(edges[arg_edges].tolist(), towns_1[arg_edges].tolist(), towns_2[arg_edges].tolist())

tree = UnionFind(N)
answer = 0

for d, t1, t2 in graph:
    if tree.isSameGroup(t1, t2):
        continue

    tree.Unite(t1, t2)
    answer += d

print(answer)

Measured memory_bytes: 49012
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for(int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for(int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for(auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef priority_queue<ll, vl> decendingQueue;              //降順
typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

void solve(long long N, std::vector<long long> A) {
    sort(all(A));

    ll minusIndex = 0;
    while(minusIndex < A.size() && A[minusIndex] <= 0) {
        minusIndex++;
    }
    if(minusIndex > 0) {
        minusIndex--;
    }
    if(minusIndex == A.size() - 1) {
        minusIndex = A.size() - 2;
    }

    vector<pair<ll, ll>> ansPair;
    ll tmp = A[minusIndex + 1];
    rep(j, 1, minusIndex + 1) {
        ansPair.push_back(mp(tmp, A[j]));
        tmp -= A[j];
    }
    ll tmp2 = A[0];
    rep(j, minusIndex + 2, N) {
        ansPair.push_back(mp(tmp2, A[j]));
        tmp2 -= A[j];
    }
    ansPair.push_back(mp(tmp, tmp2));
    ll ans = tmp - tmp2;

    print(ans);
    rep(i, 0, ansPair.size()) {
        print(ansPair[i].first << " " << ansPair[i].second);
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for(int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4336
from collections import defaultdict

N,M = map(int,input().split())

D = defaultdict(list)

for i in range(M):
    a,b = map(int,input().split())
    D[a].append(b)
    D[b].append(a)

S = [[[1],1]] #Stack 初期はwalked=[1]のnow=1
ans = 0
def dfs(ans,S):
    while(len(S)>0):
        SS = S.pop()
        walked,now = SS[0],SS[1]
        #print(SS)
        for d in D[now]:
            if d not in walked:
                ans = dfs(ans,[[walked+[d],d]])
        if len(walked)==N: return ans+1
    return ans

print(dfs(ans,S))

Measured memory_bytes: 3316
#include<stdio.h>


int main(){

    int a,b,c,d,e;
    scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);

    if(a!=1){
        printf("1");
        return 0;
    }
    if(b!=2){
        printf("2");
        return 0;
    }
    if(c!=3){
        printf("3");
        return 0;
    }
    if(d!=4){
        printf("4");
        return 0;
    }
    if(e!=5){
        printf("5");
        return 0;
    }
    return 0;
}

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

int main()
{
    int N, A, B;
    cin >> N >> A >> B;

    int ans = 0;
    bool brk = false;
    for(int h = 0; h <= 1 && !brk; h++) {
        for(int i = 0; i <= 9 && !brk; i++) {
            for(int j = 0; j <= 9 && !brk; j++) {
                for(int k = 0; k <= 9 && !brk; k++) {
                    for(int l = 0; l <= 9 && !brk; l++) {
                        int n = 10000*h + 1000*i + 100*j + 10*k + l;
                        int s = h+i+j+k+l;
                        if(s >= A && s <= B)
                            ans += n;
                        if(n >= N)
                            brk = true;
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad

main :: IO ()
main = readLn >>= main'
    where
        main' n = breads >>= print . solve n

solve :: Int -> [Int] -> Int
solve n xs = 3 ^ n - foldl' ff 1 xs
    where
        ff acc x
            | odd x = acc
            | otherwise = acc * 2



breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)


Measured memory_bytes: 508
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

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

    size_t count = 0;

    char prev = S[0];
    for (size_t i = 1; i < S.size(); ++i) {
        char c = S[i];
        if (prev != c) {
            count++;
            prev = c;
        }
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
	srand(time(0));
	rand(); rand(); rand(); rand(); rand();
	int d;
	scanf("%d", &d);
	int c[30];
	int i;
	for (i = 0; i < 26; i++)
		scanf("%d", &c[i]);
	int j;
	int s[400][30];
	for (i = 0; i < d; i++)
		for (j = 0; j < 26; j++)
			scanf("%d", &s[i][j]);
	int l[400][30];
	for (i = 0; i < 26; i++)
		l[0][i] = 0;
	int t[400];
	for (i = 0; i < d; i++)
		t[i] = (26 * 400 - i) % 26;
	int dd, q;
	int a;
	for (i = 1; i <= d; i++)
	{
		for (j = 0; j < 26; j++)
			l[i][j] = l[i - 1][j];
		l[i][t[i - 1]] = i;
	}
	int ans = 0;
	for (i = 0; i < d; i++)
	{
		ans += s[i][t[i]];
		for (j = 0; j < 26; j++)
			ans -= c[j] * (i + 1 - l[i + 1][j]);
	}
	int ans2;
	int k;
	for (k = 0; k < 200005; k++)
	{
		dd = rand() % d;
		q = rand() % 26;
		ans2 = ans;
		a = t[dd];
		ans -= s[dd][a];
		ans += s[dd][q];
		t[dd] = q;
		for (i = 0; i < d; i++)
		{
			ans += c[a] * (i + 1 - l[i + 1][a]);
			ans += c[q] * (i + 1 - l[i + 1][q]);
			l[i + 1][a] = l[i][a];
			l[i + 1][q] = l[i][q];
			l[i + 1][t[i]] = i + 1;
			ans -= c[a] * (i + 1 - l[i + 1][a]);
			ans -= c[q] * (i + 1 - l[i + 1][q]);
		}
		if (ans2 > ans)
		{
			t[dd] = a;
			ans = ans2;
			for (i = 1; i <= d; i++)
			{
				for (j = 0; j < 26; j++)
					l[i][j] = l[i - 1][j];
				l[i][t[i - 1]] = i;
			}
		}
	}
	for (i = 0; i < d; i++)
		printf("%d\n", t[i] + 1);
	return 0;
}

Measured memory_bytes: 1824
N, WW = map(int, input().split())
W = [0] * N
V = [0] * N
for i in range(N):
    w, v = map(int, input().split())
    W[i] = w
    V[i] = v
dp = [[0]*(WW+1) for _ in range(N+1)]
for n in range(1, N+1):
    w = W[n-1]
    v = V[n-1]
    for sum_w in range(WW+1):
        if sum_w <= WW - w:
            # n番目の商品を選ぶ
            dp[n][sum_w+w] = max(dp[n-1][sum_w] + v, dp[n][sum_w+w])
        dp[n][sum_w] = max(dp[n-1][sum_w], dp[n][sum_w])
print(dp[-1][-1])

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

using ll = long long;

const int mod = 1e9+7; 

int main(){
	int n;
	cin >> n;
	vector<vector<int>>v(n,vector<int>(n));
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin >> v[i][j];
		}
	} 
	vector<int> dp(1<<n);

	dp[0]=1;
	for(int mask = 0;mask<(1<<n)-1;++mask){
		int a =__builtin_popcount(mask);
		for(int b=0;b<n;b++){
			if(v[a][b] && !(mask & (1<<b))){
				int m2 = mask^(1<<b);
				dp[m2] = (dp[m2]+dp[mask])%mod;
			}
		}
	}

	cout << dp[(1<<n)-1] << "\n";
	return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << 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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll x;
  cin >> x;
  ll a = x / 200;
  print(10 - a);
}

Measured memory_bytes: 3632
import java.io.*;

public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            for (int i = 1; ; i++) {
                String line = reader.readLine();
                int n = Integer.parseInt(line);
                if (n == 0) {
                    break;
                } else {
                    System.out.println("Case " + i + ": " + n);
                }
            }
        } catch (IOException e) {
            System.out.println(e);
        } catch (NumberFormatException e) {
            System.out.println("??°????????¢????????£????????????????????????");
        }
    }
}

Measured memory_bytes: 31452
#include <stdio.h>

int main() {
   int N,A;
   int c = 1;
   scanf("%d", &N);

   for(int i = 1; i <= N; i++){
      scanf("%d", &A);
      if(A % 2 == 0){
         if((A%3) * (A%5) != 0) {
            c = 0;
         }
      }
   }
   if(c == 1) {
      printf("APPROVED");
   }else {
      printf("DENIED");
   }
   printf("\n");
   return 0;
}


Measured memory_bytes: 1712
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
const MOD: u64 = 1000000007;


fn main() {
    input!{
        N: isize, K: isize,
        X: isize, Y: isize,
    }

    println!("{}", min(N ,K) * X + max(0, (N - K)) * Y);
}

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

const int MAXN = 1e5 + 5;

int n, A[2], ans;
vector<int> adj[MAXN];
int dist[2][MAXN];
bool visited[MAXN];

int main(){
	scanf("%d %d %d", &n, &A[0], &A[1]);
	for(int i = 0; i < n-1; ++i){
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for(int j = 0; j < 2; ++j){
		memset(visited, 0, sizeof visited);
		queue<int> q;
		q.push(A[j]);
		while(!q.empty()){
			int top = q.front(); q.pop();
			if(visited[top])
				continue;
			visited[top] = true;
			for(int i : adj[top]){
				if(!visited[i]){
					dist[j][i] = dist[j][top]+1;
					q.push(i);
				}
			}
		}
	}
	for(int i = 1; i <= n; ++i){
		// printf("(%d, %d)\n", dist[0][i], dist[1][i]);
		if(dist[0][i] < dist[1][i]){
				ans = max(ans, dist[1][i]-1);
		}
	}
	printf("%d\n", ans);
}

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

int main(){
  string s;
  cin >> s;
  int a,z;
  for(int i=0;i<s.length();i++){
    if(s[i]=='A'){
      a=i;
      break;
    }
  }
  for(int i=s.length()-1;i>0;i--){
    if(s[i]=='Z'){
      z=i;
      break;
    }
  }
  cout << z-a+1;
}


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

int main() {

    int N, M;
    cin >> N >> M;

    int X[100010];

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

    sort(X, X+M);

    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }

    int D[100010];
    for (int i = 1; i < M; i++) {
        D[i - 1] = X[i] - X[i - 1];
    }

    sort(D, D + M - 1);

    int sum = 0;
    for (int i = 0; i < M - N; i++) {
        sum += D[i];
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define maxn 300005
#define mo 1000000007
using namespace std;

int n,s[maxn],i,j,k,mx,f[2][3][3],ans;

int main(){
	int p=0,q=1;f[0][0][0]=1;
	for(char ch=getchar();ch=='0'||ch=='1'||ch=='?';ch=getchar()){
		p^=1,q^=1,memset(f[p],0,sizeof(f[p]));
		if (ch=='0'||ch=='?'){
			for(i=0;i<3;i++) for(j=0;j<3;j++) 
				(f[p][i][j?(3-j):1]+=f[q][i][j])%=mo;
		} 
		if (ch=='1'||ch=='?'){
			for(i=0;i<3;i++) for(j=0;j<3;j++)	
				(f[p][min(2,i+(j==0))][max(j-1,0)]+=f[q][i][j])%=mo;
		}
	}
	for(i=0;i<3;i++) for(j=0;j<3;j++) if (i>=2||j==0) (ans+=f[p][i][j])%=mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 1576
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MAX_INF = 9223372036854775807;
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init, ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T>& v) {
	T ans = -INF;
	rep(i, 0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C & c, std::ostream & os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}
/*
ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}
*/
bool sortreverse(ll a, ll b) {
	return a > b;
}


ll kiriage(ll a, ll b) {
	if (a % b == 0)return a / b;
	return a / b + 1;
}

ll n, m, t, q, s,k,h,w;

void warshall_floyd(ll v_num,vector<vector<long long>> &d) {
	for (long long k = 0; k < v_num; k++) {       // 経由する頂点
		for (long long i = 0; i < v_num; i++) {    // 始点
			for (long long j = 0; j < v_num; j++) {  // 終点
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

ll solv(ll num,ll h,vvl &res) {
	if (h + 1 >= res.size())return 0;
	rep(i, h, res[h].size()) {
		res[h][i] = num;
		res[i + 1][h] = num;
		++num;
	}
	solv(num, h + 1, res);
}

int main() {
	cin >> n;
	ll gyou = 0;
	rep(i, 0, n+3) {
		if (i * (i + 1) / 2 == n) {
			gyou = i;
			break;
		}
		if (i * (i + 1) / 2 > n) {
			printf("No");
			exit(0);
		}
	}
	vvl res(gyou + 1, vl(gyou));
	solv(1, 0, res);
	printf("Yes\n%lld\n", gyou + 1);
	rep(i, 0, gyou + 1) {
		printf("%lld ", gyou);
		rep(j, 0, gyou-1) {
			printf("%lld ", res[i][j]);
		}
		printf("%lld\n",res[i].back());
	}
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

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

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int x, y, z;
    cin >> x >> y >> z;

    x -= z;
    cout << (x / (y + z)) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int max(int a,int b)
{return a>b?a:b;}
int main(void){
int a,b,ans1,ans2,ans3,ans;
  scanf("%d%d",&a,&b);
  ans1 = a*b;
  ans2 = a-b;
  ans3 = a+b;
ans = max(ans1,max(ans2,ans3));
printf("%d\n",ans);
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,sum=0,coun=0;
    cin>>n>>m;
    int arr[n+5];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        sum+= arr[i];
    }
    for(int i=0;i<n;i++)
    {
        if(arr[i]*4*m>=sum)
            coun++;
    }
    if(coun>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int N; cin >> N;
    vec A(N); readv(A);

    vector<Pii> p(N);
    REP(i, N) p[i] = Pii(A[i], i);
    SORT(p);

    int ans = 0;
    REP(i, (N + 1) / 2) if(p[i * 2].second % 2 == 1) ans++;
    cout << ans;

    return 0;
}

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

int main(){
  int tilelong,tiles;
  int tposx,tposy;
  int tmark,tmord,tmark2;

  cin >> tilelong >> tiles;
  vector<int> color(tiles);
  tmark = (tilelong/2)+(tilelong%2);
  tmark2 = tilelong + 1;
  for(int n = 0;n<tiles;n++){
    cin >> tposx >> tposy;
    if(tposx > tmark){
      tmord = 2;
      if(tposy > tmark){
        tmord = 4;
      }
    }
    if(tposx <= tmark){
      tmord = 1;
      if(tposy > tmark){
        tmord = 3;
      }
    }

    switch(tmord){
      case 2:
      tposx = tmark2 - tposx;
      break;
      case 3:
      tposy = tmark2 - tposy;
      break;
      case 4:
      tposx = tmark2 - tposx;
      tposy = tmark2 - tposy;
      break;
    }

    if(tposx > tposy){
      color[n] = tposy % 3;
    }else{
      color[n] = tposx % 3;
    }
  }
  for(int n = 0;n<tiles;n++){
    if(color[n] == 0){
      color[n] = 3;
    }
    cout << color[n] << endl;
  }
}

Measured memory_bytes: 1196
# -*- coding: utf-8 -*-

N = int(input().strip())
S_list = [input().strip() for _ in range(N)]
#-----

def count_brackets(brackets):
    L = R = 0
    L_rev = R_rev = 0
    max_R = 0
    max_L = 0
    
    
    for i in range(len(brackets)):
        if brackets[i] == "(":
            L += 1
        else:  # brackets[i] == ")"
            R += 1
            max_R = max(max_R, R - L)
        
        if brackets[len(brackets)-1-i] == "(":
            L_rev += 1
            max_L = max(max_L, L_rev - R_rev)
        else:  # brackets[len(brackets)-1-i] == ")"
            R_rev += 1
    
    
    return max_L, max_R


tmp_cnt1 = []  #  the number of "("  >=  the number of ")"
tmp_cnt2 = []  #  the number of "("  <   the number of ")"

for S in S_list:
    cnt_L,cnt_R = count_brackets(S)

    if cnt_L == cnt_R == 0:
        continue
    
    if cnt_L >= cnt_R:
        tmp_cnt1.append( (cnt_L,cnt_R) )
    else:
        tmp_cnt2.append( (cnt_L,cnt_R) )


tmp_cnt1.sort(key=lambda x: x[1])
tmp_cnt2.sort(key=lambda x: -x[0])


sum_bracket = 0
flag = True

for cnt_L,cnt_R in (tmp_cnt1 + tmp_cnt2):
    sum_bracket -= cnt_R
    if sum_bracket < 0:  flag = False
    
    sum_bracket += cnt_L
    if sum_bracket < 0:  flag = False
    
    if flag == False:
        break


if (sum_bracket == 0) and flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 244956
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <cmath>
#include <cstdio>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)

const double PI=4*atan(1.0);
typedef complex<double> P;

// àÏ
double dot(P a, P b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}
// OÏ
double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}
// a©çbÖ¶üèÅ½x©
double diffAngle(P a,P b){
  // cos>0&&sin>0 -> 0 -> 90
  // cos<0&&sin>0 -> 90->180
  // cos<0&&sin<0 -> 180->270
  // cos>0&&sin<0 -> 270 -> 359
    double cosn=dot(a,b)/(abs(a)*abs(b));
    double sinn=cross(a,b);
    if(cosn>1.0)
        cosn=1.0;
    else if(cosn<-1.0)
        cosn=-1.0;
    double angle=acos(cosn);
    if(sinn>0||EQ(sinn,0))
        return angle;
    return 2*PI-angle;
    //double angle=atan2(cross(a,b)/(abs(a)*abs(b)),dot(a,b)/(abs(a)*abs(b)));
    //if(angle<0)
    //    return 2*PI+angle;
    //return angle;
}

int main(){
    int n;
    while(cin>>n&&n!=0){
        vector<P> points;
        for(int i = 0; i < n; i++){
            int x,y;
            cin>>x>>y;
            points.push_back(P(x,y));
        }
        vector<bool> isUsed(points.size(),false);
        double sum=0;
        P cp=P(0,1);
        P pp=P(0,0);
        int cnt=n;
        while(cnt--){
            int idx=-1;
            double minAngle=100000000;
            for(int i = 0; i < points.size(); i++){
                if(isUsed[i]) continue;
                double ca=diffAngle(points[i]-pp,cp);
                //cout<<ca<<endl;
                if(EQ(minAngle,ca)){
                    if(abs(points[idx]-pp)>abs(points[i]-pp))
                        idx=i;
                }
                else if(minAngle>ca){
                    idx=i;
                    minAngle=ca;
                }
            }
            isUsed[idx]=true;
            double inc=abs(points[idx]-pp);
            sum+=inc;
            P p=(points[idx]-pp);
            cp=p/abs(p);
            pp=points[idx];
        }
        printf("%.1f\n",sum);
    }
    return 0;
}

Measured memory_bytes: 0
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <complex>
#include <iomanip>
//定数
#define MOD 1000000007
//マクロ
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

#define vsort(v) sort((v).begin(), (v).end());

typedef unsigned long long int ull;
typedef long long lint;

using namespace std;




int main(){
    int A, B, C;
    


    //入力
    cin >> A >> B >> C;
    int ans=B+C-A;
    if(ans>=0) cout << ans << endl;
    else       cout <<  0  << endl;
    
    

    return 0;
}

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

int main(void){
    int n, m;
    cin >> n >> m;
    
    vector<int> k(m), p(m);
    vector<vector<int>> s(m+1, vector<int>(n+1));
    
    for (int i = 0; i < m; i++){
        cin >> k[i];
        
        for (int j = 0; j < k[i]; j++){
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    
    for (int i = 0; i < m; i++){
        cin >> p[i];
    }
    
    int ans = 0;
    
    for (int temp = 0; temp < (1<<n); temp++){
        
        //今のスイッチの状態が条件を満たすかどうかをcheck変数に記録する
        bool check = true;
        
        //電球１個１個の状態を調べる
        for (int i = 0; i < m; i++){
            int swi = 0; //on になっているスイッチの個数を 記録する
            
            for (int j = 0; j < k[i]; j++){
                if (temp & (1<<s[i][j])) swi++;
            }
            
            //電球 は onスイッチの個数 % 2 == p[i]のとき点灯する
            if (swi % 2 != p[i]) check = false;
        }
        
        if (check) ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

ll xORTrick(ll n) {
	if (n % 4 == 0) {
		return n;
	}

	if (n % 4 == 1) {
		return 1;
	}

	if (n % 4 == 2) {
		return n + 1;
	}

	return 0;
}

ll solution(ll M, ll N) {
	return xORTrick(N) ^ xORTrick(M - 1);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	ll ans = solution(a, b);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<numeric>
#include<algorithm>
#include<string>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
#define int long long
#define inf 1145141919ll
#define oku 1000000007ll
using namespace std;
int a,b,c,d,e,f,g;
int dx[]={0,-1,0,1,0};
struct A{
	A *e;
	int temp;

};
struct B{
	A *src;
	A *dst;
	int cost;
};
struct C{
	int u;
	int v;
	int len;
	C(int x,int y,int z):u(x),v(y),len(z){}
};
int i,j,k,n;
int p[2][5001];
signed main(){
	cin>>a>>b;
	for(i=0;i<=a;i++)
		for(j=0;j<=a;j++)
			if(i+j<=b&&b-i-j<=a)
				n++;
	cout<<n<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
int center=0;

using namespace std;

int binarySearch(int* S, int from, int to ,int t ){

	center= floor((from + to)/2);

//	printf("(from, center, to) = (%d, %d, %d)\n", from, center, to);

	if( from >= to ){
		return t == S[center];
	}else if( t == S[center] ){
		return 1;
	}else if( S[center] < t ){
		return binarySearch(S, center+1, to, t);
	}else if( t < S[center] ){
		return binarySearch(S, from, center-1, t);
	}



}


	


int main(){

	int *S, *T;
	int S_size, T_size, temp;

	scanf("%d", &S_size);
	S=new int[S_size];
	for( int i=0; i<S_size; i++ ){
		scanf("%d", &temp);
		S[i]=temp;
	}
	scanf("%d", &T_size);
	T=new int[T_size];
	for( int i=0; i<T_size; i++ ){
		scanf("%d", &temp);
		T[i]=temp;
	}

	int ans=0;

	
	for( int i=0; i<T_size; i++ ){

		ans +=binarySearch(S, 0, S_size -1,  T[i] );
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1796
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<Integer> answer = new ArrayList<Integer>();
		boolean canFlg = false;

		for (int a = 1; a <= 9; a++) {
			for (int b = 1; b <= 9; b++) {
				answer.add(a * b);
			}
		}

		for (int c : answer) {
			if (c == N) {
				System.out.println("Yes");
				canFlg = true;
				break;
			}
		}
		if (!canFlg) {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n);
  ll sum = 0;
  for(ll i=1; i<=n; i++){
    ll num;
    cin >> num;
    vec[i-1] = num-i;
    sum += num-i;
  }
  sort(all(vec));
  if(n % 2 == 0){
    ll a, b;
    a = ceil((double)(vec[n/2]+vec[n/2-1])/2);
    b = floor((double)(vec[n/2]+vec[n/2-1])/2);
    ll aSum = 0, bSum = 0;
    rep(i, n){
      aSum += abs(vec[i]-a);
      bSum += abs(vec[i]-b);
    }
    cout << min(aSum, bSum) << endl;
  }else{
    ll mid;
    mid = vec[n/2];
    ll ans = 0;
    rep(i, n) ans += abs(vec[i]-mid);
    cout << ans << endl;
  }  
  return 0;
}
  
    

Measured memory_bytes: 4920
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<ctime>

using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
int a[1005], b[1005];

int main(){
	int n, m, i, j, flag, b[5] = {0};
	for(i = 0; i < 6; i++){
		cin >> n;
		b[n]++;
	}
	if(b[1] == 1 && b[2] == 2 && b[3] == 2 && b[4] == 1)
		cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    
    ll A,B,C,X,Y,ans;
    cin >>A>>B>>C>>X>>Y;
    if(A+B < 2*C){
        ans = A*X+B*Y;
    }else if(A < 2*C && B < 2*C){
        if(X > Y){
            ans = Y*2*C + (X-Y)*A;
        }else{
            ans = X*2*C + (Y-X)*B;
        }
         
    }else if(B < 2*C){
        if(X > Y){
            ans = X*2*C;
        }else{
            ans = X*2*C + (Y-X)*B;
        } 
    }else if(A < 2*C){
        if(X > Y){
            ans = Y*2*C + (X-Y)*A;
        }else{
            ans = Y*2*C;
        } 
    }else{
        if(X > Y){
            ans = X*2*C;
        }else{
            ans = Y*2*C;
        } 
    }
    cout << ans << endl;
    
    
    
    return 0;
    

}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

string _S;
string T;

bool solve(ll i){
    //_Tのi文字目からをTにすることができるか？
    if(i + T.size() > _S.size()) return false;
    REP(j, T.size()){
        if(_S[i + j] != '?' && _S[i + j] != T[j]) return false;
    }
    return true;
}


int main(){
    cin >> _S >> T;
    vector<string> v;
    REP(i, _S.size()){
//        printf("solve(%lld) = %d\n", i, solve(i));
        if(solve(i)){
            string S;
            REP(k, i) {
                (_S[k] == '?') ? S += "a" : S += _S[k];
            }
            S += T;
            FOR(k, i + T.size(), _S.size()){
                (_S[k] == '?') ? S += "a" : S += _S[k];
            }
            v.pb(S);
        }
    }
    SORT(v);

    cout << ((v.empty()) ? "UNRESTORABLE" : v[0]) << endl;
}


Measured memory_bytes: 256
A, B, K = map(int, input().split())

lst = []
for i in range(K):
    lst += [A + i]
for i in range(K):
    lst += [B - i]

lst.sort()
a = 0
for i in lst:
    if A <= i and i <= B:
        if a == i:
            pass
        else:
            a = i
            print (a)

Measured memory_bytes: 3064
// IOI 2021
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
 
////////////////////////////////////////////////////////////////////
 
const int N = 1e5 + 5;

int A[N], B[N], P[N];

int GetPar(int v) { return P[v] == v ? v : P[v] = GetPar(P[v]); }
void Merge(int v, int u) {
	v = GetPar(v), u = GetPar(u);
	if (u == v) return;
	P[v] = u;
}

int main() {
 
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));


	int n, x = 0, ans = 0; cin >> n;
	vector<int> a, b;
	for (int i = 0; i < n; i++) cin >> A[i], x ^= A[i];
	A[n] = x,  x = 0;
	for (int i = 0; i < n; i++) cin >> B[i], x ^= B[i];
	B[n] = x, x = 0;
	for (int i = 0; i < n; i++) if (A[i] != B[i]) a.push_back(A[i]), b.push_back(B[i]), ans++;
	a.push_back(A[n]), b.push_back(B[n]);
	sort(all(a)), sort(all(b));
	if (a != b) die(-1);
	a.resize(unique(all(a)) - a.begin()), b.resize(unique(all(b)) - b.begin());
	for (int i = 0; i < sz(a); i++) P[i] = i;
	for (int i = 0; i <= n; i++) if (A[i] != B[i]) {
		int v = lower_bound(all(a), A[i]) - a.begin();
		int u = lower_bound(all(b), B[i]) - b.begin();
		Merge(v, u);
	}
	for (int i = 0; i < sz(a); i++) ans += (GetPar(i) == i);
	cout << ans - 1 << endl;

	return 0;
}


Measured memory_bytes: 8400
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N,K = MI()
P = LI()
C = LI()

for i in range(N):
    if C[i] >= 0:
        break
else:
    print(max(C))
    exit()

from itertools import accumulate

flag = [0]*N
ans = max(C)
for i in range(N-1):
    if flag[i] != 0:
        continue
    A = [C[i]]
    flag[i] = 1
    a = i
    j = P[i]-1
    while j != i:
        A.append(C[j])
        flag[j] = 1
        j = P[j]-1
    a = len(A)
    s = 0
    if sum(A) > 0:
        if K//a > 0:
            s = sum(A)*(K//a-1)
            r = K % a + a
        else:
            s = 0
            r = K % a
    else:
        s = 0
        r = K % a + a
    A = [0] + A + A + A
    S = list(accumulate(A))
    m = 0
    for i in range(a):
        for k in range(1,r+1):
            b = S[i+k] - S[i]
            m = max(m,b)
    s += m
    ans = max(ans,s)

print(ans)


Measured memory_bytes: 69352