akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>

using namespace std;

const long long P = 1000000007;

long long fac[300001];
long long ifac[300001];

long long mod_pow(long long a, long long p) {
	long long ans = 1;

	while (p != 0) {
		if (p & 1) {
			ans = ans * a % P;
		}
		a = a * a % P;
		p = p >> 1;
	}
	return ans;
}

void init_fac_table(void) {
	fac[0] = 1;
	ifac[0] = 1;
	for (int i = 0; i < 300000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % P;
		ifac[i + 1] = ifac[i] * mod_pow(i + 1, P - 2) % P;
	}
}

long long nCr(long long n, long long r) {
	if (n == 0 && r == 0) {
		return 1;
	}
	if (n < r || n < 0) {
		return 0;
	}
	long long t = ifac[n - r] * ifac[r] % P;
	return t * fac[n] % P;
}

int main(int argc, char *argv[])
{
	int N, K;

	cin >> N >> K;

	init_fac_table();

	for (int i = 1; i <= K; i++) {
		long long c1 = nCr(N - K + 1, i);
		long long c2 = nCr(K - 1, i - 1);
		long long a = (c1 * c2) % P;
		cout << a << "\n";
	}

	return 0;
}


Measured memory_bytes: 4992
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1LL<<(x))
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 400005
#define nm 2000005
#define N 1000005
#define M(x,y) x=max(x,y)
const double pi=acos(-1);
const int inf=1e9+7;
using namespace std;
 
struct FastIO
{
    static const int S=200;
    int wpos;
    char wbuf[S];
    FastIO():wpos(0){}
    inline int xchar()
    {
        static char buf[S];
        static int len=0,pos=0;
        if(pos==len) pos=0,len=fread(buf,1,S,stdin);
        if(pos==len) exit(0);
        return buf[pos++];
    }
    inline int read()
    {
        int s=1,c=xchar(),x=0;
        while(c<=32) c=xchar();
        if(c=='-') s=-1,c=xchar();
        for(;'0'<=c&&c<='9';c=xchar()) x=x*10+c-'0';
        return x*s;
    }
    ~FastIO()
    {
        if(wpos) fwrite(wbuf,1,wpos,stdout),wpos=0;
    }
}io;

struct edge{int t,v;edge*next;}e[nm],*h[NM],*o=e;
void add(int x,int y,int v){o->v=v;o->t=y;o->next=h[x];h[x]=o++;}
int n,m,cnt,tot,c[NM],b[NM],f[NM],d[NM];
bool v[NM];
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
struct TT{
    int x,y,v;
    bool operator<(const TT&o){return v<o.v;}
}a[nm];
struct tmp{
    int x,d;
    bool operator<(const tmp&o)const{return d>o.d;}
};
priority_queue<tmp>q;

void dij(){
    inc(i,2,cnt)d[i]=inf;q.push(tmp{1,0});d[1]=0;
    while(!q.empty()){
    int t=q.top().x;q.pop();
    link(t)if(d[j->t]>d[t]+j->v)q.push({j->t,d[j->t]=d[t]+j->v});
    }
}

int main(){
    //freopen("data.in","r",stdin);
    n=io.read();m=io.read();
    if(m==0){puts("-1");return 0;}
    mem(e);mem(h);o=e;
    inc(i,1,m){a[i].x=io.read();a[i].y=io.read();a[i].v=io.read();}
    sort(a+1,a+1+m);cnt=n;
    inc(i,1,m){
        int t=i;while(a[i].v==a[t].v&&t<=m)t++;t--;
        tot=0;
        inc(j,i,t){c[++tot]=a[j].x;c[++tot]=a[j].y;}
        sort(c+1,c+1+tot);
        tot=unique(c+1,c+1+tot)-c-1;
        inc(j,1,tot)f[c[j]]=c[j],b[c[j]]=0,v[c[j]]=false;
        inc(j,i,t){
        int x=find(a[j].x),y=find(a[j].y);
        if(x==y)continue;
        f[x]=y;
        }
        inc(j,1,tot){
        int x=find(c[j]);
        if(v[c[j]])continue;
        v[c[j]]++;
        if(!b[x])b[x]=++cnt;
        add(c[j],b[x],1);add(b[x],c[j],0);
        //printf("%d %d %d\n",c[j],b[x],1);
        //printf("%d %d %d\n",b[x],c[j],0);
        }
        i=t;
    }
    dij();
    if(d[n]==inf)printf("-1\n");else printf("%d\n",d[n]);
    return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;

  int ans = 0;
  int anum = 'z' - 'a' + 1;
  bool see[anum];
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < anum; j++) {
      see[j] = false;
    }
    string bef = s.substr(0, i);
    string aft = s.substr(i, n - i);
    int cnt = 0;
    for (auto b : bef) {
      if (see[b - 'a']) {
        continue;
      }
      see[b - 'a'] = true;
      for (auto c : aft) {
        if (b == c) {
          cnt++;
          break;
        }
      }
    }
    ans = max(ans, cnt);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
s = input()

if n%2 == 1:
    print('No')
else:
    flag = True
    for i in range(n//2):
        if s[i] != s[n//2 + i]:
            flag = False
    if flag:
        print('Yes')
    else:
        print('No')


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

ll f(ll x)
{
	return x*x*x*x*x;
}

int main()
{
	ll x;
	cin >> x;
	for(int i = 0;i<=(1<<13);i++)
	{
		for(int j = 0;j<=(1<<13);j++)
		{
			if(f(i)-f(j)==x)
			{
				cout<<i<<' '<<j<<endl;
				return 0;
			}
			if(f(-i)-f(j)==x)
			{
				cout<<-i<<' '<<j<<endl;
				return 0;
			}
			if(f(i)-f(-j)==x)
			{
				cout<<i<<' '<<-j<<endl;
				return 0;
			}
			if(f(-i)-f(-j)==x)
			{
				cout<<-i<<' '<<-j<<endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<algorithm>
#include<set> 
using namespace std;
bool notfound(int i,set<int> d){
  int l=d.size();
  d.insert(i);
  int m=d.size();
  if(l==m){
    return false; 
  }else{
    d.erase(i);
    return true;
  }
}
int main(){
  int n,k,t,ok[10]={0},kk=0;
  set<int> d;
  cin>>n>>k;
  for(int i=1;i<=k;i++){
    cin>>t;
    d.insert(t);
  }
  for(int i=0;i<=9;i++){
    if(notfound(i,d)){
      ok[kk]=i;
      kk++;
    }
  }
  for(int i5=0;i5<kk;i5++){
    int yen=ok[i5];
    if(yen>=n){
      cout<<yen<<endl;
      return 0;
    }
  }  
  for(int i4=0;i4<kk;i4++){
    for(int i5=0;i5<kk;i5++){
      int yen=ok[i4]*10+ok[i5];
      if(yen>=n){
        cout<<yen<<endl;
        return 0;
      }
    } 
  } 
  for(int i3=0;i3<kk;i3++){
    for(int i4=0;i4<kk;i4++){
      for(int i5=0;i5<kk;i5++){
        int yen=ok[i3]*100+ok[i4]*10+ok[i5];
        if(yen>=n){
          cout<<yen<<endl;
          return 0;
        }
      } 
    } 
  }
  for(int i2=0;i2<kk;i2++){
    for(int i3=0;i3<kk;i3++){
      for(int i4=0;i4<kk;i4++){
        for(int i5=0;i5<kk;i5++){
          int yen=ok[i2]*1000+ok[i3]*100+ok[i4]*10+ok[i5];
          if(yen>=n){
            cout<<yen<<endl;
            return 0;
          }
        } 
      } 
    }
  }
  for(int i1=0;i1<kk;i1++){
    for(int i2=0;i2<kk;i2++){
      for(int i3=0;i3<kk;i3++){
        for(int i4=0;i4<kk;i4++){
          for(int i5=0;i5<kk;i5++){
            int yen=ok[i1]*10000+ok[i2]*1000+ok[i3]*100+ok[i4]*10+ok[i5];
            if(yen>=n){
              cout<<yen<<endl;
              return 0;
            }
          } 
        } 
      }
    }
  }
}

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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for (int i=0; i<N; i++) cin >> vec.at(i);
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
    
    int s=0;
    for (int i=0; i<N; i++) {
      if (i%2==0) s+=vec.at(i);
      else s-=vec.at(i);
    }
  
  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll h,w,r,dp[105][9];
int main(void){
    cin>>h>>w>>r;
    dp[0][0]=1;
    w--;
    if(w==0){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<1<<w;j++){
            bool o=true,p=false;
            for(int k=0;k<w;k++){
                if((j>>k&1)&&p)o=false;
                p=(j>>k&1);
            }
            if(!o)continue;
            for(int k=0;k<w;k++){
                if(j>>k&1){
                    dp[i+1][k+1]=(dp[i+1][k+1]+dp[i][k])%M;
                    dp[i+1][k]=(dp[i+1][k]+dp[i][k+1])%M;
                }else{
                    if(k==0||!(j>>(k-1)&1))dp[i+1][k]=(dp[i+1][k]+dp[i][k])%M;
                    if(k==w-1)dp[i+1][k+1]=(dp[i+1][k+1]+dp[i][k+1])%M;
                }
            }
        }
    }
    cout<<dp[h][r-1]<<endl;
}


Measured memory_bytes: 256
require 'set'

def f(s)
	0 while s.gsub!(/\((\d+)\)/, '\1')
	0 while s.gsub!(/\(\(([^\(\)]+)\)\)/, '(\1)')
	return if $checked[s]
	$checked[s] = 0

	if s.scan(/\d+/).size == 1
		$set << eval(s)
		return
	end

	op_hash = {}
	num_hash = {}

	s.gsub!(/\((-\d+)\)/) do
		c = ((?A.ord) + num_hash.size).chr
		num_hash[c] = $1.to_i
		c
	end

	s.gsub!(/\d+/) do |x|
		c = ((?A.ord) + num_hash.size).chr
		num_hash[c] = x.to_i
		c
	end
	
	s.gsub!(/(?<=[A-Z])[-+*\/](?=[A-Z])/) do |x|
		c = ((?a.ord) + op_hash.size).chr
		op_hash[c] = x
		c
	end
	
	op_hash.each do |c, op|
		d = s.dup
		begin
			d.sub!(/(\w)#{c}(\w)/){
				x, y = num_hash[$1], num_hash[$2]
				raise if op == ?/ && y == 0

				z = if x * y < 0 && op == ?/
						-(x.abs.send(op, y.abs))
					else
						x.send(op, y)
					end

				if z < 0
					"(#{z})"
				else
					z.to_s
				end
			}
			next_s = d.gsub(/[a-z]/){|l| op_hash[l]}.gsub(/[A-Z]/){|l| ?( + num_hash[l].to_s + ?)}
			f(next_s)
		rescue
		end
	end
end

loop do
	s = gets.chomp
	break if s == ?#
	$set = Set.new
	$checked = {}
	f(s)
	p $set.size
end

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

const unsigned long long mod = 1000000007;
typedef long long ll;
// Iterative C program to compute modular power

/* Iterative Function to calculate (x^y)%p in O(log y) */
ll power(ll x, unsigned long long y, ll mod)
{
	ll res = 1;	 // Initialize result

	x = x % mod; // Update x if it is more than or
				// equal to p

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = (res*x) % mod;

		// y must be even now
		y = y>>1; // y = y/2
		x = (x*x) % mod;
	}
	return res;
}

ll sumXOR(ll arr[], ll n)
{
     ll sum = 0;

    for (ll i = 0; i <64; i++)
    {
         ll zc = 0, oc = 0;

         ll idsum = 0;

        for (ll j = 0; j < n; j++)
        {
            if (arr[j] % 2 == 0)
                zc++;
            else
                oc++;
            arr[j] /= 2;
        }


        idsum =((1LL%mod*oc%mod*zc%mod*(power(2,i,mod))%mod))%mod;

        // final sum
        sum = (sum+idsum)%mod;
    }
    return sum;
}

int main()
{
     ll sum = 0;

    ll n;
    cin>>n;

     ll arr[n+2];

    for(ll i=0;i<n;i++)cin>>arr[i];

    sum = sumXOR(arr,n);

    cout << sum<<endl;

    return 0;
}


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

int main() {
    int x, y;
    for(int i=0; i<3000; i++){
        cin >> x >> y;

        if(x==0 && y==0){
            break;
        }

        if(x < y){
            cout << x << ' ' << y << endl;
        }
        else{
            cout << y << ' ' << x << endl;
        }
    }
}

Measured memory_bytes: 2992
#include<stdio.h>
int main()
{ int A,B,K,i,count;
 scanf("%d%d%d",&K,&A,&B);
 for(i=1;i<=B;i++)
 { if((A<=(K*i))&&((K*i)<=B))
   count=count+1;
 }
 if(count!=0)
   printf("OK");
  else 
    printf("NG");
return 0;
}
 


Measured memory_bytes: 1704
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

vector<int> a;
vector<vector<ll>> dp;
vector<vector<bool>> vis;

ll f(int l, int r) {
	if (vis[l][r]) return dp[l][r];
    vis[l][r] = true;
    if (l == r) {
        return dp[l][r] = a[l];
    } else {
        return dp[l][r] = max(a[l] - f(l + 1, r), a[r] - f(l, r - 1));
    }
}

int main() {
    int n; cin >> n; a.resize(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    dp.assign(n, vector<ll>(n, 0));
    vis.assign(n, vector<bool>(n, false));
    cout << f(0, n - 1) << endl;
    return 0;
}

Measured memory_bytes: 72064
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));
    int ans = 0;
    rep(i, n) Rep(j, i + 1, n)
    {
        int a = l[i], b = l[j];
        auto ite = lower_bound(all(l), a + b);
        ans += ite - l.begin() - j - 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (Math.max(a, b) > 9) {
			System.out.println(-1);
			return;
		}
		System.out.println(a * b);
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pi acos(-1)
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000001
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<pll,ll>
#define vplll vector<plll>
#define vpll vector<pll>
using namespace std;
using namespace std::chrono; 
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);


int main()
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll n,k;
    cin>>n>>k;
    ll prefix[n+1];
    prefix[0]=0;
    for(ll i=1;i<=n;i++)
    {
        cin>>prefix[i];
        prefix[i]+=prefix[i-1];
    }
    ll val=min(n,k-1);
    map<ll,ll>freq;
    ll store;
    ll ans=0;
    for(ll i=0;i<=val;i++)
    {
        store=prefix[i]-i;
        if(store>=k)
        {
            store=store%k;
        }
        ans+=freq[store];
        freq[store]++;
    }
    for(ll i=val+1;i<=n;i++)
    {
        store=prefix[i-k]-(i-k);
        if(store>=k)
        {
            store=store%k;
        }
        freq[store]--;
        store=prefix[i]-i;
        if(store>=k)
        {
            store=store%k;
        }
        ans+=freq[store];
        freq[store]++;
    }
    cout<<ans;
    return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec X(N);
    REP(i,0,N) cin >> X[i];

    ll min = INF;
    REP(i,1,101) {
        ll sum = 0;
        REP(j,0,N) sum += (X[j] - i) * (X[j] - i);
        min = MIN(min,sum);
    }
    PR(min);

    return 0;
}

/*



*/

Measured memory_bytes: 3604
#include <stdio.h>

int H, W;
int cnt;
char graph[101][101];
int Move[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}, };

void solve(int x, int y, char p){
	graph[x][y] = '.';
	for(int i = 0; i < 4; ++i){
		int nx = x + Move[i][0];
		int ny = y + Move[i][1];
		if(nx >= 0 && nx < H && ny >= 0 && ny < W && graph[nx][ny] == p){
			solve(nx, ny, p);
		}
	}
}

int main(){
	
	while(scanf("%d%d", &H, &W) == 2 && H && W){
		
		for(int i = 0; i < H; ++i){
			for(int j = 0; j < W; ++j){
				char c;
				scanf(" %c", &c);
				graph[i][j] = c;
			}
		}
		cnt = 0;
		for(int i = 0; i < H; ++i){
			for(int j = 0; j < W; ++j){
				if(graph[i][j] != '.'){
					solve(i, j, graph[i][j]);
					++cnt;
				}
			}
		}
		
		printf("%d\n", cnt);
	}
}


Measured memory_bytes: 2184
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<algorithm>
#include<cstdio>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int bm = 3010;
ll BIT[bm];
void add(int A, ll B) {
	while (A <= bm) {
		BIT[A] = max(BIT[A], B);
		A += A & -A;
	}
}
ll query(int A) {
	ll kotae = 0;
	while (A > 0) {
		kotae = max(BIT[A], kotae);
		A -= A & -A;
	}
	return kotae;
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ll V[200000], tmp[200000];

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


	int R = getint(), C = getint(), K = getint();

	rep(i, K) {
		ll r = getint(), c = getint(), v = getint();
		V[i] = v << 30 | r << 12 | c;
	}

	const int b = 12;
	int kazu[1 << b] = {}, kazu2[1 << b] = {};
	rep(i, K) kazu[V[i] & ((1 << b) - 1)]++;
	rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
	for (int i = K - 1; i >= 0; i--) tmp[--kazu[V[i] & ((1 << b) - 1)]] = V[i];
	rep(i, K) kazu2[tmp[i] >> b & ((1 << b) - 1)]++;
	rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
	for (int i = K - 1; i >= 0; i--) V[--kazu2[tmp[i] >> b & ((1 << b) - 1)]] = tmp[i];

	int mae = -1;
	ll A[4] = {};
	ll L[3001];
	int l = 0;
	rep(k, K) {
		int v = V[k] >> 30;
		int i = V[k] >> 12 & 4095;
		int j = V[k] & 4095;
		if (mae != i) {
			mae = i;
			A[0] = 0;
			A[1] = 0;
			A[2] = 0;
			A[3] = 0;
			rep(a, l) add(L[a] & 4095, L[a] >> 12);
			l = 0;
		}
		ll kari = query(j);
		A[0] = kari;
		chmax(A[3], kari);
		chmax(A[2], kari);
		chmax(A[1], kari);
		chmax(A[3], A[2] + v);
		chmax(A[2], A[1] + v);
		chmax(A[1], A[0] + v);
		L[l++] = A[3] << 12 | j;
	}

	rep(a, l) add(L[a] & 4095, L[a] >> 12);
	ll kotae = query(C);

	printf("%lld\n", kotae);

	Would you please return 0;
}

Measured memory_bytes: 4876
#include <stdio.h>

void output(int A[], int N) {
    int i;
    
    for (i = 0; i < N; i++) {
        if (i > 0) {
            printf(" ");
        }
        
        printf("%d", A[i]);
    }
    
    printf("\n");
}

void insert(int A[], int N) {
    int i;
    int j, v;
    
    for (i = 1; i < N; i++) {
        v = A[i];
        
        j = i - 1;
        
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            
            j--;
        }
            
        A[j + 1] = v;
        
        output(A, N);
    }
}

int main(){
    int N, i;
    int A[100];
    
    scanf("%d", &N);
    
    for (i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    
    output(A, N);
    insert(A, N);
    
    return 0;
}



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

long long n;
long long a[60] = {0};
long long now = 0, num = 0, p = 0, cnt = 0;
long long ans[2][120] = {0};

void solve();

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    a[i] = x;
    if(abs(num) <= abs(x)) {
      num = x;
      p = i;
    }
  }
  solve();
  cout << cnt << endl;
  for(int i = 0; i < cnt; ++i) {
    cout << ans[0][i] + 1 << " " << ans[1][i] + 1 << endl;
  }
  return 0;
}

void solve() {
  if(num == 0) return;
  for(int i = 0; i < n; ++i) {
    if(a[i] == num)
      continue;
    ans[0][cnt] = p;
    ans[1][cnt] = i;
    ++cnt;
    a[i] += num;
  }
  if(num > 0) {
    now = 0;
    while(now < n - 1) {
      if(a[now] > a[now + 1]) {
        ans[0][cnt] = now;
        ans[1][cnt] = now + 1;
        ++cnt;
        a[now + 1] += a[now];
      }
      ++now;
    }
  }
  else {
    now = n - 1;
    while(now > 0) {
      if(a[now] < a[now - 1]) {
        ans[0][cnt] = now;
        ans[1][cnt] = now - 1;
        ++cnt;
        a[now - 1] += a[now];
      }
      --now;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

int main(){
	int h,w,n;
	cin>>h;
	cin>>w;
	cin>>n;

	int ans = 0;
	int total = 0;
	if(w > h){
		for(int i = 0; i < h; i++){
			total += w;
			ans++;
			if(total >= n){
				cout<<ans;
				break;
			}
		}
	}else{
		for(int i = 0; i < w; i++){
			total += h;
			ans++;
			if(total >= n){
				cout<<ans;
				break;
			}
		}
	}

}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

int main()
{
    int K;
    cin >> K;
    cout << a[K - 1] << endl;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int N;

signed main() {
   cin >> N;
   vec<int> a(N);
   rep (i, N) {
      cin >> a[i];
   }
   sort(all(a));


   deque<int> v;
   rep (i, N/2) {
      int x = a[i], y = a[N-1-i];

      if (i&1) swap(x, y);
      v.push_front(x);
      v.push_back(y);
   }


   int sum = 0;
   repp (i, 1, v.size()) {
      sum += abs(v[i-1] - v[i]);
   }

   // rep (i, v.size()) {
   //    cout << v[i] << " ";
   // }
   // cout << endl;

   // 奇数の時
   int mid = a[N/2];
   int p = max(abs(v[0] - mid), abs(v.back() - mid));
   // dbg2(v[0], v.back())

   if (N&1) sum += p;

   cout << sum << endl;

   return 0;
}

Measured memory_bytes: 1920
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
//end of libraries ;
#define INF 99999999999
#define N 300003
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int a , b;
int main(){
fcin;
	cin>>a>>b;
	for(int i = 1 ; i<= 3 ; i++){
		if(a*b*i%2!=0) {cout<<"Yes\n"; return 0;}
	}
	cout<<"No\n";

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int n,x;
  cin>>n>>x;
  
  int sum=0;
  for(int i=1;i<=n;i++)
  {
    int element;
    cin>>element;
    
    sum+=element;
    if(sum>x)
    {
      cout<<i;
      return 0;
    }
    else if(sum==x)
    {
      cout<<i+1;
      return 0;
    }
  }
  cout<<n+1;
    
}


Measured memory_bytes: 256
def calc_cost(i,an):
  ans = 0
  for a in an:
    ans += (i-a)*(i-a)
  return ans

n = int(input())
an = list(map(int,input().split()))
ans = 0
cost = 0
pre = 10000000000
for i in range(min(an),max(an)):
  x = calc_cost(i,an)
  if pre > x:
    ans = x
  pre = x
print(ans)


Measured memory_bytes: 3060
# 初期入力
import sys
input = sys.stdin.readline
N,K = (int(i) for i in input().split())
h =[0]*N
for i in range(N):
    h[i] = int(input())
h.sort()

#K本選んだうちの最高と最低の差をリスト
ans =[10**9+1]*N
for i in range(N-K+1):
    ans[i] =h[i+K-1] -h[i]
print(min(ans))

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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i < (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p,)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do{ cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << setprecision(20);
    }
} iosetup;

// YOUR CODE GOES HERE ↓↓↓
template<const int_fast64_t mod = 1000000007>
struct ModInt{
private: using ll = int_fast64_t;
public: ll x;
    constexpr ModInt(ll t = 0) noexcept : x((t %= mod) < 0 ? t + mod : t) {}
    constexpr friend istream& operator >> (istream& s, ModInt& m) noexcept {
        s >> m.x; m.x %= mod; if(m.x < 0)m.x += mod; return s;
    }
    constexpr friend ostream& operator << (ostream& s, ModInt m) noexcept {
        return s << m.x;
    }
    constexpr ModInt operator + (const ModInt m) noexcept { return ModInt(*this) += m; }
    constexpr ModInt& operator += (const ModInt m) noexcept {
        if((x += m.x) >= mod)x -= mod; return *this;
    }
    constexpr ModInt operator - (const ModInt m) noexcept { return ModInt(*this) -= m; }
    constexpr ModInt& operator -= (const ModInt m) noexcept {
        if((x += mod - m.x) >= mod)x -= mod; return *this;
    }
    constexpr ModInt operator * (const ModInt m) noexcept { return ModInt(*this) *= m; }
    constexpr ModInt& operator *= (const ModInt m) noexcept {
        x = x * m.x % mod; return *this;
    }
    constexpr ModInt operator / (const ModInt m) noexcept { return ModInt(*this) /= m; }
    constexpr ModInt& operator /= (const ModInt m) noexcept {
        return *this *= m.inv();
    }
    constexpr ModInt inv() noexcept {
        ll a = x, b = mod, u = 1, v = 0, t = 0;
        while(b){ t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    constexpr ModInt pow(ll p) noexcept {
        ModInt res(1), mult(*this);
        for(; p; p >>= 1){ if(p & 1)res *= mult; mult *= mult; }
        return res;
    }
};

using mint = ModInt<>;
mint dp[2001][2001];
int N, M;
int S[2000], T[2000];

int main(){

    cin >> N >> M;
    rep(i, N)cin >> S[i];
    rep(i, M)cin >> T[i];

    rep(i, N + 1)dp[i][0] = mint(1);
    rep(i, M + 1)dp[0][i] = mint(1);
    rep(i, N)rep(j, M){
        dp[i + 1][j + 1] += dp[i][j + 1] + dp[i + 1][j];
        if(S[i] != T[j])dp[i + 1][j + 1] -= dp[i][j];
    }

    cout << dp[N][M] << endl;
    return 0;

}

Measured memory_bytes: 31616
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class BinaryIndexTree:  # 1-indexed
    def __init__(self, N):
        """
        INPUT
        N [int] -> 全部0で初期化
        N [list] -> そのまま初期化
        """
        if isinstance(N, int):
            self.N = N
            self.depth = N.bit_length()
            self.tree = [0] * (N + 1)
            self.elem = [0] * (N + 1)
        elif isinstance(N, list):
            self.N = len(N)
            self.depth = self.N.bit_length()
            self.tree = [0] + N
            self.elem = [0] + N
            self._init()
        else:
            raise "INVALID INPUT: input must be int or list"

    def _init(self):
        size = self.N + 1
        for i in range(1, self.N):
            if i + (i & -i) > size:
                continue
            self.tree[i + (i & -i)] += self.tree[i]

    def add(self, i, x):
        self.elem[i] += x
        while i <= self.N:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

    def lower_bound(self, val):
        if val <= 0:
            return 0
        i = 0
        k = 1 << self.depth
        while k:
            if i + k <= self.N and self.tree[i + k] < val:
                val -= self.tree[i + k]
                i += k
            k >>= 1
        return i + 1

    def upper_bound(self, val):
        if val < 0:
            return 0
        i = 0
        k = 1 << self.depth
        while k:
            if i + k <= self.N and self.tree[i + k] <= val:
                val -= self.tree[i + k]
                i += k
            k >>= 1
        return i + 1


class RangeSumAdd:
    def __init__(self, N):
        self.bit0 = BinaryIndexTree(N)
        self.bit1 = BinaryIndexTree(N)

    def RangeAdd(self, l, r, x):
        """
        閉区間[l, r]にxを加える
        """
        self.bit0.add(l, -x * (l - 1))
        self.bit0.add(r + 1, x * r)
        self.bit1.add(l, x)
        self.bit1.add(r + 1, -x)

    def getSum(self, i):
        return self.bit0.sum(i) + i * self.bit1.sum(i)

    def RangeSum(self, l, r):
        """
        閉区間[l, r]にxを加える
        """
        return self.getSum(r)-self.getSum(l-1)


if __name__ == "__main__":
    N, Q = map(int, input().split())
    bit = RangeSumAdd(N + 10)
    ans = []

    for _ in range(Q):
        T, *arg = map(int, input().split())
        if T == 0:
            bit.RangeAdd(*arg)
        else:
            ans.append(bit.RangeSum(*arg))

    if ans:
        print(*ans, sep="\n")



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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

int n;
int data[3];
double memoneMomo[301][301][301], nn;

double mmnmm(int a, int b, int c)
{
    if (a < 0 || b < 0 || c < 0) {
        return 0.0;
    }
    if (memoneMomo[a][b][c] != -1) {
        return memoneMomo[a][b][c];
    }

    return memoneMomo[a][b][c] = 
        (double)n / (a + b + c) * (
            1.0 +
            (double)c / nn * mmnmm(a, b, c-1) +
            (double)b / nn * mmnmm(a, b-1, c+1) +
            (double)a / nn * mmnmm(a-1, b+1, c)
        );
}

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

    cin >> n;
    nn = n;
    
    rep(i, n) {
        Int(tmp);
        data[tmp-1]++;
    }
    rep(i, 301) {
        rep(j, 301) {
            rep(k, 301) {
                memoneMomo[i][j][k] = -1;
            }
        }
    }
    memoneMomo[0][0][0] = 0;

    //cout << data[0] << data[1] << data[2] << endl;
    cout << Decimal << mmnmm(data[2], data[1], data[0]) << endl;
  /*
      rep(i, data[0]+1) {
        rep(j, data[1]+1) {
            rep(k, data[2]+1) {
                cout << i << j << k << " " << memoneMomo[k][j][i] << endl;
            }
        }
    }
*/
    return 0;
}


Measured memory_bytes: 213376
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
struct mint {
   ll x;
   mint(ll x = 0) { (this->x = (x + MOD)) %= MOD; }
   mint& operator+=(const mint a) {
      if ((this->x += a.x) >= MOD) x -= MOD;
      return *this;
   }
   mint& operator-=(const mint a) {
      if ((this->x += MOD - a.x) >= MOD) this->x -= MOD;
      return *this;
   }
   mint& operator*=(const mint a) {
      (this->x *= a.x) %= MOD;
      return *this;
   }
   mint operator+(const mint a) const {
      mint res(*this);
      return res += a;
   }
   mint operator-(const mint a) const {
      mint res(*this);
      return res -= a;
   }
   mint operator*(const mint a) const {
      mint res(*this);
      return res *= a;
   }
   mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t >> 1);
      a *= a;
      if (t & 1) a *= *this;
      return a;
   }
   mint inv() const { return pow(MOD - 2); }
   mint& operator/=(const mint a) { return *this *= a.inv(); }
   mint operator/(const mint a) const {
      mint res(*this);
      return res /= a;
   }
};
struct combination {
   vector<mint> fact, ifact;
   combination(int n) : fact(n + 1), ifact(n + 1) {
      assert(n < MOD);
      fact[0] = 1;
      for (int i = 1; i <= n; ++i)
         fact[i] = fact[i - 1] * i;
      ifact[n] = fact[n].inv();
      for (int i = n; i >= 1; --i)
         ifact[i - 1] = ifact[i] * i;
   }
   mint operator()(int n, int k) {
      if (k < 0 || k > n) return 0;
      return fact[n] * ifact[k] * ifact[n - k];
   }
} comb(2000005);
mint f(int r, int c) {
   return comb(r + c + 2, r + 1) - 1;
}
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int r1, c1, r2, c2;
   cin >> r1 >> c1 >> r2 >> c2;
   r1--, c1--;

   mint ans = f(r2, c2);
   ans -= f(r1, c2);
   ans -= f(r2, c1);
   ans += f(r1, c1);
   cout << ans.x << endl;
   return 0;
}

Measured memory_bytes: 31488
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector< pair<int,int> > v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(make_pair(a, i));
  }

  v.push_back(make_pair(-2,-1));
  v.push_back(make_pair(-1,N));
  sort(ALLOF(v));

  map<int,int> s;
  
  ll ret = 0;
  rep(i,v.size()){
    ll value = v[i].first;
    int idx = v[i].second;
    if(value < 0){
      s[idx] = 1;
    }else{
      map<int,int>::iterator it = s.lower_bound(idx);
      
      int ridx = it->first;
      it--;
      int lidx = it->first;
      ret += (ll)(idx-lidx) * (ll)(ridx-idx) * value;

      it++;
      s[idx] = 1;;
    }
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 11248
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;

int main() {
	string s;
	cin >> s;
	if (s == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (s == "Cloudy") cout << "Rainy" << endl;
	else if (s == "Rainy") cout << "Sunny" << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	ans := float64(0)
	for i := 1; i < n+1; i++ {
		a := i
		for ;; {
			if a >= k {
				a /= i
				break
			}
			a *= 2
		}
		
		ans += 1.0/float64(n)/float64(a)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n; cin >> n;
  int a[200005];
  for(int i=0;i<n;i++) cin >> a[i];
  int k=0;
  for(int i=0;i<n;i++){
    if(a[i]==k+1){
      k++;
    }

  }

  if(k==0) cout << -1 << endl;
  else cout << n - k  << endl;
  return 0;
}

Measured memory_bytes: 1024
n = int(input())
h = list(map(int,input().split()))
dp = [0 for i in range(n)]
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    if dp[i-2]+abs(h[i]-h[i-2]) < dp[i-1]+abs(h[i]-h[i-1]):
        dp[i] = dp[i-2]+abs(h[i]-h[i-2])
    else:
        dp[i] = dp[i-1]+abs(h[i]-h[i-1])
print(dp[n-1])

Measured memory_bytes: 54136
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int po[]=new int[n];
  for(int i=0;i<n;i++)po[i]=sc.nextInt();
  boolean b=true;
  Arrays.sort(po);
  if(n%2==0){
  	for(int i=0;i<n;i++){
      if(i%2==0)po[i]--;
    	if(i!=po[i])b=false;
    }
  }
  else {
  	for(int i=0;i<n;i++){
    	if(i%2==1)po[i]--;
      if(i!=po[i])b=false;
    }
  }
  if(b){
    int ans=1;
  	for(int i=0;i<n/2;i++){
    	ans*=2;
      ans%=1000000007;
    }
    System.out.println(ans);
  }
  else System.out.println(0);
}
}


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

int height(int h1,int h2)
{
    //cout<<"h1-"<<h1<<" h2-"<<h2<<" height-"<<abs(h1-h2)<<endl;
    return abs(h1-h2);
}

int frogjumps(int n,int *a)
{
    if(n==2)
        return height(a[0],a[1]);
    int dp[n];
    //cout<<"initial dp ";
    for(int i=0;i<n-1;i++)
    {
        dp[i]=INT_MAX;
        //cout<<dp[i]<<" ";
    }
    dp[n-1]=0;
    //cout<<dp[n-1]<<endl;
    for(int i=n-1;i>0;i--)
    {
        if(i-1>=0)
        {
            dp[i-1]=min(dp[i-1],(dp[i]+height(a[i],a[i-1])));
            //cout<<"if "<<a[i-1]<<" to "<<a[i]<<" = "<<dp[i-1]<<endl;
        }
        if((i-2)>=0)
        {
            dp[i-2]=min(dp[i-2],(dp[i]+height(a[i],a[i-2])));
            //cout<<"if "<<a[i-2]<<" to "<<a[i]<<" = "<<dp[i-2]<<endl;
        }
    }
    // for(int i=0;i<n;i++)
    //     cout<<dp[i]<<" ";
    // cout<<endl;
    return dp[0];
}

int main() {
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    // for(int i=0;i<n;i++)
    //     cout<<a[i]<<" ";
    // cout<<endl;
    cout<<frogjumps(n,a)<<endl;
    
}


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

int main() {
  string s;
  cin >> s;
  int count = 0;
  string a = "CODEFESTIVAL2016";
  for (int i = 0; i < 16; i++) {
    if (s.at(i) != a.at(i)) {
      count++;
    }
  }
  cout << count << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int top,S[1000];
void push(int x){
  S[++top]=x;
}
int pop(void){
  top--;
  return S[top+1];
}
int main(){
  int a,b;
  char ch[1000];
  top=0;
  while(scanf("%s",ch)!=EOF){
    if(ch[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    } else if(ch[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    } else if(ch[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    } else {
      push(atoi(ch));
    }
  }
  printf("%d\n",pop());
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    int A[100];
    for(int i=0; i<n; i++){
        cin >> A[i];
    }
    
    int count=0;
    int flag=1;
    while(flag==1){
        flag=0;
        for(int j=n-1; j>0; j--){
            int v;
            if(A[j] < A[j-1]){
                v = A[j];
                A[j] = A[j-1];
                A[j-1] = v;
                count++;
                flag=1;
            }
        }
    }
    
    for(int k=0; k<n; k++){
        if(k>0) cout << " ";
        cout << A[k];
    }
    cout <<endl;
    
    cout << count << endl;
    
    return 0;
}



Measured memory_bytes: 3104
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a%3==0||b%3==0||(a+b)%3==0)	printf("Possible\n");
	else	printf("Impossible\n");
	return 0;
}


Measured memory_bytes: 128
question="A"
input=raw_input
if question=="A":
	t=input()
	t=t.replace("9","n")
	t=t.replace("1","o")
	t=t.replace("n","1")
	t=t.replace("o","9")
	print(t)
if question=="B":
	pass
if question=="C":
	pass
if question=="D":
	pass
if question=="E":
	pass

Measured memory_bytes: 2572
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long ll;



int main() {
	int N; cin >> N;
	vector<int> S(N, 0);
	vector<int> A(N - 1);
	for (int i = 0; i < N - 1; i++) {
		cin >> A[i];
		S[A[i] - 1]++;
	}
	for (int i = 0; i < N; i++) cout << S[i] << endl;
}


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

int main() {
    int A, B;
    cin >> A >> B;
    int ans = 0;
    int now = 1;
    while (now < B) {
        now += A - 1;
        ans += 1;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===


// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=10000000+1;
#define M_PI           3.14159265358979323846
void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}
void inp_mat(ll *arr,ll n,ll m)
{
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        {
          ll x;cin>>x;
          *((arr+i*m) + j)=x;
        }
}
// syntax for inp_mat inp_mat((ll *)arr,n,m);
// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
ll spf[N];
void init(){

  f(i,0,N)
  spf[i]=i;

  for(int i=2;i<N;i++)
  {
    if(spf[i]==i)
    {
      for(int j=2*i;j<N;j+=i)
      spf[j]=i;
    }
  }


}
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    int t=1;
    // cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        init();
        ll ans=1;
        f(i,2,n+1)
        {
          ll x=spf[i];
          ll nn=i;ll c=0;
          while(nn%x==0)
          {
            nn/=x;
            c++;
          }
          spf[i]=spf[nn]*(c+1);
          ans+=(spf[i]*i);
        }
        cout<<ans;
    }    
} 

Measured memory_bytes: 81776
#include <cstdio>

int n, k, a[200000];

bool f(int mid) {
    int cnt = 0;
    for (int i = 0 ; i < n ; i++) {
        cnt += a[i] / mid;
        if (a[i] % mid) cnt++;
        cnt--;
        if (cnt > k) return false;
    }
    return cnt <= k;
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 0 ; i < n ; i++) scanf("%d", &a[i]);
    int l = 1, r = 1000000000, mid, ans = 1000000000;
    while (l <= r) {
        mid = (l + r) / 2;
        if (f(mid)) {
            if (mid < ans) ans = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    printf("%d", ans);
}


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

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

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

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

int main()
{
    ll N;
    string S;
    cin >> N >> S;
    REP(i, S.length())
    {
        cout << (char)('A' + (S[i] - 'A' + N) % 26);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main(){
    input!{
        n: usize
    }

    println!("{}", 1110 - n);
}

Measured memory_bytes: 4352