akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.stream.Stream;
import java.util.Arrays;

public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    // 1つ下の桁の数値が8未満の場合は現在の桁を1減算して1つ下の桁の数値を9にする
    
    String str = sc.next();
    int len = str.length();
    int[] eachNum = new int[len];
    for (int i = 0; i < len; i++){
      eachNum[i] = str.charAt(i) - '0';
      // System.out.println(eachNum[i]);
    }

    for (int i = 0; i < len - 1; i++){
      if (eachNum[i + 1] < 8 && eachNum[i] > 0) {
        eachNum[i] = eachNum[i] - 1;
        for(int j = i; j < len - 1; j++){
          eachNum[j + 1] = 9;
        }
      }
    }

    int sum = Arrays.stream(eachNum).sum();
    System.out.println(sum);

  }
}


Measured memory_bytes: 26836
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
 const int mod=1000000007;

 int main(){
	 int n,x[1111]={},y[1111]={};
	 int xx[1111]={},yy[1111]={};
	 cin>>n;
	 int f[2]={};
	 FOR(i,0,n){
		 cin>>x[i]>>y[i];
		 if(x[i]>0)xx[i]=x[i];
		 else xx[i]=-x[i];
		 if(y[i]>0)yy[i]=y[i];
		 else yy[i]=-y[i];
		 f[(xx[i]+yy[i])&1]=1;
	 }
	 if(f[0]==f[1]){
		 cout<<-1<<endl;
		 return 0;
	 }
	 LL arm[42]={};
	 int m=36;
	 FOR(i,0,m){
		 arm[i]=1LL<<i;
	 }
	 if(f[0]){
		 arm[m]=1;
		 m++;
	 }
	 cout<<m<<endl;
	 FOR(i,0,m){
		 if(i!=m-1)cout<<arm[i]<<" ";
		 else cout<<arm[i]<<endl;
	 }
	 int dx[4]={0,1,0,-1};
	 int dy[4]={1,0,-1,0};
	 char dr[4]={'U','R','D','L'};
	 FOR(i,0,n){
		 LL xx=0,yy=0;
		 char s[42]={};
		 FORD(j,m,0){
			 LL nd=0,dist=1LL*mod*mod;
				FOR(d,0,4){
					LL nx=xx+dx[d]*arm[j];
					LL ny=yy+dy[d]*arm[j];
					LL ndist=fabs(nx-x[i])+fabs(ny-y[i]);
					if(dist>ndist){
						dist=ndist;
						nd=d;
					}
				}
				s[j]=dr[nd];
				xx=xx+dx[nd]*arm[j];
				yy=yy+dy[nd]*arm[j];
				//cout<<i<<" j:"<<j<<" arm[j]:"<<arm[j]<<" xx:"<<xx<<" yy:"<<yy<<endl;
		 }
		 FOR(j,0,m){
			 cout<<s[j];
		 }
		 cout<<endl;
	 }


   return 0;
 }


Measured memory_bytes: 256
n = int(input())
s = input()
s_list = list(s)
ans = 0
total = s_list.count("R") * s_list.count("G") * s_list.count("B")
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        k = j + j - i
        if n >= k + 1:
            if (s_list[i] != s_list[j]) and (s_list[j] != s_list[k]) and (s_list[k] != s_list[i]):
                ans += 1
print(total - ans)

Measured memory_bytes: 68244
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int N, C, K;
  cin >> N >> C >> K;
  int T[N];
  for(int i=0; i<N; i++)
    cin >> T[i];
  // 入力終わり

  // Tを昇順にソートしておく
  sort(T, T+N);

  int ans = 0;
  int tmp = 1;
  for(int i=0; i<N; i++){
    tmp = 1;
    //    cout << "i : " << i << endl;
    if(i == N-1){
      ans++;
      break;
    }
    int j = i+1;
    while(T[j]-T[i] <= K && tmp<C){
      if(T[i] <= T[j] <= T[i]+K){
	tmp++;
	j++;
	if(j>=N){
	  ans++;
	  goto end;
	}
      }
      else
	break;
    }
    ans++;
    i = j-1;
  }

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


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

int main()
{
	int a,b;
	while(true){
		cin >> a;
		if(cin.eof())
			break;
		cin >> b;

		int a1=0,b1=0;
		a1=a;
		b1=b;

		int sum=0;
		while(a1%b1!=0){
			sum = b1;
			b1 = a1%b1;
			a1 = sum;
		}

		int g=0,m=0;
		g=b1;
		m=a/g*b;

		cout << g << ' ' << m << endl;
	}
	return 0;
}

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

string FILENAME = "template";
#define io ifstream fin(FILENAME + ".in"); ofstream fout(FILENAME + ".out")
#define fwrite(X) fout << X;
#define fwriteln(X) fout << X << endl;

#define forl(V, N) for(int V = 0; V < N; V++)
#define fore(E, X) for(auto &E:X)
#define print(X) cout << X
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
#define rem(X) X.top(); X.pop()
#define mid(A, B) ((A+B) / 2)
#define setmin(A, B) A = min(A, B)
#define setmax(A, B) A = max(A, B)
#define graph unordered_map<int, unordered_set<int>>
#define vi vector<int>
#define pb push_back
#define ll long long

int main() {
    int N;
    cin >> N;
    vi stones(N);
    forl(i, N) cin >> stones[i];
    vector<ll> dp(N+10);
    fill(dp.begin(), dp.end(), 999999999999);
    dp[0] = 0;
    forl(i, N) {
        setmin(dp[i+1], dp[i]+abs(stones[i]-stones[i+1]));
        setmin(dp[i+2], dp[i]+abs(stones[i]-stones[i+2]));
    }
    println(dp[N-1]);
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,W;
    cin>>n>>W;
    vi v(n),w(n);
    rep(i,n)cin>>v[i]>>w[i];
    int dp[10001]={};
    rep(i,n){
        for(int j=W;j>0;j--){
            if(j<w[i])continue;
            dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
        }
    }
    cout<<dp[W]<<endl;
}


Measured memory_bytes: 3232
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(int(input()) for _ in range(n))

    j = 1
    cnt = 0
    for i in range(n):
        if j == 2:
            break
        j = A[j - 1]
        cnt += 1
    else:
        print(-1)
        exit()

    print(cnt)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 7072
#include <stdio.h>
#define MAX 2000000
 
int H,A[MAX+1];
 
void maxHeapify(int i){
    int l,r,largest,temp;
    l=2*i;
    r=2*i+1;
    if(l <= H && A[l] > A[i])
        largest=l;
    else
        largest=i;
    if(r <= H && A[r] > A[largest])
        largest=r;
 
    if(largest != i){
        temp=A[i];
        A[i]=A[largest];
        A[largest]=temp;
        maxHeapify(largest);
    }
}
 
int main(void){
    int i;
    scanf("%d",&H);
    for(i=1;i<=H;i++)
        scanf("%d",&A[i]);
    for(i=H/2;i>=1;i--)
        maxHeapify(i);
    for(i=1;i<=H;i++)
        printf(" %d",A[i]);
    puts("");
    return 0;
}


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

int main()
{
  int n; cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  rep(i, n) cin >> x[i] >> y[i];

  double sum = 0;
  vector<int> a(n);
  rep(i, n) a[i] = i;
  do {
    for (int i=1; i<n; i++) {
      sum += sqrt(pow(x[a[i]]-x[a[i-1]], 2) + pow(y[a[i]]-y[a[i-1]], 2));
    }
  } while (next_permutation(a.begin(), a.end()));
  int div = 1;
  for (int i=1; i<=n; i++) {
    div *= i;
  }
  printf("%.10lf\n", sum/div);

  return 0;
}


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

namespace ConsoleApplication11
{
    class Program
    {
        static void Main(string[] args)
        {
            // 文字列S入力
            string strInputSData = Console.ReadLine();

            // 文字列P入力
            string strInputPData = Console.ReadLine();

            // 文字列Sを二つ繋いだものに文字列Pが含まれているか判定
            if ((strInputSData + strInputSData).Contains(strInputPData))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}



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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1000000000 + 7;
const int N = 5e3 + 5;

typedef long long ll;

int n, k, a[N], l, r;
bool dp[N];

bool check(ll x)
{
    if(a[x] >= k) return true;
    for(int i = 1; i <= k; i ++)
            dp[i] = 0;
    for(int i = 1; i <= n; i ++)
    {
        if(i != x && a[i] < k)
        {
            for(int j = k - 1; j - a[i] >= 0; j --)
            {
                if(dp[j - a[i]])
                {
                    dp[j] = 1;
                    if(j >= (k - a[x])) return true;
                }
            }
        }
    }
    return false;
}

inline void solve()
{
    scanf("%d %d", &n, &k);

    for(int i = 1; i <= n; i ++)
        scanf("%d", &a[i]);

    sort(a + 1, a + n + 1);

    dp[0] = 1;

    l = 1, r = n;
    while(r - l > 1)
    {
        ll md = (l + r) / 2;
        if(check(md))
            r = md;
        else
            l = md;
    }
    if(check(r))
        r = l;
    if(check(r))
        r = 0;
    printf("%d", r);
}

int tests = 1;

int main()
{
//    scanf("%d", &tests);

    while(tests --)
        solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


V<string> split(const string& s, char c) {
  V<string> res;
  stringstream ss(s);
  string t;
  while (getline(ss, t, c)) res.push_back(t);
  return res;
}

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  string s;
  while (getline(cin, s)) {
    auto ss = split(s, ' ');
    double a = stod(ss[0]);
    double b = stod(ss[1]);
    double c = stod(ss[2]);
    double d = stod(ss[3]);
    double e = stod(ss[4]);
    double f = stod(ss[5]);
    double x = (c * e - f * b) / (a * e - d * b) + 1e-10;
    double y = (c * d - f * a) / (b * d - e * a) + 1e-10;
    cout << fixed << setprecision(3) << x << ' ' << y << '\n';
  }
}


Measured memory_bytes: 3216
#include<stdio.h>
int main()
{
   char O[100],E[100];
   int o,e,i,k;
   scanf("%s%s",O,E);
   o=strlen(O);
   e=strlen(E);
   if(o>=e)k=o;
   else k=e;
   for(i=0;i<k;i++){
    if(i<o)printf("%c",O[i]);
    if(i<e)printf("%c",E[i]);
   }
   printf("\n");
    return 0;
}


Measured memory_bytes: 1664
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();

        for(int i = 0; i < N; i ++){
            int A = scan.nextInt();
            if(A%2 == 0 && (A%3 != 0 && A%5 != 0)) {
                os.println("DENIED");
                return;
            }
        }

        os.println("APPROVED");
    }
}

Measured memory_bytes: 23380
inpl = lambda: list(map(int,input().split()))
M = 10**9
N, K, S = inpl()
if S == M:
    if K == N:
        A = [M] * N
    else:
        A = [M//2] * (K+1) + [1]*(N-K-1)
else:
    A = [S]*K + [S+1]*(N-K)

print(' '.join(list(map(str,A))))

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

int main() {
	int n;
  	cin >> n;
  	while (n) {
    	if (n % 10 == 7)
			return cout << "Yes" << endl, 0;
     	n /= 10;
    }
  	return cout << "No" << endl, 0;
}  

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

int main()
{
  int64_t N, ans = (1LL << 62);
  cin >> N;
  vector<int64_t> A(N), S(N + 1, 0);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
    S.at(i + 1) = A.at(i) + S.at(i);
  }
  for (int k = 3; k <= N - 1; k++) // 1-indexedでDが開始するindex
  {
    auto a = lower_bound(S.begin(), S.begin() + k, S.at(k - 1) / 2);
    int64_t ic = distance(S.begin(), a); // 前半の和の半分以上となる1-indexedのindex
    int64_t s1 = S.at(k - 1);
    int64_t ma1, ma2, maa, mia;
    ma1 = max(S.at(ic), s1 - S.at(ic));
    ma2 = max(S.at(ic - 1), s1 - S.at(ic - 1));
    maa = min(ma1, ma2);
    mia = s1 - maa;

    auto b = lower_bound(S.begin() + k + 1, S.end(), (S.at(N) - S.at(k - 1)) / 2 + S.at(k - 1));
    int64_t ie = distance(S.begin(), b); // 後半の和の半分以上となる1-indexedのindex
    int64_t s2 = S.at(N) - S.at(k - 1);
    int64_t mb1, mb2, mab, mib;
    mb1 = max(S.at(ie) - S.at(k - 1), s2 - (S.at(ie) - S.at(k - 1)));
    mb2 = max(S.at(ie - 1) - S.at(k - 1), s2 - (S.at(ie - 1) - S.at(k - 1)));
    mab = min(mb1, mb2);
    mib = s2 - mab;
    ans = min(ans, max(maa, mab) - min(mia, mib));
  }
  cout << ans << endl;
}

Measured memory_bytes: 6356
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        
    }

    let mut res : Vec<(String,usize,usize)>= vec![];
    for i in 0..n{
        input!{s: String, p: usize}
        res.push((s,p,i+1));
    }

    res.sort_by(|a,b| b.1.cmp(&a.1));
    res.sort_by(|a,b| a.0.cmp(&b.0));
    
    for e in &res{
        println!("{}",e.2);
    }
}


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

int main(void){

int A[101][101],n,m;
cin>>n>>m;

for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)cin>>A[i][j];

for(int i=0;i<=n;i++)A[i][m]=0;
for(int j=0;j<=m;j++)A[n][j]=0;

for(int i=0;i<n;i++){
  for(int j=0;j<m;j++){
    A[i][m]+=A[i][j];
    A[n][j]+=A[i][j];
    A[n][m]+=A[i][j];
  }
}

for(int i=0;i<=n;i++){
  for(int j=0;j<=m;j++){
    if(j)cout<<" ";
    cout<<A[i][j];
  }cout<<endl;
}
  }


Measured memory_bytes: 3100
while True :
    q = int(input())
    if q == -1 :
        break
    
    n = 1
    x = q / 2
    while True :
        if abs(x**3 - q) < (0.00001 * q) :
            break
        x = x - (x**3 - q) / (3 * x**2)
    
    print('{:.6f}'.format(x))
        


Measured memory_bytes: 5660
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
    int ans = 0;
    int tmp;
    int n;
    cin >> n;
    vector<int64_t> x; 
    REP1(i, n){
        x.clear();
        x = divisor((int64_t)i);
        if(x.size() == 8 && i %2 == 1) ans ++;
    }
    cout << ans << endl;
}

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;

  // ここにプログラムを追記
  cout << A[0] << B[0] << C[0] << endl;
  
  return 0;
}


Measured memory_bytes: 3572
#!/usr/bin/env python3
import sys


def solve(N: int, B: "List[int]"):

    sum = 0
    for i in range(N):
        if i == (N - 1):
            sum += B[N - 2]
        elif i == 0:
            sum += B[0]
        else:
            sum += min(B[i - 1], B[i])
    print(sum)

            
    
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    B = [ int(next(tokens)) for _ in range(N-1) ]  # type: "List[int]"
    solve(N, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
$K=<>;
$v[$x=1]=1;
@q=([1,10%$K,0],[1,2%$K,1]);
while($x){
	($a,$b,$c)=@{shift@q};
	if(!$v[$b]){
		$v[$b]=$v[$a]+$c;
		$x=$b;
		unshift@q,[$x,$x*10%$K,0];
		push@q,[$x,($x+1)%$K,1];
	}
}
print$v[0]


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

using namespace std;
 
typedef long long int ll;

const ll INF=(ll)1e18;

int N;

int main(){
    cin >> N;

    vector<ll> a,b,c;

    REP(i,N){
        ll tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    REP(i,N){
        ll tmp;
        cin >> tmp;
        b.push_back(tmp);
    }
    REP(i,N){
        ll tmp;
        cin >> tmp;
        c.push_back(tmp);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

/*
    REP(i,N)cout << a[i] <<  " ";
    cout << endl;
    REP(i,N)cout << b[i] <<  " ";
    cout << endl;
    REP(i,N)cout << c[i] <<  " ";
    cout << endl;
*/

    ll ab[N], bc[N];

    int j = 0;
    REP(i,N){
        while(j < N && a[j] < b[i]){
            j++;
        }
        ab[i] = j;
    }


//    REP(i,N){
//        printf("ab %d %lld\n", i, ab[i]);
//    }

    j = 0;
    REP(i,N){
        while(j < N && b[i] >= c[j]){
            j++;
        }
        bc[i] = N-j;
    }

//    REP(i,N){
//        printf("bc %d %lld\n", i, bc[i]);
//    }

    ll ans = 0;
    REP(i,N){
        ans += ab[i] * bc[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4340
using System;

class F
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var p = Array.ConvertAll(new int[n], _ => Array.ConvertAll(Console.ReadLine().Split(), int.Parse));

		if (n == 2) { Console.WriteLine(Norm(p[0], p[1]) / 2); return; }

		var M = 0.0;
		for (int i = 0; i < n; i++)
			for (int j = i + 1; j < n; j++)
				for (int k = j + 1; k < n; k++)
					M = Math.Max(M, GetRadius(p[i], p[j], p[k]));
		Console.WriteLine(M);
	}

	static double GetRadius(int[] p, int[] q, int[] r)
	{
		double a = Norm(p, q), b = Norm(q, r), c = Norm(r, p), t;
		if (b > a) { t = b; b = a; a = t; }
		if (c > a) { t = c; c = a; a = t; }

		var cos = CosA(a, b, c);
		return a / 2 / (cos < 0 ? 1 : Math.Sqrt(1 - cos * cos));
	}

	static double Norm(int[] p, int[] q) => Math.Sqrt(Math.Pow(p[0] - q[0], 2) + Math.Pow(p[1] - q[1], 2));
	static double CosA(double a, double b, double c) => (b * b + c * c - a * a) / (2 * b * c);
}


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

typedef long long ll;
typedef long double ld;
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,x,y,ans=0,m;
    cin>>n>>x>>y;
    vector<ll> v(n+1,0);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            m=min((ll)(j-i),min(abs(y-j)+1+abs(i-x),abs(x-j)+1+abs(i-y)));
            v[m]++;
        }
    }
    for(int i=1;i<n;i++)cout<<v[i]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const long long N = 1e5 + 5;
using namespace std;

long long n, a[N], cnt, sum;

int main(){
    cin >> n;
    for (long long i = 0; i < n; i++) {cin >> a[i]; sum += a[i];}
    if (sum % ((n*(n+1))/ 2) != 0){
        cout << "NO";
        return 0;
    }
    long long X = sum * 2 / n / (n+1);
    for (long long i = 0; i < n; i++){
        long long x = a[i] - a[(i+1)%n];
        x += X;
        if (x < 0 || x % n != 0) {
            cout << "NO";
            return 0;
        }
        cnt += x / n;
    }
    if (cnt != X){
        cout << "NO";
        return 0;
    }
    else {
        cout << "YES";
        return 0;
    }
}


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

int main(){
  int n,inp,count; cin >> n;
  count = 0;
  for(int i=1; i<=n; i++){
    cin >> inp;
    if(inp!=i){count++;}
  }
  
  if(count<=2){cout << "YES";}
  else{cout << "NO";}
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()

int main(){
	int n,d,x; cin>>n>>d>>x;
	vvi v(d,vi(n));
	for(auto&l:v)for(auto&i:l)cin>>i;
	rep(k,d-1){	//毎日
		vi dp(x+1);	//dp[a]=現在a円持っているとき、翌日得られる金額の最大値
		iota(all(dp),0);	//a円持っているとき、少なくともa円以上は翌日に持ち越せる
		rep(i,n)range(j,v[k][i],x+1){	//i番目の銘柄について、jが[今日の価値,今日開始時の所持金]の範囲で
			dp[j]=max(dp[j], dp[j-v[k][i]]+v[k+1][i]);
			//j円持っているときの翌日の最大金額　=
			//	max(今の所の推定最大金額,
			//		i番目の銘柄を1つ買った後の残金(j-v[k][i])から生み出せる翌日の最大金額 + 今買った商品の価値)
		}
		x=max(0,*max_element(all(dp)));	//最大値が答え。全銘柄が値下がりすると最大値が負になるので、0とmaxする
	}
	cout<<x<<endl;
	return 0;
}



Measured memory_bytes: 3168
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			solveA();
			//			 solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int numN = nextInt();

		long res = 0;
		for (int i = 1; i <= numN; i++) {
			res += i;
		}

		out.println(res);
	}

	private void solveB() {
		int numN = nextInt();

		out.println("");
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ":" << x << "\n"
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;

int main() {
    ll N, K;
    cin >> N >> K;
    vi H(N);
    rep(i, N) {
        cin >> H.at(i);
    }
    sort(all(H));
    ll ans = 0;
    if (K < N) {
        rep(i, N - K) {
            ans += H.at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;
	vector<int> W, S;
	for(int i = 0; i * 100 * A <= F; i ++){
		for(int j = 0; i * 100 * A + j * 100 * B <= F; j ++){
			W.pb(i * 100 * A + j * 100 * B);
		}
	}
	for(int i = 0; i * C <= F; i ++){
		for(int j = 0; i * C + j * D <= F; j ++){
			S.pb(i * C + j * D);
		}
	}
	double maxRate = 0.0;
	int maxWater = 0, maxSuger = 0;
	for(int i = 0; i < W.size(); i ++){
		for(int j = 0; j < S.size(); j ++){
			if(maxRate < (double)(100 * S[j]) / (double)(W[i] + S[j]) && W[i] + S[j] <= F && S[j] <= E * W[i] / 100){
				maxRate = (double)(100 * S[j]) / (double)(W[i] + S[j]);
				maxWater = W[i];
				maxSuger = S[j];
			}
		}
	}
	if(maxSuger == 0){
		cout << 100 * A << " " << maxSuger << endl;
	}
	else cout << maxWater + maxSuger << " " << maxSuger << endl;
	
	return 0;
}

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


def judge(b_point, a_point):
    b_point = list(map(int, b_point.split()))
    a_point = list(map(int, a_point.split()))

    t = a_point[0] - b_point[0]
    x_b = b_point[1]
    x_a = a_point[1]
    y_b = b_point[2]
    y_a = a_point[2]

    distance = abs(x_a - x_b) + abs(y_a - y_b)
    if distance > t:
        return 0
    elif (t -distance) % 2 == 0:
        return 1
    else:
        return 0


def main():
    N = int(input())
    points = ["0 0 0"]
    points.extend([input() for i in range(N)])
    for i, point in enumerate(points):
        if i+1 == len(points):
            break
        else:
            if judge(points[i],points[i+1]):
                continue
            else:
                print("No")
                return
    print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 11036
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-9;
const int inf=1e8;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	ll a;
	cin>>a;
	ll out=a/11*2;
	a%=11;
	if(a>6)out+=2;
	else if(a)out++;
	cout<<out<<endl;
}










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

int main() {
    string S;
    cin >> S;
    
    set<char> st;
    for (int i=0; i<3; i++) {
        st.insert(S[i]);
    }
    
    if (st.size() == 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n";
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define double long double
const int mod = 1e9 + 7;
const int K = 26;

int32_t main()
{   
    fastio;
    
    int n, k; cin >> n >> k;
    vector<int> a(n+1);
    for(int i=1; i<=n; i++){
    	cin >> a[i];
    }

    vector<int> v(n+1, -1);
    vector<int> path;
    int ans = 1, curr = 1, offset = -1;
    while(true){
    	if(k <= 0) break;
    	if(v[curr] != -1){
    		offset = v[curr];
    		break;
    	}

    	v[curr] = path.size();
    	path.push_back(curr);
    	curr = a[curr];
    	k--;
    }

    if(k > 0){
    	//cout << k%(path.size()-offset)<< " " << offset << endl;
    	curr = path[k%(path.size()-offset) + offset];
    }

    cout << curr << endl;
    return 0;
}



Measured memory_bytes: 8460
# coding: utf-8

n = int(input().rstrip())

monsters = list(reversed(sorted(map(int, input().rstrip().split(" ")))))

cnt = [0 for i in range(n)]
cnt[n - 1] = monsters[n - 1]
for i in reversed(range(n - 1)):
    cnt[i] = cnt[i + 1] + monsters[i]

dic = {}


def can_alife(idx: int):
    if idx == 0:
        return True
    if idx in dic:
        return dic[idx]

    ret = False
    if monsters[idx - 1] <= cnt[idx] * 2:
        ret = can_alife(idx - 1)
    dic[idx] = ret
    return ret


ans = len([i for i in range(n) if can_alife(i)])
print(ans)


Measured memory_bytes: 25304
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,k=0;
    cin >> n;
    if (n/100>=1 && n/100<=12) k++;
    if (n%100>=1 && n%100<=12) k +=2;
    if (k==0) cout << "NA" << endl;
    if (k==1) cout << "MMYY" << endl;
    if (k==2) cout << "YYMM" << endl;
    if (k==3) cout << "AMBIGUOUS" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main()
{
    int n; scanf("%d",&n);
    int i,j,x[1000],y[1000];
     int max=0;
    for(i=0;i<n;i++)
        scanf("%d",&x[i]);
    for(i=0;i<n;i++)
        scanf("%d",&y[i]);
    
    for(i=1;i<4;i++)
    {
        double sum=0;
        for(j=0;j<n;j++){
            sum+=pow(abs(x[j]-y[j]),i);
        }
        printf("%lf\n",pow(sum,1/(double)i));
    }
    
    
    for(i=0;i<n;i++)
    {
      
        if(abs(x[i]-y[i])>max)
            max=abs(x[i]-y[i]);
    }
    printf("%d\n",max);
}



Measured memory_bytes: 2124
#include<cstdio>

int main(){
    int a, b, c, cnt=0;
    scanf("%d%d%d", &a, &b, &c);
    for(int i=a; i<=b;i++){
        if(c%i==0) cnt++;
    }
    printf("%d\n", cnt);

    return 0;
}



Measured memory_bytes: 2728
import java.util.*;

public class Main {

    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int num = Integer.parseInt(sc.next());
      
      long[] inputs = new long[num];
      long sum = 0;
      for (int i = 0; i < num; i++) {
        inputs[i] = Long.parseLong(sc.next());
        sum ^= inputs[i];
      }
      // only interested in 1's bit
      for (int i = 0; i < num; i++) {
        inputs[i] &= ~sum;
      }
      System.out.println(sum + (maxSubarrayXOR(inputs) << 1));
    }
  
  	public static long maxSubarrayXOR(long A[]) {
      int idx = 0;
      for (int bit = 60; bit >= 0; bit--) {
        int find = idx;

        while (find < A.length) {
          // find the element which MSB is in bit'th
          if ((A[find] & (1L << bit)) != 0) {
          	break;
          }
          find++;
        }
        
        if (find == A.length) continue;
        
        // swap element in idx and find
        if (idx != find) {
          A[idx] ^= A[find];
          A[find] ^= A[idx];
          A[idx] ^= A[find];
          find = idx;
        }
        
        for (int i = 0; i < A.length; i++) {
       	  if (i != find && (A[i] & (1L << bit)) != 0) {
            A[i] ^= A[find];
          }
        }

        idx++;
      }
      
      long ret = 0;
      for (long l: A) {
        ret ^= l;
      }

      return ret;
    } 
}

Measured memory_bytes: 48380
a = int(input())
b = [[int(input()), False]for i in range(a)]
c = 1
d = 0
while True:
    d += 1
    if b[c-1][0] == 2:
        print(d)
        exit()
    else:
        b[c-1][1] = not b[c-1][1]
        if b[c-1][1]:
            c = b[c-1][0]
        else:
            print(-1)
            exit()


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int ans = 0;
  int n = s.size();
  rep(i,n){
    if(n-1-i < i) break;
    if(s[n-1-i] != s[i]) ans++;
  }
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
a = max(A)
prime_num = [2]
sgn = [0 for _ in range(max(int(a**0.5)+1, 4))]
sgn[2] = 1
for k in range(3, len(sgn), 2):
  if sgn[k] == 0:
    prime_num.append(k)
    for j in range(k, a+1, k**2):
      sgn[k] = 1
baisu = []
count = [0 for _ in range(a+1)]
for k in range(N):
  b = 0 + A[k]
  for p in prime_num:
    if p**2 <= b:
      if b%p == 0:
        if count[p] == 0:
          baisu.append(p)
        c = 0
        while b % p == 0:
          b //= p 
          c += 1 
        if c > count[p]:
          count[p] = c
    else:
      break
  if b != 1:
    if count[b] == 0:
      count[b] = 1
      baisu.append(b)

product = 1
for item in baisu:
  product *= pow(item, count[item], mod)
  product %= mod

b = mod-2
blis = []
c = 0
while b >0:
  if b & 1 == 1:
    blis.append(c)
  c += 1
  b >>= 1

def modinv(a):
  if a == 1:
    return 1
  else:
    res = 1
    li = []
    for _ in range(c):
      li.append(a%mod)
      a = a*a%mod
    for item in blis:
      res = res *li[item] %mod
    return res

ans = 0
for k in range(N):
  ans += product*modinv(A[k])
  ans %= mod

print(ans)


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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int sum=0;
  
  for (int i = 0; i < N; i++) {
    sum =sum +vec.at(i) * (i&0x01 ? -1:1);
  }
  cout << sum <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,X=0;
  cin>>N;
  if(N/100==1)
    X+=900;
  else
    X+=100;
  if(N%10==1)
    X+=9;
  else
    X+=1;
  if(N%100/10==1)
    X+=90;
  else
    X+=10;
  cout<<X<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

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

    int64_t n, a, b;
    std::vector<int64_t> town;
    cin >> n >> a >> b;
    int64_t result = 0;
    for (int i = 0; i < n; i++) {
        int m1;
        cin >> m1;
        town.push_back(m1);
    }
    for (int i = 1; i < n; i++) {
        if ((town[i] - town[i - 1]) * a > b)
            result += b;
        else
            result += (town[i] - town[i - 1]) * a;
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define N 1000005
using namespace std;
int read(){
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
	return x*f;
}
int n,m,prt[N];
int find(int x){return x==prt[x]?x:prt[x]=find(prt[x]);}
void Merge(int x,int y){
	x=find(x),y=find(y);
	if(x==y)return;
	prt[x]=y;
}
int main(){
	n=read();m=read();
	for(int i=1;i<=n*3;i++)prt[i]=i;
	for(int i=1;i<=m;i++){
		int x=read(),y=read(),z=read();
		Merge(x+2*n,y+2*n);
//		if(z&1)Merge(x,y+n),Merge(x+n,y);
//		else Merge(x+n,y+n),Merge(x,y);
	}
	int ans=0;
	for(int i=n*2+1;i<=n*3;i++)ans+=(prt[i]==i);
	printf("%d\n",ans);
}

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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

const int maxn = 4005;
const int P = 998244353;

char a[maxn];
int f[maxn][maxn];
int n, r[maxn], b[maxn];

void add(int &x, int y){x += y; if(x>=P) x-=P;}
int main()
{
	#ifdef MPS	
		fp("1.in","r",stdin);
		fp("1.out","w",stdout);
	#endif
	sf("%s",a+1);
	n = strlen(a+1);
	fo(i,1,n)
	{
		if(a[i] == '0') r[i] = 2, b[i] = 0;
		else if(a[i] == '1') r[i] = 1, b[i] = 1;
		else r[i] = 0, b[i] = 2;
		r[i] += r[i-1]; b[i] += b[i-1];
	}
	f[0][0] = 1;
	fo(i,1,n*2) fo(j,0,min(i,n*2))
	{
		if(j >= 1 && r[min(i,n)] >= j) add(f[i][j], f[i-1][j-1]);	
		if(b[min(i,n)] >= i-j) add(f[i][j], f[i-1][j]);
		// cout << i << ' ' << j << ' ' << f[i][j] << endl;
	}
	pf("%d\n",f[n*2][r[n]]);
	return 0;
}

Measured memory_bytes: 61440
/*
	0173:Haunted House
*/
#include	<iostream>
#include	<string>

using namespace std;

int main(void) {
	for(int i = 0; i < 9; i++) {
		string name;
		int a, b;
		
		cin >> name >> a >> b;
		
		cout << name << ' ' << a + b << ' ' << a * 200 + b * 300 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


//////////////////////////////////////


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

    vi a(n);
    rep(i,n){
        cin>>a[i];
        a[i]-=(i+1);
        
    }
    sort(all(a));
    b=a[n/2];
    ll sum=0;
    rep(i,n){
        sum+=abs(a[i]-b);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=500+5;
int n;
LL a[maxn][maxn];
bool isp[100005];
vector<int>prime;
void sieve(int ps){
	memset(isp,1,sizeof(isp));isp[1]=0;
	for(int i=2;prime.size()<=ps;i++){
		if(isp[i])prime.push_back(i);
		for(int k=0;k<prime.size()&&i*prime[k]<=100000;k++){
			isp[i*prime[k]]=0;
			if(i%prime[k]==0)break;
		}
	}
}
LL lcm(LL x,LL y){return x/__gcd(x,y)*y;}
int main(){
	sieve(1000);
	scanf("%d",&n);
	if(n==2){printf("4 7\n23 10\n");return 0;}
	int nxt=n+(n-1)/2;
	for(int i=1;i<=n;i++)
	a[0][i]=a[i][0]=a[n+1][i]=a[i][n+1]=1;
	for(int i=1;i<=n;i++)
	for(int j=1+!(i&1);j<=n;j+=2)
	a[i][j]=prime[(i+j)/2-1]*prime[(i-j)/2+nxt];
	for(int i=1;i<=n;i++)
	for(int j=1+(i&1);j<=n;j+=2)
	a[i][j]=lcm(lcm(a[i-1][j],a[i+1][j]),lcm(a[i][j-1],a[i][j+1]))+1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)printf("%lld ",a[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define int long long
using namespace std;
using PII = pair<int, int>;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;


template<int Mod>
struct ModInt {
    int v;
    ModInt(): v(0){}
    template<typename T>
    explicit ModInt(T t) {
        v = t % Mod;
        if (v < 0) v += Mod;
    }

    ModInt pow(int k) {
        ModInt res(1), x(v);
        while(k) {
            if (k & 1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }

    template<typename T>
    ModInt& operator=(T a) { v = a % Mod; if (v < 0) v += Mod; return *this; }
    ModInt inv() { return pow(Mod - 2); }
    ModInt& operator+=(ModInt a) { v += a.v; if (v >= Mod) v -= Mod; return *this; }
    ModInt& operator-=(ModInt a) { v += Mod - a.v; if (v >= Mod) v -= Mod; return *this; }
    ModInt& operator*=(ModInt a) { v = 1LL * v * a.v % Mod; return *this; }
    ModInt& operator/=(ModInt a) { return (*this) *= a.inv(); }
    ModInt operator+(ModInt a) const { return ModInt(v) += a; }
    ModInt operator-(ModInt a) const { return ModInt(v) -= a; }
    ModInt operator*(ModInt a) const { return ModInt(v) *= a; }
    ModInt operator/(ModInt a) const { return ModInt(v) /= a; }
    ModInt operator-() { return ModInt(-v); }
    bool operator==(const ModInt a) const { return v == a.v; }
    bool operator!=(const ModInt a) const { return v != a.v; }
    bool operator<(const ModInt a) const { return v < a.v; }

    friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.v; }
    friend std::istream &operator>>(std::istream &is, ModInt &a) {
        int val;
        is >> val;
        a = ModInt(val);
        return is;
    }
};

template<typename T>
struct Combination {
private:
    vector<T> fac, finv;
public:
    explicit Combination(int size, int Mod): fac(size + 1), finv(size + 1) {
        fac[0] = 1;
        finv[0] = 1;
        for (int i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * T(i + 1);
            finv[i + 1] = finv[i] * T(i + 1).pow(Mod - 2);
        }
    }

    T C(int n, int r) const {
        if (r < 0 || n < r) return T(0);
        return fac[n] * finv[r] * finv[n - r];
    }

    T P(int n, int r) const {
        if (r < 0 || n < r) return T(0);
        return fac[n] * finv[n - r];
    }

    T H(int n, int r) const {
        if (r < 0 || n < r) return T(0);
        return C(n + r - 1, r);
    }
};

using mint = ModInt<MOD>;

signed main() {
    double x, y;
    cin >> x >> y;
    double n = (-1.0 * x + 2.0 * y) / 3.0;
    double m = (2.0 * x - 1.0 * y) / 3.0;
    if (n - floor(n) != 0 || m - floor(m) != 0) {
        cout << 0 << "\n";
        return 0;
    }
    int ni = (int)floor(n);
    int mi = (int)floor(m);
    Combination<mint> c(1000000, MOD);
    cout << c.C(ni + mi, ni) << "\n";
}

Measured memory_bytes: 15872
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    bool flg = true;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        if(a % 2 == 0){
            if(a%3 > 0 && a%5 > 0) flg = false;
        }
    }
    if(flg) puts("APPROVED");
    else puts("DENIED");
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

   int N, K, X, Y;
   cin>> N>> K>> X>> Y;

   int ans=0;
   for(int d=1; d<=N; d++){
      if(d<=K){
         ans+=X;
      }else{
         ans+=Y;
      }
   }

   cout<< ans<< endl;

   return 0;
}


Measured memory_bytes: 256
w, h, n = map(int, input().split())
RCT = list(list(map(int, input().split())) for _ in range(n))
l = 0
r = w
dn = 0
up = h
for i in RCT:
    if i[2] == 1:
        l = max(l, i[0])
    if i[2] == 2:
        r = min(r, i[0])
    if i[2] == 3:
        dn = max(dn, i[1])
    if i[2] == 4:
        up = min(up, i[1])
print(0 if r - l <= 0 or up - dn <= 0 else (r - l) * (up - dn))

Measured memory_bytes: 9200
s = input()
ans = "Yes"
for i in range(len(s)//2):
  if s[i]!=s[-1-i]:
    ans = "No"
    break
for i in range(len(s)//2//2):
  if s[i]!=s[len(s)//2-1-i]:
    ans = "No"
    break
print(ans)

Measured memory_bytes: 3060
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N;  cin >> N;
    string S; cin >> S;
    
    vi sb(N, 0), sw(N, 0);

    if (S[0] == '#') sb[0] = 1;
    else sw[0] = 1;

    FOR(i,1,N) {
        if (S[i] == '#') {
            sb[i] = sb[i - 1] + 1;
            sw[i] = sw[i - 1];
        }
        else {
            sb[i] = sb[i - 1];
            sw[i] = sw[i - 1] + 1;
        }
    }

    int ans = sw[N - 1];
    REP(i,N) {
        ans = min(ans, sb[i] + sw[N - 1] - sw[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long a,b,c;
  cin >> a >> b >> c;
  if((c-a-b)*(c-a-b)==4*a*b) cout << "No" << endl;
  else if(c <= a+b) cout << "No" << endl;
  else if((c-a-b)*(c-a-b)>4*a*b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000



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

	
	int l = 0;
	int ans = 1;
	for(int i=0;i<S.size();i++){
		for(int j=0;j<l%2;j++){
			if(S[i]=='B')S[i]='W';
			else S[i]='B';
		}
		
		
		if(S[i]=='B'){
			l++;
		}
		else{
			ans = mod(ans * l);
			l--;	
		}
	}
	if(l!=0)ans = 0;
	
	for(int i=0;i<N;i++){
		ans = mod(ans * (i+1));
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int a, b, h; cin >> a >> b >> h;
    cout << (a+b) * h / 2 << endl;
}

Measured memory_bytes: 3612