akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <string>
#include <vector>

using namespace std;


int main()
{
	int tmp = 0;
	int poket_num = 0;
	vector<int> area_Stack;
	stack<int> csd;
	string command;
	cin >> command;
	vector<int> Landfill(command.size());
	for (int i = 0; i < command.size(); ++i) {
		if (command[i] == '_') {
			Landfill[i] = 0;
		}
		else if(command[i] == '\\') {
			Landfill[i] = -1;
		}
		else {
			int j = i;
			while (j != 0) {
				--j;
				if (Landfill[j] == -1) {
					Landfill[j] = 0;
					break;
				}
			}
		}
	}
	for (int i = 0; i < command.size(); ++i) {
		if (Landfill[i] == -1) {
			command[i] = '_';
		}
	}
	for (int i = 0; i < command.size(); ++i) {
		if (command[i] == '_') {
			continue;
		}
		else if (command[i] == '/') {
			if (csd.empty() == false) {
				tmp += i - csd.top();
				csd.pop();
				if (csd.empty() == true) {
					area_Stack.push_back(tmp);
					poket_num++;
					tmp = 0;
				}
			}
			else {
				continue;
			}
		}
		else {
			csd.push(i);
		}
	}
	if (command[command.size()] == '/' && csd.empty() == false) {
		area_Stack.push_back(tmp);
		poket_num++;
	}
	int total_area = 0;
	decltype(area_Stack)::iterator iter = area_Stack.begin();
	while (iter != area_Stack.end()) {
		total_area += *iter++;
	}

	cout << total_area << endl;
	cout << poket_num;
	if (area_Stack.size() > 0) {
		cout << " ";
		iter = area_Stack.begin();
		decltype(area_Stack)::iterator iter_end = area_Stack.end();
		iter_end--;
		while (iter != iter_end) {
			cout << *iter++ << " ";
		}
		cout << *iter << endl;
	}else{
		cout << endl;
	}
}



Measured memory_bytes: 3348
#pragma region Macros
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn, now, ans;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos and *pos <= '9') n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos and *pos <= '9') k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos and *pos <= '9') a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos and *pos <= '9') pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos and *pos <= '9') b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7916
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
typedef long long int LL;
typedef struct node{
	int cap,to,rev;
}node;
vector<node> v1[105];
queue<int> q1;
const int S=102,T=103;
const int INF=1<<30;
int lev[105];

void bfs(){
	int a,b,c;
	int i,j;
	node na;
	memset(lev,-1,sizeof(lev));
	lev[S]=0;
	q1.push(S);
	while(!q1.empty()){
		a=q1.front(),q1.pop();
		for(i=0;i<v1[a].size();i++){
			na=v1[a][i];
			if(lev[na.to]==-1 && na.cap>0){
				lev[na.to]=lev[a]+1;
				q1.push(na.to);
			}
		}
	}
}

int dfs(int s,int t,int f){
	if(s==t)return f;
	for(int i=0;i<v1[s].size();i++){
		if(v1[s][i].cap>0 && lev[s]<lev[v1[s][i].to]){
			int d=dfs(v1[s][i].to,t,min(f,v1[s][i].cap));
			if(d>0){
				v1[s][i].cap-=d;
				v1[v1[s][i].to][v1[s][i].rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

void add_edge(int a,int b,int n){
	node na;
	na.cap=n,na.to=b,na.rev=v1[b].size();
	v1[a].push_back(na);
	na.cap=0,na.to=a,na.rev=v1[a].size()-1;
	v1[b].push_back(na);
}

int main(){
	int n;
	node na,nb;
	int a,b,c;
	int i,j,k;
	LL s=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a;
		if(a<0)add_edge(S,i,-a);
		else add_edge(i,T,a),s+=a;
		for(j=2*i;j<=n;j+=i){
			add_edge(i,j,INF);
		}
	}
	while(1){
		bfs();
		if(lev[T]==-1)break;
		while((a=dfs(S,T,INF))>0)s-=a;
	}
	cout<<s<<endl;
	return 0;
}
		


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4;
const int MOD = 1e9 + 7;

struct Mat{
	int val[N][N];
	int n;
	Mat(int a, int b)
	{
		n = a;
		for (int i=0; i<n; i++)
			for (int j=0; j<n; j++)
				val[i][j] = i == j ? b : 0;
	}
	int * operator [](int x)
	{
		return val[x];
	}
};

Mat operator *(Mat a, Mat b)
{
	int n = a.n;
	Mat res(n, 0);
	for (int i=0; i<n; i++)
		for (int j=0; j<n; j++)
			for (int k=0; k<n; k++)
				res[i][k] = (res[i][k] + 1LL * a[i][j] * b[j][k]) % MOD;
	return res;
}

Mat operator ^(Mat a, ll b)
{
	Mat res(a.n, 1);
	while (b)
	{
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;	
}

void print(Mat a)
{
	for (int i=0; i<3; i++)
	{
		for (int j=0; j<3; j++)
			cout << a[i][j] << " ";
		cout << "\n";
	}
	cout << "\n";
}

int x[100 * 1000 + 1];

int main()
{

	Mat a(3, 1);
	a[0][1] += 2; a[0][0] += 1; a[0][2] += 1;
	a[1][0] += 1;
	a[2][1] += 2; a[2][0] += 1;

	Mat b(3, 1);
	b[1][0] += 1;
	b[2][1] += 2; b[2][0] += 1;
	
	int n, m;
	cin >> n >> m;
	Mat res(3, 1);
	res[1][1] = 1;
	for (int i=1; i<=m; i++)
		cin >> x[i];
	x[++m] = n;
	x[0] = 0;
	m++;
	for (int i=0; i+1<m; i++)
	{
		res = (a ^ (x[i+1] - x[i] - 1)) * res;
		res = b * res;
	}
	cout << res[2][0] << "\n";
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int k = sc.nextInt();
    int l = b-a+1;

    int num = a;
    int num2 = b-k;

    if(l <= k*2){
      for(int i = 0 ; i < l ; ++i){
        System.out.println(num);
        num++;
      }
      
    }else if(l > k*2){
      for(int i = 0 ; i < k ; ++i){
        System.out.println(num);
        num++;
      }
      for(int i = l-k ; i < l ; ++i){
        num2++;
        System.out.println(num2);
      }
    }    
  }
}

Measured memory_bytes: 36120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  vector<int> b = a;
  sort(all(b));
  rep(i, n) {
    if (a[i] == b[n - 1]) cout << b[n - 2] << endl;
    else cout << b[n - 1] << endl;
  }
}


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

int main() {
 int a,b,c;
 cin >> a >> b >> c;
  
  int x,y,z;
  if (a <= b ){
    if( b<=c){
    x=a;
    y=b;
    z=c;
    }
  else if (a<=c){
    x=a;
    y=c;
    z=b;
  }
    else {
      x=c;
      y=a;
      z=b;
    }
  }
  if (a>b){
    if ( a<=c){
      x=b;
      y=a;
      z=c;
    }
    else if (c<=b){
      x=c;
      y=b;
      z=a;
    }
    else{
      x=b;
      y=c;
      z=a;
    }
  }
  
  
  int sa;
  sa=z-y;//（これ回数）
  int r;
  r=y-x;
  if (r%2 == 0){
    cout << sa+(r/2) << endl;
  }
  else {
    cout << sa+(r+1)/2+1 << endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 800010
#define inf 2000000000
using namespace std;
typedef long long ll;
template<typename T> inline void read(T &x)
{
    x=0;char c=getchar();bool flag=false;
    while(!isdigit(c)){if(c=='-')flag=true;c=getchar();}
    while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    if(flag)x=-x;
}
int n,q,tot,cnt;
ll ans;
int fa[maxn],val[maxn];
struct edge
{
    int x,y;
    ll v;
}e[maxn];
bool cmp(const edge &a,const edge &b)
{
    return a.v<b.v;
}
int find(int x)
{
    return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main()
{
    read(n),read(q),cnt=n-1;
    for(int i=0;i<n;++i) fa[i]=i,val[i]=inf;
    for(int i=1;i<=q;++i)
    {
        int x,y,v;
        read(x),read(y),read(v);
        e[++tot]={x,y,v},val[x]=min(val[x],v+1),val[y]=min(val[y],v+2);
    }
    for(int i=0;i<=2*n;++i) val[i%n]=min(val[i%n],val[(i-1+n)%n]+2);
    for(int i=0;i<n;++i) e[++tot]={i,(i+1)%n,val[i]};
    sort(e+1,e+tot+1,cmp);
    for(int i=1;i<=tot;++i)
    {
        int x=find(e[i].x),y=find(e[i].y);
        if(x==y) continue;
        fa[x]=y,ans+=e[i].v;
        if(++cnt==n-1) break;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 17724
from itertools import product

n, m = map(int, input().split())
xyz = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for a, b, c in product([1, -1], repeat=3):
    tmp = sorted([a * x + b * y + c * z for x, y, z in xyz])
    ans = max(ans, sum(tmp[n - m:]))
print(ans)


Measured memory_bytes: 74624
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }

inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }



int main()
{
    int a,b,ans=-1;
    cin>>a>>b;
    for(int i=20000;i>=0;i--)
    {
        int a1=((i*2)/25);
        int a2=((i*1)/10);
        if(a1==a&&a2==b)
            ans=i;
        // if(i+i)
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=5e5+50; 

int n,dest[N],qwq;
vector<pair<int,int>> a;
long long ans;
char s[N]; 
struct B{int c[N],r;void U(int p,int x){for(;p<=n;p+=p&-p)c[p]+=x;}int Q(int p){for(r=0;p>=1;p-=p&-p)r+=c[p];return r;}}tr;
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
#endif
	scanf("%s",s); 
	n=strlen(s); 
	rep(c,'a','z'){
		int p=0,q=n-1;
		while(1){
			for(;p<n&&s[p]!=c;++p);
			for(;q>=0&&s[q]!=c;--q);
			if(p>q)break;
			if(p!=q)a.pb(mp(p,q));
			else ++qwq,dest[p]=n/2;
			++p,--q;
		}
	}
	if(qwq!=(n&1))return puts("-1"),0;
	sort(all(a)),reverse(all(a));
	int l,r; if(n&1)l=n/2-1,r=n/2+1;else l=n/2-1,r=n/2;
	for(auto i:a)dest[i.first]=l--,dest[i.second]=r++;
	lop(i,0,n)ans+=i-tr.Q(dest[i]+1),tr.U(dest[i]+1,1);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4084
//ITP1_9 Shuffle

#include<iostream>
#include<string.h>
using namespace std;

int main(){
	string card;  //最初の並びを表す文字列
	int N;  //シャッフル回数
	int h;
	while(1){
		cin >> card;
		if(card == "-")
			break;
		cin >> N;
		int n = card.length();
		for(int i = 0; i < N; i++){
			cin >> h;
			string left = card.substr(0,h);
//			cout << "left: " << left << endl;
			card += left;
			card = card.substr(h,n);
//			cout << "card: " << card << endl;
		}
		cout << card << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
function prime(max){
   var arr=[];
   for(var i=0;i<=max;i++)arr[i]=i;
   arr[0]=false;
   arr[1]=false;
   var sqrt=Math.floor(Math.sqrt(max));
   for(var i=2;i<=sqrt;i++){
      if(arr[i]==false)continue;
         for(var j=i+i;j<=max;j+=i){
            arr[j]=false;
         }
   }
   var obj={};
   for(var i=0;i<=max;i++){
      if(arr[i]!==false)obj[arr[i]]=true;
   }
   return obj;
}
var p=prime(1000000);
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var nx=Arr.shift().split(" ").map(Number);
   var n=nx[0];
   var x=nx[1];
   if(n==0 && x==0)break;
   var dp=[];
   for(var i=0;i<=x;i++)dp[i]=false;
   var arr=[];
   for(var i=0;i<n;i++)arr.push(Arr.shift()-0);
   dp[0]=true;
   for(var i=0;i<x;i++){
      for(var j=0;j<n;j++){
         if(i+arr[j]>x)continue;
         if(dp[i])dp[i+arr[j]]=true;
      }
   }
   for(var i=x;i>0;i--){
      if(dp[i] && p.hasOwnProperty(i))break;
   }
   console.log((i===0)?"NA":i);
}

Measured memory_bytes: 90972
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {
    
    private static class Point {
        private final int i;
        private final int j;
        
        private Point(int i, int j) {
            this.i = i;
            this.j = j;
        }
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final int H = sc.nextInt();
        final int W = sc.nextInt();
        final int startI = sc.nextInt() - 1;
        final int startJ = sc.nextInt() - 1;
        final int endI = sc.nextInt() - 1;
        final int endJ = sc.nextInt() - 1;
        sc.nextLine();
        
        final int[][] field = new int[H][W];
        
        for (int i = 0; i < H; i++) {
            String s = sc.nextLine();
            
            for (int j = 0; j < W; j++) {
                field[i][j] = s.charAt(j) == '.'
                        ? -1 // 未検証
                        : -2; //壁
            }
        }
        
        int currJump = 0;
        Queue<Point> testTarget = new ArrayDeque<>();
        testTarget.add(new Point(startI, startJ));
        
        while (true) {
            Set<Point> pointsOfCurrJump = new HashSet<>();
            
            // ジャンプ無しで到達できる位置をすべて調べ上げる
            while (!testTarget.isEmpty()) {
                Point p = testTarget.poll();
                pointsOfCurrJump.add(p);
                
                if (1 <= p.i && field[p.i - 1][p.j] == -1) {
                    field[p.i - 1][p.j] = currJump;
                    testTarget.add(new Point(p.i - 1, p.j));
                }
                if (1 <= p.j && field[p.i][p.j - 1] == -1) {
                    field[p.i][p.j - 1] = currJump;
                    testTarget.add(new Point(p.i, p.j - 1));
                }
                if (p.i <= H - 2 && field[p.i + 1][p.j] == -1) {
                    field[p.i + 1][p.j] = currJump;
                    testTarget.add(new Point(p.i + 1, p.j));
                }
                if (p.j <= W - 2 && field[p.i][p.j + 1] == -1) {
                    field[p.i][p.j + 1] = currJump;
                    testTarget.add(new Point(p.i, p.j + 1));
                }
            }
            
            // ジャンプ無しで到達できる場所を調べつくしたら、
            // そこからジャンプして到達できる位置をすべて調べ上げる
            int j = ++currJump;
            pointsOfCurrJump.forEach(p -> {
                for (int di = -2; di <= 2; di++) {
                    for (int dj = -2; dj <= 2; dj++) {
                        int ni = p.i + di;
                        int nj = p.j + dj;
                        
                        if (0 <= ni && ni < H && 0 <= nj && nj < W && field[ni][nj] == -1) {
                            field[ni][nj] = j;
                            testTarget.add(new Point(ni, nj));
                        }
                    }
                }
            });
            if (field[endI][endJ] != -1 || testTarget.isEmpty()) {
                break;
            }
        }
        System.out.println(field[endI][endJ]);
    }
}


Measured memory_bytes: 66876
#include<stdio.h>
signed main(){
  char S[10];
  int i;
  for(i=0;i<3;i++){
  scanf("%s",&S[i]);
  }
  if(S[1]=='B'){
    printf("ARC\n");
  }else{
    printf("ABC\n");
  }
  return(0);
}

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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())

const int MOD = 1e9+7;

typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 5e3+3;
ll dp[MAXN][MAXN];
char str[MAXN];
int n,len;
ll power(ll a, ll b) {
	ll ret=1;
	while(b) {
		if(b&1) ret*=a;
		a*=a;
		b>>=1;
		a%=MOD;
		ret%=MOD;
	}
	return ret;
}
int main() {
//	freopen("TASK.in","r",stdin);freopen("TASK.out","w",stdout);
	cin>>n;
	scanf("%s",str+1);
	len=strlen(str+1);
	dp[0][0]=1;
	for(int i=1;i<=n;i++) {
		for(int j=0;j<=max(len,n);j++) {
			if(j) dp[i][j]=2LL*dp[i-1][j-1];
			if(dp[i][j]>=MOD) dp[i][j]%=MOD;
			dp[i][j]+=dp[i-1][j+1];
			if(dp[i][j]>=MOD) dp[i][j]-=MOD;
			if(!j) dp[i][j]+=dp[i-1][j];
			if(dp[i][j]>=MOD) dp[i][j]-=MOD;
		}
	}
	ll den = power(2,len);
	den = power(den,MOD-2);
	ll ans=dp[n][len];
	ans*=den;
	ans%=MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 195712
import sys
from string import ascii_lowercase as a2z

input = sys.stdin.readline


def main():
    N = int(input())
    S = [""] * N
    for i in range(N):
        S[i] = input().rstrip()

    count = {}
    for al in a2z:
        count[al] = 50

    for s in S:
        for al in a2z:
            num = s.count(al)
            if num < count[al]:
                count[al] = num

    ans = ""
    for k, v in count.items():
        ans = "".join([ans, k * v])
    ans = "".join(sorted(ans))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FI          freopen("input.txt", "r", stdin)
#define FO          freopen("output.txt", "w", stdout)
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef unsigned long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {0, -1}, dy[] = {-1, 0};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
void solve(){
    ll d, t, s;
    cin >> d >> t >> s;
    cout << (t * s >= d ? "Yes" : "No") << '\n';
}
int main(){
    FIN;
    int t = 1;
    for(int i = 1; i <= t; i++){
        solve();
    }
    //EjecuteTime;
    return 0;
}       

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	int a[n];//a[i]!=i+1にする
	rep(i,n) cin>>a[i];

	int cnt=0;
	rep(i,n){
		if(a[i]==i+1){
			cnt++;
			if(i!=n-1&&a[i+1]==i+2){
				i++;
			}
		}
	}
	cout<<cnt<<"\n";
}

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

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

int N;
ll dp[110][110], a[110][110];

int main() {
    cin >> N;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) {
            scanf("%Ld", &a[j][i]);
        }
    }
    dp[0][0] = a[0][0];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 2; j++) {
            chmax(dp[i+1][j], dp[i][j] + a[i+1][j]);
            chmax(dp[i][j+1], dp[i][j] + a[i][j+1]);
        }
    }
    cout << dp[N-1][1] << endl;

}

Measured memory_bytes: 384
loop do
  n, k = gets.split.map(&:to_i)
  
  break if n == 0 && k == 0
  
  arr, ans, sum = [], -Float::INFINITY, 0

  n.times do |i|
    arr << gets.to_i
    
    sum += arr.last
    sum -= arr.shift if i >= k
    
    ans = [ans, sum].max if i >= k - 1
  end
  
  puts ans
end

Measured memory_bytes: 9376
using System;

class Node{
  public int key;
  public int parent;
  public int left;
  public int right;
}

class A9{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    Node[] node = new Node[n + 1];
    int[] input = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
    for(int i = 1;i <= n;i++){
      node[i] = new Node();
    }
    for(int i = 0;i < n;i++){
      node[i + 1].key = input[i];
    }

    for(int i = 1;i <= n;i++){
      Console.Write("node " + i + ": key = " + node[i].key + ", ");
      if(i / 2 > 0){
        node[i].parent = node[i / 2].key;
        Console.Write("parent key = " + node[i].parent + ", ");
      }
      if(2 * i <= n){
        node[i].left = node[i * 2].key;
        Console.Write("left key = " + node[i].left + ", ");
      }
      if(2 * i + 1 <= n){
        node[i].right = node[2 * i + 1].key;
        Console.Write("right key = " + node[i].right + ", ");
      }
      Console.WriteLine();
    }
  }
}



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

int main(){
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k-1] << "\n";
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut aseq = vec![0; n];
    let mut min_ans = 0;
    let mut max_ans = 0;
    let mut open = vec![false; 30];
    for i in 0..n {
        aseq[i] = read::<usize>();
        let c = aseq[i] / 400;
        if aseq[i] >= 3200 {
            max_ans += 1;
            continue;
        }
        if open[c] {
            continue;
        }
        open[c] = true;
        min_ans += 1;
        max_ans += 1;
    }
    println!("{} {}", std::cmp::max(1, min_ans), max_ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    int n, m;
    cin >> n >> m;
    vector<int> cnt(n, 1);
    bitset<100009> red;
    red[0] = true;
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        cnt[x]--;
        cnt[y]++;
        if(red[x]) red[y] = true;
        if(cnt[x] == 0) red[x] = false;
    }

    cout << red.count() << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int n;
int dp[1010][1010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> n, n) {
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (s[i][j] == '*') dp[i][j] = 0;
        else if (i == 0 || j == 0) dp[i][j] = 1;
        else dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
        ans = max(ans, dp[i][j]);
      }
    }
    cout << ans << endl;
  }

  return 0;
}


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

void max_heapify(int *heap, int i) {
	int hsize, L, R, large, tmp;

	hsize = heap[0];
	L = 2 * i;
	R = 2 * i + 1;

	if (L <= hsize && heap[L] > heap[i]) {
		large = L;
	}
  else {
		large = i;
	}

	if (R <= hsize && heap[R] > heap[large]) {
		large = R;
	}

	if (large != i) {
		tmp = heap[i];
		heap[i] = heap[large];
		heap[large] = tmp;
		max_heapify(heap, large);
	}
}

int main(void) {
	int *heap, key, index, half, tmp;
	char com[20];

	heap = malloc(sizeof(int) * 2000001);
	heap[0] = 1;
	while (1) {
		scanf("%s %d ", com, &key);
		if (com[0] == 'i') {
			heap[0]++;
			index = heap[0];
			heap[index] = key;

			half = index / 2;
			while (index > 1 && heap[half] < heap[index]) {
				tmp = heap[index];
				heap[index] = heap[half];
				heap[half] = tmp;
				index /= 2;
				half = index / 2;
			}
		}
    else if (com[1] == 'x') {
			printf("%d\n", heap[1]);
			heap[1] = heap[heap[0]];
			heap[0]--;
			max_heapify(heap, 1);
		}
    else {
			return 0;
		}
	}

	return 0;
}



Measured memory_bytes: 5660
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
	int xa=0,xb=0;
	std::ios::sync_with_stdio(false);
	cin>>a>>b;
	int n=a.size()+b.size();
	for(int i=1;i<=n;i++)
	{
		if(i%2==0) 
		{
			cout<<b[xb];
			xb++;
		}
		else 
		{
			cout<<a[xa];
			xa++;
		}
	}
	return 0;
}

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

int main(){
    long long N,K;
    cin>>N>>K;

    set<long long> s;
    s.clear();

    long long tmp=N%K;
    while(1){
        tmp=abs(tmp-K);
        if(s.find(tmp)!=s.end()){
            break;
        }
        s.insert(tmp);
    }

    cout<<*s.begin()<<endl;
    

    return 0;
}

Measured memory_bytes: 3572
using System;
using System.Collections.Generic;
using System.IO;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Console1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            

            if (s[0] == s[1] && s[1] == s[2]) Console.WriteLine(" Yes ");
            else if (s[1] == s[2] && s[2] == s[3]) Console.WriteLine(" Yes ");
            else Console.WriteLine(" No ");

        }

    }
}


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

int main(){
	int n, l;
	cin >> n >> l;
	vector<string>s(n);
	for (int i = 0;i < n;i++) {
		cin >> s[i];
	}
	sort(s.begin(), s.end());
	for (int i = 0;i < n;i++) {
		cout << s[i];
	}
	cout << endl;


	return 0;
}

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double


int main(){
  int a, b, c, k; // 1 <= n <= 7
  cin >> a >> b >> c >> k;

  // A < B < C
  bool succeeded = false;
  int n = 0;
  while (n++ < k) {
    if (a >= b) {
      b *= 2;
      //cout << "n:" << n << "=" << a << "," << b << "," << c << endl;
      if (a < b && b < c) {
        succeeded = true;
        break;
      }
      continue;
    }
    if (b >= c) {
      c *= 2;
      //cout << "n:" << n << "=" << a << "," << b << "," << c << endl;
      if (a < b && b < c) {
        succeeded = true;
        break;
      }
      continue;
    }
    if (a < b && b < c) {
        succeeded = true;
        break;
    }
  }
  //cout << a << "," << b << "," << c << endl;


  cout << (succeeded ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int n;
    cin >> n; 
    int a, b;
    cin >> a >> b;
    cout << min(n * a, b) << endl;
}




Measured memory_bytes: 3620
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <algorithm>

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

int main() {

    int a;
    cin >> a;
    int b = a / 100;
    int c = b * 100 + b * 10 + b;
    if(c >= a){
        cout << c << endl;
    }else{
        b++;
        c = b * 100 + b * 10 + b;
        cout << c << endl;

    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
const ll mod =1e18 + 7;
ll exp(ll a , ll b){
	if(b == 0)	return 1;
	int x = b % 2 == 0 ?   ((exp(a , b/2)%mod)*(exp(a , b / 2)%mod))%mod :  (a%mod*exp(a , b - 1) % mod)%mod;
	return x;
}
int main(){
	fast;
	ll x;
	cin >> x;
	for(ll i = -200 ; i <= 200 ; i++){
		for(ll j = -200 ; j <= 200 ; j++){
			ll check = pow(i,5LL) - pow(j,5LL);
		//	cout << pow(i,5LL) << " " <<  pow(j,5LL) << " " << check << endl;
			if( check == x)
			{
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4124
import java.util.Scanner;

public class Main {
	public static void main(String[] args ) {
		Scanner sc = new Scanner(System.in);

		int gameCount = Integer.parseInt(sc.nextLine());

		int totalPointTaro = 0;
		int totalPointHanako = 0;

		for (int i = 0; i < gameCount; i++) {
			String[] cards = sc.nextLine().split(" ");
			if (cards[0].compareTo(cards[1]) == 0 ) {
				totalPointTaro += 1;
				totalPointHanako += 1;
			} else if (cards[0].compareTo(cards[1]) > 0) {
				totalPointTaro += 3;
			} else {
				totalPointHanako += 3;
			}

		}
		sc.close();

		System.out.printf("%d %d\n", totalPointTaro, totalPointHanako);

	}
}


Measured memory_bytes: 31160
S = input()
A = [int(S[0]),int(S[1]),int(S[2]),int(S[3])]

flg = 0
for i in range(len(A) - 1):
  if A[i] == A[i + 1]:
    flg = 1
    break

if flg:
  print("Bad")
else:
  print("Good")  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ( (a + b) > (c + d) ){
    cout << "Left" << endl;
  }
  else if ( (a + b) < (c + d) ){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}
    

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
	"strings"
)

func solution(h, n int, a []int) string {
	var sum int
	sort.Ints(a)
	for i := n - 1; i >= 0; i-- {
		sum += a[i]
		if sum >= h {
			return "Yes"
		}
	}
	return "No"
}

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 10240*10240)

	var h, n int
	var err error
	fmt.Scan(&h, &n)
	a := make([]int, n)
	ss := strings.Split(readLine(reader), " ")
	for i := range ss {
		a[i], err = strconv.Atoi(ss[i])
		checkError(err)
	}
	fmt.Println(solution(h, n, a))
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}


Measured memory_bytes: 7552
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

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)*}};}
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)*}};}
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, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        a: [usize;n],
        q: usize,
        operation: [(usize,usize);q]
    }

    let mut map = HashMap::new();

    let mut ans = 0;

    for &i in &a {
        let v = map.entry(i).or_insert(0);
        *v += 1;
        ans += i;
    }

    for &(target, after) in &operation {
        let target_count = map.get(&target);
        if let Some(count) = target_count {
            let count = *count;
            ans -= count * target;

            map.insert(target, 0);
            ans += after * count;
            let after_num = map.entry(after).or_insert(0);
            *after_num += count;
        }

        println!("{}", ans);
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 6740
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str,strArray[];
		ArrayList<Shachiku> list = new ArrayList<Shachiku>();

		while(!(str=br.readLine()).equals("0")){
			int n = Integer.parseInt(str);
			boolean toBe = false;

			for(int i=0; i<n; i++){
				strArray = br.readLine().split(" ");
				int id = Integer.parseInt(strArray[0]);
				long value = Long.parseLong(strArray[1]);
				long much = Long.parseLong(strArray[2]);
				long result = value*much;


				if(list.isEmpty()){
					list.add(new Shachiku(id, result));
				}else{
					boolean judge=false;
					for(int j=0; j<list.size(); j++){
						if(list.get(j).getID() == id){
							judge=true;
							list.get(j).Cal(result);
						}
					}
					if(!judge){
						list.add(new Shachiku(id, result));
					}
				}

			}

			for(int i=0; i<list.size(); i++){
				if(list.get(i).getResult() >= 1000000){
					System.out.println(list.get(i).getID());
					toBe = true;
				}
			}

			if(!toBe){
				System.out.println("NA");
			}

			list.clear();
		}
	}
}

class Shachiku{
	private int ID;
	private long re;

	Shachiku(int id, long Re) {
		this.ID = id;
		this.re = Re;
	}

	public void Cal(long s){
		this.re += s;
	}

	public long getResult(){
		return re;
	}

	public int getID(){
		return ID;
	}

	public void judge(){
		if(this.re >= 1000000){
			System.out.println(this.ID);
		}
	}
}

Measured memory_bytes: 24856
/* 

	 - If you fail to prepare, you are prepared to fail.	

	(C) Mark Spitz

*/

#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;

const bool dbg_flg = 1;
#define NAME(x) #x
#define debug if (dbg_flg) cerr

const int inf = 1e9 + 7;
const int MAXN = 2e5 + 5;

int k;
vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};


void solve() {
	cin >> k;

	cout << v[k - 1];
}


int main() {
	
	//~ freopen(".in", "r", stdin);
	//~ freopen(".out", "w", stdout);
	
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
	}

	return 0;
}

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

#define ll long long int
#define tc(t) int t;cin >> t; while(t--)
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

int main() {_
    ll n, k;
    cin >> n >> k;
    ll a[n+1] = {};
    ll dp[n+1] = {};

    for(ll i = 1; i<=n; i++) {
        cin >> a[i];
        dp[i] = INT_MAX;
    }
    dp[1] = 0;
    for(int i = 2; i<=n; i++) {
        for(int j = i-1; j>=max(1LL, i-k); j--) {
            dp[i] = min(dp[i], dp[j] + abs(a[j] - a[i]));
        }
    }
    cout << dp[n];
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
double a,b,c,d,e,f;
int ansm=100,anss=0;
int main(){
	scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f);
	a*=100,b*=100;
	for(double i1=0;i1*a<=f;i1+=1){//a水
		for(double i2=0;i2*b+i1*a<=f;i2+=1){
			for(double i3=0;i3*c+i2*b+i1*a<=f;i3+=1){
				for(double i4=0;i4*d+i3*c+i2*b+i1*a<=f;i4+=1){
					if((i3*c+i4*d)/(i1*a+i2*b+i3*c+i4*d)>=(double)anss/ansm){
						double p=(a*e*i1+b*e*i2)/100;
						if(p<(i3*c+i4*d)) continue;
						anss=(int)i3*c+i4*d;
						ansm=(int)(i1*a+i2*b+i3*c+i4*d);
					}
				}
			}
		}
	}
	cout<<ansm<<' '<<anss;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define dlwlrma ios::sync_with_stdio(0); cin.tie(0);
const int mod = 1e9+7;
int dp[2001];
int main(){
    dlwlrma
    int s;
    cin >> s;
    dp[3]=dp[4]=dp[5]=1;
    for(int i = 6; i <= s; i++)
        dp[i]=(dp[i-1]+dp[i-3])%mod;
    cout << dp[s] << "\n";
}

Measured memory_bytes: 3612
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);


	int n; cin >> n;
	vector<int> x(n);
	rep(i, n){
		cin >> x[i];
	}
	ll ans = LLINF;
	rep(i, 100){
		int num = i + 1;
		ll res = 0;
		rep(i, n){
			res += (x[i] - num) * (x[i] - num);
		}
		chmin(ans, res);

	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N,M;
    cin>>N>>M;
    if(N&1) {
        REP(i,M){
            cout<<i+1<<" "<<N-i<<endl;
        }
    }
    else{
        int state=0;
        REP(i,M){
            if(2*i+1>M) state=1;
            cout<<i+1+state<<" "<<N-i<<endl;
        }
    }
}

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

void zooprint(string s){
    for(int i=0; i<s.size()-1; i++){
        cout << s[i];
    }
    cout << endl;
}

char forward(char a, char b, char c){
    if( b=='S' ){

        if( c=='o' ){
            if( a=='S' ){
                return 'S';
            }else if( a=='W' ){
                return 'W';
            }
        }else if( c=='x' ){
            if( a=='S' ){
                return 'W';
            }else if( a=='W' ){
                return 'S';
            }            
        }
    }else if( b=='W' ){

        if( c=='o' ){
            if( a=='S' ){
                return 'W';
            }else if( a=='W' ){
                return 'S';
            }
        }else if( c=='x' ){
            if( a=='S' ){
                return 'S';
            }else if( a=='W' ){
                return 'W';
            }            
        }
    }
    return 'X';
}

int check( char af, char bf, string s ){
    string animal;
    char a, b, c, x;

    for(int i=1; i<s.size(); i++){
        if(i==1){
            animal += af;
            animal += bf;
        }
        a=animal[i-1];
        b=animal[i];
        c=s[i];
        x=forward(a,b,c);
        if( x=='X' ){
            cout << "forward error" << endl;
            return 2;
        }else{
            animal += x;
        }
    }
    a=animal[s.size()];
    if( a==animal[0] ){
        x=forward( animal[s.size()-1], a, s[0] );
        if( x==animal[1] ){
            zooprint(animal);
            return 1;
        }else{
            return 0;
        }
    }else{
        return 0;
    }
}

int main(){
    int N;
    string s;
    int iflag;
    cin >> N;
    cin >> s;

    iflag=check( 'S', 'S', s );
    if(iflag) return 0;
    iflag=check( 'S', 'W', s );
    if(iflag) return 0;    
    iflag=check( 'W', 'S', s );
    if(iflag) return 0;
    iflag=check( 'W', 'W', s );
    if(iflag) return 0;

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 776
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<cassert>

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define fdo(a,b) for(int o=a-1;o>=b;--o)
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef long long ll;
/////////////////////////////////

int const N = 241;

int n, l[N], ans;

void solve(){
	sort(l, l + n * 2);
	fi(0, n * 2){
		ans += l[i];
		++i;
	}
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d",&n);
	fi(0, n * 2) scanf("%d",&l[i]);

	solve();
	
	printf("%d\n",ans);

	return 0;
}

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

using ll = long long int;
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

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




ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int ans = 0;
int N, M, Q;

template<typename T>
void showall(vector<T> v){
  rep(i, 0, v.size()){
    cout << v[i] << " ";
  }
  cout << endl;
}

template<typename T>
ll com(T n, T m, T mod){
  ll a = 1, b = 1, ans;
  if(n == m || m == 0){
    ans = 1;
  }else{
    for(ll i = 0;i < m; i++){
      a *= n-i;
      a %= mod;
      b *= i+1;
      b %= mod;
    }
    ans = (a * powmod(b, mod-2, mod)) % mod;
  }
  
  return ans;
}


 
int main() {
  rep(i, 0, 5){
    int a;
    cin >> a;
    if(a == 0){
      cout << i+1 << endl;
    }
  }


  
  // cout << setprecision(8) << ans << endl;  // For double
}



Measured memory_bytes: 3624