akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
using namespace std; 

int main() 
{
	long long a,b,n;
	cin>>a>>b>>n;
	
	if(a == b)
		cout<<0<<endl;
	else{
		if(b > n){
			long long  max = a*n;
			max /= b;
			
			long long max1 = a*(n-1);
			max1 /= b;
			
			if(max1 > max)
				cout<<max1<<endl;
			else
				cout<<max<<endl;
		}
		else{
			
			long long max = a*(b-1);
			max /= b;
			
			long long max1 = a*(b-2);
			max1 /= b;
			
			if(max1 > max)
				cout<<max1<<endl;
			else
				cout<<max<<endl;
		}
	}
	
}
 


Measured memory_bytes: 3636
N, M = map(int, input().split())
coins = list(map(int, input().split()))

dp = [[N for _ in range(N+1)] for _ in range(M+1)]
dp[0][0] = 0

for i in range(M):
    c = coins[i]
    for j in range(N+1):
        if j-c >= 0:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j-c]+1)
        else:
            dp[i+1][j] = dp[i][j]

print(dp[M][N])



Measured memory_bytes: 43952
//                                                   ¯\_(ツ)_/¯
  #pragma GCC optimize("Ofast")
 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
#define pi pair<int,int>
const int N=3e7+5,MOD=998244353;

using namespace std;

int n,k;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);


	scanf("%d %d",&n,&k);

	std::vector<int> a(n);

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

	std::vector<int> dp(n+1,2e9);
	dp[0]=0;
	for(int i =0;i<n-1;i++){
		for(int j=1;j<=k && (i+j)<n;j++)
			dp[i+j]=min(dp[i+j],dp[i]+abs(a[i]-a[i+j]));
	}

	printf("%d\n",dp[n-1]);
	

}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s, t string
	fmt.Scan(&s)
	fmt.Scan(&t)
	if strings.Index(t, s) == 0 && len(s) + 1 == len(t) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1824
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int arr[200001];
int main(){
  int N,K;scanf("%d %d",&N,&K);
  for(int i=0;i<N;i++) scanf("%d",arr+i);
  sort(arr,arr+N);
  ll sum = 0;
  for(int i=0;i<N-K;i++) sum+=arr[i];
  printf("%lld",sum);
}

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

int main(void){
  int a, b, x[4] = {4, 6, 9, 11};
  cin >> a >> b;
  if(a == 2 || b == 2){
	cout << "No" << endl;
	return 0;
  }
  
  int flag1 = 0, flag2 = 0;
  for(int i=0; i<4; i++){
    if(a == x[i]) flag1 = 1;
    if(b == x[i]) flag2 = 1;
  }

  if((flag1 == 1 && flag2 == 1) || (flag1 == 0 && flag2 == 0)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main(){
    int h, w, i, n = 0;
    char c;
    cin >> h >> w;
    for(i=0; i<h*w; i++){
        cin >> c;
        if(c == '#'){
            n++;
        }
    }
    if(n == h+w-1){
        cout << "Possible";
    }else{
        cout << "Impossible";
    }
    return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll f = 0, t = 0, o = 0;
    REP(i, N) {
        ll a;
        cin >> a;
        if (a % 4 == 0)
            f++;
        else if (a % 2 == 0)
            t++;
        else
            o++;
    }
    if (o == 0)
        cout << "Yes" << endl;
    else {
        o += std::min(1LL, t);
        if (f == 0 || f + 1 < o)
            cout << "No" << endl;
        else
            cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
        vector<vector<int>> c(3, vector<int> (3));
        for (int i = 0; i < 3; i ++) {
                for (int j = 0; j < 3; j ++) {
                        scanf("%d", &c[i][j]);
                }
        }
        for (int i = 0; i <= 100; i ++) {
                for (int j = 0; j <= 100; j ++) {
                        for (int k = 0; k <= 100; k ++) {
                                int s = c[0][0] - i;
                                int t = c[1][0] - i;
                                int u = c[2][0] - i;
                                if (s < 0 || t < 0 || u < 0) continue;
                                if (s + j != c[0][1] || s + k != c[0][2]) continue;
                                if (t + j != c[1][1] || t + k != c[1][2]) continue;
                                if (u + j != c[2][1] || u + k != c[2][2]) continue;
                                puts("Yes");
                                return 0;
                        }
                }
        }
        puts("No");
        return 0;
}



Measured memory_bytes: 256
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
total=sum(a)
c=0
for i in a:
    if i>=(total/(4*m)):
        c+=1
    if c==m:
        print('Yes')
        exit()

print('No')    

Measured memory_bytes: 3064
#include <cstdio>
#include <set>
#include <iostream>

using std::string;

std::multiset<string> s;

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        s.insert("a");
    }
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        s.insert("b");
    }
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        s.insert("c");
    }
    while(s.size() > 1) {
        string a = *s.begin();
        string b = *(--s.end());
        s.erase(s.begin());
        s.erase(--s.end());
        s.insert((string)(a + b));
    }
    std::cout << *s.begin();
    return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    int dist = 0;
    for(int i = 0; i < N; i++){
        int x;
        cin >> x;
        int a, b;
        a = 2 * (x - 0);
        b = 2 * (x - K);
        if(b < 0){
            b = -b;
        }
        if(a < b){
            dist += a;
        }else{
            dist += b;
        }
    }
    cout << dist << endl;
}

Measured memory_bytes: 3632
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}
fn main() {
    let n: usize = read();
    let a: Vec<u32> = (0..n).map(|_| read()).collect();
    let mut ans = true;

    for i in a.iter() {
        if i % 2 == 0 {
            if i % 3 != 0 && i % 5 != 0 {
                ans = false;
            }
        }
    }

    if ans {
        println!("APPROVED");
    }else{
        println!("DENIED");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define mp make__pair
#define pb push_back
using namespace std;

typedef long long ll;
ll h[100001];
vector<int> v[100001];

int main()
{
    int n,m;
    cin >> n >> m;
    for(int i=1;i<=n;i++) cin >> h[i];
    for(int i=1;i<=m;i++){
        int a,b;
        cin >> a >> b;
        v[a].pb(b);
        v[b].pb(a);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        bool b=1;
        for(auto x : v[i]){
            if(h[i]<=h[x]){
                b=0;
                break;
            }
        }
        if(b) ans++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 9540
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int a[110000];
int b[110000];



int main()
{
  int i,j,m,n,mi,ans;
  vector<pair<int,int> > aa;
  scanf("%d%d",&n,&m);
  for (i=0;i<m;i++)
    scanf("%d%d",&a[i],&b[i]);
  aa.clear();
  for (i=0;i<m;i++)
    aa.push_back(make_pair(a[i],b[i]));
  sort(aa.begin(),aa.end());
  ans=0;
  mi=-1;
  for (i=0;i<aa.size();i++)
  {
    if (aa[i].first>=mi)
    {
      ans++;
      mi=aa[i].second;
    }
    else
    {
      if (aa[i].second<mi) mi=aa[i].second;
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

  int N=S.size();
  cout<<string(N,'x')<<endl;

  return 0;
}


Measured memory_bytes: 256
/**
	Language: C++
	Author  : ebby21
**/

#include <bits/stdc++.h>

using namespace std;

#define FastIO() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define Debug(v) cerr << '\n' << #v << ":\t" << v << '\n'
#define Loop(i, L, U) for (ll i = (L); i <= (U); ++i)
#define RLoop(i, U, L) for (ll i = (U); i >= (L); --i)
#define All(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;

int main() {
//	FastIO();

	int n,x,y;

	cin >> n >> x >> y;
	--x, --y;
	vi ans(n - 1, 0);

	Loop(i, 0, n - 1) {
		Loop (j, i + 1, n - 1) {
			ll d1 = j - i, d2 = 1;
			d2 += abs(x - i) + abs(y - j);
			ans[ min(d1, d2) - 1 ]++;
		}
	}

	for (int i: ans) cout << i << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
#define INF 1 << 30
#define MOD 1000000007;
#define pi 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
static const int dx[] = {0, 0, 1, -1};
static const int dy[] = {-1, 1, 0, 0};

int main() { 
  string s;
  cin >> s;
  s[5] = ' ';
  s[13] = ' ';
  D(s);
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

 main(){

   int a,b;
   scanf("%d %d",&a,&b);
   int x,y,z;
   x=a+b;y=a-b;z=a*b;
   if (x>=y && x>=z)
     printf("%d",x);
     else if(y>=x && y>=z)
       printf("%d",y);
     else if(z>=x && z>=y)
       printf("%d",z);
}
    

Measured memory_bytes: 128
Imports System.Text

Module Module1

    Sub Main()
        Dim ans As String = ""

        Dim getvaluelength As Integer


        Dim mojiretu As String = Console.ReadLine()

        getvaluelength = CInt(Console.ReadLine())


        Dim sb As New System.Text.StringBuilder
        sb.Append(mojiretu)

        Dim revflg As Boolean = False
        Dim sentomoji As New StringBuilder
        For i As Integer = 0 To getvaluelength - 1
            Dim tempval() As String = Console.ReadLine.Split(" "c)

            If tempval(0) = "1" Then

                revflg = Not revflg

            Else
                If (tempval(1) = "1" AndAlso Not revflg) OrElse (tempval(1) = "2" AndAlso revflg) Then
                    sentomoji.Append(tempval(2))
                Else
                    sb.Append(tempval(2))
                End If
            End If

        Next

        ans = Microsoft.VisualBasic.Strings.StrReverse(sentomoji.ToString) & sb.ToString

        If revflg Then
            ans = Microsoft.VisualBasic.Strings.StrReverse(ans)

        End If



        Console.WriteLine(ans)
        Console.ReadKey()



    End Sub




End Module

Measured memory_bytes: 26672
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const int MAXN=2000;
ll a[MAXN+5],b[MAXN+5][MAXN+5];
//b[i][j]:使用了j次魔法，获得颜色i的最少花费时间
ll n,x,ans,sum=1LL<<60LL;
int main()
{
	scanf("%lld%lld",&n,&x);
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
	{
		b[i][0]=a[i];
		for(int j=1;j<=n-1;j++)
		{
			int pos=i-j;
			if(pos<=0)
				pos=n-abs(pos);
			b[i][j]=min(b[i][j-1],a[pos]);
		}
	}
	for(int j=0;j<=n-1;j++)
	{
		ans=0;
		for(int i=1;i<=n;i++)
			ans+=b[i][j];
		sum=min(sum,ans+x*j);
	}
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

ll A[405], B[405], dp[405][405], mem[405][405];

ll modpow(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y & 1)ans *= x;
		ans %= MOD;
		y /= 2;
		x *= x;
		x %= MOD;
	}
	return ans;
}

ll eval(ll L, ll R, ll D) {
	ll ans = 0;
	for (ll i = L;i <= R;i++) {
		ans += modpow(i, D);
		ans %= MOD;
	}
	return ans;
}

int main (){
	int N, C;
	cin >> N >> C;
	for (int i = 0;i < N;i++)cin >> A[i];
	for (int i = 0;i < N;i++)cin >> B[i];
	for (int i = 0;i < N;i++) {
		for (int j = 0;j <= C;j++) {
			mem[i][j] = eval(A[i], B[i], j);
		}
	}

	dp[0][0] = 1;

	for (int i = 0;i <= C;i++) {
		for (int j = 0;j < N;j++) {
			for (int k = 0;k <= C;k++) {
				if (i + k > C)break;
				dp[i + k][j + 1] += dp[i][j] * mem[j][k];
				dp[i + k][j + 1] %= MOD;
			}
		}
	}

	cout << dp[C][N] << endl;
}

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

using namespace std;

int main()
{
  int N;
  string S;
  cin >> N >> S;
  
  int count = 0;
  for (int i = 0; i < N-2; ++i)
  {
    if (S.substr(i, 3) == "ABC") ++count;
  }

  cout << count << endl;
}

Measured memory_bytes: 256
//******\\
**udc321**	 
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define fr(e,r,v) for(int e=r;e<v;e++)
#define bc(e,r,v) for(int e=r;e>v;e--)
#define all(n) (n.begin(),n.end())
#define ft first
#define sd second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mpr make_pair
#define db  double
using namespace std;
const double pi = 3.14159265358979323846;
ll mod=1000000007;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*pair(sort and all) implementation and upper bound implementation*/
vector<vector<ll>> v;
vector<ll> h;
ll ps=0;
void dfs(ll a,ll p)
{
	h[a]=1;

	fr(j,0,v[a].size())
	{
		if(h[v[a][j]]==1){continue;}
		dfs(v[a][j],a);
		
	}
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n,m;
	cin>>n>>m;
	v.resize(n);
	fr(i,0,m)
	{
		ll a,b;
		cin>>a>>b;
		a--;b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	h.resize(n,0);
	ll an=0;
	fr(j,0,n)
	{
		if(h[j]==0)
		{an++;dfs(j,-1);}
	}
	cout<<an-1<<endl;
	v.clear();
	h.clear();

}	


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

using namespace std;

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

	int r = l + n - 1;

	int eat;
	if(r <= 0)
		eat = r;
	else if(l >= 0)
		 eat = l;
	else 
		eat = 0;

	int ans = ( r + l) * (r - l + 1) / 2 -eat;

	cout << ans << endl;
}





Measured memory_bytes: 3584
use std::str::FromStr;
use std::fmt::Debug;

fn read_line<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

fn main(){
    let n: Vec<u32> = read_line();
    let n = n[0];
    let mut a: Vec<i64> = read_line();

    for (i, x) in a.iter_mut().enumerate(){
        *x -= i as i64 +1;
    }
    a.sort();

    let b = a[(n as usize/2)];
    let sum = a.iter().fold(0, |sum, x| sum + (x - b).abs());
    println!("{}", sum);
}

Measured memory_bytes: 10492
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main() {
	int n;
	cin>>n;
	string name;
	cin>>name;
	int ans=0;
	REP(i,n){
		string s;
		cin>>s;
		REP(j,s.size()){
			FOR(k,1,s.size()){
				string t;
				int pos=j;
				while(pos<s.size()){
					t.push_back(s[pos]);
					pos+=k;
					if(t==name){
						ans++;
						goto end;
					}
				}
			}
		}
end:
		;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9

ll dp[9]; // dp[i] : i/4リットル買う時の最低金額
ll value[4];
ll N;

void input() {
	for (int i = 0; i < 4; i++) cin >> value[i];
	cin >> N;
}

void solve() {
	dp[0] = 0;
	for (int i = 1; i <= 8; i++) dp[i] = INF;

	for (int i = 1; i <= 8; i++) {
		dp[i] = dp[i - 1] + value[0];
		if (i >= 2) dp[i] = min(dp[i], dp[i - 2] + value[1]);
		if (i >= 4) dp[i] = min(dp[i], dp[i - 4] + value[2]);
		if (i >= 8) dp[i] = min(dp[i], dp[i - 8] + value[3]);
	}
	cout << (N / 2)*dp[8] + (N % 2)*dp[4] << endl;
}

int main() {
	input();
	solve();

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

// pdf editorial
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  vector<pii> b(n);
  rep(i, n) b[i] = pii(a[i], i);
  sort(all(b), greater<pii>());

  vector<vector<ll> > dp(n + 1, vector<ll>(n + 1));
  rep(z, n) {
    rep(x, z + 1) {
      int y = z - x;
      chmax(dp[x + 1][y], dp[x][y] + 1LL * b[z].F * (b[z].S - x));
      chmax(dp[x][y + 1], dp[x][y] + 1LL * b[z].F * (n - 1 - y - b[z].S));
    }
  }
  ll ans = 0;
  rep(x, n + 1) {
    int y = n - x;
    chmax(ans, dp[x][y]);
  }
  cout << ans << endl;
}


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

int main(){
    int N;
    cin>>N;
    int max = 0;
    int sum = 0;
    rep(i, N){
        int L; cin>>L;
        sum += L;
        max = std::max(max, L);
    }

    if(sum-max > max){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define pb push_back
#define f first
#define sc second
using namespace std;
ll mod=1e9+7,i,j;
ll n,m,p[1000005];
vector<ll> nod[1000005];
vector<ll> poz;
vector<ll> val;
ll ans[1000005];
bool viz[1000005];
ll dfs(ll x){
    viz[x]=true;
    poz.pb(x);
    for(unsigned int i=0;i<nod[x].size();i++){
        ll vecin=nod[x][i];
        if(viz[vecin]==0) dfs(vecin);
    }

}
int main(){
    string s;
    cin>>s;
    i=0;
    j=s.size()-1;
    ll ans=0;
    while(i<j){
        if(s[i]!=s[j]) ans++;
        i++;
        j--;
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
    enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

ll power(ll x, ll y)
{
	ll ans = 1;
	while (y>0) {
		if (y&1) {
			ans *= x;
		}
		y /= 2;
		x *= x;
	}
	return ans;
}

void solve()
{
	ll n;
	cin>>n;
	ll len = 0;
	ll p = 0;
	while (p<n) {
		len++;
		p = 26 + 26*p;
	}
	debug() << imie(len);
	string s(len, 'a');
	p = power(26, len-1);
	ll limit = (p-1)/25;
	for (ll i=0; i<len; i++) {
		ll a = n/p;
		if (n%p >= limit) {
			n = n%p;
			p /= 26;
		}
		else {
			a--;
			n = n-a*p;
			p/=26;
		}
		s[i] = 'a'+a-1;	
		limit /= 26;
	}
	cout << s << "\n";
}

int main()
{
	int t=1;
	// cin>>t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>
#include <map>

int main() {
	int m;
	std::cin >> m;
	std::cout << 24 + 24 - m << std::endl;

	return 0;
}
	


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

using namespace std;


int main() {
  
   int n,m;
   scanf("%d%d",&n,&m);
   
   int ans=(m*(m-1))/2 + (n*(n-1))/2;
   printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
X,K,D = map(int,input().split())
if X == 0:
 if K % 2 == 0:
  ans = 0
 else:
  ans = D
elif X < 0:
 if X + D * K < 0:
  ans = -X - D * K
 else:
  N = -X // D
  if (K - N) % 2 ==0:
   ans = -X - D * N
  else:
   ans = X + D * N + D
else:
 if X - D * K > 0:
  ans = X - D * K
 else:
  N = X // D
  if (K - N) % 2 ==0:
   ans = X - D * N
  else:
   ans = -X + D * N + D
print (ans)

Measured memory_bytes: 9132
n=int(input())
counter=[0,0,0,0]
for _ in range(n):
    s=input()
    if s=='AC':
        counter[0]+=1
    elif s=='WA':
        counter[1]+=1
    elif s=='TLE':
        counter[2]+=1
    else:
        counter[3]+=1

print('AC','x',counter[0])
print('WA','x',counter[1])
print('TLE','x',counter[2])
print('RE','x',counter[3])
    

Measured memory_bytes: 69908
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  int n,m; cin >> n >> m;
  int sum =0;
  rep(i,m){
    int x; cin >> x;
    sum+=x;
  }
  if(sum>n) puts("-1");
  else cout << n-sum <<endl;

}


Measured memory_bytes: 3636
//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb2l(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
void solve(){
   ll n,m;cin>>n>>m;
  if(n==m)
    cout<<"Yes";
  else cout<<"No";
}

int main(){
    ll t=1;
//cin>>t;
    while(t--){
     solve();
     cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
long long a,b,c;
int main()
{
	scanf("%lld%lld%lld",&a,&b,&c);
	long long ans=b+min(b,c);
	c-=min(b,c);
	ans+=min(a,c);
	c-=min(a,c);
	if (c) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int x = sc.nextInt();
		boolean c = false;
		int t = 0, i = 1;
		while(!c) {
			t += i;
			if(t >= x) {
				break;
			}
			i++;
		}
		System.out.println(i);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

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

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


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

long long modpow(long long a,long long n,long long MOD){
    int ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return ret;
}

long long modinv(long long a, long long MOD) {
    return modpow(a, MOD - 2, MOD);
}

int main(){
    int r1,c1,r2,c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int MOD = 1000000007;
    int MAX = r2 + c2 + 1;
    long long fact[MAX + 1];
    //factorial mod, modulo inverse
    fact[0] = fact [1] = 1;
    for (int i = 1; i < MAX; i++){
        fact[i + 1] = fact[i] * (i + 1) % MOD;
    }
    int ans = 0;
    int X = 0;
    for (int i = c1; i <= c2; i++){
        X = ((fact[r2 + i + 1] * modinv(fact[r2],MOD)) % MOD * modinv(fact[i + 1],MOD) % MOD - (fact[r1 + i] * modinv(fact[r1 - 1],MOD)) % MOD * modinv(fact[i + 1],MOD) % MOD) % MOD;
        X %= MOD;
        if (X < 0) X += MOD;
        ans += X;
        ans %= MOD;
    }
    cout << ans << endl;
}

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

void solve(int R) {
  cout << 2 * M_PI * R << endl;
}

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

  int R;
  cin >> R;
  solve(R);
  return 0;
}


Measured memory_bytes: 3804
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

ll N,A,B;
vl h(1e5);

ll floor(ll x,ll y){
  	return (x+y-1)/y;
}
bool BN(ll x){
    ll cnt=0;
    rep(i,N){
        if(x*B>=h[i]){
            continue;
        }
        else{
            cnt+=floor(h[i]-x*B,(A-B));
        }
    }
    return (cnt<=x ? true : false );
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> A >> B;
    h.resize(N);
    rep(i,N){
        cin >> h[i];
    }
    ll ok=1e9,ng=0;
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2;
        if(BN(mid)){
            ok=mid;
        }
        else{
            ng=mid;
        }
    }
    cout << ok << endl;
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
int gcd(int a,int b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
int prime(int a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(int i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int pow(int x,int y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
int main(){
  int N,a;
  cin>>N;
  unordered_map<int,int> mp;
  vector<int> vec(N);
  vector<int> tf(1000001);
  for(int i=1;i<=1000000;i++){
    tf.at(i)=prime(i);
  }
  for(int h=0;h<N;h++){
    //間に合わなかったら素数判定結果を前処理で10^6まで計算しておけば計算量を10^7台まで落とせる
    cin>>a;
    vec.at(h)=a;
    int A=a;
    if(a==2){
      mp[2]=max(mp[2],1);
    }
    if(a==3){
      mp[3]=max(mp[3],1);
    }
    for(int i=2;i*i<=A;i++){
      if(tf.at(i)==1){
        int j=0;
        while(a%i==0){
          a/=i;
          j++;
        }
        mp[i]=max(mp[i],j);
      }
      if(a==1){break;}
    }
    if(a!=1){mp[a]=max(mp[a],1);}
  }
  int ans=0;
  unordered_map<int,int> mpcopy=mp;
  for(int i=0;i<N;i++){//O(N*sqrt(max(Ai))*log())<=O(2*10^8)※実際は全てが約数が1e6/その数分持っているわけでは無いので計算量はこれより落ちる
    ll rock=1;
    int a=vec.at(i);
    int A=a;
    if(a==2){
      mp[2]=max(mp[2],1);
    }
    if(a==3){
      mp[3]=max(mp[3],1);
    }
    for(int i=2;i*i<=A;i++){
      if(tf.at(i)==1){
        while(a%i==0){
          a/=i;
          mp[i]--;
        }
      }
      if(a==1){break;}
    }
    if(a!=1){mp[a]--;}
    for(auto itr=mp.begin();itr!=mp.end();itr++){
      rock*=pow(itr->first,itr->second);
      rock%=MOD;
    }
    ans+=rock;
    ans%=MOD;
    mp=mpcopy;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 7924
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;

const int INF = 1e9;
const int MOD = 1e9+7;

int main(void){
    int n, w, h;
    while(cin >> n >> w >> h, n || w || h){
        vector<pair<int, pair<int, int> > > c;
        c.push_back(make_pair(w*h, make_pair(w, h)));
        REP(k, n){
            int p, s;
            cin >> p >> s;
            p--;
            w = c[p].second.first;
            h = c[p].second.second;
            c.erase(c.begin() + p);
            s %= w + h;
            if(s < w){
                if(w - s < s) s = w - s;
                c.push_back(make_pair(s*h, make_pair(s, h)));
                c.push_back(make_pair((w-s)*h, make_pair(w-s, h)));
            }
            else{
                s -= w;
                if(h - s < s) s = h - s;
                c.push_back(make_pair(w*s, make_pair(w, s)));
                c.push_back(make_pair(w*(h-s), make_pair(w, h - s)));
            }
        }
        sort(c.begin(), c.end());
        REP(i, n) cout << c[i].first << " ";
        cout << c[n].first << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin>>n;
    vector <int> num(n);
    int sum=0;
    for (int i = 0; i < n; ++i) {
        cin>>num[i];
        sum+=num[i];
    }
    int p=round(1.0*sum/n);
    sum=0;
    for (int i = 0; i < n; ++i) {
        sum+=(num[i]-p)*(num[i]-p);
    }
    cout<<sum<<endl;
    return 0;
}




Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <memory>
#include <limits>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <forward_list>
#include <cstdint>

using namespace std;
typedef long long ll;

#define rep(_i,_t) for (int _i=0; _i<(int)_t; _i++)
#define rep1(_i,_t) for (int _i=1; _i<=(int)_t; _i++)

int numofbits(int bits)
{
	int num = 0;

	for (; bits != 0; bits &= bits - 1) {
		num++;
	}

	return num;
}

int main()
{
	int N;
	cin >> N;
	map<char, int> M;
	string march = "MARCH";
	sort(march.begin(), march.end());
	rep(i, N) {
		string s;
		cin >> s;
		bool ret = binary_search(march.begin(), march.end(), s[0]);
		if (ret)
			M[s[0]]++;
	}
	ll ans = 0;
	int total = 1 << 5;
	rep(bit, total) {
		int n = numofbits(bit);
		if (n == 3) {
			ll count = 0;
			rep(i, 5) {
				if (bit&(1 << i)) {
					if (count == 0)
						count = 1;
					count *= M[march[i]];
					if (count == 0)
						break;
				}
			}
			ans += count;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int n, x, l, sum=0, ans=1;
  cin >> n >> x;
  for(int i=0;i<n;i++){
    cin >> l;
    sum += l;
    if(sum <= x) ans++;
  }
  cout << ans;
  return 0;
}

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

int main()
{
    int hight[10];

    for(int i = 0; i < 10; i++){
        cin >> hight[i] ;
    }
    
    sort(hight, hight+10);
    
    for(int i = 9; i > 6; i--){
        cout << hight[i] << endl;
    }
    
    return 0;
}

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

int main() {
    double W, H, x, y;
    cin >> W >> H >> x >> y;

    double res = (W * H) / 2;
    if ((int)W % 2 == 0 && (int)H % 2 == 0 && x == W / 2 && y == H / 2)
        printf("%.9f 1\n", res);
    else
        printf("%.9f 0\n", res);
    return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }

  z->parent = y;
  if(y==NIL) root  = z;
  else if(y->key > z->key) y->left=z;
  else y->right = z;

}

void inorder(Node u){
  if(u!=NIL){
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
  }
}

void preorder(Node u){
  if(u!=NIL){
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    

    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }

    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
	printf("\n");
    }

  }
  return 0;
}

Measured memory_bytes: 24040
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
//#include <unordered_set>
//#include <unordered_map>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <locale>
using namespace std;
#define MS0(I) memset(I, 0, sizeof(I));
#define MS1(I) memset(I, -1, sizeof(I));
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, s, n) for(int i = (s); i < (n); ++i)
#define per1(i, a, b) for(int i = a; i >= b; --i)
#define DRI(A) int A; scanf("%d", &A);
#define DRII(A, B) int A, B; scanf("%d %d", &A, &B);
#define DRIII(A, B, C) int A, B, C; scanf("%d %d %d", &A, &B, &C);
#define SZ(X) ((int)X.size() )
#define MP make_pair 
#define pb push_back
#define F first
#define S second
#define ALL(I) (I).begin(), (I).end()
typedef const void CV;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;
typedef long double LDB;
typedef pair<int, int> PII; 
const double eps = 1e-9;
//const double PI = acos(-1);
const LL INFF = 1e18;
const int INF = 1e9;
const int mod = 1e9+7;
const int MAX = 2e5+7;
int a[MAX];
int main(void){
	DRI(n);
	rep1(i, 1, n+1) scanf("%d", a + i);
	rep1(i, 1, n+1) a[i] -= i;
	sort(a + 1, a + n + 1);
	int v = a[n/2+1];
	LL ans = 0;
	rep1(i, 1, n+1) ans += abs(v - a[i]);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

 int main(void)
 {

 int a[10000], min, max, n, i;
 long long sum = 0;
 
scanf("%d", &n);


for(i = 0; i < n; i++)
{
 	scanf("%d", &a[i]);
 	sum += a[i];
 }
	 max = min = a[0];

for(i = 1; i < n; i++)
{
	if(a[i] > max)max = a[i];
 	if(a[i] < min)min = a[i];
 }
	
	 printf("%d %d %lld\n", min, max, sum);

 	
	return 0;

 }

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }

int m,d;

int main()
{
  cin >> m >> d;

  int res = 0;
  forn1(i,m) {
    forn1(j,d) {
      if (j/10 < 2 || j%10 < 2) continue;
      if ((j/10)*(j%10)==i) res++;
    }
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
k = gets.to_i
a = gets.split.map(&:to_i)
min = 0
max = 10**15
while max-min > 1
    mid = min+(max-min)/2
    r = mid*1
    k.times do |i|
        r -= r%a[i]
    end
    if r > 2
        max = mid
    else
        min = mid
    end
end
mx = min
min = 0
max = 10**15
while max-min > 1
    mid = min+(max-min)/2
    r = mid*1
    k.times do |i|
        r -= r%a[i]
    end
    if r < 2
        min = mid
    else
        max = mid
    end
end
mn = max
if mn > mx
    puts "-1"
else
    puts "#{mn} #{mx}"
end

Measured memory_bytes: 8588
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef int keytype;

int gcd(int a, int b){ return (a % b) ? gcd(b, a % b) : b;}
int lcm(int a, int b){ return (a / gcd(a, b)) * b;}

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

int main(){
    int r, d, x;

    scanf("%d %d %d", &r, &d, &x);

    for(int i = 0; i < 10; ++i){
        x = r * x - d;
        printf("%d\n", x);
    }

    return 0;
}


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

using namespace std;

int main(void)
{
  string str;
  cin >> str;
  string key = "keyence";
  int key_i = 0;

  for(int i = 0; i < str.size(); i++){
    if(str[i] != key[key_i]){
      break;
    }
    key_i++;
  }
  string match = "";
  for(int i = key_i; i < key.size(); i++){
    match += key[i];
  }
  if(match == ""){
    cout << "YES" << endl;
    return 0;
  }
  int start = str.size() - match.size();
  for(int k = 0; k < match.size(); k++){
  //  cout << str[i+k] << " " << match[k] << endl;
    if(str[start+k] != match[k]) break;
    if(k == match.size()-1){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 998244353;
const int maxn = 100000 + 5;

int n, m, a[maxn], b[maxn];

int pre[maxn], siz[maxn];
int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); }

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) pre[i] = i, siz[i] = 1;
    for (int i = 1; i <= m; i++) scanf("%d%d", a + i, b + i);
    ll ans = 1ll * n * (n - 1) / 2;
    vector<ll> v;
    for (int i = m; i >= 1; i--) {
        v.push_back(ans);
        int x = find(a[i]), y = find(b[i]);
        if (x == y) continue;
        ans -= 1ll * siz[x] * siz[y];
        pre[y] = x; siz[x] += siz[y] ;
    }
    for (int i = v.size() - 1; i >= 0; i--) printf("%lld\n", v[i]);
    return 0;
}

Measured memory_bytes: 3828
n,m = gets.split(' ').map(&:to_i)

flag = {}
ac_c = 0
wa_c = {}
m.times do
  p, s = gets.split(' ')
  next if flag[p] == 'AC'

  if s == 'AC'
    flag[p] = 'AC'
    ac_c += 1
  else
    wa_c[p] = 0 if wa_c[p].nil?
    wa_c[p] += 1
  end
end

w_c = 0

flag.each do |k, _|
  w_c += wa_c[k] unless wa_c[k].nil?
end

puts "#{ac_c} #{w_c}"


Measured memory_bytes: 21244
using System;
public class Hello{
    public static void Main(){
        // Your code here!
        string[] s=System.Console.ReadLine().Split(' ');
        int a=int.Parse(s[0]),b=int.Parse(s[1]);
        double x=((a+b)/2.0)+0.9;
        System.Console.WriteLine((int)x);
    }
}

Measured memory_bytes: 11092
n = gets.to_i
txy = n.times.map{gets.split.map(&:to_i)}

ans = 'Yes'
now_x = 0
now_y = 0
now_t = 0
txy.each do |t, x, y|
  diff_x = (now_x - x).abs
  diff_y = (now_y - y).abs
  diff_t = t - now_t
  dist = (diff_x + diff_y)
  unless diff_t >= dist && (diff_t - dist).even?
    ans = 'No'
    break
  end
  now_t = t
  now_x = x
  now_y = y
end

puts ans

Measured memory_bytes: 20632
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define msg(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define pri(a) cout << a << endl;

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

  ll n,k,m,d,ans=0;
  cin >> n >> k >> m >>d;
  //ll n,k,ans=0;
  //cin >> n >> k;
  // string s;
  // cin >> s;

  // vint v(n);
	// rep(i,n){
	// 	cin >> v[i];
	// }

  //昇順
  //std::sort(v.begin(),v.end());

  if(n!=m){
    cout << "1" << endl;
  }
  else{
    cout << "0" << endl;
  }
}

Measured memory_bytes: 256