akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

//! [Sのi文字目][Tのj文字目]
int dp[1005][1005];

int main()
{
	string S, T;
	cin >> S >> T;
	REP(i, S.length() + 1)
	{
		dp[i][0] = i;
	}
	REP(i, T.length() + 1)
	{
		dp[0][i] = i;
	}
	FOR(i, S.length() + 1, 1)
	{
		FOR(j, T.length() + 1, 1)
		{
			int cost = 0;
			if (S[i - 1] != T[j - 1])cost = 1;
			dp[i][j] = std::min(dp[i - 1][j] + 1, std::min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost));
		}
	}
	cout << dp[S.length()][T.length()] << endl;
	return 0;
}


Measured memory_bytes: 7104
#include <iostream>
#include <algorithm>
#include <vector>

using Int = long long int;
template <class T>
using Vector = std::vector<T>;

struct G {
    Vector<Int> idx;
    static Vector<Int> a;

    G& operator+=(const G& opp) {
        std::copy(opp.idx.begin(), opp.idx.end(),
                  std::back_inserter(idx));
        std::sort(idx.begin(), idx.end(), [&](Int i, Int j) {
            return a[i] == a[j] ? i < j : a[i] > a[j];
        });
        idx.erase(std::unique(idx.begin(), idx.end()), idx.end());
        idx.resize(2);
        return *this;
    }
};
Vector<Int> G::a;

int main() {
    Int n;
    std::cin >> n;
    Vector<Int> a(1 << n);
    for (auto& x : a) std::cin >> x;
    G::a = a;

    Vector<G> g(1 << n);
    for (Int s = 0; s < (1 << n); ++s) {
        g[s].idx.push_back(s);
    }

    // 高速ゼータ変換 下位集合版
    for (Int k = 0; k < n; ++k) {
        for (Int b = 0; b < (1 << n); ++b) {
            if ((b >> k) & 1) {
                g[b] += g[b ^ (1 << k)];
            }
        }
    }

    Int max = 0;
    for (Int s = 1; s < (1 << n); ++s) {
        max = std::max(max, a[g[s].idx[0]] + a[g[s].idx[1]]);
        std::cout << max << std::endl;
    }
    return 0;
}


Measured memory_bytes: 26112
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());

        if(a * b % 2 == 0) System.out.println("Even");
        else System.out.println("Odd");

        sc.close();
    }
}

Measured memory_bytes: 21844
n, x = gets.split.map(&:to_i)
a, b = [x, n - x].minmax
ans = n
loop{
    tmp = b % a
    if tmp == 0
        ans += a * (b / a * 2 - 1)
        break
    end
    ans += a * (b / a * 2)
    b = a
    a = tmp
    }
p ans

Measured memory_bytes: 1788
package main

import (
	"fmt"
)

func Max(x, y int) int {
    if x < y {
        return y
    }
    return x
}

func main() {
	var N, K int
	fmt.Scan(&N)
	fmt.Scan(&K)
	var A = make([]int, N)
	for i := range(A) {
		fmt.Scan(&A[i])
	}
	
	var xorSum = make([]int, 40)
	for i:=0; i<40; i++ {
		if 0 == ((K + 1) >> uint(i)) & 1 { continue }

		for _, e := range(A) {
			ui := uint(i)
			xorSum[i] += ((e >> ui) ^ ((K + 1) >> ui - 1)) << ui
		}

		for j:=0; j<i; j++ {
			var bitSum int
			for _, e := range(A) {
				bitSum += (e >> uint(j)) & 1
			}
			xorSum[i] += Max(bitSum, N - bitSum) << uint(j)
		}
	}

	var max int
	for i:=0; i<40; i++ {
		max = Max(xorSum[i], max)
	}

	fmt.Println(max)
}

Measured memory_bytes: 5504
//piupiuplu 

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <queue>
#include <stack>
#include <iostream>
#include <vector>

using namespace std;

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

Measured memory_bytes: 256
from heapq import heapify, heappush, heappop

inf = float("inf")
def dijkstra(graph, start):  # graphは隣接リスト(繋がっている先, コスト)
    vsize = len(graph)
    dist = [inf] * vsize
    seen = [False] * vsize
    pq = []
    heapify(pq)

    dist[start] = 0
    heappush(pq, (0, start))  # heapではtuple[0]で比較されるのでこの順番で追加する
    while pq:
        cost, u = heappop(pq)
        seen[u] = True
        if dist[u] < cost:
            continue
        for v, w in graph[u]:
            temp_cost = dist[u] + w
            if not seen[v] and temp_cost < dist[v]:
                dist[v] = temp_cost
                heappush(pq, (dist[v], v))
    return dist
V, E, r = map(int, input().split())
graph = [[] for _ in range(V)]
for _ in range(E):
    s, t, d = map(int, input().split())
    graph[s].append((t, d))
for min_cost in dijkstra(graph, r):
    print(min_cost if min_cost != inf else "INF")



Measured memory_bytes: 90052
#include <iostream>
#include <fstream>
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
ll a[123456];
map<ll, int>mp;

// Returns value of Binomial Coefficient C(n, k)
ll binomialCoeff(int n, int k)
{
	ll res = 1;
        if(n < k)return 0;
	// Since C(n, k) = C(n, n-k)
	if ( k > n - k )
		k = n - k;
 
	// Calculate value of [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
	for (int i = 0; i < k; ++i)
	{
		res *= ll(n - i);
		res /= ll(i + 1);
	}
 
	return res;
}

class DCandyDistribution {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n, m;
		in >> n >> m;
		mp.clear();
		memset(a, 0, sizeof(a));
		ll sum = 0;
		for (int i = 1; i <= n; ++i) {
			in >> a[i];
			if(i != 0)a[i] += a[i-1];
			a[i] %= m;
			mp[a[i]]++;
		}

		for (auto it = mp.begin(); it != mp.end(); ++it) {
			sum += binomialCoeff(it->second, 2);
		        if(it->first == 0)sum += it->second;
		}
		out << sum << endl;
	}
};
 
int main() {
	DCandyDistribution solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 5120
func main() {
    let S = Array(readLine()!)
    let n = S.count
    let A: Set = ["dream", "dreamer", "erase", "eraser"]
    
    var s = ""
    for i in 1...n {
        s.insert(S[n - i], at: s.startIndex)
        if s.count > 7 {
            print("NO")
            return
        }
        if A.contains(s) {
            s = ""
        }
    }
    
    if s.count == 0 {
        print("YES")
    } else {
        print("NO")
    }
}

main()


Measured memory_bytes: 8636
// finish date: 2018/01/11
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

#define bigmod 1000000007
using namespace std;

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

int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}

int factorial(int n) {
    int ans = 1;
    FOR(i, 1, n + 1) {
        ans = ans * i;
    }
    return ans;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(N), b(N), c(M), d(M);
    rep(i, N) cin >> a[i] >> b[i];
    rep(i, M) cin >> c[i] >> d[i];

    int points;
    int maxDis;
    int distance;
    rep(i, N) {
        points = 0;
        maxDis = INT_MAX;
        rep(j, M) {
            distance = abs(c[j] - a[i]) + abs(d[j] - b[i]);
            if (distance < maxDis) {
                points = j;
                maxDis = distance;
            }
        }
        cout << points + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n; R(n);
    W((n-2)*180);
    return 0;
}


Measured memory_bytes: 256
n,t = gets.chomp.split(" ").map{|str| str.to_i}
a = gets.chomp.split(" ").map{|str| str.to_i}

#a_iより後の値の最大値とそのindex
max_after = [[-1,[]]]

for idx in (1..n-1).to_a.reverse do
	num = a[idx]
	max = max_after[0][0..-1]
	if num > max[0] then
		max[0] = num
		max[1] = [idx] 
	elsif num == max[0] then
		max[1].push(idx)
	end
	max_after.unshift(max[0..-1])
	#p max_after
end

#p max_after

#a_iを固定した時の最大値
benefit = []

for i in 0...n do
	benefit.push(max_after[i][0] - a[i])
end

#p benefit

ben_max = benefit.max

#購入価格を上昇させるコスト
buy_num = benefit.count(ben_max)

#販売価格を上昇させるコストを計算するためにどこで販売するかの一覧を作る
sell_idx = []

for i in 0...n do
	if benefit[i] == ben_max then
		sell_idx.concat(max_after[i][1])
	end
end

sell_num = sell_idx.uniq.length

puts [buy_num, sell_num].min

Measured memory_bytes: 25088
def solve():
    X,Y = [int(i) for i in input().split()]
    if 2*X <= Y <= 4*X:
        if (4*X-Y) % 2 == 0:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

if __name__ == "__main__":
    solve()

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

using namespace std;

typedef vector<int> vi;

int median(int a, int b, int c)
{
	return (a+b+c) - max(max(a,b),c) - min(min(a,b),c);
}

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

	int N, n, x;
	while(cin >> N >> x)
	{
		n = 2*N-1;
		if(x == 1 || x == n)
		{
			cout << "No" << endl;
			continue;
		}

		vi track(n,-1);
		vector<bool> use(n+1);
		if(x < N)
		{
			track[N-1] = x;
			track[N-2] = x-1;
			use[x] = use[x-1] = true;
		}
		else if(x > N)
		{
			track[N-1] = x;
			track[N] = x+1;
			use[x] = use[x+1] = true;
		}
		for(int j=0, place = 1; j<n; j++)
		{
			if(track[j] != -1)
				continue;
			while(use[place]) place++;
			track[j] = place++;
		}
		cout << "Yes\n";
		for(auto x: track)
			cout << x << '\n';
	}

	return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
using ll = long long;

int main()
{
    ll i,j;
    ll n,t;
    cin >> n >> t;
    vector<ll> a(n);
    vector<ll> vmin(n);
    vector<ll> vmax(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    ll tmpmin = 1e9+7;
    for(i = 0;i < n;++i){
        tmpmin = min(tmpmin, a.at(i));
        vmin.at(i) = tmpmin;
    }
    ll tmpmax = -1;
    for(i = n-1;i >= 0;--i){
        tmpmax = max(tmpmax, a.at(i));
        vmax.at(i) = tmpmax;
    }
    vector<pair<ll,ll>> dif(n);
    for(i = 0;i < n;++i){
        dif.at(i) = make_pair(vmax.at(i) - vmin.at(i), i);
    }
    sort(all(dif));
    ll ans = 0;
    map<pair<ll,ll>, ll> mp;
    ll maxdif = dif.back().first;
    for(i = n-1;i >= 0;--i){
        auto x = dif.at(i);
        if(x.first != maxdif) break;
        ll ind = x.second;
        auto y = make_pair(vmin.at(ind), vmax.at(ind));
        if(mp.count(y)) continue;
        mp[y] = 1;
        ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7296
#include <cassert>
#include <vector>

template <class T = long long>
class cht_monotone
{
    struct line
    {
        T a, b;
        T eval(const T x) const { return a * x + b; }
    };

    std::vector<line> lines;
    typename std::vector<line>::iterator lp, rp;

    void realloc()
    {
        std::vector<line> cpy((rp - lp) * 2);
        cpy.swap(lines);
        rp = copy(lp, rp, lines.begin());
        lp = lines.begin();
    }

public:
    cht_monotone() : lines(1), lp(lines.begin()), rp(lp) {}

    bool empty() const { return lp == rp; }

    void add(const T a, const T b)
    {
        while(rp - lp > 1)
        {
            auto [a1,b1] = *(rp - 1);
            auto [a2,b2] = *(rp - 2);
            if((b - b1) * (a2 - a) > (b - b2) * (a1 - a)) break;
            --rp;
        }
        if(rp == lines.end()) realloc();
        *rp++ = {a, b};
    }

    T get(const T x)
    {
        assert(!empty());
        while(rp - lp > 1 && lp->eval(x) > (lp + 1)->eval(x)) ++lp;
        return lp->eval(x);
    }
};

#include <cassert>
#include <iostream>

main()
{
    int n; long long c;
    std::cin>>n>>c;

    cht_monotone cht;

    for(int i=1; i<n; i++)
    {
        long long h;
        std::cin>>h;
        if(i==1)
        {
            cht.add(-2*h,h*h+c);
        }
        else
        {
            cht.add(-2*h,cht.get(h)+h*h*2+c);
        }
    }
    long long h;
    std::cin>>h;
    std::cout<<cht.get(h)+h*h;
}

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

#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)

#define P pair<int, int >


const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;

typedef long long ll;


//---functions---//
int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

int s2i(string num){stringstream ss; ss << num << flush; int n; ss >> n; return n;}
string i2s(int n){stringstream ss; ss << n << flush; return ss.str();}

bool firstCompare(const P& firstElof, const P& secondElof){
    return firstElof.first < secondElof.first;
}
bool secondCompare(const P& firstElof, const P& secondElof){
    return firstElof.second < secondElof.second;
}
//---------------//

ll H, W, K;
ll a[102][10];

ll f(ll h, ll w){
    if(h == 0){
        if(w == 1) return 1;
        else return 0;
    }
    if((h < 0) || (h > H + 1) || (w < 1) || (w > W)) return 0;
    if(a[h][w] >= 0) return a[h][w];
    if(h == H + 1) return f(h-1, w)%MOD;
    ll X = 0;
    ll Y = 0;
    ll Z = 0;
    for(ll bit = 0; bit < (1<<(W-1)); bit++){
        bool isNotNeibour = true;
        for(ll l = 0; l < (W - 2); l++){
            if((bit & (1 << l)) && (bit & (1 << (l + 1)))){
                isNotNeibour = false;
                break;
            
            }
        }
        if(isNotNeibour){
            if(bit & (1 << (w-2))){
                Y += 1; 
            }else if(bit & (1 << (w-1))){
                Z += 1; 
            }else{
                X += 1; 
            }
        }
    }
    return a[h][w] = (X * f(h-1, w)) % MOD + (Y * f(h-1, w-1)) % MOD + (Z * f(h-1, w+1)) % MOD;
    
}
int main(){
    cin >> H >> W >> K;
    REP(i, 0, H + 2){
        REP(j, 0, W + 2){
            a[i][j] = -1;
        }
    }
    cout << f(H + 1, K) << endl;
}



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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<int> P(N + 1);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &P[i]);
  }
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    if (i != P[i]) { continue; }
    ++ans;
    if (i == N) { swap(P[i], P[i - 1]); }
    else { swap(P[i], P[i + 1]); }
  }

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>

using namespace std;

#define long long long
#define ft(i, a, b) for (int i = (long)a ; i <= (long)b ; i++)
#define fd(i, a, b) for (int i = (long)a ; i >= (long)b ; i--)

const int mxN = 1e5 + 5;
const long oo = 1e15;

long n , m , x , total;

void Solve() {  
    if (total <= n) cout << n - total;
    else cout << "-1";
}

void FastInput() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
}

void Input() {
    cin >> n >> m;
    ft(i , 1 , m) cin >> x , total += x;
}

int main() {
    FastInput();
    Input();
    Solve();
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a[1000],b[1000],c[1000],d,n,m,x,y,k,h,w,sum,mi,ma,ans,s,t,l,r,res,tmp;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<int,int> > VP;

int main(){
    cin>>x>>y;
    while(x<=y){
        x*=2;
        ans++;
    }
    p(ans);
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 100010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }

int n, k ;
ll a[N], dp[N] ;

signed main(){
	scanf("%d%d", &n, &k) ;
	for (int i = 1; i <= n; i++) scanf("%lld", &a[i]) ;
	for (int i = 0; i <= n; i++) dp[i] = linf ;
	dp[1] = 0ll ;
	for (int i = 2; i <= n; i++)
	for (int j = 1; j <= min(i - 1, k); j++)
	dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j])) ;
	printf("%lld\n", dp[n]) ;
	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
*/


Measured memory_bytes: 1792
#include <stdio.h>

int map[9];

int sum(int a,int b,int c){
	return map[a]+map[b]+map[c];
}

int main(){
	int i,flag;
	int data[8];
	char str[10];

	while(scanf("%s",str) != EOF){
		for(i = 0;i < 9;i++){
			switch(str[i]){
			case 'o':
				map[i] = 1;
				break;
			case 'x':
				map[i] = -1;
				break;
			case 's':
				map[i] = 0;
				break;
			}
		}

		data[0] = sum(0,1,2);
		data[1] = sum(3,4,5);
		data[2] = sum(6,7,8);
		data[3] = sum(0,4,8);
		data[4] = sum(2,5,8);
		data[5] = sum(1,4,7);
		data[6] = sum(0,3,6);
		data[7] = sum(2,4,6);

		flag = 0;
		for(i = 0;i < 8;i++){
			if(data[i] == 3){
				flag = 1;
				break;
			}else if(data[i] == -3){
				flag = 2;
				break;
			}
		}

		if(flag == 1){
			printf("o\n");
		}else if(flag == 2){
			printf("x\n");
		}else{
			printf("d\n");
		}
	}

	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    ll N,D;cin>>N>>D;
    ll ans = 0;
    REP(i,N){
        ll x,y;cin>>x>>y;
        if(x*x + y*y <= D*D) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3544
#include<stdio.h>

int main(void){
    int N;
    scanf("%d",&N);
    int B[N-1];
    for(int i=0;i<N-1;i++){
        scanf("%d",&B[i]);
    }
    long long int sum = 0;
    sum += B[0];
    for(int i=1;i<N-1;i++){
        if(B[i-1]<B[i]){
            sum += B[i-1];
        }else{
            sum += B[i];
        }
    }
    sum += B[N-2];
    printf("%d",sum);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  int n; cin >> n;
  vector<int>H(n);
  rep(i,n) cin >> H[i];
  for (int i=n-1; i>=1; i--){
    if (H[i] >= H[i-1]) continue;
    else{
      H[i-1]--;
      if (H[i] < H[i-1]){
        //cout << i << "," << i-1 << endl;
        //cout << H[i] << endl;
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3712
{-# LANGUAGE OverloadedStrings #-}
import           Data.Attoparsec.ByteString.Char8
import qualified Data.ByteString.Char8            as B

main :: IO ()
main = do
  Right (n, m) <- parseOnly ((,) <$> decimal <* space <*> decimal) <$> B.getLine
  B.putStrLn $ if solve n m then "Yes" else "No"

solve :: Int -> Int -> Bool
solve = (==)

Measured memory_bytes: 508
N=int(input())
ans=next([x,y,N*x*y//(4*x*y-N*(x+y))]for x in range(1,3501)for y in range(1,3501)if 4*x*y>N*(x+y) and (N*x*y)%(4*x*y-N*(x+y))==0)
print(*ans)

Measured memory_bytes: 9048
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}

int main() {
	int a, b;
	cin >> a >> b;
	cout << (a - 1) * (b - 1);

}



Measured memory_bytes: 256
#include <cstdio>

/*
max(N- [x2, ..., xN] [ 1 2 3 4 ... 4 3 2], 0)

(1 + z + z^2 + ... + z^N) (1 + z^2 + z^4 + ... + z^{2N}) ...
f(z) = 1/[(1-z){(1-z^2)(1-z^3)...(1-z^{N/2})}^2]

[z^N] (N f(z) - z * f'(z))/(1-z)

log f = \sum_{i=2}^{N/2}

*/

int n, m;


int dp[5001];
int tmp[5001];

int main(){
  scanf("%d%d", &n, &m);

  dp[0] = 1;
  for(int i = 2; i <= n/2; i++){
    for(int j = i; j <= n; j++){
      dp[j] += dp[j-i];
      if(dp[j] >= m) dp[j] -= m;
    }
  }

  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= n - i; j++){
      tmp[i+j] = ((long long) dp[i] * dp[j] + tmp[i+j]) % m;
    }
  }

  if(n & 1){
    for(int j = (n+1)/2; j <= n; j++){
      tmp[j] += tmp[j-(n+1)/2];
      if(tmp[j] >= m) tmp[j] -= m;
    }
  }

  dp[0] = tmp[0];
  for(int i = 1; i <= n; i++){
    dp[i] = dp[i-1] + tmp[i];
    if(dp[i] >= m) dp[i] -= m;
  }

  int c = 0;
  for(int i = 0; i <= n; i++){
    c = (c + (long long) (n - i) * dp[i]) % m;
  }

  printf("%d\n", c);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
int n , k , s ;
int main()
{
	ios::sync_with_stdio(false) ;
    cin.tie(0) ;
    cin >> n >> k >> s ;
    for(int i = 1 ; i <= k ; i ++)
      cout << s << ' ' ;
    int x = 1e9 ;
    for(int i = k + 1 ; i <= n ; i ++)
    {
    	if(s == x)  cout << x - 1 << ' ' ;
    	else  cout << x << ' ' ;
	}
    return 0 ;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N) for (long long i = 0; i < N; i++)
#define ll long long

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> X(M);
    rep(i, M) { cin >> X[i]; }
    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }

    sort(X.begin(), X.end());
    vector<ll> diff(M);
    rep(i, M - 1) { diff[i] = X[i + 1] - X[i]; }
    sort(diff.begin(), diff.end());
    rep(i, N - 1) { diff.pop_back(); }
    ll ans = accumulate(diff.begin(), diff.end(), 0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,C = LI()
    a = [LI() for _ in range(n)]
    u = [_[0] for _ in a]
    x = [_[1] for _ in a]
    b = [0] * n
    c = [0] * n
    d = [0] * n
    e = [0] * n
    b[0] = x[0]
    c[-1] = x[-1]
    for i in range(1, n):
        b[i] = b[i-1] + x[i]
    for i in range(n-2, -1, -1):
        c[i] = c[i+1] + x[i]
    d[0] = x[0] - u[0]
    e[-1] = x[-1] - (C-u[-1])
    for i in range(1, n):
        d[i] = max(b[i]-u[i], d[i-1])
    for i in range(n-2, -1, -1):
        e[i] = max(c[i]-(C-u[i]), e[i+1])

    r = max(d[-1], e[0], 0)
    for i in range(n):
        if i < n-1 and r < b[i] - u[i] * 2 + e[i+1]:
            r = b[i] - u[i] * 2 + e[i+1]
        if i > 0 and r < c[i] - (C-u[i]) * 2 + d[i-1]:
            r = c[i] - (C-u[i]) * 2 + d[i-1]


    return r



print(main())

###

Measured memory_bytes: 42844
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int staq1[20000]={},l1=0;
void in(int a){staq1[l1++]=a;}
int out(){return staq1[--l1];}

int staq2[20000][2]={},l2=0;
void in2(int a,int b){staq2[l2][0]=a;staq2[l2][1]=b;l2++;}
int out2(){return l2--;}

int main(){
  int  sum = 0;
  char inp;
  
  for(int cnt=0; scanf("%c",&inp)!=EOF; cnt++){
    if(inp!='\\'&&inp!='/')continue;
    if(inp=='\\') in(cnt);
    else if(inp=='/'&&l1>0){
      int j = out();
      sum += cnt - j;
      int a = cnt - j;
      while(l2>0&&staq2[l2-1][0]>j){
	a+=staq2[l2-1][1];
	out2();
      }
      in2(j,a);
    }
  }
  printf("%d\n%d",sum,l2);
  if(sum!=0){
    cout<<" ";
    for(int i=0;i<l2-1;i++){
      printf("%d ",staq2[i][1]);
    }
    cout<<staq2[l2-1][1]<<endl;
  }
  else cout<<endl;
  return 0;  
}



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

const int MAX_N = 1000007;
const int MOD = 1000000007;
int X, Y;

ll modpow(ll x, int y)
{
	ll res = 1;
	while(y){
		if(y & 1) (res*=x)%=MOD;
		(x *= x) %= MOD;
		y>>=1;
	}
	while(res < 0) res += MOD;
	return res % MOD;
}

ll fact[MAX_N];
ll invf[MAX_N];

int binom(ll n, ll k)
{
    return (((fact[n]*invf[k])%MOD)*invf[n-k])%MOD;
}

void solve()
{
    if((X+Y)%3){
        cout << 0 << '\n';
    }else{
        invf[0]=invf[1]=fact[0]=fact[1]=1;
        for(ll i=2;i<MAX_N;++i){
            fact[i] = (fact[i-1]*i)%MOD;
            invf[i] = modpow(fact[i],MOD-2);
        }
        ll n = (X+Y)/3;
        ll x = (2*Y-X)/3, y = (2*X-Y)/3;
        if(x<0 || y<0) cout << 0 << '\n';
        else{
            cout << binom(n,x) << '\n';
        }
    }
}

int main()
{
	cin >> X >> Y;
	solve();
	return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  int N;
  scanf("%d",&N);
  std::vector<int > X(N);
  for (int i=0; i<N; i++){
    scanf("%d",&X[i]);
  }
  int sum_min = 1000000;
  for (int c=1; c<=100; c++){
    int sum = 0;
    for (int i=0; i<N; i++){
      sum += (int)pow(X[i]-c, 2);
    }
    sum_min = std::min(sum_min, sum);
  }
  printf("%d\n", sum_min);
  return 0;
}


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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; i++)
#define repn(i, st, ed) for(ll i=st; i<=ed; i++)
#define repb(i, ed, st) for(ll i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

int main()
{
	int n, m;
	cin>>n>>m;
	priority_queue<ll ,vector<ll>, greater<ll>> pq;
	rep(i, 0 ,n)
	{
		ll x;
		cin>>x;
		pq.push(x);
	}
	vector<pair<ll ,ll>> vp;
	rep(i, 0 ,m)
	{
		ll x, y;
		cin>>x>>y;
		vp.pb({y, x});
	}
	sort(all(vp), greater<pair<ll, ll>>());
	ll ans = 0;
	rep(i, 0, m)
	{
		if(pq.top() > vp[i].f || pq.empty()) break;
		ll num = vp[i].f, cnt = vp[i].s;
		while(cnt-- && pq.top() < num && !pq.empty())
		{
			ans += num;
			pq.pop();
		}
	}
	while(!pq.empty())
	{
		ans += pq.top(); pq.pop();
	}
	cout<<ans<<endl;
} 


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b) {a = b; return true;}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b) {a = b; return true;}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

ll dp[1005][5][2];

int main(){
    string s; cin >> s;
    ll K; cin >> K;
    ll n = s.size();
    dp[0][0][0] = 1;
    rep(i,n){
        rep(k,4){
            dp[i+1][k+1][1] += dp[i][k][1] * 9;
            dp[i+1][k][1] += dp[i][k][1];
            if(s[i]=='0'){
                dp[i+1][k][0] += dp[i][k][0];
            }else{
                dp[i+1][k][1] += dp[i][k][0];
                REP(j,1,s[i]-'0') dp[i+1][k+1][1] += dp[i][k][0];
                dp[i+1][k+1][0] += dp[i][k][0];
            }
        }
    }
    //print2(dp[n][K][0],dp[n][K][1]);
    cout << dp[n][K][0] + dp[n][K][1] << endl;
}

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

int main(){
  int A,B;
  cin >> A >> B;
  for(int i=1;i<1010;i++){
    if(int(i*0.08)==A&&int(i*0.1)==B){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
//| #######################|
//|  ADARSH SINGH KUSHWAHA |
//| ###################### |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Bahut_tej_gand_faad ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define frb(i, a, b) for(ll i = a - 1; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define mp map<ll,ll>
#define mps map<char,ll>
#define v vector<ll>
#define srt(v) sort(v.begin(),v.end())
#define mod 1000000007
#define max 1000001
void solve() {
    string s, t;
    cin >> s;
    cin >> t;
    ll c = 0, ans = INT_MAX;
    for (ll i = 0; i <= s.size() - t.size(); i++) {
        c = 0;
        for (ll j = 0; j < t.size(); j++) {
            if (s[i + j] != t[j]) {
                c++;
            }
        }
        if (c < ans) {
            ans = c;
        }
    }
    cout << ans << endl;
}
int main() {
    Bahut_tej_gand_faad;
    //int t;
    //cin >> t;
    //while (t--) {
    solve();
    //}
    return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;

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

        if (n != 100) {
            System.out.println((int) Math.pow(100, d) * n);
        } else {
            System.out.println((int) Math.pow(100, d) * (n + 1));
        }
    }
}




Measured memory_bytes: 22612
#include<stdio.h>

int l[7];

void dice(int num){
    l[0] = l[1];
    l[1] = l[num];
    l[num] = l[6];
    l[6] = l[7-num];
    l[7-num] = l[0];
}

int main(void){
    char order;
    for(int i=0; i<6; i++) scanf("%d", &l[i+1]);
    while(scanf("%c", &order)!=EOF){
        if(order=='N') dice(2);
        else if(order=='E') dice(4);
        else if(order=='S') dice(5);
        else if(order=='W') dice(3);
    }
    printf("%d\n", l[1]);
    return 0;
}


Measured memory_bytes: 2076
#include <bits/stdc++.h>
using namespace std;
int main() {
   int arr[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
   int k;
   cin>>k;
   if(k==32) cout<<arr[31]; else
   cout<<arr[k%32-1];
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <queue>
#include <map>

using namespace std;

#define ll long long
constexpr ll inf = 1e15+7;

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

    ll N, M, S, T;
    cin>>N>>M>>S>>T;
    struct Weight { ll a; ll b; };
    map<int, vector<pair<int, Weight>>> edges;
    for (int m = 0; m < M; m++) {
        int u, v, a, b;
        cin>>u>>v>>a>>b;
        Weight w = {a, b};
        edges[u].push_back(make_pair(v, w));
        edges[v].push_back(make_pair(u, w));
    }

    vector<ll> y_dst(N+1, inf);
    vector<ll> s_dst(N+1, inf);
    y_dst[S] = 0;
    s_dst[T] = 0;

    {
        priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
        q.push(make_pair(0, S));
        while (!q.empty()) {
            auto to = q.top();
            q.pop();
            if (y_dst[to.second] < to.first) continue;

            for (auto&& next : edges[to.second]) {
                if (y_dst[next.first] > y_dst[to.second] + next.second.a) {
                    y_dst[next.first] = y_dst[to.second] + next.second.a;
                    q.push(make_pair(y_dst[next.first], next.first));
                }
            }
        }
    }

    {
        priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
        q.push(make_pair(0, T));
        while (!q.empty()) {
            auto to = q.top();
            q.pop();
            if (s_dst[to.second] < to.first) continue;

            for (auto&& next : edges[to.second]) {
                if (s_dst[next.first] > s_dst[to.second] + next.second.b) {
                    s_dst[next.first] = s_dst[to.second] + next.second.b;
                    q.push(make_pair(s_dst[next.first], next.first));
                }
            }
        }
    }

    ll ans[N+1];
    ans[N] = (ll)1e15 - y_dst[N] - s_dst[N];
    for (int n = N-1; n >= 1; n--) {
        ans[n] = max(ans[n+1], (ll)1e15 - y_dst[n] - s_dst[n]);
    }

    for (int n = 1; n <= N; n++) cout<<ans[n]<<endl;
    return 0;
}

Measured memory_bytes: 19840
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main(args: Array<String>) {
    val (N, M) = readIntList()
    val s = Array(M) { readIntList().drop(1).toTypedArray().map { it } }
    val p = readIntList()

    var result = 0

    for (i in 0 until 1.shl(N)) {
        var ok = true
        for (j in 0 until M) {
            val switches = s[j]
            var count = 0
            for (k in switches) {
                if ((i shr (N - k) and 1) == 1) count++
            }

            if (p[j] != count % 2) ok = false
        }

        if (ok) result++
    }

    println(result)
}


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

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

  vector<double> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);

  cout << fixed << setprecision(6) << endl;

  double under = 0;

  for (int i = 0; i < N; i++){
    under += 1 / vec.at(i);
  }

  double ans = 1 / under;

  cout << ans << endl;
}

Measured memory_bytes: 3820
//#pragma comment(linker, "/STACK:1024000000,1024000000")
/* vim: set fdm=marker */
//{{{
#define __ return
int ATTENTION() {
	/* pls IGNORE this function and go down and HACK me
	 * read this AFTER contest
	 * this function is empty and it will not be called !
	 */

	http://codeforces.com/group/Pmz2A2x7ES
	/* I created a group there.
	 * I hope with the group, people can finish
	 * past contests, which is important for 
	 * increasing rating.
	 * I am still getting familiar with this function.
	 */
	 __ 0;
}
// deprecated because mac doesn't support this...
/* #include <bits/stdc++.h> */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int iinf = 0x7fffffff;
const ll linf = ~(1LL<<63);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;
template<typename T>
inline T gcd(T a, T b) {
	if(a < 0) return gcd(-a, b);
	if(b < 0) return gcd( a,-b);
	if(a < b) return gcd(b, a);
	if(b == 0) return a;
	return gcd(b, a%b);
}

ll qpow(ll a, ll n, ll mod) {
	a %= mod;
	ll ans = 1LL;
	while(n) {
		if(n & 1) ans = (ans*a % mod);
		a = (a*a % mod);
		n >>= 1;
	}
	return ans;
}

inline ll rev(ll a, ll p) {
	return qpow(a, p - 2, p);
}

#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define rep(x, st, en) for(int x = st; x < en; x++)
#define rer(x, st, en) for(int x = st; x >= en; x--)
#define pb push_back
#define mp make_pair
#define dbgm(msg, var) cerr<<#msg<<" "<<#var<<" = "<<var<<endl; 
#define dbg(var) cerr<<#var<<" = "<<var<<endl;
#define X first
#define Y second
// build prefix sum
template<typename T>
inline void BPS(T* DST, T* SRC, int N, int s = 0) {
	DST[s] = SRC[s];
	rep(i, 1, N) DST[s + i] = DST[s + i - 1] + SRC[s + i];
}
inline int in() { int x; cin>>x; return x; }
#ifdef ALNDBG
namespace alndbg {
	clock_t s, e;
}
#endif

inline void tic() {
#ifdef ALNDBG
	alndbg::s = clock();
#endif
}

inline void toc() {
#ifdef ALNDBG
	alndbg::e = clock();
	cerr<<1000.0 * (alndbg::e - alndbg::s) / CLOCKS_PER_SEC<<" ms"<<endl;
#endif
}



//}}}

// -------------------- Spliters ------------------------
// BFS求最短路小心vis可能访问过
const int maxn = 1000;
int getsum(int x) {
  int res = 0;
  while(x) {
    res += x % 10;
    x /= 10;
  }
  return res;
}
int main() {
  int N;
  scanf("%d", &N);
  int minval = N * 10;
  for(int i = 1; i < N; i++) {
    int sumA = getsum(i), sumB = getsum(N - i);
    int sm = sumA + sumB;
    if(sm < minval) minval = sm;
  }
  printf("%d\n", minval);
	return 0;
}
// --USE C++11
// *-USE O2



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

using namespace std;

using ll = long long int;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

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

	sort(a.begin(), a.end());

	ll tourists = 1;
	for (int i = 0; i < n - 1; i++) {
		tourists = a[i + 1] <= 2 * a[i] ? tourists + 1 : 1;
		a[i + 1] += a[i];
	}

	cout << tourists << endl;
	return 0;
}


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

int main() {
    string s;

    cin >> s;
    int count = 0;

    if (s[0] == '1') count++;
    if (s[1] == '1') count++;
    if (s[2] == '1') count++;

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
import math

if sys.platform =='ios':
    sys.stdin=open('input133b.txt')

#+++++

count = 0
n, d = map(int, input().split())
anums = []
for i in range(n):
	anums.append( list(map(int, input().split())))

for i in range(n):
	for k in range(n - i -1):
		num = 0
		for j in range(d):
			num += pow(abs(anums[i][j] - anums[i + k + 1][j]),2)

		sq = math.sqrt(num)
		if sq.is_integer():
			count += 1

print(count)

Measured memory_bytes: 13216
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int h, w, k; cin >> h >> w >> k; --w;
	
	const i64 MOD = 1e9 + 7;
	std::vector<std::vector<i64>> dp(h + 1, std::vector<i64>(w + 1, 0)); dp[0][0] = 1;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < (1 << w); j++) {
			bool f = true;
			for(int k = 0; k < w - 1; k++) {
				if((j >> k & 1) and (j >> (k + 1) & 1)) {
					f = false;
					break;
				}
			}
			
			if(!f) continue;
			
			for(int k = 0; k < w; k++) {
				if((j >> k) & 1) {
					(dp[i + 1][k + 1] += dp[i][k]) %= MOD;
					(dp[i + 1][k] += dp[i][k + 1]) %= MOD;
				} else if(k < w - 1 and !(j >> k & 1) and !(j >> (k + 1) & 1)) {
					(dp[i + 1][k + 1] += dp[i][k + 1]) %= MOD;
				}
			}
			
			if(!(j & 1)) {
				(dp[i + 1][0] += dp[i][0]) %= MOD;
			}
			
			if(w and w - 1 != 0 and !((j >> (w - 1)) & 1)) {
				(dp[i + 1][w] += dp[i][w]) %= MOD;
			}
		}
	}
	
	cout << dp[h][k - 1] << endl;			
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int X, N;
  cin >> X >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  sort(P.begin(), P.end());
  int res = 0, diff = 1000;
  for (int i = 0; i < 200; i++) {
    if (!binary_search(P.begin(), P.end(), i) && chmin(diff, abs(X - i))) {
      res = i;
    }
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 3640
from collections import deque, defaultdict, Counter
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
ab = [map(int, input().split()) for _ in range(N - 1)]
px = [map(int, input().split()) for _ in range(Q)]

# build tree
tree = defaultdict(list)
for a, b in ab:
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

# 同じノードがきたらまとめておく
# (複数回DFSしない)
dic = defaultdict(int)
for p, x in px:
    dic[p - 1] += x

ans = [0] * N
checked = [False] * N
q = deque([0])

while q:
    n = q.pop()
    checked[n] = True
    ans[n] += dic[n]
    for u in tree[n]:
        if checked[u]:
            continue
        ans[u] += ans[n]
        q.append(u)
print(*ans)

Measured memory_bytes: 206928
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	var input = input.split("\n");
	//文字列から10進数に変換するときはparseIntを使います
    var input2 = input[0].split("");
	var input3 = input[1].split("");
  
  	var cnt = 0
  
 	for(var i=0;i<3;i++){
     
      if(input2[i] == input3[i]){
        cnt ++
      }
    }	 
  	
  console.log(cnt)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372