akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>

using namespace std;

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

typedef long long ll;

char F[20][16];
int sx, sy;
unordered_map<int, int> umap;

constexpr int to_num(int x, int y) {
  return x+y*16;
}

struct state {
  int x, y, used;
  state(int x, int y, int used) : x(x), y(y), used(used) {}
  bool operator == (state const& s) const { return x==s.x && y==s.y && used==s.used; }
};

struct state_hash
{
  size_t operator()(state const& s) const {
    return hash<int>()(to_num(s.x, s.y)) ^ hash<int>()(s.used);
  }
};


constexpr int dx[8] = {-1, 0, 1, 0,-1, 1, 1,-1};
constexpr int dy[8] = {0, -1, 0, 1,-1,-1, 1, 1};

constexpr bool inrange(int x, int y) {
  return 0<=x && x<16 && 0<=y && y<20;
}

bool is_used_xy(int used, int x, int y) {
  if(umap[to_num(x, y)] == -1) { return false; }
  return used >> umap[to_num(x, y)] & 1;
}

void debugger(int used, int cx, int cy) {
  rep(i, 20) {
    rep(j, 16) {
      if(cx == j && cy == i) {
        assert((F[i][j] == 'X' && is_used_xy(used, j, i)) || (F[i][j] == '.') || (F[i][j] == 'G'));
        cout << 'O';
      }
      else {
        cout << (is_used_xy(used, j, i) ? 'U' : F[i][j]);
      }
    }
    cout << endl;
  }
}

int dijkstra() {
  unordered_map<state, int, state_hash> dist;
  queue<state> q;
  q.emplace(sx, sy, 0);
  dist[state{sx, sy, 0}] = 0;
  while(!q.empty()) {
    int const x = q.front().x, y = q.front().y, used = q.front().used;
    int& cost = dist[state{x,y,used}];
    q.pop();
    if(x == -1 && y == 19) { return cost; }
    if(F[y][x] == 'G') { return cost; }
    rep(i, 8) {
      int nx = x+dx[i], ny = y+dy[i];
      int nused = used;
      if(!inrange(nx, ny)) { continue; }
      if(F[ny][nx] != 'X') { continue; }
      if(is_used_xy(used, nx, ny)) { continue; }
      bool ng = false;
      for(;;) {
        if(!inrange(nx, ny)) { ng = true; break; }
        if(F[ny][nx] != 'X') { break; }
        if(is_used_xy(used, nx, ny)) { break; }
        nused |= 1<<umap[to_num(nx, ny)];
        nx += dx[i], ny += dy[i];
      }
      if(ng && !(nx == -1 && ny == 19)) { continue; }
      if(inrange(nx, ny) && F[ny][nx] == 'A') { continue; }
      if(dist.find(state{nx, ny, nused})!=dist.end()) { continue; }
      dist[state{nx, ny, nused}] = cost+1;
      q.emplace(nx, ny, nused);
    }
  }
  return -1;
}

int main() {

  rep(i, 20) rep(j, 16) umap[to_num(j, i)] = -1;
  int bcnt = 0;
  rep(i, 19) rep(j, 15) {
    cin >> F[i][j];
    if(F[i][j] == 'O') {
      F[i][j] = '.';
      sx = j, sy = i;
    }
    if(F[i][j] == 'X') {
      umap[to_num(j,i)] = bcnt++;
    }
  }

  rep(i, 20) { F[i][15] = 'A'; }
  rep(i, 16) {
    if(i < 15 && F[18][i] != 'X') { F[18][i] = 'G'; }
    F[19][i] = 'G';
  }

  cout << dijkstra() << endl;

  return 0;
}

Measured memory_bytes: 4612
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  string s;
  cin>>s;
  int q;
  cin>>q;
  bool pos=false;
  string prefix="",suffix="";
  int inv=0;
  while(q--){
    int com;
    cin>>com;
    if(com==1){
      inv++;
      pos=!pos;
    }else{
      int side;
      char add;
      cin>>side>>add;
      if(side==1){
        if(!pos){
          suffix=add+suffix;
        }else{
          prefix+=add;
        }
      }else{
        if(!pos){
          prefix+=add;
        }else{
          suffix=add+suffix;
        }
      }
    }
  }
  if(inv%2==0){
    cout<<suffix+s+prefix<<endl;
  }else{
    reverse(prefix.begin(),prefix.end());
    reverse(suffix.begin(),suffix.end());
    reverse(s.begin(),s.end());
    cout<<prefix+s+suffix<<endl;
  }
  return 0;
}


Measured memory_bytes: 1416
import * as fs from "fs";

function main() {
    const [x, y] = fs.readFileSync("/dev/stdin", "utf8").split(" ").map(i => parseInt(i));


    for (let i = 0; i <= 100; i++) {
        for (let j = 0; j <= 100; j++) {
            if ((i + j == x ) && (i * 2 + j * 4 == y)) {
                console.log("Yes");
                return
            }

        }
    }
    console.log("No");
}

main();


Measured memory_bytes: 29640
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int a[3][3];
    FOR(i,3) FOR(j,3) a[i][j] = ri();
    
    int b[3][2];
    FOR(i,3) b[i][0] = a[i][1]-a[i][0],
             b[i][1] = a[i][2]-a[i][1];
    bool res = true;
    FOR(i,2) if (b[i][0] != b[i+1][0] || b[i][1] != b[i+1][1]) res = false;
    
    FOR(i,3) b[i][0] = a[1][i]-a[0][i],
             b[i][1] = a[2][i]-a[1][i];
    
    FOR(i,2) if (b[i][0] != b[i+1][0] || b[i][1] != b[i+1][1]) res = false;
    
    cout << (res?"Yes":"No") << endl;
 return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define WATCH(x) cout << (#x) << " is " << (x) << endl

#define PB push_back
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);

int main()
{   
    flash
      
      ll a, b;
      cin >> a >> b;
      int k=0 , ct=0;
      if(b==1) {
          cout << 0;
          return 0;
      }
      else if(a==b) {
          cout << 1;
          return 0;
      }
      //else if()

      while(1) {
          if(k>=b) break;
          if(k+a >=b) k=k+a;
          else k+=(a-1);
          ct++;
      }
      cout << ct;
      
}

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

const string YES = "YES";
const string NO = "NO";

void solve(long long A, long long B, long long C){
    map<ll, ll> ans;
    ans[A] = 1;
    if(!ans.count(B)) ans[B] = 1;
    else ans.at(B)++;
    if(!ans.count(C)) ans[C] = 1;
    else ans.at(C)++;

    if(ans[5]==2 && ans[7]== 1) cout << YES << endl;
    else cout << NO << endl;

}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
import sys
n,m=map(int,input().split())
a=[]
d=0
for i in range(m):
    a.append(int(input()))
a.append(0)
a.append(0)
a.append(0)
ans=[]
for i in range(m-1):
    if a[i+1]-a[i]==1:
        print(0)
        sys.exit()
ans=[0 for i in range(n+5)]
ans[1]=1
ans[2]=2

if a[0]==1:
    ans[1]=0
    ans[2]=1
    d+=1
if a[0]==2 or a[1]==2:
    ans[2]=0
    d+=1

for i in range(1,n+3):
    if i+2==a[d]:
        ans[i+2]=0
        d+=1
    else:
        ans[i+2]=ans[i+1]%1000000007+ans[i]%1000000007
   
print(ans[n]%1000000007)
    
    
    

        


Measured memory_bytes: 81904
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define REP1(i,n) for(long long i=1;i<=(n);i++)
#define REP2D(i,j,h,w) for(long long i=0;i<(h);i++) for(long long j=0;j<(w);j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=(h);i++) for(long long j=1;j<=(w);j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) ((a).begin()),((a).end())
#define RANGE(a) (a),((a)+sizeof(a))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define ENTER printf("\n")
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<(a)<<endl

#ifdef DEBUG
#define DBPRT(a) cout << "[Debug] - " << #a << " : " << (a) << endl
#define DBSTART if(1){
#define DBEND }
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);
#else
#define DBPRT(a) if(0){}
#define DBSTART if(0){
#define DBEND }
#define PRTLST(arr,num) if(0){}
#define PRTLST2(arr2,d1,d2) if(0){}
#define PRTLST2D(arr2,d1,d2) if(0){}
#endif

#define TOSUM(arr,sum,n) {sum[0]=arr[0];REP1(i,n-1) sum[i]=sum[i-1]+arr[i];}

#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v) {os<<" { ";ITE(v) {os<<*ite;if(ite!=--v.end()){os<<" , ";}} os<<" } ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& m) {ITE(m) {os<<ite->P1<<"\t\t|->\t\t"<<ite->P2<<endl;} return os;}

//---------------------
#define MAXN 100000
//---------------------

ll n,r;

int main(){
	cin >> n >> r;
	if(n>=10){
		PRT(r);
	}else{
		PRT(r + 1000 - 100 * n);
	}
	return 0;
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll N;
    cin >> N;
    vector<ll> T(N);
    for(int i = 0; i < N; i++) cin >> T.at(i);
    vector<ll> reA(N);
    for(int i = 0; i < N; i++) cin >> reA.at(i);
    
    vector<ll> maxh(N), minh(N, 1);
    
    minh[0] = T[0]; maxh[0] = T[0];
    for (ll i = 1; i < N; i++){
        if(T[i] == T[i-1]){
            maxh[i] = T[i];
        }
        else{
            maxh[i] = T[i];
            minh[i] = T[i];
        }
    }

    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        A[i] = reA[N-i-1];
    }

    if(maxh[N-1] < A[0] || minh[N-1] > A[0]){
        printf("0\n");
        return 0;
    }
    minh[N-1] = A[0]; maxh[N-1] = A[0];
    for (ll i = 1; i < N; i++) {
        if(A[i] == A[i-1]){
            if(minh[N-i-1] > A[i]){
                printf("0\n");
                return 0;
            }
            maxh[N-i-1] = min(maxh[N-i-1], A[i]);
        }
        else{
            if(minh[N-i-1] > A[i] || maxh[N-i-1] < A[i]){
                printf("0\n");
                return 0;                
            }
            maxh[N-i-1] = A[i];
            minh[N-i-1] = A[i];
        }
    }

    ll ans = 1;
    for (ll i = 0; i < N; i++) {
        ans = ans * (maxh[i] - minh[i] + 1) % MOD;
    }
    printf("%lld\n", ans);


    

}



Measured memory_bytes: 4224
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;


int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    vector<ll> dp(n, 1e9);
    dp[0] = 0;
    dp[1] = max(h[0]-h[1], h[1]-h[0]);

    for(int i=2;i<n;i++){
        dp[i] = min(dp[i], dp[i-2]+max(h[i]-h[i-2],h[i-2]-h[i]));
        dp[i] = min(dp[i], dp[i-1]+max(h[i]-h[i-1],h[i-1]-h[i]));
    }

    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1408
import java.util.*;
public class Main{
  Scanner cin = new Scanner(System.in);
  int N,M,L;
  int[] d,a,k,t;
  int[][][] dp;
  public void solve(){
    N = cin.nextInt();
    M = cin.nextInt();
    L = cin.nextInt();

    d = new int[M];
    a = new int[M];
    k = new int[M];
    t = new int[M];

    for(int i = 0;i < M;i++){
      d[i] = cin.nextInt();
      a[i] = cin.nextInt();
      k[i] = cin.nextInt();
      t[i] = cin.nextInt();
    }
    dp = new int[5 + 1][N + 1][L + 1];
    for(int i = 0;i < 5;i++){
      for(int j= 0;j < N;j++){
        for(int l = 0;l < L;l++){
          for(int m = 0;m < M;m++){
            if(d[m] == i && a[m] - 1 == j){
              dp[i + 1][0][l + 1] = Math.max(dp[i + 1][0][l + 1],dp[i][j][l] + t[m]);
              dp[i][j + k[m]][l + 1] = Math.max(dp[i][j + k[m]][l + 1],dp[i][j][l] + t[m]);
            }
            dp[i][j + 1][l] = Math.max(dp[i][j + 1][l],dp[i][j][l]);
            dp[i + 1][0][l] = Math.max(dp[i + 1][0][l],dp[i][j][l]);
          }
        }
      }
    }

    int ans = 0;
    for(int i = 0;i < 5 + 1;i++){
      for(int j = 0;j < N + 1;j++){
        for(int k = 0;k < L + 1;k++){
          ans = Math.max(ans,dp[i][j][k]);
        }
      }
    }
    System.out.println(ans);
  }
  public static void main(String[] args){
    new Main().solve();
  }
}

Measured memory_bytes: 31164
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int b[150],ans=0;
signed main(){
    int n;
    cin>>n;
    rep(i,n-1)cin>>b[i];
    ans+=b[0]+b[n-2];
    for(int i=1;i<n-1;i++){
        ans+=min(b[i-1],b[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
def isok(arg):
    count = arg
    for i in range(n):
        if -(-(h[i]-b*arg)//(a-b)) >= 0:
            count -= -(-(h[i]-b*arg)//(a-b))
    if count >= 0:
        return True
    else:
        return False

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if isok(mid):
            ok = mid
        else:
            ng = mid
    return ok

n,a,b = map(int,input().split())
h = []
for i in range(n):
    h.append(int(input()))
print(bisect(0,10**9))


Measured memory_bytes: 50008
<?php
/*
    Problem URL : http://abc060.contest.atcoder.jp/tasks/abc060_d

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

ini_set('memory_limit', '256M');

// define('DEBUG', true);
define('DEBUG', false);

list($N, $W) = explode(" ", trim(fgets(STDIN)));

// $w = array_fill(0, $N, 0);
// $v = array_fill(0, $W, 0);

for ($i = 0; $i < $N; $i++) {
    list($w[$i], $v[$i]) = explode(" ", trim(fgets(STDIN)));
}
if (DEBUG) echo implode(" ", $w) . PHP_EOL;

$cnt1 = floor($W / $w[0]);
$cnt2 = floor($W / ($w[0] + 3));
if (DEBUG) echo "\$cnt: {$cnt1} {$cnt2}\n";

if ($cnt1 == $cnt2) {
    for ($i = 0; $i < $N; $i++) {
        $w[$i] = 1;
    }
    $W = $cnt1;
}
if ($cnt1 == $cnt2 + 1) {
    $avoid = $w[0];

    for ($i = 0; $i < $N; $i++) {
        $w[$i] = $w[$i] - $avoid + 20;
    }
    $W -= ($avoid - 20) * $cnt1;
}

if (DEBUG) echo implode(" ", $w) . PHP_EOL;
if (DEBUG) echo "\$W = {$W}\n";

$tmp1 = array_fill(0, $N + 1, 0);
$tmp2 = array_fill(0, $W + 1, 0);

$dp = array($tmp1, $tmp2);

for ($j = 0; $j <= $W; $j++) {
    $dp[$N][$j] = 0;
}

for ($i = $N - 1; $i >= 0; $i--) {
    for ($j = 0; $j <= $W; $j++) {
        // printf("%d < %d\n", $j, $w[$i]);
        if ($j < $w[$i]) {
            $dp[$i][$j] = $dp[$i + 1][$j];
        } else {
            $dp[$i][$j] = max($dp[$i + 1][$j], $dp[$i + 1][$j - $w[$i]] + $v[$i]);
        }
        // printf("%d %d %d\n", $i, $j, $dp[$i][$j]);
    }
}

echo $dp[0][$W]."\n";

Measured memory_bytes: 10872
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
typedef long long ll;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int dp[41][450][450];
const int inf = 1e9;
int main(){
    int n,ma,mb;
    cin >> n >> ma >> mb;
    vector<int> a(n),b(n),c(n);

    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i] >> c[i];
    }

    rep(i,41)rep(ca,410)rep(cb,410)dp[i][ca][cb]=inf;

    dp[0][0][0]=0;

    rep(i,n){
        rep(ca,401){
            rep(cb,401){
                if(dp[i][ca][cb]==inf)continue;
                dp[i+1][ca][cb]=min(dp[i+1][ca][cb],dp[i][ca][cb]);
                dp[i+1][ca+a[i]][cb+b[i]]=min(dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]);
            }
        }
    }
    int ans = inf;
    rep(i,n){
        FOR(ca,1,401){
            FOR(cb,1,401){
                if(ca*mb-cb*ma==0)ans=min(ans,dp[n][ca][cb]);
            }
        }
    }
    if(ans==inf)cout << -1 <<endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 32384
import itertools
import math
import fractions
import functools

string = input()
s = []
for i in range(len(string)):
    s.append(int(string[i]))
count = [0,0]
for i in range(len(s)):
    if s[i] == 0: count[0] += 1
    if s[i] == 1: count[1] += 1

print(min(count)*2)

Measured memory_bytes: 71000
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long[] a = {sc.nextLong(), sc.nextLong(), sc.nextLong()};
		int ans = 0;
		for(int i = 0 ; i < 1000 ; i++) {
			for(int j = 0 ; j < 3 ; j++) {
				if(a[j] % 2 == 1) {
					System.out.println(i);
					return;
				}
			}
			long x = (a[0] + a[1]) / 2;
			long y = (a[1] + a[2]) / 2;
			long z = (a[2] + a[0]) / 2;
			a[0] = y;
			a[1] = z;
			a[2] = x;
		}
		System.out.println(-1);
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<array>
#include<numeric>

using namespace std;

const int INF=1<<29;
const int N=100;
typedef array<int,N> INTARRAY;
typedef array<bool,N> BOOLARRAY;

int d[N][N];

int sum(INTARRAY ia){
  int s=accumulate(begin(ia),end(ia),0);
  return (s==INF)?0:s;
}

int dfs(BOOLARRAY ba,INTARRAY ia,int n){
  int s=sum(ia);
  if(n==N)return s;
  int r=dfs(ba,ia,n+1);
  BOOLARRAY cba=ba;
  cba[n]=true;
  INTARRAY cia=ia;
  cia[n]=INF;
  bool f=false;
  for(int i=0;i<n;i++){
    if(cba[i]){
      cia[i]=min(cia[i],d[n][i]);
      cia[n]=min(cia[n],d[n][i]);
      f|=cia[i]==0;
      f|=cia[n]==0;
    }
  }
  if(!f){
    r=max(r,dfs(cba,cia,n+1));
  }
  return r;
}

int main(){
  for(int i=0;i<N;i++){
    d[i][i]=INF;
  }
  int n,m;
  cin>>n>>m;
  while(m--){
    int u,v,f;
    cin>>u>>v>>f;
    u--;
    v--;
    d[u][v]=d[v][u]=f;
  }
  int ans=0;
  for(int i=0;i<N;i++){
    BOOLARRAY ba={};
    ba[i]=true;
    INTARRAY ia={};
    ia[i]=INF;
    ans=max(ans,dfs(ba,ia,i+1));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1344
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  int a, b, c;
  cin >> a >> b >> c;
  cout << ((a^b)^c);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
ll N, K;

int main() {
  INCANT;
  cin >> N >> K;
  ll ans=0ll;
  for (ll i=K; i<=N+1; i++) {
    ans+=i*(2*N-i+1)/2-(i-1)*i/2+1;
    ans%=MOD;
  }

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

Measured memory_bytes: 3652
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define print(x) cout << x << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    ll sign = 1;
    ll sum = 0;
    ll cost1 = 0;
    rep(i, N) {
        sum += a[i];
        if (sign == 1)
        {
            if (sum <= 0) {
                cost1 += abs(sum - 1);
                sum = 1;
            }
        } else {
            if (sum >= 0) {
                cost1 += abs(-1 - sum);
                sum = -1;
            }
        }
        sign *= -1;
    }
    sign = -1;
    sum = 0;
    ll cost2 = 0;
    rep(i, N) {
        sum += a[i];
        if (sign == 1)
        {
            if (sum <= 0) {
                cost2 += abs(sum - 1);
                sum = 1;
            }
        } else {
            if (sum >= 0) {
                cost2 += abs(-1 - sum);
                sum = -1;
            }
        }
        sign *= -1;
    }
    print(min(cost1, cost2));
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define VECCIN(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    int N;
    cin >> N;
    vector<pair<int, int>> lr(N);
    REP(i, N)cin >> lr[i].first >> lr[i].second;

    int ans = 0;
    REP(i, N) {
        ans += lr[i].second - lr[i].first + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main(){
    int a,b; cin>>a>>b;
    int ans=-1;
    //cout<<ans*0.1<<endl;
    for(int i=1;i<1010;i++){
        if(i*8/100== a && i/10==b){
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include"iostream"
#include"algorithm"
#include"stdio.h"
using namespace std;
const int Maxn = 100005;
int a[Maxn],f[Maxn][10];
int main()
{
//	freopen("text.in","r",stdin);
	int n,maxn=0;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	f[1][0]=1;//,f[1][1]=1,f[1][2]=1;
	for(int i=2;i<=n;i++)
		if(a[i]==a[i-1]) f[i][0]=f[i-1][0]+1,f[i][1]=f[i-1][1]+1,f[i][2]=f[i-1][2]+1;
		else if(a[i]-a[i-1]==1) f[i][2]=f[i-1][1]+1,f[i][1]=f[i-1][0]+1,f[i][0]=1;
		else if(a[i]-a[i-1]==2) f[i][2]=f[i-1][0]+1,f[i][0]=1;
		else f[i][0]=1;//,f[i][1]=1,f[i][2]=1;
	for(int i=1;i<=n;i++)maxn=max(maxn,max(f[i][0],max(f[i][1],f[i][2])));
	printf("%d",maxn);
	return 0;
} 

Measured memory_bytes: 4608
import Data.List
import qualified Data.IntMap as M

primes::[Int]
primes=2:3:p where 
    p=5:q 1 7 p
    q m s (p:ps)=[n|n<-[x+y|x<-[s,s+6..p*p-2],y<-[0,4]],gcd m(toInteger n)<2]++q(m*toInteger p)(p*p)ps

fac :: [Int]->M.IntMap Int->Int->M.IntMap Int
fac _ m 1=m
fac [] m p=M.insertWith(+)p 1 m
fac pa@(p:pr) m n
    |mod n p==0=fac pa(M.insertWith(+) p 1 m)(div n p)
    |otherwise =fac pr m n

facs fs=map(foldl'(\a (p,n)->a*p^n)1.zip ps)$mapM(enumFromTo 0)ns
    where (ps,ns)=unzip fs

facsn = facs.M.toList.fac(takeWhile(<31623)primes)M.empty

main = do
    (n:m:_)<-map read.words<$>getLine::IO[Int]
    print $ solve n m

solve n m = m `div` a
    where
        a = head $ dropWhile (<n) $ sort $ facsn m

Measured memory_bytes: 1148
n, k = map(int, input().split())
baisu, amaru = 0, 0
for i in range(1,n+1):
    if i % k == 0:
        baisu += 1
    elif i % k == k // 2:
        amaru += 1
if k % 2 == 1:
    print(baisu**3)
else:
    print(baisu**3 + amaru**3)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int n;
const int maxn = 2e5 + 5;
vector<vector<int>> graph;
vector<int> fact(maxn), inv_fact(maxn);
vector<int> sz;
vector<int> dp;
vector<int> answer;
vector<int> up;
int add(int x, int y) {
	x += y;
	if (x >= mod) {
		return x - mod;
	}
	return x;
}
int mult(int x, int y) {
	return 1ll * x * y % mod;
}
int bin_pow(int x, int y) {
	if (y == 0) {
		return 1;
	}
	if (y % 2 == 0) {
		return bin_pow(mult(x, x), y / 2);
	}
	return mult(x, bin_pow(x, y - 1));
}
int inv(int x) {
	return bin_pow(x, mod - 2);
}
int C(int x, int y) {
	return mult(fact[x], mult(inv_fact[y], inv_fact[x - y]));
}

void dfs(int v, int parent = -1) {
	sz[v] = 1;
	for (int u : graph[v]) {
		if (u != parent) {
			dfs(u, v);
			sz[v] += sz[u];
		}
	}
	vector<int> szs;
	int ans = 1;
	for (int u : graph[v]) {
		if (u != parent) {
			ans = mult(ans, dp[u]);
			szs.push_back(sz[u]);
		}
	}
	int cur = sz[v] - 1;
	for (int x : szs) {
		ans = mult(ans, C(cur, x));
		cur -= x;
	}
	dp[v] = ans;
}
void push(int v, int parent = -1) {
	if (parent == -1) {
		answer[v] = dp[v];
	} else {
		answer[v] = mult(mult(dp[v], up[v]), C(n - 1, n - sz[v]));
	}
	for (int u : graph[v]) {
		if (u != parent) {
			up[u] = mult(mult(answer[v], inv(dp[u])), inv(C(n - 1, sz[u])));
			push(u, v);
		}
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	fact[0] = inv_fact[0] = 1;
	for (int i = 1; i < maxn; ++i) {
		fact[i] = mult(fact[i - 1], i);
		inv_fact[i] = inv(fact[i]);
	}
	cin >> n;
	graph.resize(n);
	sz.resize(n);
	dp.resize(n);
	answer.resize(n);
	up.resize(n);
	for (int i = 0; i < n - 1; ++i) {
		int u, v;
		cin >> u >> v;
		--u;
		--v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	dfs(0);
	push(0);
	for (int u : answer) {
		cout << u << '\n';
	}
 	return 0;
}


Measured memory_bytes: 18788
#include <stdio.h>
#include <stdlib.h>
#include<string.h>

int main(void) {
	int n[200] = { 0 };
	char stack[100];
	int top = -1;
	int temp;

	while ( scanf("%s", stack) != EOF ) {
		if (stack[0] == '+') {
			if (top > 0) {
				temp = n[top - 1] + n[top];
				top -= 1;
				n[top] = temp;
			}
		}
		else if (stack[0] == '-') {
			if (top > 0) {
				temp = n[top - 1] - n[top];
				top -= 1;
				n[top] = temp;
			}
		}		
		else if (stack[0] == '*') {
			if (top > 0) {
				temp = n[top - 1] * n[top];
				top -= 1;
				n[top] = temp;
			}
		}
		else {
			top++;
			n[top] = atoi(stack);
		}
	}

	printf("%d\n", n[top]);

	return 0;
}


Measured memory_bytes: 2104
#include<iostream>
using namespace std;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
bool isEmpty(char ch){
  if(ch=='.'||ch=='X')return true;
  else return false;
}
int change(char ch){
  if(ch=='N')return 0;
  if(ch=='E')return 1;
  if(ch=='S')return 2;
  if(ch=='W')return 3;
  return -1;
}
char change2(int x){
  if(x==0)return 'N';
  if(x==1)return 'E';
  if(x==2)return 'S';
  if(x==3)return 'W';
  return '-';
}
char t[30][30],tmp[30][30];
int W,H,gy[900],gx[900],size;
 
int main(){
  while(1){
    cin>>W>>H;
    if(W==0&&H==0)break;
    size=0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin>>t[i][j];
	if(t[i][j]=='X'){
	  gy[size]=i;
	  gx[size]=j;
	  size++;
	}
      }
    }

    int ans=0;
    while(1){
      ///////////////////////////////////////////////
      bool flag=false;
      for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
	  if(change(t[i][j])==-1)continue;
	  flag=true;
	  int dir=change(t[i][j]);
	  for(int k=5;k>=2;k--){
	    int ndir=(dir+k)%4;
	    int ny=i+dy[ndir],nx=j+dx[ndir];
	    if(isEmpty(t[ny][nx])){
	      t[i][j]=change2(ndir);
	      break;
	    }
	  }//k
	}//j
      }//i
      if(flag==false)break;
      ///////////////////////////////////////////////
      ans++;
      if(ans>180)break;
      /////////////////////////////////////////////// w s e n
      
      for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
	  if(change(t[i][j])==-1){
	    tmp[i][j]=t[i][j];
	  }else tmp[i][j]='.';
	}
      }
      
      for(int k=3;k>=0;k--){
	for(int i=0;i<H;i++){
	  for(int j=0;j<W;j++){
	    if(k!=change(t[i][j]))continue;
	    int ny=i+dy[k],nx=j+dx[k];
	    if(isEmpty(t[ny][nx])&&isEmpty(tmp[ny][nx])){
	      tmp[ny][nx]=t[i][j];
	    }else{
	      tmp[i][j]=t[i][j];
	    }
	  }
	}
      }
      
      for(int i=0;i<H;i++){
	for(int j=0;j<W;j++){
	  t[i][j]=tmp[i][j];
	}
      }

      for(int i=0;i<size;i++){
	t[gy[i]][gx[i]]='X';
      }
      ///////////////////////////////////////////////
      
    }
    if(ans>180)cout<<"NA"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1172
#include<iostream>

using namespace std;

int main(void){

    int n;
    cin >> n;

    for(int i = 0;i <= n;i += 4){
        for(int j = 0;j <= n;j += 7){
            if(i+j == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    Scanner sc = new Scanner(System.in);
    public static void main(String args[]) {
	new Main().doIt();
    }
    void doIt() { A(); }
    void A() {
        int A = sc.nextInt(), B = sc.nextInt();
	int ans = A+B;
	ans = Math.max(ans, Math.max(A-B, A*B));
	System.out.println(ans);
    }
}


Measured memory_bytes: 21844
while 1 :
    try:
        h,w=map(int,input().split())
        #print(h,w)
        if( h==0 and w==0 ): 
            break
        else:
            for hi in range(h):
                print("#" * w)
            print() #??????
        if( h==0 and w==0 ): break
    except (EOFError):
        #print("EOFError")
        break

Measured memory_bytes: 7624
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll N, ll K, vector<ll> H) {
  ll cnt{};
  if (N > K) {
    sort(ALL(H));
    cnt = accumulate(H.begin(),H.begin()+N-K,0LL);
  }
  cout << cnt << endl;
}

int main() {
  ll N;
  cin >> N;
  ll K;
  cin >> K;
  vector<ll> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  solve(N, K, move(H));
  return 0;
}


Measured memory_bytes: 1920
n, w = map(int, input().split())

values = []
weights = []
for i in range(n):
    value, weight = map(int, input().split())
    values.append(value)
    weights.append(weight)

dp = [[0 for i in range(w + 1)] for j in range(n + 1)]

for i in range(n):
    for j in range(w + 1):
        if weights[i] <= j:
            dp[i + 1][j] = max(dp[i][j - weights[i]] + values[i], dp[i][j])
        else:
            dp[i + 1][j] = dp[i][j]

print(dp[n][w])



Measured memory_bytes: 42264
#include<bits/stdc++.h>
using namespace std;
int par[51];
int len[51];
void init(int n){
  for(int i=1;i<=n;i++){
    par[i]=i;
    len[i]=1;
  }
}
int root(int n){
  if(par[n]==n) return n;
  return root(par[n]);
}
void unit(int a,int b){
  int x=root(a);
  int y=root(b);
  if(x==y) return;
  if(len[x]>len[y]){
    par[y]=x;
    len[x]+=len[y];
  }
  else{
    par[x]=y;
    len[y]+=len[x];
  }
}
int main(){
  int n,m;cin>>n>>m;
  int a[m],b[m];
  for(int i=0;i<m;i++) cin>>a[i]>>b[i];
  int ans=0;
  for(int i=0;i<m;i++){
    init(n);
    for(int j=0;j<m;j++){
      if(i==j) continue;
      unit(a[j],b[j]);
    }
    for(int j=1;j<=n;j++){
      if(root(1)!=root(j)){
        ans++;
        break;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int , int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18 


int main () {
    int n ;
    cin >> n;
    vector<ll> h (n );
    rep(i, n){
        cin >> h[i] ;
    }
    bool ans = true ;
    ll lim = INF;
    for(int i = n - 1 ; i >= 0 ; i--){
        if(h[i] > lim){
            h[i]-- ;
            if(h[i] > lim){
                ans = false ;
                break ;
            }
        }
        else {
            lim = h[i] ;
        }
    }
    
    if(ans){
        cout << "Yes" << endl ;
    }
    else{
        cout << "No" << endl ;
    }
} 


Measured memory_bytes: 3920
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt(), b = scanner.nextInt();
		if((a * b) % 2 == 0){
			System.out.println("Even");
		}else{
			System.out.println("Odd");
		}
	}

}


Measured memory_bytes: 20816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define t(x) cerr<<#x<<":"<<x<<'\n';
#define t2(a,n) { cerr<<#a<<" = "; for(int i=0; i<n; ++i){ cerr << a[i] << ' '; } ; cerr <<'\n'; }
#define t3(a){ cerr<<#a<<" = "; for(auto i: a){ cerr<<i<<" "; } cerr<<'\n'; }



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

	ll n,a,b;
	cin>>n>>a>>b;
	vector<ll> x(n);
	for(int i=0; i<n; ++i){
		cin>>x[i];
	}
	ll ans = 0;
	for(int i=1; i<n; ++i){
		ll dist = min( (x[i] - x[i-1]) * a , b );
		ans += dist;
	}
	cout<<ans<<endl;

	#ifdef LOL
	    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	#endif
	return 0;
}


Measured memory_bytes: 1024
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] NK = Console.ReadLine().Split(' ');
            int N = int.Parse(NK[0]);int K = int.Parse(NK[1]);
            string[] sh = Console.ReadLine().Split(' ');
            int[] dp = new int[N + 5];
            int[] h = new int[N + 2];
            dp[0] = 0;

            for (int i = 0; i < N; i++)
            {
                h[i] = int.Parse(sh[i]);
            }
            for (int i = 0; i < N; i++)
            {
                dp[i] = 2147483647;
            }
            dp[0] = 0;
            for (int j = 1; j < N; j++) {
                for (int i = 1; i <= K; i++)
                {
                    if (j >= i)
                    {
                        dp[j] = Math.Min(dp[j], dp[j-i]+Math.Abs(h[j] - h[j - i]));
                    }
                }
            }

            Console.WriteLine(dp[N-1]);
        }
    }
}


Measured memory_bytes: 35640
N = int(input())
data = [0]*(N-1)
cho = [0]*(N+1) #cho[i]にi番目の頂点の根元の色
res = [0]*(N-1) #枝の色
for i in range(0,N-1):
    di = list(map(int, input().split()))
    di.append(i)
    data[i] = di

data = sorted(data)
for i in range(0,N-1):
    if i != 0 and data[i][0] == data[i-1][0]:
        cur += 1
    else:
        cur = 1
    if cur == cho[data[i][0]]: cur += 1
    res[data[i][2]] = cur
    cho[data[i][1]] = cur

print(max(cho))
for item in res:
    print(item)

Measured memory_bytes: 33260
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main(){

    ll N; cin >> N;
    double ans = 0;
    vector<ll > A(N, 0);
    vector<ll > X(N, 0);
    vector<ll > Y(N, 0);

    ll mod = 1;
    for(ll i = N; i > 0; i--){
        mod *= i;
    }

    for(ll i = 0; i < N; i++){
        A[i] = i;  
    }

    for(ll i = 0; i < N; i++){
        cin >> X[i] >> Y[i];
    }

    do{
        double average = 0;
        
        for(ll i = 1; i < A.size(); i++){
            average += sqrt(pow(X[A[i-1]]-X[A[i]],2)+pow(Y[A[i-1]]-Y[A[i]],2));
        }

        ans += average;
  
    }while(next_permutation(A.begin(), A.end()));

    cout << fixed << setprecision(10) << ans / mod << endl;

}

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

int main() {

	int a, b;					 //変数の宣言（複数）：型␣変数名1, 変数名2 ;  カンマ（，）区切って宣言する
	cin >> a >> b;
        cout << a*b << " " << (a + b) * 2 << endl;       //面積 ＝ 縦 × 横、　周の長さ = （縦 + 横）× 2　 

	return 0;
}


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

using namespace std;

#define ll long long

vector<int> p, q, N;

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

    for (int i = 1; i <= n; i++)
        cin >> x, q.push_back(x);
    for (int i = 1; i <= n; i++)
        cin >> x, p.push_back(x);

    for (int i = 1; i <= n; i++)
        N.push_back(i);

    int a, b, counter = 0;

    do {
        counter++;
        if (N == p)
            a = counter;
        if (N == q)
            b = counter;

    } while(next_permutation(N.begin(), N.end()));

    cout << abs(a - b) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
 
using namespace std;
 
const int MAX = 17;
short in[MAX][MAX];
int  X,Y,data[MAX][MAX],ans;
int dx[4] = {-1,0,1};
 
 
void init(){
  memset(data,0,sizeof(data));
  ans = 0;
}
 
 
void solve(){
  for(int i = 1; i <= Y; i++)
    for(int j = 1; j <= X; j++){
      for(int k = 0; k < 3; k++)
	if(in[i][j] == 2){
	  if(in[i+2][j] != 1) data[i+2][j] += data[i][j];
	  break;
	}else if(in[i][j] == 0){
	  int nex = j+dx[k];
	  if(nex < 1 || nex > X) continue;

	  if(in[i+1][nex] == 2 && dx[k] == 0) data[i+1][nex] += data[i][j];
	  if(in[i+1][nex] == 0) data[i+1][nex] += data[i][j];

	}
    }
  
  for(int j = 1; j <= X; j++){
    if(Y-1 > 0 && in[Y-1][j] == 2) ans+=data[Y-1][j];
    ans+=data[Y][j];
  }
  cout << ans << endl;
}
 
void print(){
  for(int i = 1; i <= Y; i++){
    for(int j = 1; j <= X; j++)
      cout << data[i][j]<< " ";
    cout << endl;
  }
}
int main(){
  while(cin >> X >> Y && X+Y){
    init();
    for(int i = 1; i <= Y; i++)
      for(int j = 1; j <= X; j++)
    cin >> in[i][j];
     
    for(int i = 1; i <= X; i++)
      if(in[1][i] == 0) data[1][i] = 1;
 
    solve();
    //print();
  }
  return 0;
}

Measured memory_bytes: 1160
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,z,w; cin >> n >> z >> w;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    ll ans = 0;
    if(n > 1){
        ans = max(abs(a[n-1] - a[n-2]), abs(a[n-1] - w));
    }
    else{
        ans = abs(a[n-1] - w);
    }

    cout << ans << endl;
    
}

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

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9+7;
const LL INF = LLONG_MAX;
const LL N = 1e6+1;

int main() {
	fastio();
	
	LL k;
	cin >> k;

	LL low = k%10;

	if (low == 2 || low == 4 || low == 5 || low == 6 || low == 8 || low == 0 ) {
		cout << -1 << "\n";
		return 0;
	}

	LL mod = 7%k, c=1;
	while (mod != 0) {
		mod = ((mod *10) + 7) % k;
		c++;
	}
	cout << c << "\n";


}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

#include <atcoder/convolution>
#include <atcoder/dsu>
#include <atcoder/fenwicktree>
#include <atcoder/lazysegtree>
#include <atcoder/math>
#include <atcoder/maxflow>
#include <atcoder/mincostflow>
#include <atcoder/modint>
#include <atcoder/scc>
#include <atcoder/segtree>
#include <atcoder/string>
#include <atcoder/twosat>
using namespace atcoder;
//typedef modint998244353 mint;

int main(){
  int N,M;
  cin>>N>>M;
  VI A(M),B(M);
  rep(i,M) cin>>A[i]>>B[i];
  scc_graph G(N);
  rep(i,M) G.add_edge(A[i],B[i]);
  VVI ans=G.scc();
  cout<<ans.size()<<endl;
  rep(i,ans.size()){
    cout<<ans[i].size()<<" ";
    rep(j,ans[i].size()){
      cout<<ans[i][j]<<" ";
    }
    cout<<endl;
  }
}

Measured memory_bytes: 44404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    string s; cin>>s;
    s[5]=' ';
    s[13]=' ';
    cout<<s<<endl;
}


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

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

int MOD=1e9+7;
ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    int n, y; cin>>n>>y;

    for(int i=0; i<=2*1000+10; i++){
        for(int j=0; 4*j+9*i<=y/1000-n; j++){
            if(4*j+9*i == y/1000-n){
                if(n-i-j>=0){
                    cout << i << " " << j << " " << n-i-j << endl;
                    return 0;
                }
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Runtime;
using System.Numerics;
using System.Linq;

namespace ABC153
{
    class B
    {
        static void Main(string[] args)
        {

            uint[] nk = Console.ReadLine().Split().Select(uint.Parse).ToArray();
            uint[] h = Console.ReadLine().Split().Select(uint.Parse).ToArray();
            ulong ans = 0;
            Array.Sort(h);
            if (nk[0] <= nk[1]) { ans = 0; }
            else
            {
                for (uint i = 0; i < nk[0] - nk[1]; i++)
                {
                    ans += h[i];
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 34944