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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
signed main() {
    cin >> N;
    vector<char> ans;
    while (N > 0) {
        N--;
        ans.push_back('a' + N % 26);
        N /= 26;
    }
    for (int i = ans.size() - 1; i >= 0; i--) { cout << ans[i]; }
    cout << endl;
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
char s[N];
int t[N], f[N];

int main() {
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    int tot = 0, cnt[2] = {0, 0};
    ll ans = 0;
    for (int i = 1; i <= n; i++)
        tot += s[i] == '0';
    for (int i = 1; i <= n; i++)
        if (s[i] == '0') cnt[0]++;
        else {
            if (s[i + 1] == '1') {
                ans += tot + 1, i++;
                cnt[1] += 2;
            } else {
                cnt[1] += 1;
                ans += i % 2;
                ans += tot - cnt[0];
                if (i % 2) ans += cnt[0] / 2;
                else ans += (cnt[0] + 1) / 2;
            }
        }
    for (int i = 1; i <= cnt[1] - 1; i++)
        ans += (i + 1) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3960
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a[4][3][10];
	int n;
	int b,f,r,v;
	cin>>n;
	for(int i=0;i<4;i++)
		for(int j=0;j<3;j++)
			for(int k=0;k<10;k++)
				a[i][j][k]=0;
	for(int i=0;i<n;i++){
		cin>>b>>f>>r>>v;
		a[b-1][f-1][r-1]+=v;
	}
	for(int i=0;i<4;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<10;k++)
				cout<<" "<<a[i][j][k];
			cout<<endl;
		}
		if(i<3){
		for(int j=0;j<20;j++)
			cout<<"#";
		cout<<endl;
		}
	}
	return 0;
}

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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n, d;
	cin >> n >> d;
	int res = 0;
	vector<int> square(40010);
	rep (i, 201) square[i * i] = 1;
	vector<vector<int> > x(n, vector<int>(d));
	rep (i, n) rep (j, d) cin >> x[i][j];
	rep (i, n) {
	  FOR (j, i + 1, n) {
		int dist = 0;
		rep (k, d) dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
		if (square[dist]) res++;
	  }
	}
	cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 3572
#include<iostream>
#include<math.h>
using namespace std;
int n,a[100001],f[100001],mins = 1000000;
main()
{
	cin>>n;
	for(int i = 0;i < n;i++)cin>>a[i];
	f[0] = 0;
	f[1] = abs(a[0]-a[1]);
	for(int i = 2;i < n;i++)
	{
		f[i] = min(f[i-1]+abs(a[i-1]-a[i]),f[i-2]+abs(a[i-2]-a[i]));
	}
	cout<<f[n-1];
}

Measured memory_bytes: 1024
/*
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 |                                                                 |
 |   author : yash1399     Language : C ++                         | 
 |   college : MSIT                                                | 
 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |  
*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <cmath> 
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
# define ll  long long int 
# define TEST int t ; cin>>t; while(t--)
# define line cout<<endl;
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define loop(i,a,b) for(long long int i=a;i<b;i++)
# define loopIn(i,a,b) for(long long int i=a;i<=b;i++)
#define MAX_SIZE 10000000
vector<bool> V(MAX_SIZE,false);
int main(){
      fast
      double n;
      cin>>n;
      double f1 = ceil(n/1.08);
      int  f = f1 * 1.08 ;
      //f = ceil(f);
     // cout<<f<<" "<<f1<<endl;
      if( f == n){
          cout<< f1 <<endl;
      }
      else{
          cout<<":("<<endl;
      }
}

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

#define INF 1e10

int main(){
	int n;
	cin >> n;
	int h[110000];
	int dp[110000];
	for(int i=0; i<n; i++){
		cin >> h[i];
	}
	for(int i=0; i<n; i++){
		dp[i]=INF;
	}
	dp[0]=0;
	for(int i=0; i<n; i++){
		if(i+1<n) dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
		if(i+2<n) dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
	}
	cout << dp[n-1];
}

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

int main()
{
	cin>>str;
	int len = str.length();
	int a = 0, b = 0;
	for(int i=0;i<len;i++){
		if(str[i] == '0') a ++;
		else b ++;
	}
	cout<<2*min(a,b)<<endl;
	return 0;
}


Measured memory_bytes: 1020
import sys

x, n = map(int, input().split())
p = [ int(x) for x in input().split() ]

if n == 0 or not x in p:
    print(x)
    sys.exit()

d = 101

for k in p:
    if d > abs(x - k):
        d = abs(x - k)

for i in range(101):
    if not x - (d + i) in p:
        print(x - (d + i))
        sys.exit()
    elif not x + (d + i) in p:
        print(x + (d + i))
        sys.exit()


Measured memory_bytes: 9140
#include "bits/stdc++.h"
using namespace std;
int INF = numeric_limits<int>::max() / 2;
using ll = long long;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    char map[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> map[i][j];
        }
    }

    vector<bool> hb(h,false), wb(w,false);

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(map[i][j] == '#'){
                hb[i] = true;
                wb[j] = true;
            } 
        }
    }

    for(int i = 0; i < h; i++){
        if(hb[i]){
            for(int j = 0; j < w; j++){
                if(wb[j]) cout << map[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}

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

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

ans = num2alpha(N)

print(ans.lower())

Measured memory_bytes: 9180
x,y,z,k=gets.split.map(&:to_i)
a=3.times.map{gets.split.map(&:to_i)}
b=[]
a[0].each{|v|a[1].each{|w|b << v+w}}
c=b.sort.reverse.take(k)
d=[]
a[2].each{|v|c.each{|w|d << v+w}}

puts d.sort.reverse.take(k)

Measured memory_bytes: 109292
import java.util.*;
import java.io.*;

public class Main {


	public static void main(String[] args) {
		Main ans = new Main();
		System.out.println(ans.solve());
	}

	private String solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		int [] array = new int[N+1];
		for(int i=1;i<=N;i++){
			array[i] = sc.nextInt();
		}

		int [] dp = new int[K+1];
		dp[0]=0;
		for(int i=1;i<=K;i++){
			dp[i]=0;
			for(int j=1;j<=N;j++){
				int x = array[j];
				if ((i-x)<0) continue;
				if (i==x){
					dp[i]=1;
					continue;
				} else {
					if(dp[i-x]==0) {
						dp[i]=1;
						break;
					} else {
						dp[i]=0;
					}
				}

			}
		}
		return dp[K]==1 ? "First" : "Second";
	}
}

Measured memory_bytes: 37148
function Main(input) {
    var A = parseInt(input[0], 10);
    var P = parseInt(input[1], 10);

    var sum = P;

    sum += A * 3;

    console.log(Math.floor(sum/2));

}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

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

using namespace std;

int main(){

  long long n, id, val, num, cnt;
  long long member[4000];
  int index[4000];

  while(cin >> n){

    if(!n) break;

    cnt = 0;
    memset(member, -1, sizeof(member));
    memset(index, -1, sizeof(index));

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

      cin >> id >> val >> num;

      if(member[id - 1] == -1){
        index[cnt] = id - 1; ++cnt;
        member[id - 1] += 1 + val * num;
      } else {
        member[id - 1] += val * num;
      }

    }

    bool flag = false;

    for(int i = 0; i < cnt; ++i){
      if(member[index[i]] >= 1000000){
        cout << index[i] + 1 << endl;
        flag = true;
      }
    }

    if(!flag) cout << "NA" << endl;

  }

}

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

using namespace std;

typedef vector<int> vi;

struct UF {
	vi e;
	UF(int n) : e(n, -1) {}
	bool same_set(int a, int b) { return find(a) == find(b); }
	int size(int x) { return -e[find(x)]; }
	int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
	bool join(int a, int b) {
		a = find(a), b = find(b);
		if (a == b) return false;
		if (e[a] > e[b]) swap(a, b);
		e[a] += e[b]; e[b] = a;
		return true;
	}
};

vector<vector<pair<int, int> > > adj;
vector<int> processed;
vector<int> pos;
bool works = true;

void dfs(int curr) {
  processed[curr] = 0;
  for(int i = 0; i<adj[curr].size(); ++i) {
    if(processed[adj[curr][i].first] == -1) {
      pos[adj[curr][i].first] = pos[curr] + adj[curr][i].second;
      dfs(adj[curr][i].first);
    }
    else {
      if(pos[adj[curr][i].first] != pos[curr] + adj[curr][i].second) {
        works = false;
      }
    }
  }
  processed[curr] = 1;
}

int main() {
  int n, m; cin >> n >> m;
  UF uf(n);

  adj.resize(n);
  processed.assign(n, -1);
  pos.assign(n, 0);
  for(int i = 0; i<m; ++i) {
    int l, r, d; cin >> l >> r >> d;
    l--; r--;
    uf.join(l, r);
    adj[l].push_back(make_pair(r, d));
    adj[r].push_back(make_pair(l, -d));
  }

  for(int i = 0; i<n; ++i) {
    if(processed[i] == -1) {
      pos[i] = 0;
      dfs(i);
    }
  }
  if(works) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

signed main(){
  int p[10];
  int n;
  cin >> n;
  cin >> p[0];
  int max = p[0];
  int maxI = 0;
  for(int i = 1;i < n; i++){
    cin >> p[i];
    if(p[i] > max){
      max = p[i];
      maxI = i;
    }
  }
  int sum = 0;
  for(int i = 0; i < n; i++){
    if(i == maxI){
      sum += p[i] / 2; 
    }else{
      sum += p[i];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
program kadai
implicit none
integer  ::  n,j,m,i
integer,allocatable  ::  a(:)
integer,allocatable  ::  ans(:)

read(*,*) n,m
if (m>1) then
    allocate(a(m))
end if
if (m<2) then
    allocate(a(2))
end if
allocate(ans(n))
a=0
ans=0

do i=1,m
    read(*,*) a(i)
end do

if (m==0) then
    a=0
end if

if(m==1) then
 a(2)=0
end if
j=1
if (a(1)==1 .and. a(2)/=2 ) then
    ans(1)=0
    ans(2)=1
    j=2
end if

if (a(1)==1 .and. a(2)==2 ) then
    ans(1)=0
    ans(2)=0
    j=3
end if

if (a(1)==2) then
    ans(1)=1
    ans(2)=0
    j=2
end if

if (a(1)/=1 .and. a(1)/=2) then
    ans(1)=1
    ans(2)=2
end if

!write(*,*) ans(1)
!write(*,*) ans(2)

if (n>2) then
    do i=3,n
        if(j<m+1 .and. i==a(j)) then
            ans(i)=0
            j=j+1
        else
            ans(i)=mod(ans(i-2)+ans(i-1),1000000007)
        end if
    !write(*,*) ans(i)
    end do
end if

write(*,*) ans(n)

end program kadai


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <queue>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
using namespace std;
typedef vector<vector<char>> field_t;
typedef unsigned long long ull;
typedef pair<int, int> point_t;


int main()
{
    string S;
    cin >> S;
    rep(i,3){
        cout <<S.at(i);
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
 
using namespace ::std;
 
#define all(x)  x.begin(),x.end()
#define Unique(x) x.erase(unique(x.begin(), x.end()), x.end())

template< class T > T SQR(T N) {return (T) N * N;}
template< class T > double DIST(T a, T b) {return 1.0 * sqrt(SQR(double(a)) + SQR(double(b)));}
template< class T > bool CROSS(pair< T,T > a, pair< T,T > b, pair< T,T > c) {return (b.first - a.first) * (c.second - b.second) >= (b.second - a.second) * (c.first - b.first);}
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair< int,int > pi;
 
int px[] = {0, 1, -1, 0, -1, -1, 1};
int py[] = {1, 0, 0, -1, -1, 0, -1, -1};

const double eps = 1e-9;
 
inline ll power(ll a, ll p, ll mod)
{
    ll x = a, res = 1;
 
    while(p)
    {
        if(p&1) res = (res * x)%mod;
        p /= 2, x = (x * x)%mod;
    }
    return res;
}

int res;
int rc[10][10];
int row[10], col[10];

inline void backtrack(int rx, int cx, int n, int m, int value, int x, int k)
{
    if(cx >= m)
    {
        if((x - value) == k) res++;
        return;
    }

    if(cx < m and rx >= n)
        backtrack(rx, cx + 1, n, m, value, x, k),
        backtrack(rx, cx + 1, n, m, value + col[cx], x, k);

    if(rx < n and cx == 0)
    {
        backtrack(rx + 1, cx, n, m, value, x, k);
        for(int i = 0; i<m; ++i)
            col[i] -= rc[rx][i];

        backtrack(rx + 1, cx, n, m, value + row[rx], x, k);

        for(int i = 0; i<m; ++i)
            col[i] += rc[rx][i];
    }

}

int main()
{
    int n, m, c, d, a, b, k;
 
    int test;
 
    // scanf("%d", &test);
    // while(test--)
    // {
        scanf("%d%d%d", &n, &m, &k);
        
        string str;
        a = 0;

        for(int i = 0; i<n; ++i)
        {
            cin >> str;
            for(int j = 0; j<m; ++j)
                if(str[j] == '#')
                    row[i]++, col[j]++, ++a, rc[i][j]++;
        }

        backtrack(0, 0, n, m, 0, a, k);

        printf("%d\n", res);
    //}
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n;
  cin >> n;
  cout << (1000 - n%1000) % 1000 << '\n';
}

Measured memory_bytes: 3648
#include <stdio.h>

int main (){
    int a,b;
    while(1){
        scanf("%d%d",&a,&b);
        if (a == 0 && b == 0) break;
        else if(a > b) printf("%d %d\n",b,a);
        else printf("%d %d\n",a,b);
    }
    return 0;
}



Measured memory_bytes: 2760
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

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

  vector<int> N(S.size());
  for (size_t i = 0; i < S.size(); i++) {
    N[i] = S[i] - '0';
  }

  ll dp[200][4][2] = {};
  dp[0][0][0] = 1;

  for (size_t i = 0; i < N.size(); i++) {
    for (size_t d = 0; d < 10; d++) {
      for (size_t k = 0; k < 4; k++) {
        for (size_t l = 0; l <= 1; l++) {
          int nk = k;
          if (d != 0) {
            nk++;
          }
          if ((l == 0 && N[i] < d) || nk > 3) {
            continue;
          }
          int nl = l;
          if (N[i] > d) {
            nl = 1;
          }
          dp[i + 1][nk][nl] += dp[i][k][l];
        }
      }
    }
  }

  cout << (dp[N.size()][K][1] + dp[N.size()][K][0]) << endl;
}

Measured memory_bytes: 256
"use strict";

function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0], 10);
  var S = input[1];
  var K = parseInt(input[2], 10);
  var s = [...S];
  var k = s[K - 1];

  for (var i = 0; i < N; i++) {
    if (s[i] != k) {
      s[i] = "*";
    }
  }

  console.log(s.join(""));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define endl '\n'
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,ans=0; cin>>n;
    int arr[n];
    map<int,int> m;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        m[arr[i]]++;    
    }
    for(auto it : m){
        int x=it.ss;
        ans+=((x*(x-1))/2);
    }
    for(int i=0;i<n;i++){
        int x=m[arr[i]];
        int temp=ans-((x*(x-1))/2);
        x--;
        temp+=((x*(x-1))/2);
        cout<<temp<<endl;
    }
}

Measured memory_bytes: 11136
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return(false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return(true);
  }

  int find(int k)
  {
    if(data[k] < 0) return(k);
    return(data[k] = find(data[k]));
  }

  int size(int k)
  {
    return(-data[find(k)]);
  }

  bool same(int x, int y)
  {
      return find(x) == find(y);
  }
};

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    REP(i, N) cin >> h[i];
    sort(h.begin(), h.end());
    int ans = 1000000005;
    REP(i, N - K + 1) ans = min(ans, h[i + K - 1] - h[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MAXN 85
using namespace std;

int G[MAXN][MAXN], N, M;
//unordered_set<int> S[MAXN][MAXN];
int S[MAXN][MAXN][4 * MAXN * MAXN];

void add(int v, int i, int j) {
  S[i][j][v + G[i][j]] = 1;
  S[i][j][abs(v - G[i][j])] = 1;
  //S[i][j].insert(v + G[i][j]);
  //S[i][j].insert((abs(v - G[i][j])));
}

int main () {
  scanf("%d%d",&N, &M);
  for (int i=0;i<N;++i)
    for (int j=0;j<M;++j)
      scanf("%d",&G[i][j]);
  int t, MAX = 2 * (N + M) * 80;
  for (int i=0;i<N;++i)
    for (int j=0;j<M;++j) {
      scanf("%d",&t);
      G[i][j] = abs(G[i][j] - t);
    }
  //S[0][0].insert(G[0][0]);
  S[0][0][G[0][0]] = 1;
  for (int i=0;i<N;++i)
    for (int j=0;j<M;++j)
      for (int v=0;v<=MAX;++v)
        if (S[i][j][v] == 1) {
          //printf("%d %d: %d\n", i, j, v);
          add(v, i+1, j);
          add(v, i, j+1);
        }
  for (int v=0;v<=MAX;++v)
    if (S[N-1][M-1][v]) {
      printf("%d\n",v);
      break;
    }
  //assert(S[N-1][M-1].size() > 0);
  //int ans = INT_MAX;
  //for (auto v : S[N-1][M-1]) ans = min(ans, v);
  //printf("%d\n",ans);
}


Measured memory_bytes: 776576
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

const int mod = 1e9+7;

int dp[100005];
set<int> broken;

int32_t main(){
	int n,m,t;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>t;
		broken.insert(t);
	}
	dp[0]=1;
	for(int i=1;i<=n;i++){
		unless(broken.count(i)){
			dp[i]+=dp[i-1];
			if(i!=1){
				dp[i]+=dp[i-2];
			}
			dp[i]%=mod;
		}
	}
	cout<<dp[n];
}


Measured memory_bytes: 4992
def solve():
    from sys import stdin
    f_i = stdin
    
    N, K = map(int, f_i.readline().split())
    H = tuple(map(int, f_i.readline().split()))
    
    if N == K:
        return 0
    
    dp1 = list(H)
    for i in range(1, N - K):
        dp2 = dp1[:i]
        for x, H_x in enumerate(H[i:], start=i):
            v = min(dp_j + max(0, H_x - H_j) for dp_j, H_j in zip(dp1[i-1:x], H[i-1:x]))
            dp2.append(v)
        dp1 = dp2
    return min(dp1[N-K-1:])

print(solve())

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, vector<long long> a) {
  ll all = 0;
  ll ans = 1LL << 50;

  vll aa(N, 0);
  REP(i, N) {
    aa[i] = a[i];
    if (i != 0)
      aa[i] += aa[i - 1];
  }

  all = aa[N - 1];
  ans = abs(all - 2LL * aa[0]);

  FOR(i, 1, N - 1) { ans = min(ans, abs(all - 2LL * aa[i])); }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> a(N - 1 + 1);
  ll mi = 0;
  for (int i = 0; i <= N - 1; i++) {
    cin >> a[i];
    mi = min(mi, a[i]);
  }
  for (int i = 0; i <= N - 1; i++) {
    // a[i] -= mi;
  }
  solve(N, a);
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main() {
  do {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  } while (false);
  int n, m;
  cin >> n >> m;
  vector<vector<int> > adj(n);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[--u].push_back(--v);
    adj[v].push_back(u);
  }
  vector<vector<int> > father(n, vector<int>(n, -1));
  for (int root = 0; root < n; root++) {
    function<void (int)> dfs = [&] (int u) {
      for (int v : adj[u]) {
        if (v != father[root][u]) {
          father[root][v] = u;
          dfs(v);
        }
      }
    };
    dfs(root);
  }
  vector<vector<int> > top(n, vector<int>(n, -1));
  vector<vector<bool> > graph(n, vector<bool>(n));
  function<void (int, int)> add = [&] (int u, int v) {
    if (top[u][v] == v || top[v][u] == v) {
      return;
    } else if (top[u][v] != -1) {
      add(top[u][v], v);
    } else if (top[v][u] != -1) {
      add(top[v][u], u);
    } else {
      vector<pair<int, int> > edges;
      for (int count = 0; count < 2; count++) {
        graph[u][v] = true;
        top[u][v] = v;
        queue<int> que;
        que.push(v);
        while (!que.empty()) {
          int x = que.front();
          que.pop();
          for (int y : adj[x]) {
            if (y != father[u][x]) {
              if (top[u][y] == -1) {
                top[u][y] = v;
                que.push(y);
              } else if (graph[u][y]) {
                graph[u][y] = graph[y][u] = false;
                edges.emplace_back(v, y);
              }
            }
          }
        }
        swap(u, v);
      }
      for (auto &it : edges) {
        add(it.first, it.second);
      }
    }
  };
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    add(--u, --v);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    function<void (int, int)> dfs = [&] (int u, int fa) {
      if (top[fa][u] == u) {
        fa = u;
        ans++;
      }
      for (int v : adj[u]) {
        if (v != father[i][u]) {
          dfs(v, fa);
        }
      }
    };
    for (int j : adj[i]) {
      dfs(j, i);
    }
  }
  cout << ans / 2 << endl;
  return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<pair<int, int> > v(n, {0, 0});

  for (int i = 0; i < n; i++)
  {
    cin >> v[i].first;
    cin >> v[i].second;
  }

  sort(v.rbegin(), v.rend());
  cout << v[0].first + v[0].second << endl;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int M = sc.nextInt();
   
   int d = M/N;
   int ans =0;
   boolean s = true;
   for(int i=1;i<=Math.sqrt(M);i++)
   {
     if(M%i==0&&M/i<=d)
     {
       ans =M/i;
       s = false;
       break;
     }
   }
   if(s)
   {
     for(int i=(int)Math.sqrt(M);i>=1;i--)
     {
       if(M%i==0&&i<=d)
       {
         ans =i;
         break;
       }
     }
   }
   System.out.println(ans);   
 }
}

Measured memory_bytes: 25300
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int main() {
ll n,x;
cin>>n>>x;

ll a[2*n];
rrep(i, n){
	cin>>a[i];
}

for(int i=n;i<=2*n-1;i++){
a[i]=a[i-n];
}

ll minv[n+1][n];
for(int j=0;j<=n-1;j++){
for(int i=0;i<=n-1;i++){
if(i==0) {minv[j][i]=a[j];
continue;}
minv[j][i]=min(minv[j][i-1], a[n+j-i]);
}
}

ll ans=inf;
for(int i=0;i<=n-1;i++){
	ll cnt=0;
for(int j=0;j<=n-1;j++){
cnt+=minv[j][i];
}
cnt+=x*i;
ans=min(ans,cnt);
}


cout<<ans<<endl;
return 0;

}







Measured memory_bytes: 31488
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int ans= 0;
    int n;
    cin >> n;
    rep(i,n/2){
        int a,b;
        cin>> a >> b;
        if(a%2){
            ans++;
        }
    }
    if(n%2){
        int a;
        cin >> a;
        if(a%2){
            ans++;
        }
    }
    cout << ans<< endl;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<endl
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

ll calc(ll k,ll d) {
  return k*(k+1)/2*d;
}

const ll n=26;
ll c[n],q[444];
ll a[444][n];
set<ll> s[n];

ll solve(ll x,ll y) {
  ll ans=0;
  {
    ans-=a[x][q[x]];
    iter(s[q[x]]) it2=s[q[x]].lower_bound(x);
    iter(s[q[x]]) it1=it2,it3=it2;it1--,it3++;
    ans+=calc(*it2-*it1-1,c[q[x]]);
    ans+=calc(*it3-*it2-1,c[q[x]]);
    ans-=calc(*it3-*it1-1,c[q[x]]);
    s[q[x]].erase(it2);
  }
  {
    q[x]=y;
    s[q[x]].in(x);
    ans+=a[x][q[x]];
    iter(s[q[x]]) it2=s[q[x]].lower_bound(x);
    iter(s[q[x]]) it1=it2,it3=it2;it1--,it3++;
    ans-=calc(*it2-*it1-1,c[q[x]]);
    ans-=calc(*it3-*it2-1,c[q[x]]);
    ans+=calc(*it3-*it1-1,c[q[x]]);
  }
  return ans;
}

         
void Main() {
  srand((unsigned)time(NULL));
  int T;
  R T;
  rep(i,n) R c[i];
  rep(i,T)rep(j,n) R a[i][j];
  rep(i,n) s[i].in(-1),s[i].in(T);
  rep(k,T) {
    ll M=0,x=0;
    rep(i,n) {
      if(M<a[k][i]) {
        M=a[k][i];
        x=i;
      }
    }
    q[k]=x;
    s[x].in(k);
  }
  ll ans[T];
  mem(ans);
  clock_t t2=clock();
  for(int tt=0;;tt++) {
    ll x=rand()%T,y=rand()%n;
    ll e=q[x];
    if(solve(x,y)<0) {
      s[q[x]].erase(x);
      q[x]=e;
      s[q[x]].in(x);
    } else ans[x]=y;
    clock_t t3=clock();
    double t4=(double)(t3-t2)/CLOCKS_PER_SEC;
    if(tt>=2&&(double)t3/CLOCKS_PER_SEC+t4*2>1.800) break;
    t2=t3;
  }
  rep(i,T) pr(ans[i]+1);
}

int main(){Main();return 0;}


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

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<ll,int> P;

const ll MAX_N=131072;
int bit[MAX_N*2-1];
ll n;
void add(ll a,ll w){
  ll x=a;
  while(x<=n){
    bit[x]+=w;
    x+=x&(-x);
  }
}
ll sum(int a){
  ll ret=0;
  while(a>0){
    ret+=bit[a];
    a-=a&(-a);
  }
  return ret;
}
int main(){
  cin>>n;
  ll a[n];
  rep(i,n) cin >>a[i];
  ll b[n];
  rep(i,n) b[i]=a[i];
  sort(b,b+n);
  map<ll,int> m;
  rep(i,n) m[b[i]]=i+1;
  ll ans=0;
  rep(i,n){
    ans+=i-sum(m[a[i]]);
    add(m[a[i]],1);
  }
  cout<<ans<<endl;

}



Measured memory_bytes: 19560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String S = sc.next();
		sc.close();

		if(S.substring(0, N / 2).equals(S.substring(N / 2, N ))) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 21844
N=int(input())
a=list(map(int,input().split()))
M=max(a)
m=min(a)

if M-m>=2:
    print("No")

elif M-m==0:
    count=0
    for i in range(N):
        if a[i]==N-1 or a[i]<=N//2:
            count+=1
    if count==N:
        print("Yes")
    else:
        print("No")
else:
    q=0
    p=0
    for i in range(N):
        if a[i]==M:
            q+=1
        elif a[i]==m:
            p+=1
    if p+q//2 >= max(a) and max(a)>=p+1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 14008
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
 
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

long long n,m;
ll cnts[222222];
void solve(istream& cin, ostream& cout) {
	cin >> n;
	vector<int> A(n);
	cin >> A;
	REP(i, n) cnts[A[i]]++;
	ll ans = 0;
	REP(i, n+10) ans += cnts[i]*(cnts[i]-1)/2;
	REP(i, n) {
		cout << (ans-(cnts[A[i]]-1)) << endl;
	}
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


Measured memory_bytes: 3968
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
#include<map>
#include<set>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b)cout << c;
	else if (b == c)cout << a;
	else if (c == a)cout << b;

	return 0;
}





Measured memory_bytes: 256
import itertools
from collections import defaultdict
from heapq import heappush, heappop

inf = float("inf")

N, M, R = map(int, input().split())
towns = list(map(int, input().split()))

vertices = [i for i in range(1, N+1)]
edge_costs = {i: defaultdict(int) for i in range(N+1)}

for _ in range(M):
    a, b, c = map(int, input().split())
    edge_costs[a][b] = c
    edge_costs[b][a] = c

def dijkstra(s):
    dist = [inf for _ in range(N+1)]
    dist[s] = 0
    searched = [False for _ in range(N+1)]
    
    q = [] # heap
    heappush(q, (0, s))
    
    while len(q) != 0:
        d, v = heappop(q)
        # don't need to check when the stored vertex has been already searched, 
        # or the stored value is greater than provisional distance
        if searched[v] or d > dist[v]:
            continue
            
        for u, c in edge_costs[v].items():
            temp = d + c
            if temp < dist[u]:
                dist[u] = temp
                heappush(q, (dist[u], u))
        
        searched[v] = True
        
        if sum(searched) == N: # finish when all vertices have been searched
            break
    
    return [dist[t] for t in towns]

D = [dijkstra(t) for t in towns]

ans = min([sum([D[perm[i]][perm[i+1]] for i in range(R-1)]) for perm in itertools.permutations(range(R))])
print(ans)

Measured memory_bytes: 8452
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int M = 1 << N;
		char[] cs = sc.next().toCharArray();
		boolean[] winBig = new boolean[M - 1];
		for (int i = 0; i < M - 1; i++) {
			winBig[i] = cs[i] == '1';
		}
		int[][] winner = new int[N + 1][M];
		int[] P = new int[M];
		for (int i = 0; i < M; i++) {
			P[i] = Integer.parseInt(sc.next());
			winner[0][i] = P[i];
		}
		int len = 1;
		for (int i = 0; i < N; i++, len *= 2) {
			for (int j = 0; j < M; j++) {
				int p1 = winner[i][j];
				int p2 = winner[i][(j + len) % M];
				int hi = Math.max(p1, p2);
				int lo = Math.min(p1, p2);
				winner[i + 1][j] = winBig[hi - lo - 1] ? hi : lo;
			}
		}
		PrintWriter writer = new PrintWriter(System.out);
		for (int i = 0; i < M; i++) {
			writer.println(winner[N][i]);
		}
		writer.flush();
	}

}



Measured memory_bytes: 113836
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
    #include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
    #define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
    #define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0;}
#else
    #define debug(x...)
    #define light_debug(x) 
#endif

template<typename T>
T& ckmin(T& a, T b){ return a = a > b ? b : a; }

template<typename T>
T& ckmax(T& a, T b){ return a = a < b ? b : a; }

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

namespace ioUtils {

    char vector_delimiter = ' ';

    template<typename T>
    istream& operator >>(istream&, vector<T>&);

    template<typename... Ts>
    istream& operator >>(istream& is, pair<Ts...>& p){
        is >> p.first >> p.second;
        return is;
    }

    template<typename T> 
    istream& operator >>(istream& is, vector<T>& v){
        for(auto& e : v) is >> e;
	       return is;
    }

    template<typename T>
    ostream& operator <<(ostream&, vector<T>&);

    template<typename... Ts>
    ostream& operator <<(ostream& os, pair<Ts...>& p){
        os << p.first << " " << p.second;
        return os;
    }

    template<typename T>
    ostream& operator <<(ostream& os, vector<T>& v){
        for(auto&& e : v) os << e << vector_delimiter;
        return os;   
    }   
}

using namespace ioUtils;


int N;
vi a;
ll dp[3000][3001];
bool ch[3000][3001];

ll rec(int i, int j){
	if(i >= j) return 0;
	if(ch[i][j]) return dp[i][j];
	ch[i][j] = 1;
	if((i ^ j ^ N) & 1) return dp[i][j] = min(rec(i + 1, j) - a[i], rec(i, j - 1) - a[j - 1]);
	else return dp[i][j] = max(rec(i + 1, j) + a[i], rec(i, j - 1) + a[j - 1]);
}

int main(){

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

    #ifdef DEBUG
        freopen("debug", "w", stderr);
    #endif
    
    cin >> N;
    a.resize(N);
    cin >> a;

    cout << rec(0, N) << '\n';
    #ifdef DEBUG
        dbg::dout << "\nExecution time: " << clock() << "ms\n";
    #endif

    return 0;
}


Measured memory_bytes: 58672
def line1(n):
    if n == 1:
        return("#")
    if n % 2 ==0:
        return "#." * (n/2)
    else:
        return "#." * (n/2) + "#"

def line2(n):
    if n == 1:
        return(".")
    if n % 2 ==0:
        return ".#" * (n/2)
    else:
        return ".#" * (n/2) + "."

while True:
    H, W = map(int, raw_input().split())
    if H == W == 0:
        break
    for i in xrange(H):
        if i % 2 == 0:
            print line1(W)
        else:
            print line2(W)
    print

Measured memory_bytes: 6436
/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;

void add_self(int& a, int b)
{
    a += b;
    if(a >= mod)
        a -= mod;
}

void sub_self(int& a, int b)
{
    a -= b;
    if(a < 0)
        a += mod;
}

int dp[102][N];
// dp[i][j] - No. of ways to distribute j candies among first i childs 
void solve()
{
    int n, k;
    scn(n); scn(k);

    vi child(n);

    rep(i, 0, n) {
        scn(child[i]);
    }

    dp[0][0] = 1;

    rep(i, 0, n) {
        rep(j, 1, k+1)
            add_self(dp[i][j], dp[i][j-1]);

        for(int used = 0; used <= k; used ++) {
            int l = used, r = used + min(k - used, child[i]);
            add_self(dp[i+1][l], dp[i][used]);
            sub_self(dp[i+1][r+1], dp[i][used]);
        }
    }

    prin(dp[n][k]);
} 

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

Measured memory_bytes: 43508
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
int dp[64][2][2][2];
 
signed main() {
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	IOS;
	int l, r;
	cin >> l >> r;
	dp[61][1][1][0] = 1;
	for(int i = 61; i >= 1; i--){
		for(int x = 0; x < 2; x++){
			for(int y = 0; y < 2; y++){
				for(int a = 0; a < 2; a++){
					if(dp[i][x][y][a] == 0)	continue;
					bool l1 = (l & (1LL << (i-1))), r1 = (r & (1LL << (i-1)));
					// cout << i << " " << x << " " << y << " " << a << " " << dp[i][x][y][a] << endl;
					for(int j = 0; j < 2; j++){
						for(int k = 0; k < 2; k++){
							if(j > k)	continue;
							if(x && j < l1)	continue;
							if(y && k > r1)	continue;
							if(!a && j != k)	continue;	
							bool xx = x & (j == l1);
							bool yy = y & (k == r1);
							bool aa = a | j;
							dp[i-1][xx][yy][aa] += dp[i][x][y][a];
							dp[i-1][xx][yy][aa] %= mod;
						}
					}
				}
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < 2; j++)
			ans = (ans + dp[0][i][j][1]) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int A,B,C,max,mid,min;
    
    cin >> A>> B>> C;
    
    
    if (A>B) {max=A;mid=B;min=C;}
    else {max=B;mid=A;min=C;}
    
    if (max<C) {max=C;mid=A;min=B;}
    
    cout << 10*max+mid+min << endl;
    
}


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

int binarySearch(vector<int> A, int key){
	int left = 0, right = A.size();
	while(left < right){
		int mid = (left + right) / 2;
		if(A[mid] < key)
			left = mid + 1;
		else
			right = mid;
	}

	// cout<<left<<endl;
	return left;
}

void LISout(vector<int> v){
	for(int i=0;i<v.size();i++)
		cout<<v[i]<<" ";
	cout<<endl;
}

int LIS(vector<int> a){
	vector<int> lis;

	lis.push_back(a[0]);
	for(int i=1;i<a.size();i++)
		if(a[i] > lis[lis.size()-1]){
			lis.push_back(a[i]);
			// LISout(lis);
		}else if(a[i] < lis[lis.size()-1]){
			// cout<<"* ";
			lis[binarySearch(lis, a[i])] = a[i];
			// LISout(lis);
		}

		return lis.size();
}

int main(){

	int n, num;
	vector<int> a, lis;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>num;
		a.push_back(num);
	}

	// cout<<endl;
	cout<<LIS(a)<<endl;
	return 0;
}

Measured memory_bytes: 2596
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  ll X, Y;
  cin >> X >> Y;
  int cnt = 0;
  ll now = X;
  while(now <= Y) {
    now *= 2;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256