akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()



int main() {
    int n;
    cin >> n;
    vector<vector<int>> ctr(10, vector<int>(10, 0));
    rep (i, 1, n+1) {
        int top = to_string(i)[0] - '0';
        int bot = i % 10;
        ctr[top][bot]++;
    }
    ll ans = 0;
    rep (i, 1, 10) {
        rep (j, 1, 10) {
            ans += ctr[i][j] * ctr[j][i];
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int a[4] = {};
    int sum = 0;
    for (int i = 0; i < 4; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int ans = 1000000;
    for (int i = 1; i < 4; i++) {
        ans = min(ans, abs((a[0] + a[i]) - (sum - a[0] - a[i])));
    }
    cout << ans << endl;
}



Measured memory_bytes: 3104
<?php
list($s) = strs();
for ($i = 0; $i < strlen($s) - 1; ++$i)
    if ($s[$i] === 'A' && $s[$i + 1] === 'C') exit('Yes') . PHP_EOL;
echo 'No' . PHP_EOL;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


Measured memory_bytes: 16232
import sys
import numpy as np

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

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

A = np.arange(M)
B = 2 * M - 1 - A
B[:M//2] -= (2*M+1)

A %= N
B %= N
A += 1
B += 1
for a, b in zip(A.tolist(), B.tolist()):
    print(a,b)

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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                               \
  cerr << #v << ": ";                              \
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", "; \
  cerr << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()
#define MM << " " <<
int main() {
    int N,K;
    cin >> N >> K;

    ll MOD = 998244353;
    
    set<int> s;
    vector<int> L(K);
    vector<int> R(K);
    vector<ll> val(K);
    for(int i=0;i<K;i++){
        cin >> L[i] >> R[i];
    }

    vector<ll> dp(N+1,0);
    dp[1] = 1;
    for(int i=2;i<=N;i++){
        for (int k=0;k<K;k++) {
            int l = L[k], r = R[k];
            if(i-l>0) val[k] += dp[i-l]%MOD;
            if(i-r-1>0) val[k] -= dp[i-r-1]%MOD;
            dp[i] = (dp[i]+val[k])%MOD;
        }
    }

    cout << dp[N]%MOD << endl;

}


Measured memory_bytes: 4840
#include <iostream>
#include <stack>
#include <stdio.h>
#include <cstdlib>

using namespace std;

int main(){
	int x;
	char s[100];
	stack<int> aiueo;
	int y;

	while(scanf("%s", s) != EOF){
//		cout << "Detected "<< s << "\n";
		if( s[0] == '+' ){
			int a = aiueo.top();
			aiueo.pop();
			int b = aiueo.top();
			aiueo.pop();
			aiueo.push(a + b);
//			cout << "The answer is " << aiueo.top() << '\n';
			y = aiueo.top();
		}else if( s[0] == '-' ){
			int a = aiueo.top();
			aiueo.pop();
			int b = aiueo.top();
			aiueo.pop();
			aiueo.push(b - a);
//			cout << "The answer is " << aiueo.top() << '\n';
			y = aiueo.top();
		}else if( s[0] == '*' ){
			int a = aiueo.top();
//			cout << "a = " << a << "\n";
			aiueo.pop();
			int b = aiueo.top();
//			cout << "b = " << b << "\n";
			aiueo.pop();
			aiueo.push(a * b);
//			cout << "The answer is " << aiueo.top() << '\n';
			y = aiueo.top();
		}else if(s != " "){
			x = atoi(s);
			aiueo.push(x);
//			cout << "x was updated to" << x << "\n";
		}
	}
	cout << y << '\n';
}


Measured memory_bytes: 3244
#!/usr/bin/env python3

D = int(input())
c = list(map(int, input().split()))

s = []
for d in range(D):
    s.append(list(map(int, input().split())))

def get_objective_function(output):
    objective_function = 0
    last = [[-1 for i in range(26)] for d in range(D)]

    for d in range(D):
        objective_function += s[d][output[d]]

        last[d][output[d]] = d
        if d < D-1:
            for i in range(26):
                last[d+1][i] = max(last[d][i], last[d+1][i])

        for i in range(26):
            objective_function -= c[i] * (d-last[d][i])
        print(objective_function)

    point = max(10 ** 6 + objective_function, 0)

## outputの作成
# IOに基づくパターン
output = []
for _ in range(D):
    output.append(int(input())-1)

# 最大効用での戦略
#output = []
#for d in range(D):
#    output.append(s[d].index(max(s[d])))
#for d in output:
#    print(d+1)

## 目的関数の確認
get_objective_function(output)

Measured memory_bytes: 9400
N,M=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
G={}
for i in range(1,N*M+1):
  G[i]=[]
for i in range(N):
  G[A[i]].append(i+1)
for i in range(M):
  G[B[i]].append(-(i+1))
A=sorted(A)
B=sorted(B)
ans=1
import bisect
mod=10**9+7
for i in range(N*M,0,-1):
  if len(G[i])>2:
    print(0)
    exit()
  elif len(G[i])==2:
    if G[i][0]*G[i][1]>0:
      print(0)
      exit()
  elif len(G[i])==1:
    if G[i][0]>0:
      d=bisect.bisect_left(B,i)
      ans*=M-d
      ans%=mod
    else:
      e=bisect.bisect_left(A,i)
      ans*=N-e
      ans%=mod
  else:
    d=bisect.bisect_left(B,i)
    e=bisect.bisect_left(A,i)
    f=N*M-i
    ans*=(M-d)*(N-e)-f
    ans%=mod
print(ans)

Measured memory_bytes: 236472
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    rep(i,n-1) {
        if (a[i] == a[i+1]) {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ll long long
        #define ld long double

        int n;
        double dist(double a,double b)
        {
            return a*a + b*b;
        }
        int main()
        {
            tani_nachi_ke  


            int n;
            cin >> n;
            pair<double,double> pp[n];
            double x = 0,y = 0;
            for(int i = 0; i < n; i++)
            {
                cin >> pp[i].ff >> pp[i].ss;
                x += pp[i].ff;
                y += pp[i].ss;
            }
            x/=n;
            y/=n;

            double d,e;
            double P = 0.1;
            for (int i = 0; i < 30000; i++) {
                int f = 0;
                d = dist(x - pp[0].ff, y - pp[0].ss);
                for (int j = 1; j < n; j++) {
                    e = dist(x - pp[j].ff, y - pp[j].ss);
                    if (d < e) { d = e; f = j; }
                }
                x += (pp[f].ff - x)*P;
                y += (pp[f].ss - y)*P;
                P *= 0.999;
            }
            cout << setprecision(9) << fixed;
            cout << (ld)sqrt(d) << endl;





           return 0;
        }

Measured memory_bytes: 256
/*input

*/

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i < b;i++)
#define rrep(i,b,a) for(int i=b ; i > a ; i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define check1(a) cerr << a << endl
#define check2(a,b) cerr << a << "|" << b << endl
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
/*----------------------------------------------*/
const int MAX = (int)2e5 + 10;
int n;
int arr[MAX];
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    rep(i,0,n){
    	cin >> arr[i];
    }
    vector<ll> pref;
    pref.pb(0);
    rep(i,0,n){
    	pref.pb(pref.back()+arr[i]);
    }
    ll sum = pref.back();
    ll diff = (ll)1e18;
    rep(i,1,n){
    	ll z1 = pref[i];
    	ll z2 = sum-pref[i];
    	check2(z1,z2);
    	diff = min(diff,abs(z2-z1));
    }
    cout << diff;
}


Measured memory_bytes: 3188
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int A = Integer.parseInt(in.next());
		int B = Integer.parseInt(in.next());
		int C = Integer.parseInt(in.next());
		if(A==B)System.out.println(C);
		else if(B==C)System.out.println(A);
		else if(C==A)System.out.println(B);
	}
}

Measured memory_bytes: 22484
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <iomanip>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}

const int MAX = 510000;
const int MOD = 1000000007;

int64_t fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    int n ;
    cin >> n ;
    int64_t ans = 0 ;
    int64_t M = 0 ;
    int64_t a ;
    for (int i = 0; i < n; i++)
    {
        cin >> a ;
        M = max(a,M) ;
        ans += M - a ;
    }
    cout << ans << endl ;
    
    
}

Measured memory_bytes: 3620
// abc116_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, ll> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N, K;
    cin >> N >> K;
    vector<P> sushi(N);
    REP(i, N) {
        cin >> sushi[i].first >> sushi[i].second;
        sushi[i].first--;
    }

    sort(ALL(sushi), [](const P& a, const P& b){
        return a.second > b.second;
    });

    priority_queue<ll, vector<ll>, greater<ll>> pq_already;
    priority_queue<ll> pq_notyet;
    vector<ll> dp(N+1);

    // 各ネタごとに美味しさ順に
    vector<vector<ll>> values(N);
    REP(i, N){ values[sushi[i].first].emplace_back(i); }

    // 上位K個使ったときの種類と値
    ll sm = 0;
    set<int> kinds;
    REP(i, K){
        sm += sushi[i].second;
        kinds.insert(sushi[i].first);

        // すでに食べた種類なら、削除候補
        if (i != values[sushi[i].first][0]) pq_already.push(sushi[i].second);
    }

    // 各種類の一番大きいやつだけ入れる。
    REPN(i, K, N){
        if (i == values[sushi[i].first][0]) pq_notyet.push(sushi[i].second);
    }

    dp[kinds.size()] = sm;
    ll ans = dp[kinds.size()] + kinds.size() * kinds.size();
    REPN(x, kinds.size()+1, N+1){
        if (pq_already.empty() || pq_notyet.empty()) break;

        ll already = pq_already.top(); pq_already.pop();
        ll notyet = pq_notyet.top(); pq_notyet.pop();
        dp[x] = dp[x-1] - already + notyet;
        ans = max(ans, dp[x] + (ll)x * x);
    }


    print(ans);


    return 0;
}


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

struct star{int x,y,b;};

bool operator<(const star& s1,const star& s2){
    return s1.b < s2.b;
}

class xma{
public:
    bool operator()(const star& s1,const star& s2){
        return s1.x < s2.x;
    }
};

class yma{
public:
    bool operator()(const star& s1,const star& s2){
        return s1.y < s2.y;
    }
};

class xmi{
public:
    bool operator()(const star& s1,const star& s2){
        return s1.x > s2.x;
    }
};

class ymi{
public:
    bool operator()(const star& s1,const star& s2){
        return s1.y > s2.y;
    }
};

star s[200001];

int main() {

    int n;
    int d;

    cin >> n >> d;

    for(int i=0;i<n;i++){
        cin >> s[i].x >> s[i].y >> s[i].b;
    }

    sort(s,s+n);

    long long int ans = 0;

    map<int,int> x,y;

    priority_queue<star,vector<star>,xma> xmax;
    priority_queue<star,vector<star>,yma> ymax;
    priority_queue<star,vector<star>,xmi> xmin;
    priority_queue<star,vector<star>,ymi> ymin;

    for(int k=0;k<n;k++){

        xmax.push(s[k]);
        ymax.push(s[k]);
        xmin.push(s[k]);
        ymin.push(s[k]);


        //x[s[k].x] += 1;
        //y[s[k].y] += 1;

        while(!xmax.empty() && xmax.top().b + d < s[k].b){
            xmax.pop();
        }
        while(!ymax.empty() && ymax.top().b + d < s[k].b){
            ymax.pop();
        }
        while(!xmin.empty() && xmin.top().b + d < s[k].b){
            xmin.pop();
        }
        while(!ymin.empty() && ymin.top().b + d < s[k].b){
            ymin.pop();
        }

        long long int dx = xmax.top().x - xmin.top().x;
        long long int dy = ymax.top().y - ymin.top().y;

        //cout << xmax.top().x << " "  << -xmin.top().x << " " << ymax.top().y << " " << -ymin.top().y << endl;

        ans = max(ans,dx*dy);

    }

    cout << ans << endl;





    return 0;
}

Measured memory_bytes: 14668
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 100000000
#define inf 1e18 
 
using namespace std;

signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    while(b<=a)
    {
        b*=2;
        k--;
    }
    while(c<=b)
    {
        c*=2;
        k--;
    }
    if(k<0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
using namespace std;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); }

bool ptt(std::vector<int> &a, std::vector<int> &b) {
	int n = a.size();
	int an = 0;
	for (int i = 0; i < n; ++i) {
		an += ((a[i] - b[i]) * (a[i] - b[i]));
	}
	int y = sqrt(an);
	if (y * y == an || (y + 1) * (y + 1) == an || (y - 1) * (y - 1) == an) {
		return true;
	} 
	return false;
}

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int n; cin >> n;
	int d; cin >> d;
	std::vector<std::vector<int> > v(n, std::vector<int> (d, 0));
	for (int i = 0; i < n; ++i) 
		for (int j = 0; j < d; ++j) 
			cin >> v[i][j];
	int cn = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (ptt(v[i], v[j])) 
				cn++;
		}
	}
	cout << cn;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
//const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
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 conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n){
        cin >> a[i] >> b[i];
    }
    sort(all(a));
    sort(all(b));
    ll ans = 0;
    if(n % 2 == 1){
        ll am = a[n / 2];
        ll bm = b[n / 2];
        ans = abs(am - bm) + 1;
    } else {
        ld am = (a[n / 2 - 1] + a[n / 2]) / 2.0;
        ld bm = (b[n / 2 - 1] + b[n / 2]) / 2.0;
        //cout << am << bm << endl;
        ans = (abs(am - bm) + 0.5) / 0.5;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6364
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
lli modexp(lli x, lli y)
{
    x%=MOD;
    lli ans=1ll;
    while(y>0ll)
    {
        if(y&1ll)
            ans=(ans*x)%MOD;
        x=(x*x)%MOD;
        y>>=1ll;
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    lli x=0ll,res=0ll;
    for(int i=0;i<n;++i)
    {
        int len=n-i-1;
        if(s[i]=='1')
        {
            res+=(modexp(2ll,x)*modexp(3ll,len))%MOD;
            ++x;
        }
    }
    res+=modexp(2ll,x);
    cout<<res%MOD<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()
int res = 0;
long long n;
string sft[] = { "7","5","3" };

void check(string s)
{
	if (s.find("7") != string::npos && s.find("5") != string::npos && s.find("3") != string::npos && stoll(s) <= n) ++res;
}

void dfs(int depth, int now, string s)
{
	if (depth == now)
	{
		check(s);
		return;
	}
	rep(i, 0, 2)
	{
		dfs(depth, now + 1, s + sft[i]);
	}
}

int main()
{
	cin >> n;
	int d = to_string(n).size();
	rep(i, 3, d)
	{
		string s = "";
		dfs(i, 0, s);
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

//const int mod = 998244353;
const int mod=1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// 出力は.xで！！！！

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
    int n; cin >> n;
    vector<ll> a(n);
    ll sum=0;
    rep(i,n){
        cin >> a[i];
        sum+=a[i];
    }
    mint ans=0;
    rep(i,n){
        ll now=(sum-a[i])%mod;
        ans+=a[i]*now;
    }
    ans/=2;
    cout << ans.x << endl;
return 0;
}


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

using namespace std;

using ll = long long;

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

    ll n, k;

    cin >> n >> k;
    ll cnt = 0;
    for (ll a = 1; a <= n; ++a) {
        if ((2 * a) % k != 0) continue;

        ll x = (n + a) / k, y = a / k, z = x - y;
        cnt += z * z;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#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++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)
const ll INF = 99999999999;

int main() {
    int N, M, R; cin >> N >> M >> R;
    vector<int> r(R);
    rep(i, R) {
        cin >> r[i];
        r[i]--;
    }
    sort(ALL(r));
    vector<vector<ll>> dp(N, vector<ll>(N, INF));
    ll A, B, C;
    rep(i, M) {
        cin >> A >> B >> C;
        A--; B--;
        dp[A][B] = dp[B][A] = C;
    }
    rep(i, N) dp[i][i] = 0;
    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
    ll ans = INF*1000000;
    do {
        ll cnt = 0;
        rep(i, R-1) {
            cnt += dp[r[i]][r[i+1]];
        }
        chmin(ans, cnt);
    } while(next_permutation(ALL(r)));
    cout << ans << endl;
}


Measured memory_bytes: 3920
# ABC062C - Chocolate Bar

H, W = map(int, input().split())

Ans = 99999999999999999
# Three Division Pattern
TDPAns = min((1 if H % 3 != 0 else 0) * W, (1 if W % 3 != 0 else 0) * H)

OTDPAns = Ans
TODPAns = Ans

# One Two Division Pattern
for x in range(1, W + 1):
    width = W - x
    row_mass = x * H
    sub = Ans
    if H % 2 == 0:
        y = H // 2
        sub = max(row_mass, (width * y)) - min(row_mass, (width * y))
    else:
        y1 = (H // 2) + 1
        y2 = (H // 2)
        sub = max(row_mass, (width * y1), (width * y2)) - min(row_mass, (width * y1), (width * y2))

    OTDPAns = min(OTDPAns, sub)

# Two One Division Pattern
for y in range(1, H + 1):
    height = H - y
    line_mass = height * W
    sub = Ans
    if W % 2 == 0:
        x = W // 2
        sub = max(line_mass, x * y) - min(line_mass, x * y)
    else:
        x1 = (W // 2) + 1
        x2 = (W // 2)
        sub = max(line_mass, x1 * y, x2 * y) - min(line_mass, x1 * y, x2 * y)
    TODPAns = min(TODPAns, sub)

# print(f'{TDPAns}, {OTDPAns}, {TODPAns}')
print(min(TDPAns, OTDPAns, TODPAns))


Measured memory_bytes: 3064
N = int(input())
B = [int(x) for x in input().split(' ')]

ans = [B[0], B[0]]
for i in range(1, N - 1):
    if B[i] - B[i-1] > 0:
        pass
    else:
        ans[i] = B[i]
    ans.append(B[i])

print(sum(ans))

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

using namespace std;

int main() {

	string s;
	cin >> s;

	string t;
	cin >> t;

	long counter = 0;
	for (long i = 0; i < 3; i++) {
		if (s[i] == t[i]) { counter++; }
	}

	cout << counter << endl;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;
const LL mod=998244353;
const int Max_N=3010;

LL dp[Max_N][Max_N];

int main(){
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	dp[A][B]=1;
	for(int i=A; i<=C; i++){
		for(int j=B; j<=D; j++){
			(dp[i][j]+=dp[i-1][j]*j)%=mod;
			(dp[i][j]+=dp[i][j-1]*i)%=mod;
			(dp[i][j]-=dp[i-1][j-1]*(i-1)%mod*(j-1))%=mod;
		}
	}
	while(dp[C][D]<0) dp[C][D]+=mod;
	cout << dp[C][D] << endl;

	return 0;
}

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

bool Travel_from_zero(vector<int> a){
  int move = abs(a.at(1)) + abs(a.at(2));
  return a.at(0) >= move && (a.at(0) - move) % 2 == 0;
}

bool travel(vector<int> &F, vector<int> &T){
  return Travel_from_zero({T.at(0) - F.at(0), T.at(1) - F.at(1), T.at(2) - F.at(2)});
}

int main(){
  int N;
  cin >> N;
  
  vector<vector<int>> A(N, vector<int>(3));
  
  for(vector<int> &i:A)
    cin >> i.at(0) >> i.at(1) >> i.at(2);
  
  A.insert(A.begin(),{0,0,0});
  bool flag = true;
  for(int i = 0; i < N; i++){
    if(!travel(A.at(i), A.at(i+1))){
      flag = false;
      break;
    }
  }
  
  cout << (flag?"Yes":"No") << endl;
}


Measured memory_bytes: 9856
import sys
input = sys.stdin.readline
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
res = [[0] * W for _ in range(H)]
s = []
for i in range(N): s += [i + 1] * a[i]
for i in range(H):
  if i % 2:
    for j in range(W - 1, -1, -1): res[i][j] = s.pop()
  else:
    for j in range(W): res[i][j] = s.pop()
for r in res: print(*r)

Measured memory_bytes: 42096
N,W=map(int,input().split())
dp=[ [0]*(W+1) for i in range(N+1) ]
#print(dp)
Wl=[]
Vl=[]
for i in range(N):
  w,v=map(int,input().split())
  Wl.append(w)
  Vl.append(v)

for i in range(1,N+1):
  for w in range(W+1):
    #print(i,w)
    if w>=Wl[i-1]:
      dp[i][w]=max(dp[i-1][w-Wl[i-1]]+Vl[i-1],dp[i-1][w])
    else:
      dp[i][w]=dp[i-1][w]
print(dp[-1][-1])


Measured memory_bytes: 119916
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define sll set<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define fo(i,n) for(i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define sc(n) scanf(" %lld",&n)
#define sci(n) scanf(" %d",&n)
#define srt(v) sort(v.begin().v.end())
using namespace std;

bool dp[3005][3005]={false};
ll ans1=1,ans2,a,b,c,d,e,f;
double d2=0;
void calc(ll i,ll j)
{
    if(dp[i][j])
        return;

    if(d2<j*100.0/(i+j)+1e-6)
    {
        d2=j*100.0/(i+j);
        ans1=i;ans2=j;
    }
    if(100*a+i+j<=f)
        calc(100*a+i,j);
    if(100*b+i+j<=f)
        calc(100*b+i,j);

    if(i+j+c<=f && j+c<=i*e/100)
        calc(i,j+c);
    if(i+j+d<=f && j+d<=i*e/100)
        calc(i,j+d);
    dp[i][j]=true;
}

int main()
{
    ios::sync_with_stdio(false),cin.tie(0);
    #ifdef UJJWAL_HOME
        freopen("000.txt","r",stdin);
    #endif // UJJWAL_HOME

    ll i,j,k,n,t;

    cin>>a>>b>>c>>d>>e>>f;

    calc(0,0);
    cout<<ans1+ans2<<" "<<ans2;
    return 0;
}


Measured memory_bytes: 6400
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def count_zero(arr):
    cnt = 0
    for a in arr:
        if a == 0:
            cnt += 1

    return cnt
def main():
    N = I()
    a = LI()
    min_element = inf
    min_ix = -1
    while True:
        prev_min = min_element
        for i in range(N):
            if 0 < a[i] < min_element:
                min_element = a[i]
                min_ix = i
        if count_zero(a) == N-1:
            break
        for i in range(N):
            if i == min_ix:
                continue
            a[i] %= min_element
    print(prev_min)
main()



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

int dp[101][101];
int INF = 1000100100;


int main(){
    int n,r[101],c[101];
    cin >> n;
    for(int i=1; i<n+1; i++){
        cin >>r[i] >> c[i];
    }

    //dp[][]を初期化
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++){
            dp[i][j]=INF;
        }
    }

    //dp[i][i]=0にする。
    for(int i=1;i<n+1;i++){
        dp[i][i]=0;
    }
    //区間幅をずらしていく。2からスタート
    for(int k=2; k < n+1; k++){
        //対象区間の始点を一つずつ見ていく
        for(int i=1; i+k -1 < n+1; i++){
            //対象区間を2つの小区間にわける
            for(int j =i; j < i+k; j++){
                dp[i][i+k-1]=min(dp[i][i+k-1], dp[i][j]+dp[j+1][i+k-1] + r[i]*c[j]*c[i+k-1]);
            }
        }//添え字が間違ってないか不安。。
    }
    //全区間の答えを出力
    cout << dp[1][n] << endl;
    return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
int main(){
    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    vector<int> b(n);
    rep(i,n){
        b[a[i]-1]=i+1;
    }
    rep(i,n) cout << b[i]<<" ";
    cout <<endl;
}

Measured memory_bytes: 1536
H, W = map(int, input().split())
G = [list(input()) for _ in range(H)]
v = [g for g in G if g.count('.') != W]
for i in reversed(range(W)):
    chk = True
    for vv in v:
        if vv[i] == '#':
            chk = False
            break
    if chk:
        for vv in v:
            vv.pop(i)
for vv in v:
    print(''.join(vv))

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include <fstream>
#include<unordered_set>
#include<stack>
#include <map>
#include<unordered_map>
#include<time.h>
#include <chrono>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define all(x) x.begin(),x.end()
using namespace std;
#define MAX 1000001 
#define M 998244353
ll inverse(ll n)
{
	ll modu = M;
	ll m = modu;
	ll a = 0, b = 1;
	if (modu == 1)
		return 0;
	while (n > 1)
	{
		ll quo = n / modu;
		ll temp = modu;
		modu = n % modu, n = temp;
		temp = a;
		a = b - (quo * a);
		b = temp;
	}
	if (b < 0)
		b += m;
	return b;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s1, s2;
	cin >> s1 >> s2;
	string s3 = s2;
	s3 += s1;
	cout << s3;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m,d;
	while (cin>>m>>d)
	{
		int sum=0;
		for (int i=2;i<=9;i++)
		{
			for (int j=2;j<=9;j++)
			{
				int t=i*10+j;
				if (t<=d&&(i*j<=m))
				{
//					cout<<i*j<<"-"<<i<<j<<endl;
					sum++;
				}
						
			}		
		}	
		cout<<sum<<endl;
	}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <cmath>
#include <cstdio>
using namespace std;
typedef complex<double> xy_t;

double dot_product(xy_t a, xy_t b) { return (conj(a) * b).real(); }
double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); }
xy_t projection(xy_t p, xy_t b) { return b * dot_product(p, b) / norm(b); }

int main()
{
    int m;
    cin >> m;
    double x, y;
    xy_t P[110];
    for (int i = 0; i < m; i++)
    {
        cin >> x >> y;
        P[i] = xy_t(x, y);
    }
    double sum = 0.0;
    for (int i = 0; i + 2 < m; i++)
    {
        sum += cross_product(P[i + 1] - P[0], P[i + 2] - P[0]) / 2;
    }
    printf("%.1f\n", abs(sum));
    return 0;
}



Measured memory_bytes: 3212
/*************************************************************************
	> File Name: 1.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Blog: https://blog.csdn.net/Pig_cfbsl 
	> Created Time: 2020/9/6 11:59:52
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
const int maxx=1e5+10;
int n,a[maxx],c[maxx],cnt=0;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	n=read();
	For(i,1,n){
		int u=read(),l=1,r=cnt,mid,x=0;
		while(l<=r){
			mid=(l+r)>>1;
			if(c[mid]>=u) l=mid+1;
			else{
				x=mid;
				r=mid-1;
			}
		}
		if(!x) c[++cnt]=u;
		else c[x]=u;
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 4068
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d, N, ans=0;
    vector<int> v(3);
    vector<char> L(3);
    char tmp, tmp2;
    string S, S2, S3;
    bool flag=true;
    
    cin >> a >> b >> c >> d;

    ans = (abs(a - c) <= d) || ( (abs(a - b) <= d) && (abs(b - c) <= d) );
    cout << (ans ? "Yes" : "No") << endl;
    // ans = a<=b ? a:a-1;

    
    // ans = min(A, B) + min(C, D);
    // cout << ans<< endl;

    // if(S[1]==S[2] &&(S[0]==S[1] | S[2]==S[3]))
    // 	cout << "Yes" <<endl;
    // else
    // 	cout << "No" <<endl;

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(abs(a-b) <=d && (b-c) <=d ||abs(c-a)<=d)
    // 	puts("Yes");
    // else
    // 	puts("No");
}



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

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

int main()
{
    int A[3][3];
    bool result[3][3] = {false};
    rep(i, 3)
    {
        rep(j, 3)
        {
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;

    vector<int> b(10);

    rep(i, N)
    {
        cin >> b[i];
        rep(j, 3)
        {
            rep(k, 3)
            {
                if (A[j][k] == b[i])
                {
                    result[j][k] = true;
                }
            }
        }
    }
    string ans = "No";
    rep(i, 3)
    {
        if (result[i][0] && result[i][1] && result[i][2] == true)
        {
            ans = "Yes";
        }
    }
    rep(i, 3)
    {
        if (result[0][i] && result[1][i] && result[2][i] == true)
        {
            ans = "Yes";
        }
    }
    if (result[0][0] && result[1][1] && result[2][2] == true)
    {
        ans = "Yes";
    }
    if (result[2][0] && result[1][1] && result[0][2] == true)
    {
        ans = "Yes";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll MOD = 998244353;
ll dp[200001][30];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, T;
	cin >> N >> T;
	vector<ll> vec1;
	vector<P> vec2;
	for (int i = 0; i < N; i++) {
		ll a, b;
		cin >> a >> b;
		if (a == 0) {
			vec1.push_back(b);
		}
		else {
			vec2.emplace_back(a, b);
		}
	}
	sort(begin(vec1), end(vec1));
	sort(begin(vec2), end(vec2), [](P a, P b) {return b.first*(a.second + 1) < a.first*(b.second + 1); });
	fill((ll*)dp, (ll*)(dp + 200001), 1LL << 60);
	dp[0][0] = 0;
	for (int i = 0; i < vec2.size(); i++) {
		for (int j = 0; j <= min(i, 28); j++) {
			if (dp[i][j] == 1LL << 60) continue;
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			ll after = (vec2[i].first + 1)*dp[i][j] + (vec2[i].first + vec2[i].second + 1);
			if (after <= T) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], after);
		}
	}
	int ans = 0;
	for (int i = 0; i <= min((int)vec2.size(), 28); i++) {
		if (dp[vec2.size()][i] == 1LL << 60) continue;
		ll now = dp[vec2.size()][i];
		int cnt = i;
		for (int j = 0; j < vec1.size(); j++) {
			ll after = now + 1 + vec1[j];
			if (after > T) break;
			now = after;
			cnt++;
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
}

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

#define ll long long
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;

int N, A, B;
int ans = 0;
set<int> st;

int main() {

	cin >> N >> A >> B;

	for(int i = 0; i < N ;i ++){
		int T;
		cin >> T;
		if(T >= A && T < B) continue;
		st.insert(T);
	}

	cout << st.size() << "\n";;;
	
	return 0;
}

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

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) &= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
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();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N;
  cin >> N;
  vec a(N);
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    a[i] = tmp - i - 1;
  }
  sort(ALL(a));

  int mid = (a.size()) / 2;
  int m = a[mid];

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += abs(a[i] - m);
  }

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


Measured memory_bytes: 1792
from statistics import mean
import math
n = int(input())
a = list(map(int, input().split()))

m = mean(a)
Min = math.fabs(a[0]-m)
ret = []

for i in range(1, len(a)):
    if math.fabs(a[i]-m) < Min:
        Min = math.fabs(a[i]-m)
        ret.append(i)


if len(ret) > 0:
    print(ret[-1])
else:
    print(0)

Measured memory_bytes: 5276
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    vector<bool> b(n,false);
    int i = 0;
    int cnt = 0;
    while(true) {
        if(b[i]) {cout << "-1" << endl; return 0;}
        if(i == 1) {cout << cnt << endl;return 0;}
        b[i] = true;
        cnt++;                
        i = a[i]-1;
    }
}

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

int x[20][20]={};
int y[20][20]={};

int main() {
  int n; cin>>n;
  vector<int> a(n);
  rep(i, n) {
    cin>>a[i];
    rep(j, a[i]) {
      cin>>x[i][j]>>y[i][j];
      x[i][j]--;
    }
  }
  int ans=0;
  for (int bit=0;bit<(1<<n);bit++) {
    vector<int> c(n, 0);
    rep(i, n) {
      if (bit&(1<<i)) c[i]=1;
      else c[i]=-1;
    }
    bool frag=true;
    int tmp=0;
    rep(i, n) {
      if (c[i]==1) {
        tmp++;
        rep(j, a[i]) {
          if (y[i][j]==1) {
            if (c[x[i][j]]==-1) frag=false;
            else c[x[i][j]]=1;
          }
          else {
            if (c[x[i][j]]==1) frag=false;
            else c[x[i][j]]=-1;
          }
        }
      }
    }
    if (frag) ans=max(tmp, ans);
  }
  cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << ":" << #x << " = " << (x) << endl;
#else
#define dbg
#endif

#pragma endregion Macros

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

    int x = 0;

    for(int i=0;i<N.size();i++){
        x += N[i] - '0';
        x %= 9;
    }

    string ans;
    if (x == 0) {
        ans = "Yes";
    }else{
        ans = "No";
    }

    cout << ans << endl;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int p[50];
	for (int i = 0; i < n; i++)
		cin >> p[i];

	int differentCount = 0;
	// 昇順配列との誤差が2つ以内
	for (int j = 0; j < n; j++)
	{
		int sorted = j + 1;
		if (p[j] != sorted)
			differentCount += 1;
	}

	if (differentCount <= 2)
		cout << "YES";
	else
		cout << "NO";
	

	return 0;
}

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

#define reverse_array(type, a, n)     \
    for (int i = 0; i < n / 2; i++) { \
        type __t = a[i];              \
        a[i] = a[n - 1 - i];          \
        a[n - 1 - i] = __t;           \
    }
int main(void)
{
    char s[100001];
    scanf("%s", s);

    int s_len = strlen(s);

    int children_num[s_len];
    for (int i = 0; i < s_len; i++) {
        children_num[i] = 0;
    }

    for (int direction = 0; direction < 2; direction++) {
        int count = 0;
        for (int i = 0; i < s_len; i++) {
            if (s[i] == 'R') {
                count++;
            } else {
                children_num[i - 1] += (count + 1) / 2;
                children_num[i] += count / 2;
                count = 0;
            }
        }

        reverse_array(char, s, s_len);
        reverse_array(int, children_num, s_len);

        for (int i = 0; i < s_len; i++) {
            s[i] = (s[i] == 'R' ? 'L' : 'R');
        }
    }

    for (int i = 0; i < s_len; i++) {
        printf("%d ", children_num[i]);
    }

    putchar('\n');
    return 0;
}


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

int main()
{
	string tempStr;
	cin >> tempStr;
	vector<char> str;
	for (int i = 0; i < tempStr.length(); ++i)
	{
		str.push_back(tempStr[i]);
	}
	str.pop_back();			//at least one character deletion.
	bool even = false;
	while (even != true)
	{
		// cout << str.size() << "\tEven " << even << endl;
		if (str.size() <= 1) break;

		if (str.size() % 2 == 1) str.pop_back();
		else
		{
			bool flag = true;
			for (int i = 0; i < str.size()/2; ++i)
			{
				int s = str.size();
				if (str[i] != str[s/2 + i]) 
				{
					flag = false;
					break;
				}
			}
			if (flag) even = true;
			else str.pop_back();
		}
	}

	if (even) cout << str.size() << endl;
	else cout << 0 << endl;



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    int a; cin >> a;
    ++mp[a];
  }
  bool ok = [&]() -> bool {
    if (mp.size() > 3) return false;
    if (mp.size() == 1) return !begin(mp)->first;
    if (mp.size() == 3) {
      int s = 0;
      for (const auto& e : mp) {
        s ^= e.first;
        if (3 * e.second != n) return false;
      }
      if (s) return false;
    }
    if (mp.size() == 2) {
      if (3 * mp[0] != n) return false;
      if (3 * prev(end(mp))->second != 2 * n) return false;
    }
    return true;
  }();
  cout << (ok ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int main() {
  int n,L,t[300],sum = 0;
  cin >> n >> L;
  for(int i = 0; i < n; i++) {
    t[i] = L+i;
    sum += t[i];
  }
  
  int m = 400, a;
  for(int i = 0; i < n; i++) {
    if(m > abs(t[i])) {
      m = abs(t[i]);
      a = i;
    }
  }
  if(t[a] >= 0)
    cout << sum-m << endl;
  else 
    cout << sum+m << endl;
}

Measured memory_bytes: 3636