akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
//int INF = numeric_limits<int>::max() / 2;
using ll = long long;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	map<int, int> mp;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		int temp = 0;
		while(a % 2 == 0 && temp < 2){
			temp++;
			a /= 2;
		}
		mp[temp]++;

	}
	bool result = false;
	if(mp[1] != 0){
		result = mp[2] >= mp[0];
	}else{
		result = mp[2] >= mp[0]-1;
	}
	string ans = "No";
	if(result){
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#define ff(i,x,y)for(int i=x;i<y+1;i++)
#define fs(i,x,y)for(int i=x;i>y-1;i--)
#define all(x) x.begin(),x.end()
#define Ins(x) inserter(x,x.begin())
//set<int>::iterator set_stater
//typedef pair<int,int> pii;
using namespace std;
typedef long long ll;
int n,ans,cnt[220];
typedef struct node
{
    int x,y,col;
};
node mes[220];
int cmp(node a,node b)
{
    return a.x<b.x;
}
int main()
{
    scanf("%d",&n);
    ff(i,1,2*n)
    {
        scanf("%d%d",&mes[i].x,&mes[i].y);
        if(i<=n)
            mes[i].col=1;
        else
            mes[i].col=2;
    }
    sort(mes+1,mes+1+2*n,cmp);
    ff(i,1,2*n)
    {
        if(mes[i].col==1)//red
        cnt[mes[i].y]++;
        else
        {
            fs(j,mes[i].y-1,0)
            {
                if(cnt[j])
                {
                    cnt[j]--;
                    ans++;
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int k, n; cin >> k >> n;
   if (k == 1){
      rep(i,(n+2-1)/2)cout << 1 << " ";
      return 0;
   }
   if (k % 2 == 0){
      cout << (k+2-1)/2 << " ";
      rep(i,n-1)cout << k << " ";
      return 0;
   }
   vector<int> ans(n,(k+2-1)/2);
   int idx = n-1;
   n = n/2;
   while(n--){
      if(ans[idx]==0){
         idx--;
         if (ans[idx]==1){
            ans[idx]--;
            continue;
         }
         idx = ans.size()-1;
         int i = idx;
         while(ans[i]==0){
            ans[i]=k;
            i--;
         }
         ans[i]--;
      }
      else{
         ans[idx]--;
      }
   }
   for (auto &&i : ans){
      if (i == 0)continue;
      cout << i << " ";
   }
   
}


Measured memory_bytes: 4340
#include <iostream>
using namespace std;
int main()
{
	int N;
	int sum=0;
	int d[60];
	cin>>N;
	for(int i =0;i<N;i++)
	{
		cin>>d[i];
	}
	for(int i =0;i<N-1;i++)
	{
		for(int j=i+1;j<N;j++)
		{
			sum+=(d[i]*d[j]);
		}
	}
	cout<<sum;
	return 0;
	
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())
sm=a+b+c
half=sm//2
if sm%2==1:
    print("No")
else:
    if a==half or b==half or c==half or (a+b)==half or (b+c)==half or (c+a)==half:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

typedef tuple<ll, ll, ll> tup3;
vector<vector<tup3>> g;	// node, cost, time
vector<vll> d;	// time, coin
ll cmax;

void dijkstra(ll s) {
	priority_queue<tup3, vector<tup3>, greater<tup3>> q;	// time, node, coin
	q.push(make_tuple(0, 0, min(s, cmax)));
	d[0][min(s, cmax)] = 0;
	while(!q.empty()) {
		ll cur_time, cur_node, coin;
		tie(cur_time, cur_node, coin) = q.top();
		q.pop();
		for(auto i: g[cur_node]) {
			ll nxt_node, cost, taken_time;
			tie(nxt_node, cost, taken_time) = i;
			if(coin < cost) continue;
			ll nxt_coin = min(coin - cost, cmax);
			if(d[nxt_node][nxt_coin] <= cur_time + taken_time) continue;
			q.push(make_tuple(cur_time + taken_time, nxt_node, nxt_coin));
			d[nxt_node][nxt_coin] = cur_time + taken_time;
		}
	}
}

int main() {
//	cout << fixed << setprecision(15);
	ll n, m, s;
	cin >> n >> m >> s;

	g = vector<vector<tup3>>(n);
	ll amax = 0;
	rep(i, m) {
		ll u, v, a, b;
		cin >> u >> v >> a >> b;
		u--, v--;
		g[u].push_back(make_tuple(v, a, b));
		g[v].push_back(make_tuple(u, a, b));
		chmax(amax, a);
	}
	rep(i, n) {
		ll c, d;
		cin >> c >> d;
		g[i].push_back(make_tuple(i, -c, d));
	}

	cmax = amax * (n - 1);
	d = vector<vll>(n, vll(cmax + 1, INFL));
	dijkstra(s);
	rep1(i, n - 1) {
		ll ans = INFL;
		rep(j, cmax + 1) chmin(ans, d[i][j]);
		cout << ans << endl;
	}
}


Measured memory_bytes: 7248
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

int main()
{
    string s, t;
    cin >> s >> t;
    
    rep(i, 0, s.size())
        if (s[i] != t[i])
        {
            cout << "No" << endl;
            return 0;
        }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 3628
n=int(input())
if n<10:
    print("Yes")
else:
    k=0
    for i in range(9,0,-1):
        if n%i==0:
            n=n//i
            if n>9:
                k+=1
                break
    if(k==0):
        print("Yes")
    else:
        print("No")



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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,m;
  cin >> n >> m;
  vl a(n);
  REP(i,n) cin >> a[i];
  vector<pll> bc(m);
  REP(i,m){
    ll b,c;
    cin >> b >> c;
    bc[i] = make_pair(b,c);
  }
  sort(a.begin(),a.end());
  sort(bc.begin(),bc.end(),[](pll a, pll b){return a.second>b.second;});
  ll ans = 0;
  ll cur = 0;
  REP(i,m){
    REP(j,bc[i].first){
      if(cur>n-1) break;
      ans += max(a[cur],bc[i].second);
      cur++;
    }
    if(cur>n-1) break;
  }
  while(cur<n){
    ans += a[cur++];
  }
  cout << ans<< endl;
  return 0;
}


Measured memory_bytes: 2560
// 2011/01/31 Tazoe

#include <iostream>
using namespace std;

void eratos(bool prime[], int n)
{
	if(n>=1)
		prime[0] = false;
	if(n>=2)
		prime[1] = false;

	for(int i=2; i<n; i++)
		prime[i] = true;

	for(int i=2; i<n; i++){
		if(!prime[i])
			continue;
		for(int j=i+i; j<n; j+=i)
			prime[j] = false;
		if(n<i*i)
			return;
	}
}

int main()
{
	bool prime[10001];
	eratos(prime, 10001);

	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		for(int i=n; i>=5; i--)
			if(prime[i]&&prime[i-2]){
				cout << i-2 << ' ' << i << endl;
				break;
			}
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int a,b,k;
	cin>>a>>b>>k;
	loop(i,a,a+k){
		if(b<i)break;
		cout<<i<<endl;
	}
	loop(i,b-k+1,b+1){
		if(i<a+k)continue;
		cout<<i<<endl;
	}
	return 0;
}

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


#define int long long 

const int N = 2e5 + 7, inf = 1e18;

int a[N], f[20][100][10];

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, ans = 0; cin >> n;
	for(int i = 1; i <= n; i++) { 
		string str; cin >> str;

		int y = 0, flag = 0, cnt = 0;

		for(auto ch: str) {
			if(ch == '.') {
				flag = 1;
				continue;
			}
			cnt += flag;
			y = y * 10 + (ch - '0');

		}
		for(int j = cnt + 1; j <= 9; j++) {
			y *= 10;
		}
		
		int c10 = 0, c2 = 0, c5 = 0;

		while(y % 10 == 0) {
			++c10;
			y /= 10;
		}
		
		while(y % 2 == 0) {
			++c2;
			y /= 2;
		}
		while(y % 5 == 0) {
			++c5;
			y /= 5;
		}
		if(!c2) {
			for(int j = 0; j <= 20; j++) {
				int need = max(18 - j - c10, 0LL);
				if(need > c5) continue;
				ans += f[j][need][2];
			}
		} else {
			for(int j = 0; j <= 20; j++) {
				int need = max(18 - j - c10, 0LL);
				if(need > c2) continue;
				ans += f[j][need][5];
			}
		}
		for(int j = c5; j >= 0; j--) {
			f[c10][j][5]++;
		}
		for(int j = c2; j >= 0; j--) {
			f[c10][j][2]++;
		}
		
		
	}
	cout << ans << endl;
}

Measured memory_bytes: 3716
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = 998244353ll;

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[410410],s[410410];
int l[15],r[15];

int main(void){
	int n,m,i,j;
	ll tmp;
	std::cin >> n >> m;
	for(j=0; j<m; ++j){
		std::cin >> l[j] >> r[j];
		++r[j];
	}
	dp[n+1] = 1ll; s[n+1] = 1ll;
	for(i=1; i<n; ++i){
		for(j=0; j<m; ++j){
			tmp = s[n+i+1-l[j]];
			add_mod(tmp,MOD-s[n+i+1-r[j]]);
			add_mod(dp[n+i+1],tmp);
		}
		s[n+i+1] = s[n+i];
		add_mod(s[n+i+1],dp[n+i+1]);
	}
	std::cout << dp[2*n] << std::endl;
	return 0;
}


Measured memory_bytes: 6740
object Main {
  case class Line(string: String) {
    def strings: Seq[String] = string.split(' ')
    def ints: Seq[Int] = strings.map(_.toInt)
    def i(n: Int): Int = ints(n)
  }

  def readLine: Line = Line(io.StdIn.readLine())
  def readLines(n: Int): Seq[Line] = List.fill(n)(Line(io.StdIn.readLine()))

  def yesNo(b: Boolean): String = if (b) "Yes" else "No"

  def main(args: Array[String]) {
    val Seq(a, b, c) = readLine.ints
    println(yesNo(a < b && c > b))
  }
}

Measured memory_bytes: 43896
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

struct dice{
  int ue,shita,temae,migi,hidari,oku;
  
  void rollN(){
    int tmp;
    tmp=ue;
    ue=temae;
    temae=shita;
    shita=oku;
    oku=tmp;
  }
  void rollE(){
    int tmp;
    tmp=ue;
    ue=hidari;
    hidari=shita;
    shita=migi;
    migi=tmp;
  }
  void rollW(){
    int tmp;
    tmp=ue;
    ue=migi;
    migi=shita;
    shita=hidari;
    hidari=tmp;
  }
  void rollS(){
    int tmp;
    tmp=ue;
    ue=oku;
    oku=shita;
    shita=temae;
    temae=tmp;
  }
  bool operator==(const dice& x) const{
    return (x.shita==shita&&x.temae==temae&&
    x.ue==ue&&x.hidari==hidari&&x.migi==migi&&x.oku==oku);
  }
};


int main(){
  dice d;
  cin>>d.ue>>d.temae>>d.migi>>d.hidari>>d.oku>>d.shita;
  dice s;
  cin>>s.ue>>s.temae>>s.migi>>s.hidari>>s.oku>>s.shita;
  bool ans=(s==d);
  //めっちゃまわせばいいや
  //全パターン試すのどんだけ回せばええねん。
  int YATTETRY=100;
  rep(i,YATTETRY){
    rep(j,i){
      rep(k,i){
        s.rollE();
        ans=(ans||s==d);
      }
      s.rollN();
      ans=(ans||s==d);
    }
    s.rollE();
    ans=(ans||s==d);
  }
  cout<<(ans?"Yes":"No")<<endl;
  return 0;
}



Measured memory_bytes: 3100
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.flush();
  	int x,a,b;
    cin >> x >> a >> b;
  	cout<<(x-a)%b<<endl;
	return 0;
	// BYE BYE 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
//struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;


void solve(long long N, std::vector<long long> x, std::vector<long long> y){
	double res = 0;
	vector<ll> R(N);
	REP(i, N) R[i] = i;
	ll i = 0;
	ll c = 0;
	do {
		REP(n, N-1) {
			ll from = R[n];
			ll to = R[n+1];
			ll xi = x[from];
			ll xj = x[to];
			ll yi = y[from];
			ll yj = y[to];
			double dist = sqrt(pow(xi-xj,2) + pow(yi-yj,2));
			res += dist;
			c++;
		}
		i++;
	}while (next_permutation(ALL(R)));
	res /= i;
	PRINTD(res, 10);
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int a,b;
    cin >> a >> b;
    if(a+b >=10){
        cout << "error" << endl;
    }
    else{
        cout << a+b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, h, n, a;
  scanf("%lld%lld", &h, &n);
  for(i = 0; i < n; ++i) scanf("%lld", &a), h -= a;
  printf("%s", h > 0 ? "No" : "Yes");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long MOD = 1000000007;

vector<int> places[210000];
long long dp[210000];
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
    // 入力
    int N; cin >> N;
    vector<int> c(N);
    for (int i = 0; i < N; ++i) cin >> c[i];

    // places[i] := (c[j] = i となるような j の集まり)
    for (int i = 0; i < 210000; ++i) places[i].clear();
    for (int i = 0; i < N; ++i) places[c[i]].push_back(i);

    // DP
    dp[0] = 1;
    for (int i = 1; i <= N; ++i) {
        // 特に操作しない場合
        add(dp[i], dp[i-1]);

        // 操作する場合
        int color = c[i-1];
        int it = lower_bound(places[color].begin(), places[color].end(), i-1)
            - places[color].begin(); // c[i] が color 色の何番目の要素か
        if (it > 0) {
            int j = places[color][it - 1]; // c[j] = c[i] となる j
            if ((i-1) - j > 1) add(dp[i], dp[j+1]);
        }
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 13824
use std::io;


fn main() {
    let q = read_one::<usize>();
    let mut vec = Vec::new();
    for _ in 0..q {
        let s = read::<isize>();
        match s[0] {
            0 => { vec.push(s[1]); },
            1 => { println!("{}", vec[s[1] as usize]); },
            _   => { vec.pop(); },
        }
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


Measured memory_bytes: 7080
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}

Int h, w;
vector<vector<Int> > mp;

Int calc(Int y,Int x, Int n,Int m){
  if(y + n - 1 >= h || x + m - 1 >= w) return -INF;

  Int height = INF;
  for(int i=0;i<n;i++) Min(height, mp[y + i][x]);
  for(int i=0;i<n;i++) Min(height, mp[y + i][x + m - 1]);
  for(int i=0;i<m;i++) Min(height, mp[y][x + i]);
  for(int i=0;i<m;i++) Min(height, mp[y + n - 1][x + i]);

  Int sum = 0;
  for(int i=0;i<n-2;i++)
    for(int j=0;j<m-2;j++){
      int num = mp[y + 1 + i][x + 1 + j];
      if(num >= height) return -INF;
      sum += (height - num);
    }
  return sum;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(1){
    cin>>h>>w;
    if(h == 0 && w == 0) break;
    mp.clear();
    mp.resize(h, vector<Int>(w));
    
    cin>>mp;
    Int ans = 0;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	for(int n=3;n<=h;n++)
	  for(int m=3;m<=w;m++) Max(ans, calc(i, j, n, m));

    cout<<ans<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3196
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n, d1[N], dn[N];

vector<int> g[N];


void dfs(int u, int pre,int* d ){
    
    for(auto i: g[u]){
        if (i==pre)continue;
        d[i] = d[u] + 1;
        dfs(i, u, d);
    }
}

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    
    int a,b;
    for (int i = 1; i <= n-1; i++){
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    
    dfs(1, -1, d1);
    dfs(n, -1, dn);
    
    int ans = 0;
    for (int i = 2; i <= n-1; i++){
        if(d1[i]<= dn[i])ans++;
        else ans --;
    }
    
    if(ans >0) cout<<"Fennec"<<endl;
    else cout<<"Snuke"<<endl;
    
    
    
    
    
    return 0;
}



Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0, left, right;
    vector<int> V(3);
    char tmp, tmp2;
    string S, S2;
    bool flag=true;
    
    cin >> A >> B;
    // ans = 24 + (24-A);
    S = A*B%2==0 ? "Even" : "Odd";
    cout << S << endl;

    // if(left <right )
    // 	cout << "Right" <<endl;
    // else if(left > right)
    // 	cout << "Left" <<endl;
    // else
    // 	cout << "Balanced" <<endl;


    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B==C || B+C==A || C+A==B)
    // 	puts("Yes");
    // else
    // 	puts("No");
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from bisect import bisect_left
from itertools import accumulate

n = int(readline())
a = sorted(list(map(int, readline().split())))
b = sorted(list(map(int, readline().split())))
c = sorted(list(map(int, readline().split())))
check = [0] * n
ans = 0
for i in range(n):
    index = bisect_left(c, b[i])
    if index != n:
        if c[index] == b[i]:
            index = bisect_left(c, b[i] + 1)
    check[i] = n - index
cumsum = [0] + list(accumulate(check[::-1]))
for aa in a:
    index = bisect_left(b, aa)
    if index != n:
        if b[index] == aa:
            index = bisect_left(b, aa + 1)
    ans += cumsum[n - index]
print(ans)


Measured memory_bytes: 25716
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


#define INF 1000000000000
signed main()
 {
   int n,m,x;
   cin>>n>>m>>x;
   vector<vector<int>>a(n,vector<int>(m));
   vector<int>cost(n);
   for(int i=0;i<n;i++){
     cin>>cost[i];
     for(int j=0;j<m;j++){
       cin>>a[i][j];
     }
   }
int ans=-1;
   for(int bit=0; bit<(1<<n); bit++){
     vector<int>r(m);
     int tmp=0;
     for(int i=0;i<n;i++){
       if(bit&(1<<i)){
         tmp+=cost[i];
         rep(j,m){
           r[j]+=a[i][j];
         }
       }
     }

     int b=1;
     rep(i,m){
       if(r[i]<x){b*=0;}
       else b*=1;
     }
     if(b){
       if(ans==-1){ans=tmp;}
       else ans=min(ans,tmp);
     }
   }
   cout<<ans;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>//小数点以下表示
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n;
    cin>>n;
    cout<<(n+1)/2<<endl;
}

Measured memory_bytes: 764
#include<cstdio>
#include<set>
using namespace std;
int main(){
	set<int> ss1;
	set<int> ss2;
int x,n,t1=0,t2=0;
  scanf("%d%d",&x,&n);
for(int i=1;i<=n;i++)
  {   int y,z;
     scanf("%d%d",&y,&z);
       if(y==1)
       {ss1.insert(z);
         if(ss2.count(z))
           {
	    		printf("POSSIBLE\n");
	  			return 0;
			}
 	   }
  		 if(z==x)
   			{ss2.insert(y);
  				 if(ss1.count(y))
 					 {
    				 printf("POSSIBLE\n");
    				 return 0;
 					}
  			 }

  }
  
  printf("IMPOSSIBLE\n");

  return 0;
  
	
}

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

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n , res =0 ; 
	cin>>n ;
	int a[n] ; 
	for(int i =0; i<n ;i++){
		cin>>a[i];
		
		}

	for(int i =0 ; i<n ;i++){
		if (i>=1&& i<n-1){
			if((a[i]<a[i+1]&& a[i]>a[i-1]) ||(a[i]>a[i+1]&& a[i]<a[i-1]) ){
				res++;
			}}

	}
	cout<<res<<endl;

	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include<string>
#include <algorithm>
#include <functional>
#include <cmath>
using namespace std;
typedef vector <int> ivector;

void save(ivector &a, int n){
	int ceil = sqrt(n);
	
	a.push_back(2);
	for (int i = 3; i < n; i++){
		bool frag = false;
		for (int j = 0; j < a.size(); j++){
			int now = a[j];
			if (i%now == 0){
				frag = true;
				break;
			}
		}
		if (!frag){
			a.push_back(i);
		}
	}

}
bool isPrime(int num,ivector &prime){
	int max = sqrt(num);
	for (int i = 0; i < prime.size(); i++){
		int p = prime[i];
		if (max < p)break;
		if (num%p == 0){
			return false;
		}
	}
	return true;
}
int main(){
	
	ivector prime;
	save(prime, 10000);
	int N;
	cin >> N;
	int count = 0;
	for (int i = 0; i < N; i++){
		int num;
		scanf("%d", &num);
		if (isPrime(num, prime)){
			count++;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 1276
n,k=[int(i) for i in input().split()]
v=[int(i) for i in input().split()]
res=0
for right in range(k+1):
    for left in range(min(n,k)-right+1):
        ans=[]
        ans+=v[:right]
        ans+=v[n-left:]
        ans.sort()
        for i in range(min(k-right-left,len(ans))+1):
            res=max(res,sum(ans[i:]))
print(res)

Measured memory_bytes: 42076
#include<queue>
#include<iostream>
#include<string.h>
using namespace std;

int dx[8] = {-1,1,0,0,1,-1,1,-1};
int dy[8] = {0,0,-1,1,1,-1,-1,1};
int score[1010][1010];
queue< pair<int,int> > que;
int h,w;
void bfs(){
while(que.empty() != true){
pair<int,int>temp = que.front();que.pop();
for(int i=0;i<4;i++){
int ny = temp.first + dy[i];
int nx = temp.second + dx[i];
if(nx <= 0 || w +1 <= nx || ny <= 0 || h+1 <= ny)continue;
else if(score[ny][nx] != -1)continue;
else{
score[ny][nx] = score[temp.first][temp.second] +1;
que.push(make_pair(ny,nx));
}
}
}
}

int main(){
cin >> h >>w;
memset(score,-1,sizeof(score));
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++){
    char temp;
    cin >> temp;
if(temp == '#'){
    score[i][j] = 0;
    que.push(make_pair(i,j));
}
}
bfs();
int ans =-1;
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
ans = max(ans,score[i][j]);
//cout << score[i][j] << "  ";
}
//cout << endl;
}
cout << ans <<endl;
return 0;
}

Measured memory_bytes: 12432
#include <iostream>
#include <math.h>

using namespace std;

int main() {
	int n, num, ans = 0;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> num;
		int j = 2;
		if (num == 2 || num == 3) ans++;
		else {
			while (j <= (int)sqrt(num)) {
				
				if ((num % j) == 0) break;
				if (j == (int)sqrt(num)) ans++;
				
				j++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
    ll K;
    ll L;
    cin >> K;
    if(0 == K%2 || 0 == K%5){
        cout << -1 << endl;
        return 0;
    }
    if(0 == K%7){
        L = 9*K/7;
    }else{
        L = 9*K;
    }
    ll x = 10;
    ll cnt = 1;
    while(1 != x%L){
        x %= L;
        x *= 10;
        cnt++;
    }
    cout << cnt << endl;
}

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

long H ;
long A[500001];

long l(long i) {
    return i * 2;
}

long r(long i) {
    return i * 2 + 1;
}

long p(long i) {
    return i/2;
}

void maxify(long i) {
    long mi = i;
    if (l(i) <= H && A[l(i)] > A[i]) {
        mi = l(i);
    }
    if (r(i) <= H && A[r(i)] > A[mi]) {
        mi = r(i);
    }
    if (mi != i) {
        swap(A[i], A[mi]);
        maxify(mi);
    }
}

int main() {
    cin >> H;
    for (long i = 1; i <= H; ++i) {
        cin >> A[i];
    }

    for (long j = H; j >= 1 ; --j) {
        maxify(j);
    }

    for (long k = 0; k < H; ++k) {
        cout << " " << A[k + 1];

    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 6872
#include <iostream>

using namespace std;

int main(void) {
	int A, B, T;
	cin >> A >> B >> T;
	int sum = 0;
	for (int i = 1; ; ++i) {
		if (i * A >= T + 0.5) break;
		sum += B;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
ll M = 1e9 + 7;
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} }


int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	int s,w; cin>>s>>w;
	if(s<=w) cout<<"unsafe";
	else cout<<"safe";
	return 0;
}


Measured memory_bytes: 3640
import itertools

n, m = [int(_) for _ in input().split()]
a = []
b = []
for i in range(0, m):
    ai, bi = [int(_) for _ in input().split()]
    a.append(ai)
    b.append(bi)

first = [b[i] for i in range(0, m) if a[i] == 1]
second = [a[i] for i in range(0, m) if b[i] == n]

if set(first) & set(second):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 28116
#include<iostream>
using namespace std;
int main(){
    int n=1,A=0,B=0;
    while(n!=0){
        cin>>n;
        if(n==0){break;}
        for(int i=0;i<n;i++){
            int ap=0,bp=0;
            cin>>ap;
            cin>>bp;
            if(ap<bp){
                B=B+ap+bp;
            }
            if(ap>bp){
                A=A+ap+bp;
            }
            if(ap==bp){
                A=A+ap;
                B=B+bp;
            }
        }
        cout<<A<<" "<<B<<endl;
        A=0;B=0;
    }
    return 0;
}

Measured memory_bytes: 2964
#include<stdio.h>
#include<math.h>

struct Point { double x, y; };

void koch(int n, Point a, Point b){
	if(n==0) return;
	
	Point s,t,u;
	double th = M_PI * 60.0 / 180.0; //度からラジアンへ単位を変換
	
	s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
	s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
	t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
	t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
	
	koch( n-1, a, s);
	printf("%.8f %.8f\n", s.x, s.y);
	koch( n-1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	koch( n-1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	koch( n-1, t, b);
}

int main(){
	Point a, b;
	int n;
	
	scanf("%d",&n);
	
	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;
	
	printf("%.8f %.8f\n",a.x, a.y);
	koch(n, a, b);
	printf("%.8f %.8f\n",b.x, b.y);
	
	return 0;
}


Measured memory_bytes: 2620
#include<iostream>

int main(){
    int_fast16_t a,b,c,x,count;
    count = 0;
    std::cin >> a >> b >> c >> x;
    for (size_t i = 0; i <= a; i++)
    {
        for (size_t j = 0; j <= b; j++)
        {
            for (size_t k = 0; k <= c; k++)
            {
                if(x == 500*i + 100*j + 50*k)
                {
                    count++;
                }
            }
            
        }
        
    }
     std::cout << count << std::endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
	static void Main(string[] args)
    {
		var input = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
		var _N = input[0];
		var _K = input[1];
		var _AList = Console.ReadLine().Split().Select(x => long.Parse(x)).OrderByDescending(x => x).ToArray();

		COMinit();
		var maxSum = new MInt(0);
		var minSum = new MInt(0);
		for (var i = 1; i <= _N; i++)
		{
			maxSum += (new MInt(COM(_N - i, _K - 1)) * new MInt(_AList[i - 1]));
			minSum += (new MInt(COM(_N - i, _K - 1)) * new MInt(_AList[_N - i]));
		}
		Console.WriteLine((maxSum - minSum).V);

#if DEBUG
		Console.ReadKey();
#endif
    }

	private const long MAX = 510000;
	private const long MOD = 1000000007;
	private static long[] fac = new long[MAX];
	private static long[] finv = new long[MAX];
	private static long[] inv = new long[MAX];

	static void COMinit()
	{
		fac[0] = fac[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		for (int i = 2; i < MAX; i++)
		{
			fac[i] = fac[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}
	static long COM(long n, long k)
	{
		if (n < k) return 0;
		if (n < 0 || k < 0) return 0;
		return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}

	struct MInt
	{
		const int M = 1000000007;
		public long V;
		public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }

		public static implicit operator MInt(long v) => new MInt(v);
		public static MInt operator +(MInt x) => x;
		public static MInt operator -(MInt x) => -x.V;
		public static MInt operator +(MInt x, MInt y) => x.V + y.V;
		public static MInt operator -(MInt x, MInt y) => x.V - y.V;
		public static MInt operator *(MInt x, MInt y) => x.V * y.V;
		public static MInt operator /(MInt x, MInt y) => x * y.Inv();

		public MInt Pow(int i) => MPow(V, i);
		public MInt Inv() => MPow(V, M - 2);

		static long MPow(long b, int i)
		{
			for (var r = 1L; ; b = b * b % M)
			{
				if (i % 2 > 0) r = r * b % M;
				if ((i /= 2) < 1) return r;
			}
		}
	}
}



Measured memory_bytes: 46084
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n, c, a[30], b[31];
  while(cin >> n >> c, n){
    for(int i = 0; i < n; i++){
      a[i] = 0;
      for(int j = 0; j < 16; j++){
        int aa;
        cin >> aa;
        if(aa) a[i] |= 1 << j;
      }
    }
    for(int i = 0; i < c; i++){
      b[i] = 0;
      for(int j = 0; j < 16; j++){
        int bb;
        cin >> bb;
        if(bb) b[i] |= 1 << j;
      }
    }
    b[c] = 0;
    c++;
     
 
    int dp[31][1 << 16];
    fill_n( *dp, 31 * (1 << 16), -1);
    dp[0][0] = 0;
    for(int i = 0; i < n; i++){ //今押している所
      for(int j = 0; j < 1 << 16; j++){ //前のbitの状態
        if(dp[i][j] == -1) continue;
        for(int k = 0; k < c; k++){
          int bits = (a[i]|j)&~b[k];
          dp[i + 1][bits] = max( dp[i + 1][bits], dp[i][j] + __builtin_popcount((a[i]|j) & b[k]));
        }
      }
    }
    cout << *max_element(dp[0], dp[0] + 31 * (1 << 16)) << endl;
  }
}

Measured memory_bytes: 9100
// 5_abc129_e
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

string l;
int n;
vector<ll> powmod;

ll dfs(int itr){
    if(itr == n - 1){
        if(l[itr] == '1') return 3;
        else return 1;
    }

    if(l[itr] == '1'){
        return (2 * dfs(itr + 1) + powmod[n - itr - 1]) % MOD;
    }else{
        return dfs(itr + 1) % MOD;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> l;
    n = l.length();
    if(n == 1){
        cout << 3 << endl;
        return 0;
    }
    powmod.resize(n + 1);
    powmod[0] = 1;
    for(int i = 1; i <= n; i++){
        powmod[i] = 3 * powmod[i - 1] % MOD;
    }

    ll ans = powmod[n - 1];

    ll ans2 = 2 * dfs(1);

    cout << (ans + ans2) % MOD << endl;

    return 0;
}


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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define make0(a) memset(a,0,sizeof(a))
#define make1(a) memset(a,-1,sizeof(a))
#define ALL(v) v.begin(),v.end()
#define pi pair <int,int>
#define pll pair <ll,ll>
#define fast_cin() ios_base::sync_with_stdio(0)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int mod = 1e9+7;



int main()
{
	string s;
	cin >> s;
	cout << s.substr(0, s.size() - 8) << endl;
	return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  ll n;
  cin >> n;
  ll ans = INFL;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ans = min(ans, i + n / i - 2);
    }
  }
  cout << ans << endl;
}


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

#define INF 1LL << 60;
typedef long long ll;

int N, K;
int h[100005];
ll dp[100005];

ll solve() {
    for (int i = 0; i <= N; i++) dp[i] = INF;
    dp[0] = dp[1] = 0;
    for (int i = 2; i <= N; i++) {
        for (int k = 1; k <= K; k++) {
            if (i - k > 0) {
                dp[i] = min(dp[i], dp[i-k] + abs(h[i] - h[i-k]));
            }
        }
    }
    return dp[N];
}

int main() {
    cin >> N >> K;
    for (int i = 1; i <= N; i++) {
        cin >> h[i];
    }
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 1408
# include <stdio.h>

int max(int a,int b,int c){
  int m=a;
  if(m<b) m=b;
  if(m<c) m=c;
  return m;
}
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  printf("%d\n",a+b+c-max(a,b,c));
  return 0;
}


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

int main()
{
  int n = 0;
  int operands[200];
  char s[100];

  while( scanf("%s", s) != EOF )
    {
      if ( s[0] == '+' ){
	n--;
	operands[n] = operands[n] + operands[n + 1];
      } 
      else if ( s[0] == '-' ){
	n--;
	operands[n] = operands[n] - operands[n + 1];
      } 
      else if ( s[0] == '*' ){
	n--;
	operands[n] = operands[n] * operands[n + 1];
      } 
      else {
	n++;
	operands[n] = atoi(s);
      }
    }
  printf("%d\n", operands[n]);
  
  return 0;
}

Measured memory_bytes: 548
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
string S[101010];
vector<string> v = { "AC", "WA", "TLE", "RE" };
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> S[i];

	map<string, int> C;
	rep(i, 0, N) C[S[i]]++;

	fore(x, v) printf("%s x %d\n", x.c_str(), C[x]);
}







Measured memory_bytes: 6908
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

vector<int> gph[2005];
int n, k, l[2005], r[2005];

void dfs(int x, int p, int d, int *c){
	c[d]++;
	for(auto &i : gph[x]){
		if(i != p) dfs(i, x, d+1, c);
	}
}
int main(){
	cin >> n >> k;
	for(int i=0; i<n-1; i++){
		int s, e;
		cin >> s >> e;
		gph[s].push_back(e);
		gph[e].push_back(s);
	}
	int ret = 0;
	for(int i=1; i<=n; i++){
		if(k % 2 == 0){
			memset(l, 0, sizeof(l));
			dfs(i, -1, 0, l);
			for(int i=1; i<=n; i++) l[i] += l[i-1], r[i] += r[i-1];
			ret = max(ret, l[k/2]);
		}
		for(auto &j : gph[i]){
			if(k % 2 == 1 && i < j){
				memset(l, 0, sizeof(l));
				memset(r, 0, sizeof(r));
				dfs(i, j, 0, l);
				dfs(j, i, 0, r);
				for(int i=1; i<=n; i++) l[i] += l[i-1], r[i] += r[i-1];
				ret = max(ret, l[k/2] + r[k/2]);
			}
		}
	}
	cout << n-ret << endl;
}


Measured memory_bytes: 512
n,m=map(int,input().split())
a=set(int(input()) for i in range(m))
mod=10**9+7
dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
    dp[1]=1

for i in range(2,n+1):
    if i not in a:
        dp[i]+=(dp[i-2]+dp[i-1])%mod
print(dp[-1])

    

Measured memory_bytes: 11884
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    string s;
    cin >> s;
    int count=0;
   
    for(int i=0;i<4;i++){
        for(int j=i+1;j<4;j++){
            if(s[i]==s[j]){
                count++;
            }
        }
    }
    if(count==2){
        cout << "Yes" <<endl;
    }else{
        cout <<"No"<<endl;
    }
}

Measured memory_bytes: 256
import sys
from functools import lru_cache

sys.setrecursionlimit(10**6)


def main():
    T = int(input())
    TESTCASEs = [list(map(int, input().split())) for _ in range(T)]


    def calc_cost(N, A, B, C, D):


        @lru_cache(maxsize=None)
        def calc(N):
            if N == 0:
                return 0
            if N == 1:
                return D

            cost = N * D
            
            for T, Tcost in ((2, A), (3, B), (5, C)):
                div, mod = divmod(N, T)

                cost = min(cost, calc(div) + Tcost + mod * D)
                if mod:
                    cost = min(cost, calc(div + 1) + Tcost + (T - mod) * D)

            return cost


        return calc(N)


    for TESTCASE in TESTCASEs:
        total_cost = calc_cost(*TESTCASE)
        print(total_cost)


if __name__ == '__main__':
    main()

sys.exit()


Measured memory_bytes: 20652
#include<iostream>
using namespace std;
bool f(int n){
  while(n>0){
    if(n%10==7) return true;
    n/=10;
  }
  return false;
}
int main(){
  int n;
  cin>>n;
  if(f(n)) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

// 取るだけ取った後戻せばいい
// 右から幾つ取るか、左から幾つ取るか、幾つ戻すかを全探索する
int n,k;

ll search(int t, const vector<ll> &a) {
    // 右から取るのがi回, 左から取るのがj回, 戻すのがc = (t-(i+j))回
    ll ret = 0;
    for (int i = 0; i <= min(t,n); ++i) {
        for (int j = 0; i+j <= min(t,n); ++j) {
            for (int c = 0; c <= min(t-(i+j),i+j); ++c) {
                vector<ll> b;
                for (int l = n-i; l < n; ++l) b.push_back(a[l]);
                for (int l = 0; l < j; ++l) b.push_back(a[l]);
                sort(b.begin(), b.end());
                chmax(ret, accumulate(b.begin()+c, b.end(), 0ll));
                // printf("t = %d, i = %d, j = %d, c = %d, accum = %lld\n",t,i,j,c,accumulate(b.begin()+c, b.end(), 0ll));
            }
        }
    }

    return ret;
}

int main(int argc, char const *argv[]) {
    cin>>n>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    ll ans = search(k,a);
    
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

vi32 prime_list(i32 n) {
  vi32 primes;
  vector<bool> f(n, true);
  f[0] = f[1] = false;
  repi(i, 2, n) {
    if (!f[i]) continue;
    primes.push_back(i);
    for (int j = i * 2; j < n; j += i) {
      f[j] = false;
    }
  }
  return primes;
}

void solve() {
  auto list = prime_list(1000000);
  while (true) {
    int n; cin >> n;
    if (n == 0) return;
    i64 sum = 0;
    rep(i, n) sum += list[i];
    cout << sum << '\n';
  }
}



Measured memory_bytes: 3484
import java.util.Scanner;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner momoko = new Scanner(System.in);

        int[] shuzu = new int[3];

        for (int i = 0; i < 3; i++) {
            shuzu[i] = momoko.nextInt();
        }
        Arrays.sort(shuzu);
        System.out.println(shuzu[0] + " " + shuzu[1] + " " + shuzu[2]);
    }
}


Measured memory_bytes: 26208