akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H,W,K;
  cin >> H >> W >> K;
  vector<string> G(H);
  for(int i=0; i<H; i++){
    cin >> G[i];
  }
  int ans = 0;
  for(int bit=0; bit<(1LL<<H); bit++){
    for(int bit2=0;bit2<(1LL<<W); bit2++){
      vector<string> now;
      now = G;
      for(int i=0; i<H; i++){
        if(bit & (1LL<<i)){
          for(int j=0; j<W; j++){
            now[i][j] = '0';
          }
        }
      }
      for(int i=0; i<W; i++){
        if(bit2 & (1LL<<i)){
          for(int j=0; j<H; j++){
            now[j][i] = '0';
          }
        }
      }
      int cnt = 0;
      for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
          cnt += (now[i][j] == '#');
        }
      }
      if(cnt == K){
        ans++;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3660
/*
------------------------------|بسم الله الرحمن الرحيم|------------------------------//
------------"IN THE NAME OF ALLAH, THE MOST GRACIUOS, THE MOST MERCIFUL"-------------//
__________________________________ShahnawazShaikh_____________________________________
*/

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define int int64_t
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);	
vector<int> v(5);
int i;
for(i=0;i<5;i++)cin>>v[i];

for(i=0;i<5;i++){
   if(v[i]==0){
     cout<<i+1;
     break;
   }
}
return 0;	
}

Measured memory_bytes: 3604
#define ll long long int
#define pb push_back
#define mp make_pair
#include <bits/stdc++.h>
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	ll t=1,r,n,a,b,c,x,y,sum,cnt,i,j,k,m,l,q,maxx,minn,temp,ans,flag,z,h,w,p,ts;
	
	string str,ttr;
	long double dans;
	
	
	
//	cin >> t;

	
	for(ts=1;ts<=t;ts++)
	{
	    flag=0;sum=0;cnt=0;ans=0;maxx=0,minn=99999999999; x=0;y=0;temp=0;
	    
	    cin >> str;
	    
	    n=str.size();
	    if(n!=6)
	    cout<<"No\n";
	    else{
	        if(str[2]==str[3] && str[4]==str[5])
	        cout<<"Yes\n";
	        else
	        cout<<"No\n";
	    }
	    
	    
	   
	}
	return 0;
}

Measured memory_bytes: 256
N,A,B,C = map(int,input().split())
l = [int(input()) for _ in range(N)]

def dfs(cur,a,b,c):
    if cur == N:
        return abs(a-A) + abs(b-B) + abs(c-C)-30 if min(a,b,c) > 0 else 10**9
    ret0 = dfs(cur+1,a,b,c)
    ret1 = dfs(cur+1,a+l[cur],b,c) + 10
    ret2 = dfs(cur+1,a,b+l[cur],c) + 10
    ret3 = dfs(cur+1,a,b,c+l[cur]) + 10
    return min(ret0,ret1,ret2,ret3)
print(dfs(0,0,0,0))

Measured memory_bytes: 3064
/*
  Vivek Rathi
  CSE 2nd Year
  MNNIT
*/
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 1e17
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//-------------------------------Template--Above------------------------------------------------
ll bit[200001];
ll n;
void update(ll idx,ll val)
{
	for(ll i=idx+1;i<=n+1;i+=(i&(-i)))
	{
		bit[i]=max(bit[i],val);
	}
}
ll query(ll idx)// range max
{
	ll ans=0;
	for(ll i=idx+1;i>0;i-=(i&(-i)))
	{
		ans=max(ans,bit[i]);
	}
	return ans;
}
int main()
{
	boost
	
	cin>>n;
	ll h[n];
	ll maxi=0;
	for(ll i=0;i<n;i++)
	{
		cin>>h[i];
		maxi=max(maxi,h[i]);
	}
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(ll i=0;i<n;i++)
	{
		ll maxBeauty0toH = query(h[i]-1);
		//debug1(maxBeauty0toH);
		update(h[i],maxBeauty0toH+a[i]);// update H
	}
	cout<<query(maxi)<<endl;
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

ll dp[20][20];

int pref( int x ){
	while( x >= 10 ){
		x -= x%10;
		x /= 10;
	}
	return x;
}

int main(){
	int n; cin >> n;
	ll ans = 0;
	for( int k = 1; k <= n; ++k ){
		int x = pref(k);
		int y = k%10;
		if( x == 0 || y == 0 ) continue;
		ans += dp[y][x]*2;
		if( x == y ) ans += 1;
		dp[x][y] += 1;
	}
	cout << ans << endl;
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define MOD 1000000007
#define IINF (INT_MAX/2)
#define LLINF (LLONG_MAX/2)

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
    int N, M; cin >> N >> M;
    vvi ab(N);
    rep(i,M) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        ab[a].emplace_back(b);
        ab[b].emplace_back(a);
    }
    vi ch(N);
    rep(i,N) ch[i] = i;

    int ans = 0;

    do{
        bool flag = true;
        rep(i, N-1) {
            auto itr = find(ab[ch[i]].begin(), ab[ch[i]].end(), ch[i+1]);
            if(itr == ab[ch[i]].end()) {
                flag = false;
                break;
            }
        }
        if(flag) ans++;
    }while(next_permutation(ch.begin(), ch.end()) && ch[0] == 0);

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  vi count(n + 1);
  vl a(n);
  REP(i, n) { cin >> a[i]; }

  ll ans = 3;
  count[0] = 1;
  if (a[0] != 0) {
    cout << 0 << endl;
    return 0;
  }
  FOR(i, 1, n) {
    if (a[i] == 0LL) {
      ans = (ans * (3 - count[0])) % MOD;
    } else {
      ans = (ans * (count[a[i] - 1] - count[a[i]])) % MOD;
      if (count[a[i] - 1] == 0 && count[a[i]] > 0) {
        cout << 0 << endl;
        return 0;
      }
    }
    count[a[i]]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
double s;
int n,x[10],y[10],k;
double dst(int i, int j) {
    double dx=x[i]-x[j];
    double dy=y[i]-y[j];
    return sqrt(dx*dx+dy*dy);
}
int main()
{
    cin>>n;
    vector<int> v(n);
    for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
    for(int i=0;i<n;i++) v[i]=i+1;
    do{
        for(int i=0;i<n-1;i++) s+=dst(v[i],v[i+1]);
        k++;
    }while(next_permutation(v.begin(),v.end()));
    cout<<fixed<<setprecision(10)<<s/k<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;


int main(){
  ll n;
  cin >> n;
  vector<int> a(n);
  map<int,int> mp;
  rep(i,n){
    cin >> a[i];
    mp[a[i]]++;
  }

  vector<ll> b;
  for(auto it:mp){
    b.emplace_back(it.S);
  }
  sort(b.begin(),b.end());
  ll m= b.size();
  vector<ll> r(n+1,0);
  rep(i,n){ r[i+1] = r[i]+(i<m?b[i]:0); }

  REP(k,1,n+1){
    ll ok=-1,ng=n+1,mid=(ok+ng)/2;
    while(ng-ok>1){
      mid=(ok+ng)/2;
      ll pos = lower_bound(b.begin(),b.end(),mid) - b.begin();
      ll cnt = r[pos] + mid*(m-pos);      
      if(cnt >= mid*k){ 
        ok=mid; 
      }else{ 
        ng=mid; 
      }
    }
    ll ans = ok;
    cout << ans << ln;
  }
  return 0;
}

Measured memory_bytes: 22420
using System;
using System.Linq;

namespace _0063
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 0;
            while (true)
            {
                string before = Console.ReadLine();
                if (before == null)
                {
                    break;
                }
                string after = new string(before.Reverse().ToArray());
                if (before == after)
                {
                    x++;
                }
            }
            Console.WriteLine(x);
        }
    }
}

Measured memory_bytes: 9368
#include<bits/stdc++.h>
#define pb push_back
#define ll long long int
using namespace std;


int main(){
  
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	
	string s,p="", c="";
	cin>>s;
	ll cnt=0, n=s.size();
	for(int i=0; i<n; i++){
		c+=s[i];
		if(c!=p){
			cnt++;
			p=c;
			c="";
		}
	}
	cout<<cnt;
	
	
    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  int a[n];
  rep(i,n) R a[i];
  ll dp[5000][51];
  mem(dp);
  dp[0][0]=1;
  rep(i,n) {
    rrep(j,n+1) {
      rrep(k,5000) {
        if(k+a[i]<5000) dp[k+a[i]][j+1]+=dp[k][j];
      }
    }
  }
  ll ans=0;
  rep(i,5000) {
    REP(j,1,n+1) {
      if((double)i/j==m) ans+=dp[i][j];
    }
  }
  pr(ans);
}
int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n;
  cin>>n;
  if(n%10==3) cout<<"bon"<<endl;
  else if(n%10==0 or n%10==1 or n%10==6 or n%10==8) cout<<"pon"<<endl;
  else cout<<"hon"<<endl;

}

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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main(){
    string S;
    cin>>S;
    int l = S.size();
    if(S[l-1]=='s') S += "es";
    else S += 's';
    cout<<S<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE
std::vector<int> Eratosthenes( const int N )
{
    std::vector<bool> is_prime( N + 1 );
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;
    }
    std::vector<int> P;
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}

void solve(void)
{
  int X;
  cin>>X;
  vector<int> E = Eratosthenes(10e5+1);
  cout<<*lower_bound(ALL(E),X)<<endl;
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 1528
import sys
sys.setrecursionlimit(1000000)
N=int(input())
MAXN=1005
MAXV=N*(N-1)//2

a=[[0 for j in range(N-1)] for i in range(N)]
for i in range(N):
  line=list(map(int,input().split()))
  for j in range(N-1):
    a[i][j]=line[j]-1

id=[[0 for j in range(MAXN)] for i in range(MAXN)]
v=0
for i in range(N-1):
  for j in range(i+1,N):
    id[i][j]=v
    v+=1

def toId(i,j):
  if i>j:
    i,j=j,i
  return id[i][j]

to=[[] for i in range(MAXV)]
for i in range(N):
  for j in range(N-1):
    a[i][j]=toId(i,a[i][j])
  for j in range(N-2):
    to[a[i][j+1]].append(a[i][j])
    
visited=[False for i in range(MAXV)]
calculated=[False for i in range(MAXV)]
dp=[0 for i in range(MAXV)]

def dfs(v):
  if visited[v]:
    if not calculated[v]:
      return -1
    return dp[v]
  visited[v]=True
  for u in to[v]:
    val=dfs(u)
    if val==-1:
      return -1
    if val+1>dp[v]:
      dp[v]=val+1
  calculated[v]=True
  return dp[v]
    
ans=0
for i in range(v):
  res=dfs(i)
  if res==-1:
    print(-1)
    break
  if ans<res:
    ans=res
else:
  print(ans+1)
    

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


int main()
{
	int h, w, i;
	string a[100];
	cin >> h >> w;
	for (i = 0; i < h; i++) cin >> a[i];

	for (i = 0; i < w + 2; i++)cout << "#";
	cout << endl;
	for (i = 0; i < h; i++) {
		cout << "#" << a[i] << "#" << endl;
	}
	for (i = 0; i < w + 2; i++)cout << "#";
	cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

int main(){
    long long N,X,Y;
    long long ans;
    cin >> N;
    ans = N;
    for(long long i=1;i*i<=N;i++){
        if(N % i == 0){
            X = i;
            Y = N / i;
            ans = min(ans,X-1+Y-1);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new ABC130().Solve130C(new ConsoleInput(Console.In, ' '));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
    
   class ABC130
   {
   public void Solve130C(ConsoleInput cin)
        {
            var w = cin.ReadInt;
            var h = cin.ReadInt;
            var x = cin.ReadInt;
            var y = cin.ReadInt;
            double area = ((double)w) * h / 2;
            int center = 0;
            if (x * 2 == w && y * 2 == h)
                center = 1;
            WriteLine($"{area} {center}");
            ReadLine();
        }
   }
}


Measured memory_bytes: 13268
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int a,b,c,ans=0,max;
  scanf("%d %d %d",&a,&b,&c);
  if(a%2==b%2&&b%2-c%2){
    a++;
    b++;
    ans++;
  }
  else if(a%2==c%2&&a%2-b%2){
    a++;
    c++;
    ans++;
  }
  else if(b%2==c%2&&a%2-b%2){
    b++;
    c++;
    ans++;
  }
  max=MAX(a,MAX(b,c));
  ans+=(max-a)/2;
  ans+=(max-b)/2;
  ans+=(max-c)/2;
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
	int n, m;
	int a[50], b[50];
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		cin >> a[i] >> b[i];
	}
	int result[50] = { 0 };
	for(int i = 0; i < m; i++){
		result[a[i]-1]++;
		result[b[i]-1]++;
	}
	for(int i = 0; i < n; i++){
		cout << result[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
using ll=long long;

int main(){
  ll N; cin>>N;
  vector<ll> A(N,0); for(ll i=0;i<N;i++){cin>>A[i]; A[i]-=i;}
   
  sort(A.begin(),A.end());
  ll num=A[N/2];
  ll ans=0;
  for(ll i=0;i<N;i++) ans+=abs(A[i]-num);

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cstdlib>
#include <stack>
#include <random>

using namespace std;

typedef long long ll;





int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    cout << max(n + m, max(n - m, n * m)) << "\n";
    
    return 0;
}


Measured memory_bytes: 256
from sys import stdin


def main():
    N, M = [int(x) for x in stdin.readline().rstrip().split()]
    ab = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]
    ab1 = [b for a, b in ab if a == 1]
    ab2 = [a for a, b in ab if b == N]
    print('POSSIBLE' if len(set(ab1) & set(ab2)) else 'IMPOSSIBLE')


if __name__ == '__main__':
    main()


Measured memory_bytes: 48632
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#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 INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
/* 素因数分解 */
map<ll, ll> primeFactMap;
void primeFactor(ll n)
{
    if ((n % 2) == 0){
        while((n % 2) == 0) {
            primeFactMap[2]++;
            n = n / 2;
        }
    }

    for(ll i = 3; (i * i) <= n; i += 2){
        while ((n % i) == 0){
            primeFactMap[i]++;
            n = n / i;
        }
    }

	if (n != 1) {
		primeFactMap[n]++;
	}
}

// メイン
int main()
{
	// 入力
	int N;
	cin >> N;

	// 2～N!を素因数分解
	for (int i = 2; i <= N; i++) {
		primeFactor(i);
	}

	ll res = 1;
	for (auto one : primeFactMap) {
		res *= one.second + 1;	// +1は0乗分
		res %= MOD;
	}

	// 結果
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define repr(i, a, n) for (ll i = n - 1; (ll)a <= i; i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 + 99);
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T>
T mpow(T a, T n)
{
   T res = 1;
   for (; n; n >>= 1)
   {
      if (n & 1)
         res = res * a;
      a = a * a;
   }
   return res;
}
vector<string> v(200);

int bfs(int s, int n)
{
   queue<int> q;
   vector<int> used(n, 0);
   q.push(s);
   q.push(0);
   q.push(-1);

   while (!q.empty())
   {
      int now = q.front();
      q.pop();
      int way = q.front();
      q.pop();
      int mae=q.front();
      q.pop();
      way++;

      if (used[now])
      {
         if ((max(used[now],way)-min(used[now],way))%2 != 0)
         {
            return -1;
         }
         else
         {
            continue;
         }
      }

      used[now] = way;

      rep(i, 0, n)
      {
         if (v[now][i] == '1' && i!=mae)
         {
            q.push(i);
            q.push(way);
            q.push(now);
         }
      }
   }

   int res = 0;
   rep(i, 0, n) res = max(res, used[i]);
   return res;
}
//cin.tie(0);ios::sync_with_stdio(false);

signed main()
{
   int n, ans = -1;
   cin >> n;

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

   //cout<<bfs(5,n);
   rep(i, 0, n)
   {
      ans = max(ans, bfs(i, n));
   }
   cout << ans << endl;
}

Measured memory_bytes: 856
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<set>
#include<queue>
#include<string>
#include<sstream>
#include<iostream>
#include<sstream>
#include<stack>
#include<map>
#include<vector>
using namespace std;
set<string> ss;
int main()
{
	string b;
	char t = '*';
	int n, cnt = 0;
	cin >> n;
	while (n--)
	{
		cin >> b;
		if (ss.count(b) || (cnt++ != 0 && b[0] != t)) {
			cout << "No" << endl;
			return 0;
		}
		else ss.insert(b), t = b[b.size() - 1];
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
const int maxn=200010;
int n;
int a[maxn];
int ar[maxn],nm;
int In() {
    register char c;
    for(;c=getchar(),c!='-'&&!isdigit(c););
    register bool f=c=='-';
    register int s=f?0:c-'0';
    for(;c=getchar(),isdigit(c);)s=s*10+c-'0';
    return f?-s:s;
}
bool ck(register int ans) {
	nm=0;
	for(register int i=1;i<=n;++i) {
		if(!nm) ar[++nm]=a[i];
		else if(ar[nm]<a[i]) ar[nm]=a[i];
		else {
			if(ar[nm]>a[i]) {
				for(;nm&&ar[nm]>a[i];--nm);
				for(;nm>=ans&&ar[nm-ans+1]==ar[nm]&&ar[nm];--ar[nm-ans+1]);
				if(nm&&ar[nm]<=0) return 0;
				ar[++nm]=a[i];
			}
			for(;nm>=ans&&ar[nm-ans+1]==ar[nm]&&ar[nm];--ar[nm-=ans-1]);
			if(nm&&ar[nm]<=0) return 0;
			ar[++nm]=a[i];
		}
	}
	return 1;
}
int main() {
	n=In();
	for(register int i=1;i<=n;++i)a[i]=In();
	register int ll=1,rr=n;
	for(register int mm;mm=(ll+rr)>>1,ll<rr;ck(mm)?rr=mm:ll=mm+1);
	printf("%d\n",ll);
	return 0;
}

Measured memory_bytes: 1664
#候補数を取得
N = int(input())
#TとAの値を取得
T, A = map(int, input().split())
#N個の国のHを配列に格納
H = list(map(int, input().split()))
#差を計算し絶対値をとる
min_index = [abs(A - (T - i*0.006)) for i in H]
#最小値を持つインデックスを探し出力
print(min_index.index(min(min_index))+1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
template<typename T> inline T& Max(T &x,const T &y) {return x<y?(x=y):x;}
template<typename T> inline T& Min(T &x,const T &y) {return y<x?(x=y):x;}
inline int read() {
	int x=0,f=1;
	char c=getchar();
	for (;!isdigit(c);c=getchar()) if (c=='-') f=-1;
	for (;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int maxn=2e5+10;
const int maxm=4e5+10;
const int maxj=19;
const int inf=1e9;
int n,k,a[maxn],mxj,tot=0;
int mx[maxn][maxj],mi[maxn][maxj];
int fr[maxn],bk[maxn],bin[maxn];
bool alr[maxn],st[maxn][maxj];
struct req {
	int t,x,y;
	inline bool operator < (const req &r) const {
		return x!=r.x?x<r.x:t<r.t;
	}
} q[maxm];
bool sorted(int l,int r) {
	assert(l<=r);
	int j=bin[r-l+1];
	return st[l][j] && st[r-(1<<j)+1][j];
}
int getmin(int l,int r) {
	if (l>r) return inf;
	int j=bin[r-l+1];
	return min(mi[l][j],mi[r-(1<<j)+1][j]);
}
int getmax(int l,int r) {
	if (l>r) return -inf;
	int j=bin[r-l+1];
	return max(mx[l][j],mx[r-(1<<j)+1][j]);
}
int get_fr(int x) {
	int y=x-1,lim=x+k-1;
	for (int j=mxj;j--;) {
		int p=y+(1<<j);
		if (p>lim) continue;
		if (sorted(x,p) && a[p]<getmin(p+1,lim)) y=p;
	}
	return y+1;
}
int get_bk(int x) {
	int lim=x+k-1,y=lim+1;
	for (int j=mxj;j--;) {
		int p=y-(1<<j);
		if (p<x) continue;
		if (sorted(p,lim) && getmax(x,p-1)<a[p]) y=p;
	}
	return y-1;
}
namespace bit {
	int c[maxn];
	inline int lowbit(int x) {
		return x&-x;
	}
	void inc(int x,int d) {
		for (;x<maxn;x+=lowbit(x)) c[x]+=d;
	}
	int sum(int x) {
		int ret(0);
		for (;x;x-=lowbit(x)) ret+=c[x];
		return ret;
	}
}
int main() {
	for (int i=2;i<maxn;++i) bin[i]=bin[i>>1]+1;
	n=read(),k=read();
	for (mxj=0;(1<<mxj)<=n;++mxj);
	for (int i=1;i<=n;++i) a[i]=read()+1;
	for (int i=1;i<=n;++i) mx[i][0]=mi[i][0]=a[i],st[i][0]=1;
	for (int j=1;j<mxj;++j) for (int i=1;i<=n;++i) {
		int p=i+(1<<(j-1));
		mx[i][j]=mx[i][j-1],mi[i][j]=mi[i][j-1],st[i][j]=st[i][j-1];
		if (p>n) continue;
		Max(mx[i][j],mx[p][j-1]);
		Min(mi[i][j],mi[p][j-1]);
		st[i][j]=st[i][j-1] && st[p][j-1] && mx[i][j-1]<mi[p][j-1];
	}
	for (int i=1;i<=n-k+1;++i) {
		fr[i]=get_fr(i);
		bk[i]=get_bk(i);
		if (fr[i]==i+k) {
			alr[i]=true;
			continue;
		}
		q[++tot]=(req){0,bk[i],i}; // insert
		q[++tot]=(req){1,i+k-1,i};
	}
	sort(q+1,q+tot+1);
	int ans=0;
	for (int i=1;i<=n-k+1;++i) ans|=alr[i];
	for (int i=1;i<=tot;++i) {
		if (q[i].t==0) bit::inc(q[i].y,1); else
		if (q[i].t==1) {
			int tmp=bit::sum(fr[q[i].y])-bit::sum(q[i].y);
			ans+=(tmp==0);
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 42496
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional;
import std.algorithm, std.container;

void main()
{
    string S = readln.strip;

    long res=  long.max;
    foreach(n; [0, 1])
    {
        long count;
        foreach(i, c; S)
        {
            if(c == ((i % 2 == n) ? '1' : '0'))
            {
                count++;
            }
        }
        res = min(count, res);
    }
    writeln(res);
}

class UnionFind{
    UnionFind parent = null;

    void merge(UnionFind a)
    {
        if(same(a)) return;
        a.root.parent = this.root;
    }
    UnionFind root()
    {
        if(parent is null)return this;
        return parent = parent.root;
    }
    bool same(UnionFind a)
    {
        return this.root == a.root;
    }
}

void scanValues(TList...)(ref TList list)
{
    auto lit = readln.splitter;
    foreach (ref e; list)
    {
        e = lit.fornt.to!(typeof(e));
        lit.popFront;
    }
}

T[] scanArray(T = long)()
{
    return readln.split.to!(long[]);
}

void scanStructs(T)(ref T[] t, size_t n)
{
    t.length = n;
    foreach (ref e; t)
    {
        auto line = readln.split;
        foreach (i, ref v; e.tupleof)
        {
            v = line[i].to!(typeof(v));
        }
    }
}

T scanElem(T = long)()
{
    char[] res;
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        res ~= cast(char) c;
        c = getchar;
    }
    return res.strip.to!T;
}

template fold(fun...) if (fun.length >= 1)
{
    auto fold(R, S...)(R r, S seed)
    {
        static if (S.length < 2)
        {
            return reduce!fun(seed, r);
        }
        else
        {
            import std.typecons : tuple;

            return reduce!fun(tuple(seed), r);
        }
    }
}

struct Factor
{
    long n;
    long c;
}

Factor[] factors(long n)
{
    Factor[] res;
    for (long i = 2; i ^^ 2 <= n; i++)
    {
        if (n % i != 0)
            continue;

        int c;
        while (n % i == 0)
        {
            n = n / i;
            c++;
        }
        res ~= Factor(i, c);
    }
    if (n != 1)
        res ~= Factor(n, 1);

    return res;
}
long[] primes(long n)
{
    if(n<2)return [];
    auto table = new long[n+1];
    long[] res;
    for(int i = 2;i<=n;i++)
    {
        if(table[i]==-1) continue;
        for(int a = i;a<table.length;a+=i)
        {
            table[a] = -1;
        }
        res ~= i;
    }
    return res;
}
bool isPrime(long n)
{
    if (n <= 1)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;
    for (long i = 3; i ^^ 2 <= n; i += 2)
        if (n % i == 0)
            return false;
    return true;
}

Measured memory_bytes: 508
//  @ /\/\ BESH //

#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,s,e) for(int i=s;i<=e;i++)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define pb push_back


using namespace std;

typedef long long ll;
typedef long double ld;

const int MAXN = 1000001;
const int mod = 1000000007;


int main(){
    int n;
    cin>>n;
    ll a[n];
    fr(i,n)cin>>a[i];
    ll p[n];
    p[0] = a[0];

    for(int i = 1; i < n; i++)p[i] = a[i] + p[i-1];

    ll ans = 1e18;

    // p[n-1] - 2*p[i]

    for(int i = 1; i < n; i++){
        ans = min(ans, abs(p[n-1]-p[i]+a[i] - p[i-1]));
    }

    cout<< ans << endl;

}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,m;
  cin >> n >> m;
  vector<string> a(n);
  vector<string> b(m);
  REP(i,n) cin >> a[i];
  REP(i,m) cin >> b[i];
  bool bj = false;
  REP(i,n-m+1){
    REP(j,n-m+1){
      bool judge = true;
      REP(k,m){
        REP(l,m){
          if(a[i+k][j+l]!=b[k][l]){
            judge = false;
            break;
          }
        }
        if(!judge) break;
      }
      if(judge){
        bj = true;
        break;
      }
    }
    if(bj) break;
  }
  if(bj) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
// Author : ps41

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll M = 1e9 + 7, N = 1e6 + 5;
ll f[N];

ll binexpmod(ll a, ll b, ll m)
{
    a %= m;
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll ncr(ll n, ll r)
{
    ll num = f[n];
    ll den = (f[r] * f[n - r]) % M;
    return (num * binexpmod(den, M - 2, M)) % M;
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    f[0] = 1;
    for (ll i = 1; i < N; i++) f[i] = (i * f[i - 1]) % M;
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= n - 1; i++)
    {
        ll t1 = ncr(n, i);
        ll t2 = binexpmod(9, n - i, M);
        ll t3 = binexpmod(8, n - i, M);
        ll t4 = (t2 - t3 + M) % M;
        ll t5 = (t1 * t4) % M;
        ans = (ans + t5) % M;
    }
    cout << ans;
}

Measured memory_bytes: 11452
import java.math.BigInteger;

public class Main {
	final private static BigInteger BIG_8 = BigInteger.valueOf(8);
	final private static BigInteger BIG_9 = BigInteger.valueOf(9);
	final private static BigInteger BIG_2 = BigInteger.valueOf(2);

	public static void main(String[] args) {
		var sc = new java.util.Scanner(System.in);
		var n = sc.nextInt();
		var m = BigInteger.valueOf(1000000000 + 7);
		var all = BigInteger.TEN.pow(n);
		var all9 = BIG_9.pow(n);
		var all8 = BIG_8.pow(n);
		var etc = all9.multiply(BIG_2).subtract(all8);
		System.out.println(all.subtract(etc).mod(m));
	}
}


Measured memory_bytes: 88988
import itertools

n=input()
x=0

s=list(map(int,input().split()))
s2=set(s)
s3=sorted(s2)

s4=list(itertools.combinations(s3,3))

for i in s4:
    if i[0]+i[1]>i[2]:
        x=x+s.count(i[0])*s.count(i[1])*s.count(i[2])

print(x)

Measured memory_bytes: 20496
NMXY =  list(int(i) for i in input().split())
x =  list(int(i) for i in input().split())
y =  list(int(i) for i in input().split())

x.append(NMXY[2])

y.append(NMXY[3])

if max(x) < min(y):
    print('No War')
else:
    print('War')


Measured memory_bytes: 2940
N = int(input())

AC = 0
WA = 0
TLE = 0
RE = 0

for i in range(N):
  ans = input()
  
  if ans == "AC":
    AC += 1
    
  elif ans == "WA":
    WA += 1
    
  elif ans == "TLE":
    TLE += 1
    
  elif ans == "RE":
    RE += 1
    
print("AC x", AC)
print("WA x", WA)
print("TLE x", TLE)
print("RE x", RE)


Measured memory_bytes: 9076
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  if(a>b) swap(a,b);
  b-=a;
  n--;
  for(Int i=0;i<=n;i++){
    Int x=i;
    Int y=n-i;
    Int s=d*x-c*y;
    Int t=c*x-d*y;
    if(t<=b&&b<=s){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
class Die
    def initialize(t, f)
        @top, @left, @front = 1, 2, 3

        if bottom == t
            @top, @left = bottom, right
        elsif top != t
            spin until front == t
            @top, @front = front, bottom
        end
        spin until front == f

        @x = @y = 0
    end
    attr_reader :top, :front, :left, :x, :y

    def spin
        @front, @left = right, front
    end

    def bottom
        7 - top
    end

    def back
        7 - front
    end

    def right
        7 - left
    end

    def rollable(i, board)
        h = board[[@x, @y]].size
        case i
            when front then return board[[@x, @y-1]].size < h
            when back  then return board[[@x, @y+1]].size < h
            when left  then return board[[@x-1, @y]].size < h
            when right then return board[[@x+1, @y]].size < h
        end
        false
    end

    def roll(i)
        case i
        when front
            @top, @front = back, top
            @y -= 1
        when back
            @top, @front = front, bottom
            @y += 1
        when left
            @left, @top = top, right
            @x -= 1
        when right
            @left, @top = bottom, left
            @x += 1
        end
    end
end


loop do
    n = gets.to_i
    break if n == 0

    board = Hash.new([])
    n.times do
        die = Die.new(*gets.split.map(&:to_i))
        loop do
            rolled = false
            [6, 5, 4].each do |i|
                if die.rollable(i, board)
                    die.roll(i)
                    rolled = true
                    break
                end
            end
            break unless rolled
        end
        a = board[[die.x, die.y]]
        if a.empty?
            board[[die.x, die.y]] = [die]
        else
            a << die
        end
    end
    count = [0] * 6
    board.each_value do |dice|
        count[dice.last.top - 1] += 1
    end
    puts count * ' '
end

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

typedef struct node {
    int n, x;
    struct node *next;
} node;

int main()
{
    int i, j, k;

    node *head = NULL, *cur = NULL;
    while( 1 ){
        node *new = (node *)malloc(sizeof(node));
        if( new == NULL ) exit(-1);
        scanf("%d%d", &new->n, &new->x);
        if( new->n == 0 && new->x == 0 ){
            free(new);
            break;
        }
        new->next = NULL;
        if( head == NULL ) head = new;
        else cur->next = new;
        cur = new;
    }

    int kind;
    cur = head;
    while( cur ){
        kind = 0;
        for( i = 1; i <= cur->n; ++i )
            for( j = i+1; j <= cur->n; ++j )
                for( k = j+1; k <= cur->n; ++k )
                    if( i + j + k == cur->x ) ++kind;
        cur = cur->next;
        printf("%d\n", kind);
    }

   return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
int main() {

    int n, m, l, k,t;
    scanf("%d%d",&n,&m);
    if(n==m){
        printf("Draw\n");
    } else if(n>m&&m==1){
        printf("Bob\n");
    }
    else if(n>m&&m!=1){
        printf("Alice\n");
    }
    else if(n<m&&n==1){
        printf("Alice\n");
    } else if(n<m&&n!=1){
        printf("Bob\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    ll m,k;cin>>m>>k;
    ll mx=pow(2,m)-1;
    if(k>mx){
        cout<<-1<<endl;
        return 0;
    }
    if(k==0){
        vl z;
        rep(i,mx+1){
            z.push_back(i);
            z.push_back(i);
        }
        rep(i,(int)z.size()) cout<<z[i]<<" ";
        cout<<endl;
        return 0;
    }
    ll sum=0;
    rep(i,mx+1){
        if(i==k)continue;
        sum^=i;
    }
    if(sum!=k){
        cout<<-1<<endl;
        return 0;
    }
    vl ans;
    ans.push_back(k);
    rep(i,mx+1){
        if(i==k)continue;
        ans.push_back(i);
    }
    ans.push_back(k);
    drep(i,mx+1){
        if(i==k)continue;
        ans.push_back(i);
    }
    rep(i,(int)ans.size())cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3952
a = input().split()
# print(a)
b = int(a[0])
c = int(a[1])
d = []
for i in range(b):
    d.append(c + i)
# print(d)
if d.count(0) == 1:
    d.remove(0)
elif c < 0:
    del d[-1]
elif c > 0:
    del d[0]
# print(d)
e = sum(d)
print(e)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		loop: while (true) {
			w = scanner.nextInt();
			h = scanner.nextInt();
			if ((w | h) == 0)
				break;
			count = 0;
			sy = -1;
			map = new boolean[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					int now = scanner.nextInt();
					if (now == 0) {
						count++;
						if (sy == -1) {
							sy = i;
							sx = j;
						}
					} else {
						map[i][j] = true;
					}
				}
			}
			if (count % 2 == 1 || count == 0) {
				System.out.println("No");
				continue;
			}
			for (int i = 0; i < h; i++) {
				lo: for (int j = 0; j < w; j++) {
					if (map[i][j])
						continue;
					int c = 0;
					for (int[] m : move) {
						int ny = i + m[0];
						int nx = j + m[1];
						if (!isOK(ny, nx))
							continue;
						if (map[ny][nx])
							continue;
						c++;
						if (c == 2)
							continue lo;
					}
					System.out.println("No");
					continue loop;
				}
			}
			System.out.println(dfs(sy, sx, 0, -100) ? "Yes" : "No");
		}
	}

	private boolean dfs(int y, int x, int deep, int prev) {
		if (count - deep < Math.abs(y - sy) + Math.abs(x - sx))
			return false;
		for (int r = 0; r < 4; r++) {
			int ny = y + move[r][0];
			int nx = x + move[r][1];
			if (!isOK(ny, nx))
				continue;
			if (Math.max(r, prev) - Math.min(r, prev) == 2)
				continue;
			if (ny == sy && nx == sx && count - 1 == deep)
				return true;
			if (map[ny][nx])
				continue;
			if (!check(ny, nx))
				continue;
			map[ny][nx] = true;
			if (dfs(ny, nx, deep + 1, r))
				return true;
			map[ny][nx] = false;
		}
		return false;
	}

	private boolean check(int y, int x) {
		lo: for (int[] m : move2) {
			int ny = y + m[0];
			int nx = x + m[1];
			if (!isOK(ny, nx))
				continue;
			if (nx == sx && ny == sy)
				continue;
			if (map[ny][nx])
				continue;
			int c = 0;
			for (int[] mm : move) {
				int nny = ny + mm[0];
				int nnx = nx + mm[1];
				if (!isOK(nny, nnx))
					continue;
				if (map[nny][nnx])
					continue;
				c++;
				if (c == 2)
					continue lo;
			}
			return false;
		}
		return true;
	}

	private boolean isOK(int y, int x) {
		if (0 <= y && y < h && 0 <= x && x < w)
			return true;
		return false;
	}

	int count;
	boolean[][] map;
	int[][] move = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };
	int[][] move2 = { { -1, -1 }, { -1, 1 }, { 1, -1 }, { 1, 1 } };
	int h, w, sx, sy;
}

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

using namespace std;

int main()
{
  int N, A[3] = {};

  cin >> N;
  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[a % 3]++;
  }
  if(A[1] < A[2]) swap(A[1], A[2]);

  if(A[1] == 0) {
    cout << 1 << endl;
  } else {
    int get = min(A[1] - 1, A[2]);
    A[1] -= get + 1;
    A[2] -= get;
    int up = get * 2 + A[0] + 1;
    if(A[1] > 0) ++up, --A[1];
    if(A[1] > 0 || A[2] > 0) ++up;
    cout << up << endl;
  }
}

Measured memory_bytes: 3092
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {
	int i, j, l;
	int aa, ab,ac,ad,ae,af,ag;
	double ba, bb, bc;
	char ca, cb, cc;
////////////////////////////////////////////////////////
	
	while (scanf("%d",&aa) != EOF && scanf("%d", &ab) != EOF) {
		ac = aa + ab;
		ad = 0;
		while (ac) {
			ac = ac / 10;
			ad++;
		}
		cout << ad<<"\n";

	}
	return 0;

}



Measured memory_bytes: 3140
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;


class Main {

        static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        public static void main(String[] args) throws Exception{
            String[] words = reader.readLine().split(" ");
           
            HashMap<String, Integer> dist = new HashMap<String, Integer>();
            String longest = ""; 

            for (int i=0; i<words.length; i++) {
                if (dist.containsKey(words[i])) {
                    dist.put(words[i], dist.get(words[i]) + 1);
                } else {
                    dist.put(words[i], 1);
                }

                if (words[i].length() > longest.length())
                    longest = words[i];
            }

            int max_dist = -1;
            String max_word = ""; 
            for (String key : dist.keySet()) {
                if (max_dist < dist.get(key)) {
                    max_word = key;
                    max_dist = dist.get(key);   
                }
            }

            System.out.println(max_word + " " + longest);
            
        }

}

Measured memory_bytes: 16892
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


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


int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  map<char, ll> cnt;
  string march = "MARCH";

  int num = 0;

  rep(i, n){
    cin >> s[i];
  }

  rep(i, 5) {
    cnt[march[i]] = 0;
  }

  rep(i, n){
    cnt[s[i][0]]++;
  }

  rep(i, 5){
    if(cnt[march[i]] != 0) {
      num++;
    }
  }
  ll ans = 0;

  if(num >= 3) {
    for(int i = 0; i < 5; ++i){
      for(int j = i + 1; j < 5; ++j){
        for(int k = j + 1; k < 5; ++k){

          ans += cnt[march[i]] * cnt[march[j]] * cnt[march[k]];

        }
      }
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 6144