akhauriyash/Code-Regression huggingface dataset:
N,K=[int(x) for x in raw_input().split()]
H=[int(x) for x in raw_input().split()]
C=[0 for x in range(N)]
for i in range(1,min(N,K)):
    C[i]=abs(H[0]-H[i])
for i in range(K,N):
    C[i]=min([ C[i-k]+abs(H[i]-H[i-k]) for k in range(1,K+1) ])
print C[-1]


Measured memory_bytes: 42220
n = int(input())
card = list(map(int,input().split()))

a = 0
b = 0

card.sort(reverse=True)

#print(card)
for i in range(1,n+1):
#  print(a,b)
  if i % 2 == 0:
    b = b + card[i-1]
  else:
    a += card[i-1]
#print(a,b)
print(a - b)

Measured memory_bytes: 3064
/*************************************************************************

**  **  **  ****   ****    ******   **    **  **     **   **   **   **              
** **   **  ** ** ** **   **     *  **    **  **   *    *    *    *    *
****    **  **   *   **   **        ********  **   *         *         *
****    **  **       **   **        ********  **     *     *   *     *
** **   **  **       **   **     *  **    **  **        *         *
**  **  **  **       **    ******   **    **  **  ***********************      

*************************************************************************/

#include<bits/stdc++.h>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    long A,B,C;
    cin >> A >> B >> C;
    long area = (A*B)/2;
    cout << area;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int pow3(int j){
  return (j==0)?(1):(3*pow3(j-1));
}
int q=1;
int main(void){
  for(;;){
    int n,m;
    cin >> n >> m;
    if(n == 0 && m == 0){ return 0; }
    int a[n];
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    int w[m];
    for(int i=0;i<m;i++){
      cin >> w[i];
    }
    
    int measurable[pow3(m)];
    for(int i=0;i<pow3(m);i++){ measurable[i]=0; }    
    for(int i=0;i<pow3(m);i++){
      for(int j=0;j<m;j++){
	if((i/pow3(j))%3==1){ measurable[i]+=w[j]; }
	if((i/pow3(j))%3==2){ measurable[i]-=w[j]; }
      }
    }

    int candidate[pow3(m)];
    int intersection[pow3(m)];
    bool buyweight=false;
    
    for(int i=0;i<n;i++){
      for(int j=0;j<pow3(m);j++){
	candidate[j] = abs(measurable[j] - a[i]);
      }
      sort(candidate,candidate+pow3(m));

      if(candidate[0]==0){
      }else{
	if(buyweight==false){
	  for(int j=0;j<pow3(m);j++){
	    intersection[j] = candidate[j];
	  }
	  buyweight=true;
	}else{
	  int j=0; int k=0;
	  while(j<pow3(m) && k<pow3(m)){
	    if(intersection[k] == -1){
	      k++;
	    }else if(candidate[j] == intersection[k]){
	      j++; k++;
	    }else if(candidate[j] < intersection[k]){
	      j++;
	    }else{
	      intersection[k]=-1; k++;
	    }
	  }
	}
      }
    }

    if(buyweight==false){
      cout << 0 << endl;
    }else{
      int ans=-1;
      for(int j=0;j<pow3(m);j++){
	if(intersection[j]>=0){ ans=intersection[j]; break; }
      }
      cout << ans << endl;
    }
  }
}



Measured memory_bytes: 3732
import java.util.*;
import java.lang.*;

public class Main {
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int[] oldsurf = new int[6];
        int[] newsurf = new int[6];
        for (int i = 0; i < 6; i++) {
            oldsurf[i] = sc.nextInt();
        }
        String s = sc.next();

        
        for (int i = 0; i < s.length(); i++) {
            char command = s.charAt(i);
            if (command == 'N') {
                newsurf[0] = oldsurf[1];
                newsurf[1] = oldsurf[5];
                newsurf[2] = oldsurf[2];
                newsurf[3] = oldsurf[3];
                newsurf[4] = oldsurf[0];
                newsurf[5] = oldsurf[4];
            } else if (command == 'S') {
                newsurf[0] = oldsurf[4];
                newsurf[1] = oldsurf[0];
                newsurf[2] = oldsurf[2];
                newsurf[3] = oldsurf[3];
                newsurf[4] = oldsurf[5];
                newsurf[5] = oldsurf[1];
                
            } else if (command == 'E') {
                newsurf[0] = oldsurf[3];
                newsurf[1] = oldsurf[1];
                newsurf[2] = oldsurf[0];
                newsurf[3] = oldsurf[5];
                newsurf[4] = oldsurf[4];
                newsurf[5] = oldsurf[2];
                
            } else if (command == 'W') {
                newsurf[0] = oldsurf[2];
                newsurf[1] = oldsurf[1];
                newsurf[2] = oldsurf[5];
                newsurf[3] = oldsurf[0];
                newsurf[4] = oldsurf[4];
                newsurf[5] = oldsurf[3];
                
            }
            for (int j = 0; j < 6; j++) {
                oldsurf[j] = newsurf[j];
            }
        }
        System.out.println(newsurf[0]);

    }
}



Measured memory_bytes: 26340
#include <stdio.h>

int main()
{
	int i, K, N, A[200001];
	scanf("%d %d", &K, &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));

	int max = A[1] + (K - A[N]);
	for (i = 1; i < N; i++) {
		if (A[i+1] - A[i] > max) max = A[i+1] - A[i];
	}
	printf("%d\n", K - max);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int d;cin>>d;
    vin c(26);rep(i,26)cin>>c[i];
    vvin s(d,vin(26));
    rep(i,d)rep(j,26)cin>>s[i][j];
    vin last(26,0);int sum,tmp,m;
    vin ans(d);
    rep(i,d){
        m=-inf;
        rep(j,26){
            sum=0;
            sum+=s[i][j];
            rep(k,26){
                if(k==j)continue;
                sum-=c[k]*(i+1-last[k]);
            }
            if(sum>m)tmp=j;
        }
        ans[i]=tmp;
        last[tmp]=i+1;
    }
    rep(i,d)cout<<ans[i]<<endl;
}

Measured memory_bytes: 3660
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c, d, e int
	fmt.Scan(&a, &b, &c, &d, &e)
	N := 5
	var time = []int{a,b,c,d,e}
	next := make([]int, N)
	for i := 0; i < N; i++{
		if time[i] % 10 == 0 {
			next[i] = time[i]
		} else {
			next[i] = time[i] - time[i] % 10 + 10
		}
	}
	ans := 1000000000
	for i := 0; i < N; i++ {
		sum := 0
		for j := 0; j < N; j++ {
			if i == j {
				sum = sum + time[j]
			} else {
				sum = sum + next[j]
			}
		}
		ans = int(math.Min(float64(ans),float64(sum)))
	}
	fmt.Println(ans)
}


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

int main() {
  string S;
  cin>>S;
  
 if(S.at(0)=='A'){
   if(S.at(1)=='A'&&S.at(2)=='A'){
     cout<<"No"<<endl;
   }
   
   if(S.at(1)=='B'||S.at(2)=='B'){
     cout<<"Yes"<<endl;
   }
 }
  
 if(S.at(0)=='B'){
   if(S.at(1)=='B'&&S.at(2)=='B'){
     cout<<"No"<<endl;
   }
   
   if(S.at(1)=='A'||S.at(2)=='A'){
     cout<<"Yes"<<endl;
   }
 }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n, k;
    string s;
    cin >> n >> k >> s;
    int score = 0;
    for(int i = 0; i + 1 < n; ++i){
        if(s[i] == s[i + 1])    ++score;
    }
    int ans = min(n - 1, score + k * 2);
    cout << ans << endl;
}

Measured memory_bytes: 512
// Copyright lzt
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
#include<ctime>
using namespace std;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef std::pair<long long, long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, j, k)  for (register int i = (int)(j); i <= (int)(k); i++)
#define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--)
#define Debug(...) fprintf(stderr, __VA_ARGS__)

inline ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}

const int maxn = 100100;
int n;
int a[maxn], f[maxn];

void work() {
  n = read();
  rep(i, 1, n) a[i] = read();
  rep(i, 2, n) {
    f[i] = f[i - 1] + abs(a[i] - a[i - 1]);
    if (i > 2) f[i] = min(f[i], f[i - 2] + abs(a[i] - a[i - 2]));
  }
  printf("%d\n", f[n]);
}

int main() {
  #ifdef LZT
    freopen("in", "r", stdin);
  #endif

  work();

  #ifdef LZT
    Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
  #endif
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()

int main () {
  int a,b,c,d;
  cin >> a >> b >> c >> d;

  if(a <= c && c <= b) cout << min(b,d) - c << endl;
  else if(c <= a && a <= d) cout << min(b,d) - a << endl;
  else cout << "0" << endl;
  return 0;
}


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

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

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


typedef struct tree_t{
	int parent;
	int sibling;
	int degree;
	int depth;
	int height;
	int left;
	int right;
} TREE_T;

TREE_T *TREE;


// 深さを調査
void Add_depth(TREE_T *box, int soeji, int depth)
{
	int i;

	box[soeji].depth = depth;

	if(box[soeji].left != -1)
		Add_depth(box, box[soeji].left, depth + 1);

	if(box[soeji].right != -1)
		Add_depth(box, box[soeji].right, depth + 1);
}


// 高さを調査
void Add_height(TREE_T *box, int soeji, int height)
{
	if(soeji == -1)
		return;

	if(height > box[soeji].height)
		box[soeji].height = height;

	Add_height(box, box[soeji].parent, height + 1);
}


int main()
{
	int n;
	int id;
	int left, right;
	int count;
	int i, j;

	scanf("%d", &n);

	// 初期化
	TREE = (TREE_T *)malloc(sizeof(TREE_T) * n);
	for(i = 0; i < n; i++){
		TREE[i].parent = -1;
		TREE[i].sibling = -1;
		TREE[i].left = TREE[i].right = -1;
		TREE[i].height = -1;
	}

	// 必要な情報を入れていく
	for(i = 0; i < n; i++){
		count = 0;
		scanf("%d %d %d", &id, &left, &right);
		TREE[id].left = left;
		TREE[id].right = right;

		if(left != -1){
			TREE[left].parent = id;
			TREE[left].sibling = right;
			count++;
		}
		if(right != -1){
			TREE[right].parent = id;
			TREE[right].sibling = left;
			count++;
		}

		TREE[id].degree = count;
	}

	// 根から辿って深さを調べる
	i = -1;
	while(TREE[++i].parent != -1);
	Add_depth(TREE, i, 0);

	// 葉から辿って高さを求める
	for(i = 0; i < n; i++){
		// leafである条件
		if(TREE[i].parent != -1 && TREE[i].degree == 0)
			Add_height(TREE, i , 0);
	}
	if(n == 1)
		TREE[0].height = 0;

	/* 表示 */
	for(i = 0; i < n; i++){
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
		i, TREE[i].parent, TREE[i].sibling, TREE[i].degree, TREE[i].depth, TREE[i].height);

		if(TREE[i].parent == -1)
			printf("root\n");
		else if(TREE[i].left != -1 ||  TREE[i].right != -1)
			printf("internal node\n");
		else
			printf("leaf\n");

	}

	return 0;
}


Measured memory_bytes: 2068
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
  string s;
  cin >> s;
  for(int i=0; i<s.size(); i++)
    if(i % 2 == 0)
      cout << s[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>

using namespace std;

long long a,b;
long long ans = 0;

long long f(long long n){
	if(n<0) return 0;
	if(n % 4 == 1){
		return 1;
	}
	else if(n % 4 == 2){
		return n + 1;
	}
	else if(n % 4 == 3){
		return 0;
	}
	else{
		return n;
	}
}


int main(){
	cin>>a>>b;
	ans = f(b) ^ f(a - 1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsinged long long
#define ld long double
#define mem(a,b) memset(a,b,sizeof(a))
#define inf (1LL<<62)
#define sf scanf
#define pf printf
#define repi(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define depi(i,a,b) for(int i=a;i>=b;--i)
#define dep(i,a,b) for(ll i=a;i>=b;--i)
#define mod 1000000007

using namespace std;

int main()
{
    //std::ios::sync_with_stdio(false);
    string s;
    while(cin>>s)
    {
        if(s=="Sunny")
            cout<<"Cloudy"<<endl;
        else if(s=="Cloudy")
            cout<<"Rainy"<<endl;
        else
            cout<<"Sunny"<<endl;
    }

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if(x>=400 && x<600){
            System.out.println(8);
        }else if(x>=600 && x<800){
            System.out.println(7);
        }else if(x>=800 && x<1000){
            System.out.println(6);
        }else if(x>=1000 && x<1200){
            System.out.println(5);
        }else if(x>=1200 && x<1400){
            System.out.println(4);
        }else if(x>=1400 && x<1600){
            System.out.println(3);
        }else if(x>=1600 && x<1800){
            System.out.println(2);
        }else if(x>=1800 && x<2000){
            System.out.println(1);
        }
                    
    }
}

Measured memory_bytes: 35700
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a;
	cin>>n>>a;
	cout<<n*n-a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 100000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
int main(){
      ll n,cnt=0;
      cin>>n;
      while(n!=1){
            n=(n+2)/3;cnt++;
      }
      cout<<cnt<<endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <stack>
#include <map>
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(var) var.begin(), var.end()
#define vi vector<int>
int const MOD = 1e9+7;
typedef long long ll;
using namespace std;

vector<map<int, bool>> adjf;
vector<map<int, bool>> adjb;
vector<int> component;
vector<pair<int, int>> nodes;

void dfs(int node, int compnnt){
    stack<int> mystack;
    mystack.push(node);
    int nodeCounter = 0;
    while(!mystack.empty()){
        int trav = mystack.top(); mystack.pop();
        if(nodes[trav].first == -1){
            nodes[trav].first = 1;
            nodes[trav].second = compnnt;
            nodeCounter++;
        }
        for(auto it: adjf[trav])
            if(nodes[it.first].first == -1)
                mystack.push(it.first);
    }
    component.push_back(nodeCounter);
}


void input(int n, int m, int k){
    adjf.resize(n+1);
    adjb.resize(n+1);
    while(m--){
        int x, y;
        cin >> x >> y;
        adjf[x][y] = true;
        adjf[y][x] = true;
    }
    while(k--){
        int x, y;
        cin >> x >> y;
        adjb[x][y] = true;
        adjb[y][x] = true;
    }
}
 
int main(){
    fast;
    int n, m, k;
    cin >> n >> m >> k;
    nodes.resize(n+1, {-1,-1});
    input(n, m, k);
    int compnt = 0;
    for(int i = 1; i <= n; i++){
        if(nodes[i].first  == -1){
            dfs(i, compnt);
            compnt++;
        }
    }
    vector<int> ans(n+1);
    for(int i = 1; i <= n; i++){
        ans[i] = component[nodes[i].second] - 1 - adjf[i].size();
        for(auto itr: adjb[i])
            if(nodes[itr.first].second == nodes[i].second && !adjf[i][itr.first])
                ans[i]--;
    }
    for(int i = 1; i <= n; i++)
        cout << ans[i] << ' ';
    cout << endl;
}


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

public class Main {
    static class Reader {
        BufferedReader in;

        Reader() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in));
        }

        Reader(String name) throws IOException {
            in = new BufferedReader(new FileReader(name));
        }

        StringTokenizer tokin = new StringTokenizer("");

        String next() throws IOException {
            if (!tokin.hasMoreTokens()) {
                tokin = new StringTokenizer(in.readLine());
            }
            return tokin.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

    }
    static class Writer {
        PrintWriter cout;

        Writer() throws IOException {
            cout = new PrintWriter(System.out);
        }

        Writer(String name) throws IOException {
            cout = new PrintWriter(new FileWriter(name));
        }

        StringBuilder out = new StringBuilder();

        void print(Object a) {
            out.append(a);
        }

        void println(Object a) {
            out.append(a + "\n");
        }

        void close() {
            cout.print(out.toString());
            cout.close();
        }
    }

    //a > b
    static int gcd(int a, int b){
        if(b == 0){
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    public static void main(String args[]) throws IOException {
        Reader in = new Reader();
        Writer out = new Writer();
        int n = in.nextInt();
        int x0 = in.nextInt();
        ArrayList<Integer> arr = new ArrayList<>(n + 1);
        for (int i = 0; i < n; i++) {
            arr.add(in.nextInt());
        }
        arr.add(x0);
        Collections.sort(arr);
        int gc = 0;
        for (int i = 0; i < n; i++) {
            int d = arr.get(i + 1) - arr.get(i);
            gc = gcd(Math.max(gc, d), Math.min(gc, d));
        }
        out.print(gc);
        out.close();
    }
}

Measured memory_bytes: 40284
H, W = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
A = [list(map(int, input().split())) for h in range(H)]

for i in range(10):
  for j in range(10):
    for k in range(10):
      c[j][k] = min(c[j][k], c[j][i] + c[i][k])

ans = 0
for h in range(H):
  for w in range(W):
    if A[h][w] != -1:
      ans += c[A[h][w]][1]
print(ans)

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        StringBuilder sb=new StringBuilder();
        String str="ACL";
        for(int i=0;i<n;i++)
        sb.append(str);
        System.out.println(sb.toString());
    }
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(3);
    double a, b, c, d, e, f;
    while(cin>>a>>b>>c>>d>>e>>f) {
        cout<<(c*e-b*f)/(a*e-b*d)+0<<' '<<(a*f-c*d)/(a*e-b*d)+0<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
ull cbs(int n, int p) {
  vector<vector<ull>> v(n+1,vector<ull>(n+1,0));
  for(int i = 0;i < n+1; i++) {
    v[i][0]=1;
    v[i][i]=1;
  }
  for(int i = 1;i < n+1;i++) {
    for(int j = 1;j < i;j++) v[i][j]=(v[i-1][j-1]+v[i-1][j]);
  }
  ull sum = 0;
  for(int i = p;i < n+1;i+=2) sum += v[n][i];
  return sum;
}
int main() {
  int n, p, x, a = 0, b = 0;
  cin >> n >> p;
  for(int i = 0;i < n;i++) {
    cin >> x;
    if(x % 2 == 0) a++;
    else b++;
  }
  cout << (ull)pow(2, a)*cbs(b, p) << endl;
}

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

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

  vector<int> card(N);

  for(int i=0; i<N; i++){
    cin >> card.at(i);
  }

  int alice = 0;

  for(int i=0; i<card.size(); i++){
    vector<int>::iterator iter = max_element(card.begin(), card.end());
    size_t index = distance(card.begin(), iter);
    if(i%2==0){
      alice += card.at(index);
    }else{
      alice -= card.at(index);
    }
    card.at(index)=0;
  }

  cout << alice << endl;

}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int vis1[200001],vis2[200001];
int to[200001];

int main(){
    long long n,k;
    cin>>n>>k;
    for(int i=1;i<=n;++i){
        cin>>to[i];
    }
    int s=1,flag=0;
    int cnt1=0,cnt2=0;
    while(!vis1[s]){
        if(cnt1==k){
            flag=1;
            break;
        }
        ++cnt1;
        vis1[s]=1;
        s=to[s];
    }
    while(!flag&&!vis2[s]){
        ++cnt2;
        vis2[s]=1;
        s=to[s];
    }
    if(!flag){
        k-=(cnt1-cnt2);
        k%=cnt2;
        for(int i=0;i<k;++i){
            s=to[s];
        }
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 5892
#include<stdio.h>
short imos[5001][5001];
int max(int a,int b){return a>b?a:b;}
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	int i,j;
	for(i=0;i<=n;i++)for(j=0;j<=n;j++)imos[i][j]=0;
	for(i=0;i<m;i++){
		int x,y,s;
		scanf("%d %d %d",&x,&y,&s);
		x--;y--;
		imos[x][y]=max(imos[x][y],s+1);
	}
	int ans=0;
	for(i=0;i<n;i++){
		for(j=0;j<=i;j++){
			if(imos[i][j]>0){
				ans++;
				imos[i+1][j]=max(imos[i+1][j],imos[i][j]-1);
				imos[i+1][j+1]=max(imos[i+1][j+1],imos[i][j]-1);
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}
				

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

int main(){
	
	int n, x, y, sumx=0, sumy=0;

	while(cin >> n && n > 0){
		sumx=0, sumy=0;
		for(int i=0; i<n; i++){
			x=0,y=0;
			cin >> x >> y;
			if(x > y){
				sumx = sumx + x + y;
			}
			else if(x < y){
				sumy = sumy + x + y;
			}
			else if(x == y){
				sumx = sumx + x;
				sumy = sumy + y;
			}
		}
	
		cout << sumx << " " << sumy << endl;
	 }
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main() {
 int n,k;
 cin >>n>>k;
 vector<int> v;
 for(int i=0;;i++)
 {
  if(n>=k){

  int r=n%k;
  v.push_back(r);
  n=n/k;}
  if(n<k){
  v.push_back(n);
  break;
}
 }
  cout<<v.size();
 
 }

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a;
    double ans;
    double num;

    scanf("%d",&a);

    if(a%2==0){
        ans=0.50000000000;
    }else{
        num=(a+1)/2;
        ans=num/a;
    }

    printf("%lf",ans);

    return 0;
}

Measured memory_bytes: 128
h, w = map(int, input().split())
arr = []
for i in range(h):
    _s = str(input())
    arr.append(_s)

arr = ['.' + s + '.' for s in arr]
arr = ['.'*(w+2)] + arr + ['.'*(w+2)]
arr = [list(s) for s in arr]
arr2 = []
for lst in arr:
    _lst = []
    for s in lst:
        if s=='.': 
            s = 0 
        else: 
            s = 1
        _lst.append(s)
    arr2.append(_lst)

arr = []
for i in range(1, h+1):
    lst = []
    for j in range(1, w+1):
        if arr2[i][j]==1:
            lst.append('#')
        else:
            cnt = sum(arr2[i][j-1:j+2]) + sum(arr2[i-1][j-1:j+2]) + sum(arr2[i+1][j-1:j+2]) - arr2[i][j]
            # print(i, j, arr2[i][j], cnt)
            lst.append(str(cnt))
    arr.append(lst)

arr = [''.join(lst) for lst in arr]
for s in arr:
    print(s)


Measured memory_bytes: 3188
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int H, A, ans=0;

    cin >> H >> A;

    while(H>0) {
        H -= A;
        ans++;
    }

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 256
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);
#define asc(A) sort(A.begin(),A.end())
#define dsc(A) sort(A.begin(),A.end(),greater<ll>())
#define input(A,N) for(ll i=0;i<N;i++) cin>>A[i];
int main()
{
    fasino
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    #endif
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll i=0;
    while(true)
    {
        if(i%2!=0)
            a-=d;
        else
            c-=b;
        i++;
        if(a<=0)
        {
            cout<<"No";
            return 0;
        }
        if(c<=0)
        {
            cout<<"Yes\n";
            return 0;
        }
        // cout<<a<<" "<<c<<"\n";
    }
    
    return 0;
}

Measured memory_bytes: 3612
// AOJ CGL_3_C Polygon-Point Containment
// 2018.5.3 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct { double x, y; } PP;
typedef struct { PP s, e; } SEG, LINE;

#define INF			1e8
#define EPS			1e-8
#define EQ(a,b)		(fabs((a)-(b))<EPS)
#define PPeQ(a,b)	(EQ(a.x,b.x)&&EQ(a.y,b.y))

int dcmp(double x) { if (fabs(x) < EPS) return 0; return x <= 0 ? -1 : 1; }
PP vset(double x, double y) { PP r; r.x = x, r.y = y; return r; }
PP vadd(PP p1, PP p2) { PP r; r.x = p1.x + p2.x, r.y = p1.y + p2.y; return r; }
PP vsub(PP p1, PP p2) { PP r; r.x = p1.x - p2.x, r.y = p1.y - p2.y; return r; }
PP vsmul(PP p, double k) { PP r; r.x = p.x * k, r.y = p.y * k; return r; }
PP vmul(PP p1, PP p2) { PP r;
	r.x = p1.x * p2.x - p1.y * p2.y, r.y = p1.x * p2.y + p1.y * p2.x; return r; }
double vabs(PP a) { return hypot(a.x, a.y); }
double dist(PP p1, PP p2) {	return hypot(p1.x-p2.x, p1.y-p2.y); };
double cross(PP a, PP b) { return a.x * b.y - a.y * b.x; }
double dot(PP a, PP b) { return a.x * b.x + a.y * b.y; }
double norm(PP a) { return a.x * a.x + a.y * a.y; }

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int containsSegP(PP p1, PP p2, PP p)   // p1-p2 = seg
{
	double x1 = p1.x, y1 = p1.y, x2 = p2.x, y2 = p2.y;
	if (x1 > x2) {
		double t;
		t = x1, x1 = x2, x2 = t;
		t = y1, y1 = y2, y2 = t;
	}
	return x1 <= p.x && p.x <= x2 &&
		((y1 <= y2 && y1 <= p.y && p.y <= y2) ||
		(y1 > y2 && y2 <= p.y && p.y <= y1))
		&& EQ((p.y - y1)*(x2 - x1), (y2 - y1)*(p.x - x1));
}

// 点が多角形に含まれているかの判定　1:含まれる, 0:含まれない
int containsPolyP(int n, PP *poly, PP p)
{
	int i, f;
	PP a, b, t;
	double c;		// cross(a,b)

	f = 0;
	for (i = 0; i < n; i++) {
		if (containsSegP(poly[i], poly[i+1], p)) return 1;
		a = vsub(poly[i], p), b = vsub(poly[i+1], p);
		if (EQ((c=cross(a, b)), 0) && dot(a, b) < EPS) return 0;
		if (!EQ(a.y, b.y) && a.y >= b.y) t = a, a = b, b = t, c = -c;
		if (a.y < EPS && EPS < b.y && c > EPS) f = !f;
	}
	return f? 2: 0;
}

PP pp[110];

int main()
{
	int n, q, i;
	PP p;

	n = in();
	for (i = 0; i < n; i++) pp[i].x = in(), pp[i].y = in();
	pp[n] = pp[0];
	q = in();
	while (q--) {
		p.x = in(), p.y = in();
		putchar('0'+ containsPolyP(n, pp, p)), putchar('\n');
	}
	return 0;
}



Measured memory_bytes: 2128
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

S = input()
N = len(S)

child = [1]*N

for i in range(N-1):
    if S[i]=='R' and S[i+1]=='R':
        child[i+2] += child[i]
        child[i] = 0

for i in range(N-1):
    if S[-(i+1)]=='L' and S[(-(i+2))]=='L':
        child[-(i+3)] += child[-(i+1)]
        child[-(i+1)] = 0

for c in child:
    print(c)

Measured memory_bytes: 4864
N=input()
if N[-1]=="2" or N[-1]=="4" or N[-1]=="5" or N[-1]=="7" or N[-1]=="9" :
	print("hon")
elif N[-1]=="0" or N[-1]=="1" or N[-1]=="6" or N[-1]=="8" :
	print("pon")
else :
	print("bon")

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

typedef long long ll;

const int MOD = 1e9 + 7;
const int N = 1e6 + 5;
int x, y;
ll fac[N], inv[N];

ll power(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res = (res * a) % MOD;
        }
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i < N; ++i) {
        fac[i] = fac[i - 1] * i % MOD;
    }
    inv[N - 1] = power(fac[N - 1], MOD - 2);
    for (int i = N - 2; i >= 0; --i) {
        inv[i] = inv[i + 1] * (i + 1) % MOD;
    }
}

ll C(ll a, ll b) {
    return fac[a] * inv[b] % MOD * inv[a - b] % MOD;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    init();
    cin >> x >> y;
    int sum = x + y;
    if (sum % 3) {
        cout << 0 << endl;
    } else {
        int cnt = sum / 3;
        int two = x - cnt;
        if (two < 0 || two > cnt) {
            cout << 0 << endl;
            exit(0);
        }
        ll res = C(cnt, two);
        cout << res << endl;
    }

    return 0;
}



Measured memory_bytes: 15872
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())

const int maxn=55;
int n;
ll a[maxn],b[maxn];

bool check(ll cnt){
	ll cur=n-1-cnt;
	ll need=0;
//	REP(i,n)b[i]=a[i]+cnt;
	REP(i,n){
		if(a[i]>cur){
			need+=(a[i]-cur+(ll)n)/(ll)(n+1);
		}
	} 
	return need<=cnt;
}

int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	REP(i,n)cin>>a[i];
	ll l=0,r=(ll)INF*(ll)INF;
	while(r-l>1){
		ll mid=(l+r)>>1;
		if(check(mid))r=mid;
		else l=mid;
	}
	ll ans=(ll)INF*(ll)INF;
	for(ll i=max(l-100*n,0ll);i<=min(l+100*n,(ll)INF*(ll)INF);i++)
	if(check(i))ans=min(ans,i);
	cout<<ans;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  long L[86];
  L[0]=2;
  L[1]=1;
  for(int i=2;i<=N;i++){
    L[i] = L[i-2] + L[i-1];
  }
  cout << L[N] << endl;
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */


int main() {
    string s;
    cin >> s;
    int o=0;
    int z=0;
    rep(i, s.size()){
        if(s[i] == '0') z++;
        else o++;
    }
    cout << min(o, z) * 2 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    ll n; cin >> n;
    ll T; cin >> T;
    vector<ll> t(n);
    rep(i, n) cin >> t.at(i);

    ll now = t.at(0);
    ll last = t.at(0);
    ll cnt = 0;
    for(int i=0; i<n; i++){
        if(i==n-1){
            cnt+=T;
            break;
        }
        if(t.at(i)+T>=t.at(i+1)){
            cnt += t.at(i+1) - t.at(i);
        }
        else{
            cnt += T;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();

        int coverage = d * 2 + 1;
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j < coverage; j++) {
                i++;
            }
            ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21716
#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 pq priotity_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
ll n,m,a,b;
vector<pair<ll,ll>> vec;

int main(){
	cin >> n >> m;
	REP(i,0,n) cin >> a >> b, vec.push_back(make_pair(a,b));
	
	REP(i,0,n){
		REP(j,0,n){
			vec.push_back(make_pair(vec[i].first, vec[j].second));
			vec.push_back(make_pair(vec[j].first, vec[i].second));
		}
	}
	
	ll mi=0;
	REP(i,0,vec.size()){
		REP(j,i+1,vec.size()){
			ll rx=max(vec[i].first, vec[j].first);
			ll ry=max(vec[i].second, vec[j].second);
			ll lx=min(vec[i].first, vec[j].first);
			ll ly=min(vec[i].second, vec[j].second);
			
			int c=0;
			REP(k,0,n) if((lx<=vec[k].first and vec[k].first<=rx) and (ly<=vec[k].second and vec[k].second<=ry)) c++;
			if(c>=m and !mi) mi=(ll)(rx-lx)*(ll)(ry-ly);
			if(c>=m) mi=min(mi, (ll)(rx-lx)*(ll)(ry-ly));
		}
	}
	
	cout << mi << endl;
	return 0;
}


Measured memory_bytes: 512
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
use std::cmp::Ordering;
 
use std::cmp;
use std::cmp::min;
use std::collections::BTreeMap;
use std::process;
use std::cmp::Ord;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::collections::BTreeSet;
use std::mem;
 
use std::ops::{Deref, DerefMut, Index, IndexMut};
use std::any::{Any, TypeId};


fn main(){
    input!{
        h:usize,
        w:usize,
        a:[chars;h],
    }
    let inf= 1000000000;
    let mut v = Vec::new();
    let mut d = vec![vec![1000000000;w];h];
    for i in 0..h{
        for j in 0..w{
            if a[i][j] == '#'{
                d[i][j] = 0;
                v.push((i, j));
            }
        }
    }
    let dx = vec![0, 0, -1, 1];
    let dy = vec![1, -1, 0, 0];
    while(v.len()!=0){
        let mut tmp = Vec::new();
        for k in 0..v.len(){
            for i in 0..4{
                let nx = v[k].0 as i64 + dx[i];
                let ny = v[k].1 as i64 + dy[i];
                
                if 0<=nx && nx<h as i64 && 0<=ny && ny<w as i64{
                    if d[nx as usize][ny as usize] == inf{
                        d[nx as usize][ny as usize] = d[v[k].0][v[k].1] + 1;
                        tmp.push((nx as usize, ny as usize));
                    }
                }
            }
        }
        mem::swap(&mut v, &mut tmp);
    }
    let mut res= 0;
    for i in 0..h{
        for j in 0..w{
            res = cmp::max(d[i][j], res);
        }
    }
    println!("{}", res);
}



Measured memory_bytes: 28916
N = int(input())
T = [[] for i in range(N)]
for i in range(N - 1):
    u, v, w = map(int, input().split())
    u, v = u - 1, v - 1
    T[u].append([v, w])
    T[v].append([u, w])


ans = [-1] * N
stack = [[0, 0]]
while stack:
    n, color = stack.pop()
    ans[n] = color

    for to, w in T[n]:
        if ans[to] != -1:
            continue

        if w % 2 == 0:
            stack.append([to, color])
        else:
            stack.append([to, color ^ 1])

print(*ans, sep='\n')


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

long long int DP[401][401];
long long int a[401];

long long int sum(int l,int r){
	long long int ret=0;
	for(int i=l;i<=r;i++){
		ret+=a[i];
	}
	return ret;
}

int N;
long long int solve(int l,int r){
	if(l == r)return 0;
	if(DP[l][r]!=(long long)1e15) return DP[l][r];
	long long ret = 1e14;
	for(int i = l; i < r; i++){
		ret = min(ret, solve(l,i) + solve(i+1, r));
	}
	ret += sum(l,r);
	return DP[l][r] = ret;
}

int main(){
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>a[i];
	}
	for(int i=0;i<=N;i++){
		for(int j=0;j<=N;j++){
			DP[i][j]=(long long )1e15;
		}
	}
	cout<<solve(1,N)<<"\n";
	return 0;
}

Measured memory_bytes: 1536
Scanf.scanf "%d %d" (fun n m ->
    let foods = Array.make m 0 in
    for i = 1 to n do
        Scanf.scanf " %d" (fun k ->
            for j = 1 to k do
                Scanf.scanf " %d" (fun a -> foods.(a - 1) <- foods.(a - 1) + 1)
            done
        )
    done;
    Array.fold_left (fun acc v -> if v = n then acc + 1 else acc) 0 foods |> Printf.printf "%d\n"
)

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define piii pair<int, pii >
#define ppp pair<pii, pii >
#define F first
#define S second
#define pb push_back
#define pp pop_back

const int P = 1000000007;

using namespace std;

int h, w;
bitset<101> s[101];
int p[101][101];
priority_queue<piii > q;

int main(){

	cin >> h >> w;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			char b;
			cin >> b;
			if(b=='#') s[i][j] = 1;
			p[i][j] = P;
		}
	}

	q.push({0, {0, 0}});

	while(!q.empty()){
		
		piii c = q.top();
		q.pop();
		int i = c.S.F;
		int j = c.S.S;
		int v = -c.F;

		if(v > p[i][j]) continue;

		p[i][j] = v;

		if(i<h-1){
			int nv = v;
			if(!s[i][j] && s[i+1][j]) nv++;
			if(p[i+1][j] > nv){
				p[i+1][j] = nv;
				q.push({-nv, {i+1, j}});
			}
		}
		if(j<w-1){
			int nv = v;
			if(!s[i][j] && s[i][j+1]) nv++;
			if(p[i][j+1] > nv){
				p[i][j+1] = nv;
				q.push({-nv, {i, j+1}});
			}
		}
	}

	/*
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(p[i][j] != P) cout << p[i][j] << ' ';
			else cout << 'I' << ' ';
		} cout << '\n';
	}
	*/

	if(s[0][0]) p[h-1][w-1]++;
	cout << p[h-1][w-1] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define INF 1000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
// #define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  REP(i, n) { cin >> h.at(i); }
  int dp[n];
  REP(i, n) { dp[i] = INF; }
  dp[0] = 0;
  REP(i, n) {
    for (int j = 1; j <= k;j++) {
      if (i + j < n)
        dp[i + j] = min(dp[i] + abs(h.at(i + j) - h.at(i)), dp[i + j]);
    }
  }
  cout << dp[n - 1] << "\n";
  return 0;
}


Measured memory_bytes: 1024
fun main() {
    val XN = readLine()!!.split(" ").map { it.toInt() }
    val X = XN[0]
    val N = XN[1]
    var answer = 0
    if (N > 0) {
        val ps = readLine()!!.split(" ").map { it.toInt() }
        for (i in 0..101) {
            if (!ps.contains(X - i)) {
                answer = X - i
                break
            } else if (!ps.contains(X + i)) {
                answer = X + i
                break
            }
        }
    } else {
        val b= readLine()!!
        answer = X
    }

    println(answer)
}

Measured memory_bytes: 36480
N=int(input())
A=[int(i) for i in input().split()]
A.sort()
cnt={}
K=list(set(A))
K.sort()
for k in K:
  cnt[k]=0
for a in A:
  cnt[a]+=1
E=[]
for k in K:
  if cnt[k]>=2:
    if cnt[k]>4:
      E.append(k)
    E.append(k)
E.sort()
# print(E)
if len(E)>=2:
  print(E[-1]*E[-2])
else:
  print(0)

Measured memory_bytes: 20232
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
using ll = long long;

int n,m,k,l;
string s,t;

int main() {
  cin >> l;
  printf("%.10f\n",(double)l*l*l/27);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

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

int Judge(const string & s) {
	if (s[0] == '0' || s[s.size() - 1] == '1')
		return 0;
	int i;
	rep(i, s.size() >> 1) {
		if (s[i] != s[s.size() - 2 - i])
			return 0;
	}
	return 1;
}

void print(int a, int b) {
	printf("%d %d\n", a, b);
	return;
}

int main(void) {
	int num, i, j, k = 0, t = 1, n = 1;
	list<int> d;
	string s;
	cin >> s;
	if (!Judge(s)) {
		printf("-1\n");
		return 0;
	}
	s[s.size() - 1] = '1';
	for (i = 1; i < s.size(); i++) {
		if (s[i] == '1') {
			print(t, ++n);
			t = n;
			rep(j, k) {
				print(t, ++n);
			}
			k = 0;
		}
		else
			k++;
	}
	return 0;
}

Measured memory_bytes: 3796
n = int(input())
number = list(map(int, input().split()))
count = 0
for i in range(1, len(number)-1):
    if((number[i] > number[i-1]) & (number[i] < number[i+1])):
        count += 1
    elif((number[i] < number[i-1]) & (number[i] > number[i+1])):
        count += 1
print(count)

Measured memory_bytes: 3064
#pragma region Macros
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
#pragma endregion
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	string s, t, u;
	int a, b;

	cin >> s >> t >> a >> b >> u;
	if (u == s)
	{
		cout << a - 1 << ' ' << b;
	}
	else
	{
		cout << a << ' ' << b - 1;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();


        if ((A + B) % 2 == 0) {
            System.out.println((A + B) / 2);
        } else {
            System.out.println("IMPOSSIBLE");
        }
    }
}

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

#define _ << " " <<
#define tr(x) cout << #x _ x << endl

#ifdef _WIN32
#define LD "%I64d"
#else
#define LD "%ld"
#endif

using namespace std;

typedef long long ll;

struct Comp {
    bool operator()(string & lf, string & rg) {
        return lf < rg;
    }
};

int n, k;
int used[10];

int read() {
    if (scanf("%d %d", &n, &k) < 2) {
        return 0;
    }
    memset(used, 0, sizeof used);
    int x;
    for (int i = 0; i < k; i++) {
        scanf("%d", &x);
        used[x] = 1;
    }
    return 1;
}

bool can(int x) {
    while (x > 0) {
        int d = x % 10;
        if (used[d]) return false;
        x /= 10;
    }
    return true;
}

void solve() {
    for (int i = n; ; i++) {
        if (can(i)) {
            printf("%d\n", i);
            break;
        }
    }
}

int main() {
//    freopen(in, r, stdin);
    while (1) {
        if (!read()) break;
        solve();
    }
}


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

using namespace std;

typedef pair<int, int> pii;

const int MAX_N = 1e4, M = 30;

struct Point {
    int x, y;
};

int N;
Point poi[MAX_N];
char seq[MAX_N];

int main() {
    scanf("%d", &N);
    bool odd = false, even = false;
    for (int i = 1; i <= N; i++) {
        scanf("%d%d", &poi[i].x, &poi[i].y);
        if (poi[i].x + poi[i].y & 1) odd = true;
        else even = true;
    }
    if (odd && even) {
        printf("-1\n");
        return 0;
    }
    if (even) {
        seq[M + 1] = 'U';
        for (int i = 1; i <= N; i++) poi[i].y--;
    }
    printf("%d\n", M + 1 + even);
    for (int i = 0; i <= M; i++) printf("%d ", 1 << i);
    if (even) printf("%d ", 1);
    printf("\n");
    for (int i = 1; i <= N; i++) {
        Point p = poi[i];
        for (int j = M; j >= 0; j--) {
            int v = 1 << j;
            if (abs(p.x) > abs(p.y)) {
                if (p.x > 0) seq[j] = 'R', p.x -= v;
                else seq[j] = 'L', p.x += v;
            } else {
                if (p.y > 0) seq[j] = 'U', p.y -= v;
                else seq[j] = 'D', p.y += v;
            }
        }
        printf("%s\n", seq);
    }
}


Measured memory_bytes: 256