akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	for (int i = 1; i <= 9; i++)
	{
		for (int j = 1; j <= 9; j++)
		{
			printf("%dx%d=%d\n",i,j,i*j);
		}
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector <long long> A(N);
  long long mul = 1;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    if (A[i] == 0LL) {
    	cout << 0 << endl;
    	return 0;
    }
  }
  for (int i = 0; i < N; ++i) {
    if (mul > 1000'000'000'000'000'000LL / A[i]) {
    	cout << -1 << endl;
    	return 0;
    }
    mul *= A[i];
  }
  cout << mul << endl;
  return 0;
}
  


Measured memory_bytes: 3676
/*input
1817181712114
*/
/*input
2624726247
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    ll q[2][2019];
    rep(i, 2019) q[0][i] = 0;

    int r[2019];
    rep(i, 2019) r[i] = (i*10)%2019;

    string s;
    cin >> s;
    int len = s.length();
    ll ans = 0;
    // int start = s[0]-'0';
    // q[0][start] = 1;
    //cout << q[0][1] << endl;
    rep(i, len) {
        int before = i%2;
        int next = (i+1)%2;
        rep(k, 2019) q[next][k] = 0;

        int a = s[i]-'0';
        rep(j, 2019) {
            q[next][(r[j]+a)%2019] += q[before][j]; 
        }
        q[next][a] += 1;
        ans += q[next][0];
        // cout << ans << " " << q[next][1] << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;

int n;
int a[N];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    int ans = 0;
    for (int i = 2; i < n; ++i)
    {
        if (a[i] != min(a[i], min(a[i - 1], a[i + 1])) && a[i] != max(a[i], max(a[i - 1], a[i + 1])))
            ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;

const ll mod=1e9+7;
const int maxn=2e5+5;

pair<int,int> b[maxn];
int a[maxn];

int main(){
	int n;
	scanf("%d",&n);
	b[1].first=0x3f3f3f3f;b[n].second=0x3f3f3f3f;
	for(int i=1;i<=n-1;i++){
		scanf("%d",a+i);
		b[i].second=a[i];
		b[i+1].first=a[i];
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=min(b[i].first,b[i].second);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n;
    cin >> n;
    int a[n];
    map<int, int> mp;
    ll ans = 0;
    rep (i, 0, n) {
        cin >> a[i];
        mp[a[i]]++;
        ans += a[i];
    }
    int q;
    cin >> q;
    rep (i, 0, q) {
        int b, c;
        cin >> b >> c;
        int cnt = mp[b];
        mp[b] -= cnt;
        mp[c] += cnt;
        ans = ans + (c - b) * cnt;
        cout << ans << "\n";
    }
}


Measured memory_bytes: 8408
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/


// 2^20 = 10^6
ll N;
vector<int> A;

int main(){
    cin >> N;
    A.resize(N);
    rep(i,N){
        cin >> A[i];
        //cout << static_cast<bitset<20>>(A[i]) << endl;
    }


    vector<int> bits[21];
    rep(i,21){
        bits[i].assign(N+1,0);
        rep(j,N){
            if((1<<i) & A[j]){
                bits[i][j] = 1;
            }else{
                bits[i][j] = 0;
            }
        }
    }

    vector<int> sumbits[21];
    rep(i,21){
        sumbits[i].assign(N+1,0);
        rep(j,N){
            sumbits[i][j+1] = sumbits[i][j] + bits[i][j];
        }
    }

    ll ans = 0;
    rep(i,N){
        //cerr << "i = " << i << endl;
        bool f=true;
        rep(j,20){
            if(sumbits[j][i+1]>=2){
                f=false;
                break;
            }
        }
        if(f){
            ans += (i+1);
            continue;
        }
        int l,r;
        l = 0;
        r = i;
        while(r-l>1){
            int m = (l+r)/2;

            bool ok = true;
            rep(j,20){
                int t = sumbits[j][i+1] - sumbits[j][m];
                if(t>=2){
                    ok = false;
                    break;
                }
            }

            if(ok){
                r = m;
            }else{
                l = m;
            }
        }
        //cerr << "l,r " << l << " " << r << endl;
        //cerr << "add " << i-l << endl;
        ans += i-l;
    }
    cout << ans << endl;
}


Measured memory_bytes: 35968
/* SANDEEP YADAV*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define lld long double
#define umap unordered_map<>
#define sz(x) ((ll)((x).size()))
#define all(x) (x).begin(),(x).end()
#define vi vector<int>
#define pi pair<int, int>
#define setp cout<<fixed<<setprecision(6)
#define loop(i,a,b)  for(int i=a;i<b;i++)
#define rloop(i,b,a) for(int i=b-1;i>=a;i--)
#define vl vector<ll>
#define pl pair<ll, ll>
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll gcd(ll a,ll b){ if(a<b) { a=a+b; b=a-b; a=a-b;}while(b!=0){ll r=a%b; a=b; b=r;} return a;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long power(long long a, long long b, long long m) {a %= m;long long res = 1;while (b > 0) {if (b & 1)res = res * a % m;a = a * a % m;b >>= 1;}return res;}
const int N=1000005;
void judge()
{
      #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
    #endif
}
struct myhash
{
    static uint64_t fxn(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator ()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return fxn(x + FIXED_RANDOM);
    }
};
void solve(int tc)
{
    
    ll n;
    cin>>n;

    ll a[n][3],dp[n][3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
            cin>>a[i][j],dp[i][j]=a[i][j];

    }
    
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
            dp[i][j]=a[i][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    return;
}
int main()
{
    fastio;
    //judge();

    int T=1;
    // cin>>T;
    for(int tc=1;tc<=T;tc++)
    {
        solve(tc);
    }
    return 0;
}

Measured memory_bytes: 8312
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
# import numpy as np
starttime = time.time()
# import numpy as np
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

try:
    # sys.setrecursionlimit(int(pow(10,5)))
    sys.stdin = open("input.txt", "r")
    # sys.stdout = open("../output.txt", "w")
except:
    pass




n=L()[0]
A=[L() for i in range(n)]
cnt=0
for i in range(n):
    if A[i][1]==A[i][0]:
        cnt+=1
    else:
        cnt=0
    if cnt==3:
        print("Yes")
        exit()
print("No")






endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")


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

int main() {
    int N;
    cin >> N;
    int z = 0;
    long long int h[N];
    for(int i=0;i<N;i++){
        cin >> h[i];
        if(h[i] == 0){
             z = 1;
             break;
        }
    }
    long long int k = 1LL;
    long long int border = 1000000000000000000LL;
    if(z == 1){
        k = 0;
    } else {
        for(int j=0;j<N;j++){
            if(k < LONG_MAX / h[j]){
                k *= h[j];
            }
            else {
                k = -1;
                break;
            }
        }
        if(k > border) {
            k = -1;
        }
    }
    cout << k << '\n';
}

Measured memory_bytes: 4372
using namespace std;
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 1000000007
#define mod 998244353
#define sec setprecision
#define Pair pair<int,int>
#define _CRT_SECURE_NO_WARNINGS
#define veccin(a) rip(i,n)cin>>a[i]; 
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow((x * x)%mod , n / 2)%mod);
	else
		return (x * pow(x, n - 1))%mod;
}
int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	veccin(a);
	sort(all(a));
	ld ans = a[0];
	for (int i = 1; i < n; i++) {
		ans = (ans + a[i]) / 2;
	}
	cout << fixed << sec(10) << ans << endl;
}

Measured memory_bytes: 3732
#include <iostream>
#define rep(i,n) for(int i=0; i<(n); ++i)

int h, w, k;
std::string c[6];

bool check(int rmask, int cmask) {
    int black=0;
    rep(i,h) {
        rep(j,w) {
            if (((rmask >> i) & 1) == 0 &&
                ((cmask >> j) & 1) == 0 &&
                c[i][j] == '#') ++black;
        }
    }
    return black == k;
}

int main() {
    std::cin >> h >> w >> k;
    rep(i,h) rep(j,w) std::cin >> c[i][j];

    int ans=0;
    rep(rmask,1<<h) {
        rep(cmask,1<<w) {
            if (check(rmask, cmask)) ++ans;
        }
    }
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3604
x = int(input())
if 400<=x and x<=599:
  print(8)
if 600<=x and x<=799:
  print(7)
if 800<=x and x<=999:
  print(6)
if 1000<=x and x<=1199:
  print(5)
if 1200<=x and x<=1399:
  print(4)
if 1400<=x and x<=1599:
  print(3)
if 1600<=x and x<=1799:
  print(2)
if 1800<=x and x<=1999:
  print(1)
exit()
 

Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define ll long long
#define reg register
using namespace std;
ll n,t,l,s;
int main()
{
    scanf("%lld",&n);
    for(reg ll i=sqrt(n);i>=1;i--)
    {
        if(n%i==0)
		{
            t=i;
			l=n/i;
			s=1;
            while(l>=10)
            {
                s++;
                l/=10;
            }
        	printf("%lld",s);
        	return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}
    
void run(){
    int n,m,k;
    cin>>n>>m>>k;
    vi a(n),b(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    int ans=*min_element(all(a))+*min_element(all(b));
    rep(i,k){
        int x,y,c;
        cin>>x>>y>>c;
        x--,y--;
        ans=min(ans,a[x]+b[y]-c);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n+1];
	for(int i=1;i<=n;i++)
	   cin>>a[i];
	sort(a+1,a+n+1);
	int minx=1e9;
	for(int i=1;i<=(n-k+1);i++){
		minx=min(a[i+k-1]-a[i],minx);
	} 
	cout<<minx<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <cmath>
#include <iostream>
#include <vector>

double calc_dist(const std::vector<double>& x, const std::vector<double>& y) {
    const std::size_t size = x.size();
    double ret = 0.0;
    for (std::size_t i = 0; i < size; ++i) {
        const double diff = x[i] - y[i];
        ret += diff * diff;
    }

    return std::sqrt(ret);
}

bool is_int(double x) {
    return x == std::floor(x);
}

int main() {
    int N, D;
    std::cin >> N >> D;

    std::vector<std::vector<double>> x;
    x.reserve(N);
    int a;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < D; ++j) {
            std::cin >> a;
            x[i].push_back(a);
        }
    }

    int ret = 0;
    for (int i = 0; i < N - 1; ++i) {
        for (int j = i + 1; j < N; ++ j) {
            const auto dist = calc_dist(x[i], x[j]);
            if (is_int(dist)) {
                ++ret;
            }
        }
    }

    std::cout << ret << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	int a, b;
	string s, ans = "Yes";
	cin >> a >> b >> s;
	if (s.size() != a + b + 1) {
		ans = "No";
	} else {
		for (int i = 0; i < a; i++) {
			if (!('0' <= s[i] && s[i] <= '9')) ans = "No";
		}
		if (s[a] != '-') ans = "No";
		for (int i = a + 1; i < s.size(); i++) {
			if (!('0' <= s[i] && s[i] <= '9')) ans = "No";
		}
	}
	cout << ans << endl;	
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
char c[232],top; 
int main() {
	char ch;
	while(cin>>ch) {
		if(ch=='B'&&top)top--;
		if(ch!='B')c[top++]=ch;
	}
	for(int i=0;i<top;++i) cout<<c[i]; cout<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()

    var cnt = 0
    repeat(n){
        val (l, r) = listOfInt()
        cnt += (r - l) + 1
    }

    println(cnt)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 35896
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
void Parking() {
	int n, a,b;
	cin >> n >> a >> b;

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

	Parking();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

const int MAX_V = 1000;
vector<int> G[MAX_V];
int odd, even;
vector<P> d; 
// 2部グラフ判定
struct BipartiteGraph{
    int n;    
    vector<int> color;
    BipartiteGraph(int _n){
        n = _n;
        color.resize(n, 0);
    }
    bool dfs(int v, int c){
        color[v] = c;
        if(c == 1) odd++;
        else even++;
        bool res = true;
        for(int i = 0; i < G[v].size(); i++){
            if(color[G[v][i]] == c) res &= false;
            if(color[G[v][i]] == 0) res &= dfs(G[v][i], -c);
        }
        return res;
    }
    bool isBipartiteGraph(){
        bool res = true;
        for(int i = 0; i < n; i++){
            if(color[i] == 0){
                odd = even = 0;
                res &= dfs(i, 1);
                d.push_back({odd, even});
            }
        }
        return res;
    }
};

bool l[1000][1000];
bool dp[1000], nxt[1000];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    rep(i, 0, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        l[a][b] = true;
        l[b][a] = true;
    }
    rep(i, 0, n){
        rep(j, i + 1, n){
            if(!l[i][j]){
                G[i].push_back(j);
                G[j].push_back(i);
            }
        }
    }
    BipartiteGraph bg(n);
    if(!bg.isBipartiteGraph()){
        cout << -1 << endl;
        return 0;
    }
    rep(i, 0, 1000) dp[i] = false;
    dp[0] = true;
    rep(i, 0, d.size()){
        rep(j, 0, 1000) nxt[j] = false;
        rep(j, 0, 1000){
            if(!dp[j]) continue;
            nxt[j + d[i].first] = true;
            nxt[j + d[i].second] = true;
        }
        swap(dp, nxt);
    }
    int ans = INF;
    rep(i, 0, n + 1){
        if(dp[i]){ 
            int tmp = i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2;
            chmin(ans, tmp);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6016
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
bcs = []
for i in range(Q):
  j,k = map(int,input().split())
  bcs.append([j,k])
s = sum(A)
cnts = [0]*100000
for a in A:
  cnts[a-1]+=1
for b,c in bcs:
  t = cnts[b-1]
  s -= t * b
  cnts[b-1]=0
  cnts[c-1]+=t
  s += t*c 
  print(s)

Measured memory_bytes: 29172
import Control.Monad

main = do
  n <- readLn
  ass <- replicateM n getLine
  print $ solve n ass

solve n ass
  | or hasblacks = minimum costs + length (filter id todos)
  | otherwise = -1
  where
  (todos,hasblacks) = foldr f (falses,falses) ass
  falses = replicate n False
  f as (todos,hasblacks) = (zipWith g todos as,zipWith h hasblacks as)
    where
    g a b = a || b=='.'
    h a b = a || b=='#'
  costs = g ass hasblacks
  g [] _ = []
  g (as:ass) (hasblack:hbs)
    | hasblack = whites : g ass hbs
    | otherwise = 1 + whites : g ass hbs
    where whites = length $ filter (=='.') as

Measured memory_bytes: 18556
A,B,C,X,Y=map(int,input().split(' '))
ans=-1
for n_ab in range(max(X,Y)+1):
  n_a = max(X-n_ab, 0)
  n_b = max(Y-n_ab, 0)
  p = n_a*A+n_b*B+n_ab*2*C
  ans=p if ans==-1 or p<ans else ans
print(ans)

Measured memory_bytes: 3060
#include <iostream>

using lli = long long int;

int main(void){
    lli q, h, s, d; scanf("%lld%lld%lld%lld", &q, &h, &s, &d);
    lli n; scanf("%lld", &n);
    lli Half = ((q << 1) > h) ? h : (q << 1);
    lli One = ((Half << 1) > s) ? s : (Half << 1);
    lli Two = ((One << 1) > d) ? d : (One << 1);
    lli res = (n >> 1) * Two + (n & 1) * One;
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  int n,m; cin >> n >> m;
  int x = 100*(n-m) +  m * 1900;
  int x1 = x*(int)pow(2,m);
  cout << x1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,q;
int a[200010];
int main(){
	int sum=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum^=a[i];
	}
	for(int i=1;i<=n;i++){
		printf("%d ",sum^a[i]);
	}	
} 

Measured memory_bytes: 4500
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int main(){
  int n;
  bool f[102][13];
  int p[102][13];
  cin>>n;
  REP(i,n)REP(j,10)cin>>f[i][j];
  REP(i,n)REP(j,11)cin>>p[i][j];
  int ans=(-1)*mod;
  for(int i = 1; i < (1<< 10); i++) {
    int tmp=0;
    REP(j,n){
      int c=0;
      REP(k,10)if(i>>k&1&&f[j][k])c++;
      tmp+=p[j][c];
    }
    ans=max(ans,tmp);
  }
  print(ans);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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



	public void run() {
		Scanner sc = new Scanner(System.in);
		char abcd[] = sc.next().toCharArray();
		int a = abcd[0] - '0';
		int b = abcd[1] - '0';
		int c = abcd[2] - '0';
		int d = abcd[3] - '0';
		if     (a+b+c+d==7)System.out.printf("%d+%d+%d+%d=7\n", a,b,c,d);
		else if(a+b+c-d==7)System.out.printf("%d+%d+%d-%d=7\n", a,b,c,d);
		else if(a+b-c+d==7)System.out.printf("%d+%d-%d+%d=7\n", a,b,c,d);
		else if(a+b-c-d==7)System.out.printf("%d+%d-%d-%d=7\n", a,b,c,d);
		else if(a-b+c+d==7)System.out.printf("%d-%d+%d+%d=7\n", a,b,c,d);
		else if(a-b+c-d==7)System.out.printf("%d-%d+%d-%d=7\n", a,b,c,d);
		else if(a-b-c+d==7)System.out.printf("%d-%d-%d+%d=7\n", a,b,c,d);
		else if(a-b-c-d==7)System.out.printf("%d-%d-%d-%d=7\n", a,b,c,d);
		sc.close();
	}

}


Measured memory_bytes: 23892
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long

int n,k;
int p[1010];

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

int main(){
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%d",&p[i]);}
  qsort(p,n,sizeof(int),up);
  int sum=0;
  for(int i=0;i<k;i++){
    sum+=p[i];}
  
  printf("%d\n",sum);
  
  return 0;
}


Measured memory_bytes: 1740
import numpy as np

N = int(input())
x_lis = []
y_lis = []

for i in range(N):
  num_x, num_y = map(int, input().split())
  x_lis.append(num_x)
  y_lis.append(num_y)

def a(X,Y,Z):
  A = np.dot(Y-Z,Y-Z)
  B = np.dot(Z-X,Z-X)
  C = np.dot(X-Y,X-Y)

  T = A*(B+C-A)
  U = B*(C+A-B)
  W = C*(A+B-C)

  if not T+U+W:
    return [10**9,10**9]
  else:
    return (T*X+U*Y+W*Z)/(T+U+W)

r = 10**9
for i in range(len(x_lis)-1):
  for j in range(i+1,len(x_lis)):
    x1 = x_lis[i]
    y1 = y_lis[i]
    x2 = x_lis[j]
    y2 = y_lis[j]
    center_x = (x1+x2)/2
    center_y = (y1+y2)/2
    dist = ((x1-x2)**2+(y1-y2)**2)**0.5/2
    if max([((center_x-i)**2+(center_y-j)**2)**0.5 for i,j in zip(x_lis, y_lis)]) == dist:
      r = min(dist, r)
    
for i in range(len(x_lis)-2):
  for j in range(i+1,len(x_lis)-1):
    for k in range(j+1,len(x_lis)):
      x1 = x_lis[i]
      y1 = y_lis[i]
      x2 = x_lis[j]
      y2 = y_lis[j]
      x3 = x_lis[k]
      y3 = y_lis[k]
      center = a(np.array([x1,y1]), np.array([x2,y2]), np.array([x3,y3]))
      dist = ((center[0]-x1)**2+(center[1]-y1)**2)**0.5
      if max([((center[0]-i)**2+(center[1]-j)**2)**0.5 for i,j in zip(x_lis,y_lis)]) == dist:
        r = min(dist, r)
      
print(r)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

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

	ll r, D, x;
	ll ans = 0;

	cin >> r >> D >> x;

	ans = x;
	rep(i, 10) {
		ans = r * ans - D;
		cout << ans << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
N = gets.strip.to_i
a = gets.strip.split('')

def chmax(a, b) a > b ? a : b end

def f(x, y)
  res = 0
  x.uniq.each do |c|
    res += 1 if y.include?(c)
  end
  res
end

res = 0
(N - 1).times do |i|
  res = chmax(f(a[0..i], a[i+1..-1]), res)  
end

puts res


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

using Graph = vector<vector<int>>;
using ll = long long;
vector<int> c;

bool dfs(const Graph &G, int v, int cr=0) {
  c.at(v) = cr;
  for(auto nv : G[v]) {
    if(c.at(nv) != -1) {
      if(c.at(nv) == cr)
        return 0;
      continue;
    }

    if(!dfs(G, nv, 1-cr))
      return 0;
  }
  return 1;
}

int main() {
  int N,M,i,A,B;
  ll c1=0, c2=0;
  bool isBipartite = 1;
  cin >> N >> M;
  Graph G(N);

  for(i=0; i<M; i++) {
    cin >> A >> B;
    A--; B--;
    G[A].push_back(B);
    G[B].push_back(A);
  }

  c.assign(N, -1);
  for(i=0; i<N; i++) {
    if(c.at(i) != -1)
      continue;
    if(!dfs(G, i))
      isBipartite = 0;
  }

  if(isBipartite) {
    for(i=0; i<N; i++)
      if(c.at(i) == 0)
        c1++;
      else
        c2++;
    cout << c1*c2-M;
  } else
    cout << (ll)N*(N-1)/2-M;
  cout << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// ordered_set X;
// *X.find_by_order(i) = ith largest element (counting from zero)
// X.order_of_key(k) = number of items in X < k (strict lt)
int main(){
    int N;
    ll C, K;

    cin >> N >> C >> K;
    
    vll T(N);
    for (int i=0;i<N;i++) cin >> T[i];

    sort(T.begin(), T.end());
    int ans = 0;
    ll curbus = -1;
    ll curcap = 0;

    for (ll t : T) {
        if (curcap == 0 || t > curbus) {
            ans++;
            curbus = t+K;
            curcap = C-1;
        } else {
            curcap--;
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 0x3f3f3f3f
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int num[100005];
int main()
{
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
                scanf("%d", &num[i]);
        }
        sort(num + 1, num + 1 + n);
        if (n == 2)
        {
                cout << num[2] << " " << num[1] << endl;
                return 0;
        }
        else
        {
                int minn = 1e9;
                cout << num[n] << " ";
                int now = num[n] / 2;
                int now2 = num[n] / 2 + num[n] % 2;
                for (int i = 1; i <= n - 1; i++)
                {
                        minn = min(minn, min(abs(num[i] - now), abs(num[i] - now2)));
                }
                for (int i = 1; i <= n - 1; i++)
                {
                        if (min(abs(num[i] - now), abs(num[i] - now2)) == minn)
                        {
                                cout << num[i] << endl;
                                return 0;
                        }
                }
        }
}


Measured memory_bytes: 640
//#include <bits/stdc++.h>
// utility
#include <bitset>
#include <tuple>
#include <typeinfo>
// error handling
#include <cassert>
// string
#include <cctype>
#include <cstring>
#include <string>
// container
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
// algorithm
#include <algorithm>
// iterator
#include <iterator>
// math
#include <cmath>
#include <complex>
#include <numeric>
#include <random>
// i/o
#include <iostream>
#include <iomanip>
#include <cstdio>



using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);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> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]) == typeid(INF) and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  int A, B; cin >> A >> B;
  A--,B--;
  cout<<A*B<<endl;

    return 0;
}


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

int main()
{
   ll int n,i,k=0;
    cin>>n;
string s[n];
   ll int cnt=0,ans=0;
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s,s+n);
    for(int i=0;i<n-1;i++)
    {
        if(s[i]==s[i+1]){cnt++;ans+=cnt;}
        else cnt=0;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define forup(i,l,r) for (register int i = l ; i <= r ; i += lowbit(i))
#define fordown(i,id) for (register int i = id ; i ; i -= lowbit(i))
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define lowbit(x) (x&(-x))

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll,int> pr;

const int inf = 2e8;
const int maxn = 100020;
const ll mod = 1e9 + 7;
struct node{
	int next,to,w;
}e[maxn * 2];

int head[maxn],cnt,rt,sz[maxn],n,h[maxn];
ll f[maxn],fac[maxn],inv[maxn],g[maxn];

inline ll power(ll x,ll y){
	ll res = 1;
	while ( y ){
		if ( y & 1) res = res * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
void init(){
	fac[0] = inv[0] = 1;
	rep(i,1,n) fac[i] = fac[i - 1] * i % mod , inv[i] = power(fac[i],mod - 2);	
}

inline void adde(int x,int y){
	e[++cnt].to = y;
	e[cnt].next = head[x];
	head[x] = cnt;
}
inline void up(ll &x,ll y){ x = (x + y) % mod; }
inline ll C(int n,int m){
	if ( n < 0 || m < 0 || n < m ) return 0;
	return fac[n] * inv[m] % mod * inv[n - m]  %mod;
}
void dfs(int x,int fa){
	sz[x] = 1; int mx = 0;
	fore(i,x){
		if ( e[i].to == fa ) continue;
		dfs(e[i].to,x);
		sz[x] += sz[e[i].to];
		mx = max(mx,sz[e[i].to]);
	}
	mx = max(mx,n - sz[x]);
	if ( !rt || mx < h[rt] ) rt = x;
	h[x] = mx;
}
void dfs2(int x,int fa){
	sz[x] = 1;
	fore(i,x){
		if ( e[i].to == fa ) continue;
		dfs2(e[i].to,x);
		sz[x] += sz[e[i].to];
	}
}
int main(){
	scanf("%d",&n);
	rep(i,1,n - 1){
		int x,y;
		scanf("%d %d",&x,&y);
		adde(x,y) , adde(y,x);
	}
	init();
	dfs(1,0);
	f[0] = 1 , sz[rt] = 1;
//	cout<<rt<<endl;
	fore(i,rt){
	   	dfs2(e[i].to,rt);
		rep(j,0,sz[rt]) g[j] = f[j] , f[j] = 0;
		rep(j,0,sz[rt]) rep(k,0,sz[e[i].to]){
//			if ( j - 2 * k  + sz[e[i].to] < 0 ) break;
			up(f[j + k],g[j] * C(sz[e[i].to],k) % mod * C(sz[e[i].to],k) % mod * fac[k]);
		}
		sz[rt] += sz[e[i].to];
//		rep(j,0,sz[rt]) cout<<f[j]<<" ";
//		cout<<endl;
	}
	ll ans = 0;
	rep(i,0,n){
		ll tp = (i & 1) ? -1 : 1;
		up(ans,f[i] * tp * fac[n - i]);
	}
	cout<<(ans + mod)% mod<<endl;
}



Measured memory_bytes: 4736
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;char c;char str[1024];string s;ll l;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;

struct edge
{
	int to, cost;
	edge(){};
	edge(int to, int cost) : to(to), cost(cost){};
};

int dat[50][50];
int c[4];

int dist[50][50][4];

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

int main(){
	while(1){
		int w = in.nextInt(), h = in.nextInt();
		if(w == 0 && h == 0) break;
		rep(i, h) rep(j, w) dat[i][j] = in.nextInt();
		rep(i, 4) c[i] = in.nextInt();
		rep(i, 50) rep(j, 50) rep(k, 4) dist[i][j][k] = (i == 0 && j == 0 && k == 0 ? 0 : INF);
		
		auto dijkstra = [&]{
			typedef pair<pii, pii> P;
			priority_queue<P, vector<P>, greater<P> > q;
			q.push({{0, 0}, {0, 0}});
			P p;
			while(!q.empty()){
				p = q.top();	q.pop();
				int cost = p.fi.fi, dir = p.fi.se, y = p.se.fi, x = p.se.se;
				for(int i = 0; i < 4; i++){
					int ndir = (dir + i) % 4;
					int nx = x + dx[ndir], ny = y + dy[ndir];
					if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
					int nc = (i == dat[y][x] ? 0 : c[i]);
					if(dist[ny][nx][ndir] <= cost + nc) continue;
					dist[ny][nx][ndir] = cost + nc;
					q.push({{cost + nc, ndir}, {ny, nx}});
				}
			}
		};
		dijkstra();
		
		int ans = INF;
		rep(i, 4) ans = min(ans, dist[h-1][w-1][i]);
		
		printf("%d\n", ans);
		
		// for(int  k = 0; k < 4; k++){
		// 	for(int i = 0; i < h; i++){
		// 		for(int j = 0; j < w; j++){
		// 			int t = dist[i][j][k];
		// 			if(t == INF) t = -1;
		// 			printf(" %3d", t);
		// 		}
		// 		cout<<endl;
		// 	}
		// 	cout<<endl;
		// }
	}
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    int tri = 0, cnt = 0;
    int omit;
    while(1){
        tri += cnt;
        if(tri >= n){
            omit = tri - n;
            break;
        }
        cnt++;
    }
    
    rep3(i, 1, cnt) {
        if(i != omit) cout << i << endl;
    }
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3640
N, M = map(int, input().split())
A = [True] * (N+1)
for _ in range(M):
  idx = int(input())
  A[idx] = False

step = [0] * (N+1)
step[0] = 1
for i in range(1, N+1):
  if A[i]:
    step[i] = step[i-1] + step[i-2]
  else:
    step[i] = 0
print(step[N]%(10**9+7))
  
  


Measured memory_bytes: 460788
N = int(input())
a = list(map(int, input().split()))

if N >= 2:
    if a[1] >= a[0]:
        a[0] -= 1
for i in range(N-1):
    if a[i] < a[i+1]:
        a[i+1] -= 1

if a == sorted(a):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14396
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define ff(i,a,b) for(int i=a;i<=b;++i)

using namespace std;

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

const int N = 2e5+5;

int n,k,h[N],dp[N];

void solve(){
	cin>>n>>k;
	ff(i,1,n)cin>>h[i];
	ff(i,1,n)dp[i]=1e9;
	dp[0]=0;
	dp[1]=0;
	ff(i,1,n){
		ff(j,1,k){
			if(i-j>=1)
				dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
		}
	}
	cout<<dp[n];
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while (T--)solve();
}

Measured memory_bytes: 4368
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<int> a(N+1);
  for(int i=1; i<=N; i++){
    cin >> a[i];
  }
  vector<bool> used(N+1,false);
  int k=1;
  int cnt = 0;
  while(k != 2){
    if(used[k]){
      break;
    }
    used[k] = true;
    k = a[k];
    cnt++;
  }
  if(k == 2){
    cout << cnt << endl;
  }else{
    cout << -1 << endl;
  }
  return 0;
}


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

#define MAXN 100100
long long n,w,a[MAXN],b[MAXN],dp[110][MAXN];

int main (){
    cin >> n >> w;
    for(int i=0;i<n;++i){
        cin >> a[i] >> b[i];
    }
    for (int i=0;i<n;++i){
        for(int j=0;j<=w;++j){
            if (i==0){
                if (a[i]<=j){
                    dp[i][j]=b[i];
                }
            }
            else {
                dp[i][j]=dp[i-1][j];
                if (a[i]<=j){
                    dp[i][j]=max(dp[i][j],b[i]+dp[i-1][j-a[i]]);
                }
            }
        }
    }
    cout << dp[n-1][w];
    return 0;
}

Measured memory_bytes: 80128
//tree DP
//ABC036-D
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}

typedef struct{
long long val;
long long node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val > ((sd*)b)->val){return -1;}
if(((sd*)a)->val < ((sd*)b)->val){return 1;}
return 0;
}

typedef struct{
    long long st;
    long long fi;
    long long kr;
}rs;

typedef struct{
    long long st;
    long long kz;
}mkj;

int sortfnc(const void *a,const void *b){
if(((rs*)a)->st == ((rs*)b)->st){return 0;}
if(((rs*)a)->st < ((rs*)b)->st){return -1;}
return 1;
}

void makemkj(rs g[],mkj x[],long long n){
    long long i,ms=0,nst=g[0].st;
    for(i=1;i<n;i++){
        if(g[i].st!=g[i-1].st){
            x[nst].kz=i-ms;
            x[nst].st=ms;
            nst=g[i].st;ms=i;
        }
    }
    x[nst].kz=n-ms;
    x[nst].st=ms;
}

long long dist[524288],par[524288];
void dfs(long long t,long long l,long long bp,rs g[],mkj x[]){
  long long i;
  if(dist[t]<=l){return;}
  dist[t]=l;
  par[t]=bp;
  for(i=x[t].st;i<x[t].st+x[t].kz;i++){
    dfs(g[i].fi,l+1,t,g,x);
  }
}

int main(void){
    long long i,j,n,m,k,a,b,c,h,w,r,l,t;
    long long bk[524288]={0};
    long long dp[524288]={0};
    rs g[524288];
    mkj x[524288];
    sd dat[524288];
    scanf("%lld",&n);
    for(i=0;i<(n-1);i++){
      scanf("%lld%lld",&a,&b);
      bk[a]++;bk[b]++;
      g[2*i].st=a;
      g[2*i].fi=b;
      g[2*i].kr=1;
      g[2*i+1].st=b;
      g[2*i+1].fi=a;
      g[2*i+1].kr=1;
    }
    qsort(g,2*(n-1),sizeof(g[0]),sortfnc);
    makemkj(g,x,2*(n-1));
    r=-1;
    for(i=0;i<n;i++){
      dist[i]=inf;
      if(bk[i]>=3){r=i;}
    }
    if(r==-1){
      printf("1\n");
      return 0;
    }
    dfs(r,0,-1,g,x);
    for(i=0;i<n;i++){
      dat[i].node=i;
      dat[i].val=dist[i];
    }
    qsort(dat,n,sizeof(dat[0]),sdsortfnc);
    for(i=0;i<n;i++){
      w=dat[i].node;
      t=0;h=0;
      for(j=x[w].st;j<x[w].st+x[w].kz;j++){
        if(par[w]==g[j].fi){continue;}
        t+=dp[g[j].fi];
        if(dp[g[j].fi]==0){h++;}
      }
      //printf("%lld:%lld %lld\n",w,t,h);
      dp[w]=t+llmax(0,h-1);
    }
    printf("%lld\n",dp[r]);
    return 0;
}


Measured memory_bytes: 31748
#include<bits/stdc++.h>
#define mod 1000000007

/*long long power(long long a,int k)
{
	long long ans=1,y=a;
	while(k!=0)
	{
		if(k%2!=0)
			ans=ans*y%mod;
		y=y*y%mod;
		k=k/2;
	}
	return ans;
}
*/
long long fun[1000005],ans=1;

long long power(long long a,int k)
{
	long long ans=1,y=a;
	while(k!=0)
	{
		if(k%2==1)
		    ans=ans*y%mod;
		y=y*y%mod;
		k/=2;
	}
	return ans;
}
int main()
{
	long long n,m;
	scanf("%lld%lld",&n,&m);
	fun[0]=1;
	for(int i=1; i<1000000; i++)
		fun[i]=fun[i-1]*i%mod;
	for(int i=2; i*i<=m; i++)
		if(m%i==0)
		{
			long long s=0;
			while (m%i==0)
			{
				m=m/i;
				s++;
			}
			ans=ans*fun[n+s-1]%mod*power(fun[n-1], mod-2)%mod*power(fun[s], mod-2)%mod;
		}
	if(m>1)
		ans=ans*n%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8064
c = [list(map(int, input().split())) for i in range(3)]

a = [0, -1, -1]
b = [0, 0, 0]
for i in range(3):
    b[i] = c[0][i] - a[0]
a[1] = c[1][1] - b[1]
a[2] = c[2][1] - b[1]

flag = True
for i in range(3):
    for j in range(3):
        if a[i] + b[j] == c[i][j]:
            pass
        else:
            flag = False
            break

if flag:
    print('Yes')
else:
    print('No')

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

using namespace std;
#define ll long long int

int main()
{
    ll t;
    t = 1;
    // cin t;
    while (t--)
    {
        ll n;
        cin >> n;
        ll a[n];
        ll ans = 0;
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            ans = ans ^ a[i];
        };
        for (int i = 0; i < n; i++)
        {
            cout << (a[i] ^ ans) << " ";
        }
    }
}


Measured memory_bytes: 5140
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 ans = a - b*2;
		//判定
		if (ans <= 0){
			ans = 0 ;
		}
		//出力
		System.out.println(ans);
	}
}


Measured memory_bytes: 23636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>

using namespace std;

int main(int argc, char const *argv[])
{
	string s;

	cin >> s;

	int place = s.rfind("FESTIVAL");

	cout << s.replace(place,place+7,"") << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

count = 0

for i in range(N):
    minj = i
    for j in range(i+1, N):
        if a[minj]>a[j]:
            minj = j
    if a[i]!=a[minj]:
        a[i], a[minj] = a[minj], a[i]
        count += 1
print(' '.join(map(str, a)))
print(count)



Measured memory_bytes: 5600
import math

yen = int(input())
happiness = 0

if yen / 500 > 0:
    fivehandred_number = math.floor(yen / 500)
    happiness = happiness + (1000 * fivehandred_number)
    yen = yen - (500 * fivehandred_number)

if yen / 5 > 0:
    five_number = math.floor(yen / 5)
    happiness = happiness + (5 * five_number)

print(happiness)

Measured memory_bytes: 3060