akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

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

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int D, X, Y;
std::vector<int> A, B;

int main(){
    std::cin >> D;
    
    std::cin >> X;
    REP(i, X){
        char a;
        int p;
        std::cin >> a >> p;

        if(a == 'D'){A.push_back(p);}
    }
    std::sort(A.begin(), A.end(), std::greater<int>());
    
    std::cin >> Y;
    REP(i, Y){
        std::string b;
        int q;
        std::cin >> b >> q;
        
        if(b == "DD"){B.push_back(q);}
    }
    std::sort(B.begin(), B.end(), std::greater<int>());

    int res = 0;
    REP(i, D+1){
        int x = i, y = D - i;
        int value = 0;
        
        for(auto a : A){
            if(x > 0){value += a; x -= 1;}
        }

        for(auto b : B){
            if(y > 1){value += b; y -= 2;}
        }

        res = std::max(res, value);
    }

    std::cout << res << std::endl;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int a,b,k;
  cin>>a>>b>>k;

  bool f=1;
  REP(i,k){
    if(f){
      if(a%2) a--;
      b+=a/2;
      a/=2;
      f=0;
    }else{
      if(b%2) b--;
      a+=b/2;
      b/=2;
      f=1;
    }
  }

  cout<<a<<" "<<b<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int H,W;
long M,dp[4][2000][2000];
string s[2000];
int dx[2]={0,1},dy[2]={1,0};
main()
{
	cin>>H>>W>>M;
	for(int i=0;i<H;i++)cin>>s[i];
	dp[3][0][0]=1;
	dp[1][0][0]=1;
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)
	{
		if(s[i][j]>='0'&&s[i][j]<='9')
		{
			(dp[2][i][j]+=(s[i][j]-'0')*dp[3][i][j])%=M;
		}
		for(int r=0;r<2;r++)
		{
			int tx=i+dx[r],ty=j+dy[r];
			if(tx>=H||ty>=W)continue;
			(dp[0][tx][ty]+=dp[0][i][j])%=M;
			(dp[1][tx][ty]+=dp[1][i][j])%=M;
			if(s[tx][ty]=='+')
			{
				(dp[0][tx][ty]+=dp[2][i][j])%=M;
				(dp[3][tx][ty]+=dp[1][i][j])%=M;
			}
			else if(s[tx][ty]=='*')
			{
				//(dp[1][tx][ty]+=dp[1][i][j]*dp[2][i][j])%=M;
				(dp[3][tx][ty]+=dp[2][i][j])%=M;
			}
			else
			{
				//(dp[1][tx][ty]+=dp[1][i][j]*dp[3][i][j])%=M;
				(dp[2][tx][ty]+=dp[2][i][j]*10)%=M;
				(dp[3][tx][ty]+=dp[3][i][j])%=M;
			}
		}
	}
	cout<<(dp[0][H-1][W-1]+dp[2][H-1][W-1])%M<<endl;
}



Measured memory_bytes: 131920
#include<iostream>
using namespace std;
int count[13];
int main(){

  int N;
  cin>>N;
  while(N--){
    int ai;
    cin>>ai;
    count[ai/400]++;
  }
  int min =0, max = 0;
  for(int i= 0;i<(3200/400);i++){
    if(count[i]!=0)
      min++,max++;
  }
  for(int i=3200/400;i<=(4800/400);i++)
    max+=count[i];
  if(min==0&&max!=0)
    min=1;
  cout<<min<<" "<<max<<endl;

  return 0;
}


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

long long solve(string s, long long k){
    long long n = (long long)s.size();

    long long d = 0;
    long long m = 0;
    long long dm = 0;
    long long dmc = 0;
    long long l = 0;
    for(long long r = 0; r < n; r++){

        if(r - l == k){
            if(s[l] == 'D'){
                d--;
                dm -= m;
            }else if(s[l] == 'M'){
                m--;
            }

            l++;
        }

        if(s[r] == 'D'){
            d++;
        }else if(s[r] == 'M'){
            dm += d;
            m++;
        }else if(s[r] == 'C'){
            dmc += dm;
        }

        

        
    }


    return dmc;
}

int main(){
    long long n; cin >> n;
    string s; cin >> s;
    long long q; cin >> q;
    for(long long i = 0; i < q; i++){
        long long k; cin >> k;

        cout << solve(s, k) << endl;
    }
    return 0;
}

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

int main(){
    long long n,a;
    long long max = -1000000;
    long long min = 1000000;
    long long sum = 0;
    cin >>n;
    for(int i;i<n;i++){
        cin>>a;
        if(max<a)max=a;
        if(min>a)min=a;
        sum+=a;
    }
    cout << min <<" "<< max<< " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
mt19937 R(chrono::system_clock().now().time_since_epoch().count());

const int N = 531441+11;
int n,len,mi[N],f[N];char s[N];int pos[N],lst[N],val[N],posnew[N];
int qz[N];
int main() {
	read(n);scanf("%s",s+1);int len=strlen(s+1);
	rep(i,1,len)qz[i]=qz[i-1]+(s[i]=='S');
	mi[0]=1;rep(i,1,n)mi[i]=mi[i-1]*3;
	rep(i,0,n-1){
		static int g[N];memset(g,0,sizeof(g));
		memset(lst,0,sizeof(lst));rep(j,0,mi[i+1]-1)val[j]=j/mi[i];
		rep(t,1,len)if(s[t]!='S'){
			rep(x,0,2){
				if(val[x*mi[i]+pos[t]]&&(qz[t]-qz[lst[x*mi[i]+pos[t]]]&1))val[x*mi[i]+pos[t]]=3-val[x*mi[i]+pos[t]];
				val[x*mi[i]+pos[t]]++;
				if(val[x*mi[i]+pos[t]]==3)val[x*mi[i]+pos[t]]=0,posnew[t]=x*mi[i]+pos[t];
				lst[x*mi[i]+pos[t]]=t;
			}
		}
		rep(x,0,mi[i+1]-1){
			int res=val[x];if(val[x]&&(qz[len]-qz[lst[x]]&1))res=3-res;
		//	printf("%d:%d %d\n",x,val[x],res);
			g[x]=f[x%mi[i]]+mi[i]*res;
		}
		memcpy(f,g,sizeof(g));
		memcpy(pos,posnew,sizeof(posnew));
	}
	static int ans[N];rep(i,0,mi[n]-1)ans[f[i]]=i;
	rep(i,0,mi[n]-1)printf("%d ",f[i]);
	return 0;
}


Measured memory_bytes: 16156
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
typedef long long int llint;

using namespace std;

int n3( vector<vector<char>> &c, char x, char y, char z) {
	int retx = 0,rety=0,retz=0;
	for (int i = 0; i < 5; i++) {
		if (c[i][0] != x) {
			retx++;
		}
	}
	for (int i = 0; i < 5; i++) {
		if (c[i][1] != y) {
			rety++;
		}
	}
	for (int i = 0; i < 5; i++) {
		if (c[i][2] != z) {
			retz++;
		}
	}
	int sumn3;
	sumn3 = retx + rety + retz;
	return sumn3;
}

signed main() {
	int n;
	cin >> n;
	if (n % 10 == 2 || n % 10 ==4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9) {
		cout << "hon" << endl;
	}
	else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) {
		cout << "pon" << endl;
	}
	else {
		cout << "bon" << endl;
	}


} 

Measured memory_bytes: 3584
# 0や1のケースに注意
# index out of range
# 貪欲

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    k = int(input())
    s = input().rstrip()
    if len(s) <= k:
        print(s)
    else:
        res = s[:k] + '...'
        print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 65220
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    x,y = mi()
    flag = False
    for i in range(x+1):
        if i*2+(x-i)*4 == y:
            flag = True
    if flag:
        print(yes)
    else:
        print(no)



main()




Measured memory_bytes: 10028
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
 
ll mod = 1e9+7;
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll w,h,x,y;
	cin >> w >> h >> x >> y;
	cout << setprecision(60) << ld(ld(h)*ld(w)/ld(2)) << " ";
	if ((w & 1) || (h & 1)) cout << 0 << endl;
	else if (x == w/2 && y == h/2) cout << 1 << endl;
	else cout << 0 << endl;
	cin >> w;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  bool flag = false;
  rep(i, 10) rep(j, 10) {
    int tmp = i * j;
    if (tmp == n)
      flag = true;
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <queue>
#define ll long long
#define N 10000
#define mod 1000000007
#define LL 100
using namespace std;

int main(){
    int n,m;
    ll x;
    cin>>n>>m>>x;
    ll num[n+1][m+1];
    ll money[n+1];
    vector<ll> ans;
    
    for (int i=1; i<=n; i++){
        cin>>money[i];
        for (int j=1; j<=m; j++){
            cin>>num[i][j];
        }
    }
    
    for (int bit = 0; bit < (1<<n); ++bit){
        vector<int> S;
        ll p=0;
        ll sum[m+1];
        for (int i=1; i<=m; i++) sum[i]=0;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i))  S.push_back(1);
            else S.push_back(0);
        }
        for (int i=0; i<n; i++){
            if (S[i]==1){
                p+=money[i+1];
                for (int j=1; j<=m; j++){
                    sum[j]+=num[i+1][j];
                }
            }
        }
        bool q=true;
        for (int i=1; i<=m; i++){
            if (sum[i]<x) q=false;
        }
        
        //cout<<endl;
        if(q) ans.push_back(p);
    }
    
    sort(ans.begin(),ans.end());
    
    //cout<<ans.size()<<endl;
    if (ans.size()==0) cout<<"-1"<<endl;
    else cout<<ans[0]<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<stdlib.h>
using namespace std;
int main()
{
  int a[3][3],b[3][3]={0},p=0;
  int i,j,n,k;
  for(i=0;i<3;i++)
    for(j=0;j<3;j++)
        cin>>a[i][j];
  cin>>n;
  int c[n];
  for(i=0;i<n;i++)
    cin>>c[i];
  for(i=0;i<n;i++)
  {
      for(j=0;j<3;j++)
      {
          for(k=0;k<3;k++)
          {
              if(c[i]==a[j][k])
              {
                  b[j][k]=1;
                  goto jum;
              }
          }
      }
      jum:{}
  }
  for(i=0;i<3;i++)
  {
      p=0;
      for(j=0;j<3;j++)
      {
            if(b[i][j]!=0)
            {
                p++;
            }
            else
                break;
        }
        if(p==3)
        {
            cout<<"Yes";
            goto jump;
        }
  }

  for(i=0;i<3;i++)
  {
      p=0;
      for(j=0;j<3;j++)
      {
            if(b[j][i]!=0)
            {
                p++;
            }
            else
                break;
        }
        if(p==3)
        {
            cout<<"Yes";
            goto jump;
        }
  }
  p=0;
  for(i=0,j=0;i<3 && j<3;i++,j++)
  {
      if(b[i][j]!=0)
      {
          p++;
      }
  }
  if(p==3)
        {
            cout<<"Yes";
            goto jump;
        }
  p=0;
  for(i=2,j=0;i>=0 && j<3;i--,j++)
  {
      if(b[i][j]!=0)
      {
          p++;
      }
  }
   if(p==3)
        {
            cout<<"Yes";
            goto jump;
        }
 cout<<"No";
 jump:{};

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long L;
using namespace std;
  
#define U [100005]={}
map<L,L> path U;
L par U,dep U,siz U,hev U,cst U,add U,pos U,hl_par U,bit U,
k,n,a,b,c,p,r;
char s U;
L dfs(L a){
    siz[a]=1;
    for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){
        L d=I->first;
        if(d-par[a]){
            par[d]=a;
            dep[d]=dep[a]+1;
            cst[d]=I->second;
            dfs(d);
            siz[a]+=siz[d];
            if(!hev[a]|siz[hev[a]]<siz[d])
                hev[a]=d;
        }
    }
}
    
L edgecost(L a){
    r=add[a]+add[par[a]]+cst[a];
    return r%k?r:0;
}
    
L sum(L i){
    for(r=0;i;r+=bit[i],i-=i&-i);
    return r;
}
L S(L i,L x){
    for(x=edgecost(x)-sum(i+1)+sum(i++);
        i<100005;bit[i]+=x,i+=i&-i);
}
  
main(){
    for(cin>>n>>k;p<n-1;p++)
        cin>>a>>b>>c,
        path[a][b]=path[b][a]=c;
    dfs(0);
    
    for(c=p=0;p<n;p++)
        if(!p|hev[par[p]]-p)
        for(a=p;!c|a;a=hev[a])
            pos[a]=c++,
            hl_par[a]=p,
            S(pos[a],hev[a]);
    
    for(cin>>a;cin>>s>>a>>b;)
        if(*s&2){
            for(c=0;p=hl_par[a],n=hl_par[b],p-n;a=par[p])
                dep[p]<dep[n]?swap(p,n),swap(a,b),0:0,
                c+=sum(pos[a])-sum(pos[p])+edgecost(p);
            cout<<c+abs(sum(pos[a])-sum(pos[b]))<<endl;
        }else
            add[a]+=b,
            S(pos[a],hev[a]),
            a?S(pos[a]-1,a):0;
}

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

const int M = 1000000007;

long long dp[210][210];

int main() {
    int n;
    cin >> n;
    int c[205];
    for (int i = 0; i < n; ++i) {
        char cc;
        cin >> cc;
        c[i] = cc == 'U' ? 1 : cc == '-' ? 0 : -1;
    }
    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        if (c[i] == 1) {
            for (int j = 0; j < 205; ++j) {
                dp[i + 1][j + 1] = (dp[i][j] + dp[i][j + 1]) * (j + 1) % M;
            }
        }
        if (c[i] == 0) {
            for (int j = 0; j < 205; ++j) {
                dp[i + 1][j] = dp[i][j];
            }
        }
        if (c[i] == -1) {
            for (int j = 0; j < 205; ++j) {
                dp[i + 1][j] = (dp[i][j] * j + dp[i][j + 1] * (j + 1)) % M;
            }
        }
        // for (int j = 0; j < i + 3; ++j) {
        //     cout << dp[i + 1][j] << " ";
        // }
        // cout << "\n";
    }
    cout << dp[n][0] << "\n";
    return 0;
}

Measured memory_bytes: 3428
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VL a(n);
    REP(i,n) a[i] = in();
    ll ans = 0;
    FOR(d,1,n){
        ll tmp = 0;
        set<int> st;
        REP(x,n){
            int i = d * x;
            int j = n - 1 - d * x;
            if (i >= n - 1) break;
            tmp += a[i] + a[j];
            if (j < d) break;
            if (st.count(i)) break;
            st.insert(i);
            if (st.count(j)) break;
            st.insert(j);
            chmax(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7808
#include <iostream>
#include <queue>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, M; in(N); in(M);

  int A[M], B[M];
  rep(i, M) {
    in(A[i]); in(B[i]);
    --A[i]; --B[i];
  }
  bool visited[N];
  int ans = 0;
  rep(bridge, M) {
    bool is_connected = true;
    fill(visited, visited+N, false);

    queue<int> q; q.push(0);
    while (!q.empty()) {
      int p = q.front(); q.pop();
      if (visited[p])
        continue;
      visited[p] = true;
      rep(i, M) {
        if (i == bridge)
          continue;
        if (A[i] == p) q.push(B[i]);
        if (B[i] == p) q.push(A[i]);
      }
    }
    rep(i, N) {
      if (!visited[i])
        is_connected = false;
    }
    if (!is_connected)
      ++ans;
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int n, m; cin >> n >> m;
  vector<pair<ll, ll>> pa;

  rep (i, n) {
    int a, b;
    cin >> a >> b;
    pa.push_back({a, b});
  }
  sort(pa.begin(), pa.end());

  ll ans = 0;
  for (auto v : pa) {
    if (m > 0) {
      if (m < v.second) {	
	ans += v.first * m;
	m = 0;
      } else {
	m -= v.second;
	ans += v.first * v.second;
      }
    }
  }

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


Measured memory_bytes: 5368
#!/usr/bin/env python

def main():
    b = input()

    if b == 'A':
        return 'T'
    elif b == 'T':
        return 'A'
    elif b == 'G':
        return 'C'
    elif b == 'C':
        return 'G'

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 2940
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

long long int ans = 0;

void dfs(long long int t, long long int got, long long int n)
{
	if(t > n)
		return;
	if(got == 7)
		ans++;
	dfs(t*10+7, got|4,n);
	dfs(t*10+3, got|2,n);
	dfs(t*10+5, got|1,n);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  //  freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    long long int s;
    cin>>s;
    dfs(0,0,s);
    cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import scala.collection.mutable

object Main extends App {
  val k = scala.io.StdIn.readInt()
  var x: Long = 0L

  var queue = mutable.Queue(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L)
  for (_ <- 1 to k) {
    x = queue.dequeue
    val b = x % 10L

    if (b != 0) {
      queue.enqueue(10L * x + (b - 1L))
    }

    queue.enqueue(10L * x + b)

    if (b != 9) {
      queue.enqueue(10L * x + (b + 1L))
    }
  }

  println(x)
}


Measured memory_bytes: 49484
#include <bits/stdc++.h>
using namespace std;
#define testing 0
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto i : v) cerr << i << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto i : v) cerr << "{"  << i.f << ',' << i.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9
#define oo (ll)1e18
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
string lts(ll x) {stringstream s; s << x; return s.str(); }
ll stl(string x) {stringstream s(x); ll temp; s >> temp; return temp; }
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
template <typename T> void maxself(T& a, T b) {
    a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
    a = min(a, b);
}
#define MAXN 
#if !testing
    #define cerr if(0)cout
#endif

int main() {
    IAMSPEED
    // set testing to 0 when submitting to judge
    #if testing
        freopen("input.txt", "r", stdin);
    #endif
    int n; cin >> n;
    string a,b; cin >> a >> b;
    string ans;
    FOR(i,0,n-1) {
        ans.pb(a[i]);
        ans.pb(b[i]);
    }
    cout << ans;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

void go(auto& ops, vector<double>& a, int l, int r) {
    if (l + 1 == r) return;

    int sp = l;
    for (int i = l + 1; i < r; i++)
        if (abs(a[i]) > abs(a[sp]))
            sp = i;

    if (a[sp] < 0) {
        if (sp + 1 < r) {
            go(ops, a, sp + 1, r);
            if (a[sp] > a[sp + 1]) {
                ops.push_back({ sp + 1, sp });
                a[sp] += a[sp + 1];
            }
        }
        for (int i = sp - 1; i >= l; i--) {
            for (int rep = 0; rep < 2; rep++) {
                ops.push_back({ i + 1, i });
                a[i] += a[i + 1];
            }
        }
    } else {
        if (sp > l) {
            go(ops, a, l, sp);
            if (a[sp - 1] > a[sp]) {
                ops.push_back({ sp - 1, sp });
                a[sp] += a[sp - 1];
            }
        }
        for (int i = sp + 1; i < r; i++) {
            for (int rep = 0; rep < 2; rep++) {
                ops.push_back({ i - 1, i });
                a[i] += a[i - 1];
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int N;
    cin >> N;

    vector<double> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    vector<array<int, 2>> ops;
    go(ops, a, 0, N);
    for (int i = 0; i + 1 < N; i++)
        assert(a[i] <= a[i + 1]);
    assert(sz(ops) <= 2 * N);

    cout << sz(ops) << "\n";
    for (auto m : ops)
        cout << m[0] + 1 << " " << m[1] + 1 << "\n";

    return 0;
}



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

int main()
{
  int N, K[100], L[100], dp[1 << 16];

  while(scanf("%d", &N), N) {
    for(int i = 0; i < N; i++) {
      int M;
      scanf("%d %d", &M, L + i);
      K[i] = 0;
      while(M--) {
        int S, E;
        cin >> S >> E;
        S -= 6, E -= 6;
        K[i] |= (1 << E) - (1 << S);
      }
    }
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
    int ret = 0;
    for(int j = 0; j < 1 << 16; j++) {
      if(~dp[j]) {
        ret = max(ret, dp[j]);
        for(int i = 0; i < N; i++) {
          if(!(K[i] & j)) {
            dp[K[i] | j] = max(dp[K[i] | j], dp[j] + L[i]);
          }
        }
      }
    }
    printf("%d\n", ret);
  }
}

Measured memory_bytes: 1492
from collections import defaultdict
from heapq import heapreplace, heappush

n, v = map(int, input().split())
programs = defaultdict(list)
for _ in range(n):
    s, t, c = map(int, input().split())
    programs[c].append((s, t))

combined = []
for c, p in programs.items():
    p.sort()
    ps, pt = p[0]
    for s, t in p[1:]:
        if pt == s:
            pt = t
        else:
            combined.append((ps, pt, c))
            ps, pt = s, t
    combined.append((ps, pt, c))
combined.sort()

recorders = [(-1, None)]
for s, t, c in combined:
    end, channel = recorders[0]
    if end < s or c == channel:
        heapreplace(recorders, (t, c))
    else:
        heappush(recorders, (t, c))
print(len(recorders))


Measured memory_bytes: 25632
#include <cstdio>

using namespace std;

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

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

    int ans = 0;
    for (int i = 0; i < n; ++i)
        if (a[a[i] - 1] == i + 1)
            ans += 1;
    printf("%d\n", ans / 2);

    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,a,n)	for(int i=a;i<n;i++)
int main(){
	int n;
	cin>>n;
	int a[100010];
	rep(i,0,n+3){
		a[i]=0;
	}
	long long int sum=0;
	long long int ans=0;
	rep(i,1,n+1){
		cin>>a[i];
		if(a[i]>0&&a[i-1]>0){
			sum++;
			a[i]--;
			a[i-1]--;
		}		
		sum+=(a[i]/2);
		a[i]-=a[i]/2*2;	
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,K;
  cin>>N;
  cin>>K;
  string L;
  cin>>L;
  int cou=0;
  for(int i=0;i<N-1;i++){
    if(L.at(i)!=L.at(i+1)){
      cou=cou+1;
    }
  }
  int ans=0;
  if(cou>2*K){
    ans=N+2*K-cou-1;
  }
  else{
    ans=N-1;
  }
  cout<<ans;
}

Measured memory_bytes: 512
from sys import stdin
from math import sqrt
input = stdin.readline

N = int(input())

ans = 10 ** 9

for A in range(1, int(sqrt(N)) + 1):
    if N % A == 0:
        B = N // A
        str_A = str(A)
        str_B = str(B)
        ans = min(ans, max(len(str_A), len(str_B)))

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
    ll n,m,t,i,j,k,l,b,x,cnt=0;
    cin>>n;
    map <string,int> me;
string s;
    for(i=0;i<n;i++)
    {
        cin>>s;
        sort(s.begin(),s.end());
        cnt+=me[s];
        
        me[s]++;
    }
    cout<<cnt;
    return 0;
}







Measured memory_bytes: 11136
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
typedef pair <long long, long long> pll;
 
ll mod = 1000000000;
 
int main(){
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  if (n%2 == 0){
    cout << "-1";
    return 0;
  }
  ll t = 7;
  for (int i = 1; i <= 10000000; i++){
    if (t%n == 0){
      cout << i;
      return 0;
    }
    t*=10, t+= 7, t%=n;
  }
  cout << "-1";
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
const ll maxn=2*1e5;
ll bin(ll a, ll b) {
	//a%=m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a; //mod
        a = a * a; //mod
        b >>= 1;
    }
    return res;
}

int gcd(int a, int b, int & x, int & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll fact(ll x)
{
  ll res=1;
  for(ll i=1;i<=x;i++)
    res=(res*i)%mod;

  return res;
}

ll bcof(ll x,ll y) //x choose y
{
  return fact(x)*bin(fact(x-y)*fact(y)%mod,mod-2)%mod;
}

ll lmod(string n,ll x)
{
	
	ll res=0;
	for(ll i=0;i<n.length();++i)
	{
		res=(res*10+(int)n[i]-'0')%x;
	}
	return res;
}
bool ispal(string s,int l,int r)
{
	string t=s;
	for(int i=l,j=r;i<=r;++i)
	{
		if(s[i]!=s[j])
			return false;
		else
			{
				--j;
			}
	}
	return true;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	ll n,i,j,k,b=0;
	cin>>n;
	ll a[n];
	ll freq[maxn+3];
	memset(freq,0,sizeof(freq));
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		
		++freq[a[i]];
	}
	ll ans=0;
	for(i=1;i<maxn+3;i++)
	{
		if(freq[i]!=0)
		ans+=freq[i]*(freq[i]-1)/2;
	}
	for(i=0;i<n;i++)
	{
		ll ff=freq[a[i]];
		ll tans=ans-ff*(ff-1)/2+max(b,(ff-1)*(ff-2)/2);
		cout<<tans<<"\n";
	}
		
}

Measured memory_bytes: 5760
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a>b){
			System.out.println("a > b");
		}
		if(a<b){
			System.out.println("a < b");
		}
		if(a==b){
			System.out.println("a == b");
		}
	}
}


Measured memory_bytes: 26240
S = input()

sList = []
sSentence = ""

sList.append(S[0])

for i in range(1, len(S)):
    sSentence += S[i]
    if sList[len(sList)-1] != sSentence:
        sList.append(sSentence)
        sSentence = ""
print(len(sList))


Measured memory_bytes: 8296
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}
int main(){
    string s;
    bool b=false;
    ll k;
    cin>>s;
    cin>>k;
    ll c=0;
    ll cc=0;
    char ss;
    for(ll i=0;i<s.size();i++){
        if(i==0){
            ss=s[0];
            c=1;
        }else if(ss==s[i]){
            c++;
            if(i==s.size()-1){
                cc=cc+c/2;
            }
        }else{
            cc=cc+c/2;
            ss=s[i];
            c=1;
            b=true;
        }
    }
    ll ca=0;
    c=0;
    s=s+s;
    for(ll i=0;i<s.size();i++){
        if(i==0){
            ss=s[0];
            c=1;
        }else if(ss==s[i]){
            c++;
            if(i==s.size()-1){
                ca=ca+c/2;
            }
        }else{
            ca=ca+c/2;
            ss=s[i];
            c=1;
        }
    }
    ll ans=0;
    
    ans=cc+(ca-cc)*(k-1);
    if(b==false){
        cout<<(k*s.size())/4<<endl;
    }else if(s.size()==2){
        cout<<k/2<<endl;
    }else{
        cout<<ans<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 10000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

ll A[110000];

int main(){
    int N;
    ll ans=0;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>A[i];
    }

    for(int i=0;i<N;i++){
        ans+=A[i]/2;
        A[i]%=2;
        if(A[i]==1 && A[i+1]!=0){
            ans++;
            A[i+1]--;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1656
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
   
   string s;
   int ans=0;
   cin>>s;
  if(s[0]=='R' &&s[1]=='R' && s[2]=='R') ans=3;
  else if(s[0]=='R' && s[1]=='R' &&s[2]=='S' || s[0]=='S' && s[1]=='R' && s[2]=='R') ans=2;
  else if(s[0]=='R'&&s[1]=='S'&&s[2]=='S'||s[0]=='S'&&s[1]=='R'&&s[2]=='S'||s[0]=='S'&&s[1]=='S'&&s[2]=='R'||s[0]=='R'&&s[1]=='S'&&s[2]=='R') ans=1;
  else ans=0;
  cout<<ans<<endl;
}

Measured memory_bytes: 3564
#include<stdio.h>
#include<stdlib.h>
typedef struct A{char m;int n,f;}A;
A sum[100005];
int N,i,flg=0;
void num(A *a,A *b)
{
	A c=*a;
	*a=*b;
	*b=c;
}

int tum(int p,int r)
{
	int i,j,pos;
	A x;
	x=sum[r];
	i=p-1;
	for(j=p;j<r;j++)
	{
		if(sum[j].n<=x.n)
		{
			num(&sum[++i],&sum[j]);
		}
	}
	num(&sum[i+1],&sum[r]);
	return i+1;
}

void rum(int p,int r)
{
	int q;
	if(p<r)
	{
		q=tum(p,r);
		rum(p,q-1);
		rum(q+1,r);
	}
}


int main()
{
	scanf("%d\n",&N);
	for(i=1;i<=N;i++)
	{
		scanf("%c %d\n",&sum[i].m,&sum[i].n);
		sum[i].f=i;
	}
		
	rum(1,N);
	for(i=2;i<=N;i++)
		if(sum[i-1].n==sum[i].n&&sum[i-1].f>sum[i].f)
			flg=1;
	puts(flg?"Not stable":"Stable");
	for(i=1;i<=N;i++)
		printf("%c %d\n",sum[i].m,sum[i].n);
	return 0;
}



Measured memory_bytes: 2876
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	int a,b,x;
	cin >> a >> b >> x;
	double theta;
	double ans;

	if(x<a*a*b/2){
		theta = atan2(a*b*b,2*x);
		ans=theta*180/M_PI;
	}else{
		theta = atan2(2*(a*a*b-x),a*a*a);
		ans=theta*180/M_PI;
	}

	cout << std::setprecision(12) << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/*
  This C++ Source Is
  Writen By syksykCCC
  (2020)
*/
#include <bits/stdc++.h>
#define rep(i, x, y) for(register int i = x; i < y; i++)
#define REP(i, x, y) for(register int i = x; i <= y; i++)
#define per(i, x, y) for(register int i = x; i > y; i--)
#define PER(i, x, y) for(register int i = x; i >= y; i--)
#define repl(i, x, y) for(register long long i = x; i < y; i++)
#define REPL(i, x, y) for(register long long i = x; i <= y; i++)
#define perl(i, x, y) for(register long long i = x; i > y; i--)
#define PERL(i, x, y) for(register long long i = x; i >= y; i--)
#define LLL __int128
#define int128 __int128
#define DEBUG(x) cerr << #x << " : " << x << endl
using namespace std;
typedef unsigned int uint;
typedef long long int64;
typedef long long LL;
typedef unsigned long long uint64;
typedef long long ULL;
typedef long double LLF;
template<typename T> inline void read(T &val)
{
	val = 0; char c = getchar(); int f = 1;
	while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)) { val = (val << 3) + (val << 1) + (c ^ 48); c = getchar(); }
	val *= f;
}
template<typename T> void write_(T val) { if(!val) return; write_(val / 10); putchar(val % 10 + 48); }
template<typename T> inline void write(T val)
{
	if(val == 0) putchar(48);
	else if(val < 0) { putchar('-'); write_(-val); }
	else write_(val);
}

const LL MOD = 1e9 + 7;
const int N = 1e5 + 5;
LL n, x[N], d[N], ans, fac = 1;
LL qpow(LL a, LL p)
{
	LL res = 1;
	while(p)
	{
		if(p & 1) res = res * a % MOD;
		a = a * a % MOD;
		p >>= 1;
	}
	return res;
}
LL inv(LL x)
{
	return qpow(x, MOD - 2);
}

int main()
{
#ifdef LOCAL
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin >> n;
	REP(i, 1, n - 1) 
	{
		fac = fac * i % MOD;
	}
	REP(i, 1, n)
	{
		cin >> x[i];
	}
	LL s1 = 0, s2 = 0;
	rep(i, 1, n)
	{
		s1 = (s1 + fac * x[i] % MOD * (i - 1) % MOD * inv(i) % MOD) % MOD;
	}
	rep(i, 1, n)
	{
		s2 = (s2 + fac * x[i] % MOD * (n - i - 1) % MOD * inv(n - i) % MOD) % MOD;
	}
	ans = s1 - s2 + MOD;
	rep(i, 1, n)
	{
		ans = (ans + fac * inv(n - i) % MOD * (x[n] - x[i]) % MOD) % MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>

using namespace std;

int main() {
    int n, l;
    cin >> n >> l;
    int ans=l, sum=l;
    for(int i=2; i<=n; i++) {
        ans = (abs(ans)>abs(l+i-1)? l+i-1: ans);
        sum += l+i-1;
    }
    cout << sum - ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main()
{
  int t[4][14];
  int n, i,j,c;
  char m, d;
  for(i=0; i < 4; i++){
    for(j=0; j < 14; j++){
      t[i][j]=0;
    }
  }
 scanf("%d", &c);
  for(i = 0; i < c; i++){
    scanf("%c", &d);
    scanf("%c %d", &m, &n);
    if(m == 'S'){
      t[0][n] = 1;
    }
    else if(m == 'H'){
      t[1][n] = 1;
    }
    else if(m == 'C'){
      t[2][n] = 1;
    }
    else if(m == 'D'){
      t[3][n] = 1;
    }
  }
  for(j=1; j < 14; j++){
    if(t[0][j] != 1){
      printf("S %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[1][j] != 1){
      printf("H %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[2][j] != 1){
      printf("C %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[3][j] != 1){
      printf("D %d\n", j);
    }
  }
 return 0;
}
 



Measured memory_bytes: 2060
#include <iostream>
using namespace std;
#define INF 1000000;

int main(){
  int dp[100010];

  int N; cin >> N;

  dp[0] = 0;
  for(int i = 1;i <= 100000;i++){
    dp[i] = INF;
    int power = 1;

    while(power <= i){
      dp[i] = min(dp[i],dp[i-power]+1);
      power*=6;
    }


    power = 1;

    while(power <= i){
      dp[i] = min(dp[i],dp[i-power]+1);
      power*=9;
    }

  }

  cout << dp[N] << endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int x = -1;
	int count = 0;
	
	cin >> x;
	while (x != 0) {
	  count++;
	  cout << "Case " << count << ": " << x << endl;
	  cin >> x;
	}	  
}


Measured memory_bytes: 3056
import java.util.*

fun main(args: Array<String>) {
    val argList = Scanner(System.`in`)


    val n = argList.nextInt()
    val l = argList.nextInt()
    val executor = BiteEating()
    println(executor.execute(n, l)) 

}

class BiteEating {
    fun execute(appleArg: Int, tasteArg: Int): Int {
        val tastes = (1..appleArg).toList().mapIndexed { index, i ->
            // Calculate taste
            index to tasteArg + i - 1
        }

        return tastes.map { Math.abs(it.second) to it.second }
                .sortedBy { it.first }
                .drop(1)
                .sumBy { it.second }

//        return (1..appleArg).toList().mapIndexed { index, i ->
//            // Calculate taste
//            index to tasteArg + i - 1
//            // Sort by taste abs asc
//        }.sortedWith(compareBy({ Math.abs(it.second) }, {it.first}))
//                // Smallest taste(abs) will be drop
//                .drop(1)
//                .map { it.second }
//                .sum()

    }
}

Measured memory_bytes: 36164
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<P, int> PI; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };
bool visited[1000][1000];
char stage[1000][1000];
int h, w, n;

int main(void)
{
	ios::sync_with_stdio(false);
	while(cin >> h >> w >> n && n)
	{
		PArray goals(n + 1);
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				cin >> stage[i][j];
				if(stage[i][j] == 'S') goals[0] = P(i, j);
				int num = stage[i][j] - '0';
				if(inRange(n + 1, num)) goals[num] = P(i, j);
			}
		}

		int ans = 0;
		for (int i = 0; i < n; i++)
		{
			P start = goals[i], goal = goals[i + 1];
			memset(visited, false, sizeof(visited));
			queue<PI> que;
			que.push(PI(start, 0));
			while (!que.empty())
			{
				PI pi = que.front(); que.pop();
				if(goal == pi.first)
				{
					ans += pi.second;
					break;
				}
				int r = pi.first.first, c = pi.first.second;

				for (int i = 0; i < 4; i++)
				{
					int nr = r + dr[i], nc = c + dc[i];
					if(!inRange(h, nr) || !inRange(w, nc) || stage[nr][nc] == 'X' || visited[nr][nc]) continue;
					que.push(PI(P(nr, nc), pi.second + 1));
					visited[nr][nc] = true;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  string s,t;
  cin >> s >> t;
  if(s==t){
    cout << "Yes" << endl;
    return 0;
  }
  n=s.size();
  for(char c='a';c<='z';c++){
    map<char,int> mp;
    bool f=true;
    for(int i=0;i<n;i++){
      if(t[i]==c){
        mp[s[i]]++;
        if(!f){
          if(mp[s[i]]==1){
            cout << "No" << endl;
            return 0;
          }
        }
        f=false;
      }
    }
  }
  for(char c='a';c<='z';c++){
    map<char,int> mp;
    bool f=true;
    for(int i=0;i<n;i++){
      if(s[i]==c){
        mp[t[i]]++;
        if(!f){
          if(mp[t[i]]==1){
            cout << "No" << endl;
            return 0;
          }
        }
        f=false;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    char a[60],b[60];
    while(cin>>a>>b&&(strlen(a)-strlen(b)==0||strlen(a)-strlen(b)==1)){
        for(int i =0;i<strlen(a);i++)
            if (i>=strlen(b))
                cout << a[i];
            else
            cout << a[i]<<b[i];
cout <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int L, k, d;
int main() {
	scanf("%d%d%d", &L, &k, &d);
	int ans = (L - d) / (k + d);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
num=[]
ans= 0
for i in range(N):
    num.append(int(input().rstrip()))
num.sort()
ans = sum(num)
if ans%10==0:
    for i in range(N):
        if num[i]%10 != 0:
            ans -= num[i]
            print(ans)
            exit()
    print(0)
else:
    print(ans)

Measured memory_bytes: 3064
#include"stdio.h"

int sum;
int ave;
int num[51] = {};
long long int dp[51][51][2501] = {};
long long int ans = 0;

int main() {
	scanf("%d %d", &sum, &ave);
	for (int i = 0; i < sum; i++) {
		scanf("%d", &num[i+1]);
	}
	dp[1][0][0] = 1;
	dp[1][1][num[1]] = 1;
	for (int i = 2; i < sum+1; i++) {
		for (int j = 0; j < sum+1; j++) {
			for (int k = 0; k < 2501; k++) {
				
				if(k-num[i]>=0)	dp[i][j][k] += dp[i - 1][j - 1][k - num[i]];
				dp[i][j][k] += dp[i - 1][j][k];
			}
		}
	}
	for (int i = 1; i < sum+1; i++) {
		ans += dp[sum][i][i*ave];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 49024
from collections import defaultdict
import sys
input = sys.stdin.readline

n = int(input())
ss = [input().strip() for _ in range(n)]

count = defaultdict(int)
for s in ss:
    count[s] += 1

print('AC x {}'.format(count['AC']))
print('WA x {}'.format(count['WA']))
print('TLE x {}'.format(count['TLE']))
print('RE x {}'.format(count['RE']))


Measured memory_bytes: 16620
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;

ll binary_search(function<bool(ll)> func, ll start, ll end) {
    /*      func:int ->bool
            returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
             */
    if (end <= start) {   return end;  }   // has to be here, otherwise func(end-1) in next line could be a problem
    if (!func(end-1)) {  return end;  }
    while (end-start>1) {
        ll mid = (start+end)/2;
        if (func(mid)) {  end = mid;  } else { start = mid;   }
    }
    if (func(start)) {  return start;  } else {  return end;   }
};


template<class T>
T fastpower(T a, long long n) {  // n must be >= 1
  if (n==0) {return 1;}
  if (n % 2 == 0) {  
      T halfpower = fastpower<T>(a, n/2);
      return (halfpower*halfpower) % modd;
  } else {
      if (n == 1) {  return a; } else {  
          T halfpower = fastpower<T>(a, n/2);
          return (((halfpower*halfpower)%modd)*a)%modd;
      }
  }
};


int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        vector<ll> a;
        forr(i,0,n) {
            readint(kk); a.push_back(kk-1-i);
        }
        sort(a.begin(), a.end());

        ll x = a[a.size()/2];
        ll ret = 0;
        for(auto y : a) {
            ret += abs(x-y);
        }
        cout << ret << endl;

    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}

Measured memory_bytes: 5396