akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


void Dijkstra(Graph& G, ll s, Array& d,Array &u,ll l) {//O(|E|log|V|)
	d.resize(G.size());
	u.resize(G.size());
	REP(i, d.size())d[i] = l;
	REP(i, u.size())u[i] = INF;
	d[s] = 0;
	u[s] = 0;
	priority_queue<pair<pair<ll,ll>,ll>,vector<pair<pair<ll,ll>,ll>>,greater<pair<pair<ll,ll>,ll>>> q;

	q.push(make_pair(make_pair(0,0), s));
	while (!q.empty()) {
		ll k = q.top().first.first;
		ll dd = q.top().first.second;
		ll v = q.top().second;
		//cout << k << dd << v<<endl;
		q.pop();
		if (u[v] < k)continue;
      if(d[v]>dd)continue;

		REP(i, G[v].size()) {
          
			Edge e = G[v][i];
          if(e.cap>l)continue;
			ll nd = dd + e.cap;
			ll nk = k;
			if (nd > l ) {
				nd = e.cap;
				nk++;
			}
			if (u[e.to] > nk) {
				u[e.to] = nk;
				d[e.to] = nd;
				q.push(make_pair(make_pair(nk,nd), e.to));
				//cout << "aa" << nk << nd << e.to<<endl;
			}
			else if (u[e.to] == nk && d[e.to] > nd) {
				d[e.to] = nd;
				q.push(make_pair(make_pair(nk, nd), e.to));
				//cout << "bb" << nk << nd << e.to << endl;
			}
		}
	}
}

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

	ll n,m,l;
	cin >> n >> m >> l;
	Graph g(n);
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b>>c;
		a--; b--;
		add_edge(g, a, b, c, true, c);
	}

	Matrix ans(n);
	Matrix d(n);

	REP(i, n) {
		Dijkstra(g, i, d[i], ans[i], l);
	}
	/*
	for (auto i : ans) {
		for (auto j : i) {
			cout << j << " ";
		}
		cout << endl;
	}
	*/
	
	ll q;
	cin >> q;

	REP(i, q) {
		ll s, t;
		cin >> s >> t;
		s--; t--;
		if (ans[s][t] != INF) {
			cout << ans[s][t] << endl;
		}
		else {
			cout << -1 << endl;
		}
	}




	return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
    template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
    template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
    template<typename T> void chadd(T& a, T b) { a = a + b; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
    };

    // 2次元用の標準入出力
    template<typename T>
    struct inpn {
        std::size_t szi, szj;
        inpn(std::size_t _szi, std::size_t _szj) : szi(_szi), szj(_szj) {}
        operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i)
                for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j];
            return a;
        }
    };

    inp inp1; // input one
}

int main() {

    int n = inp1;
    vector<char> s = inp(n);

    map<char, int> mp;

    rep(i, s.size()) {
        ++mp[s[i]];
    }

    if (mp.size() == 3) Cout("Three");
    else Cout("Four");

    return 0;
}

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

int main(void)
{
    string s, t;

    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    for(int i = 0; i < min(s.size(), t.size()); i++)
    {
        if(s.at(i) == t.at(i)) continue;
        if(s.at(i) < t.at(i))
        {
            cout << "Yes" << endl;
            return 0;
        }
        else
        {
            cout << "No" << endl;
            return 0;
        }
        
    }

    if(s.size() < t.size())
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    

    
   

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n;
    cin>>n;
    cout<<n*n*n<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
class _0023
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        double ax, ay, ar, bx, by, br, d;
        for (int i = 0; i < n; i++)
        {
            string[] data = Console.ReadLine().Split();
            ax = double.Parse(data[0]); ay = double.Parse(data[1]); ar = double.Parse(data[2]);
            bx = double.Parse(data[3]); by = double.Parse(data[4]); br = double.Parse(data[5]);
            d = Math.Sqrt(Math.Pow((ax - bx), 2.0) + Math.Pow((ay - by), 2.0));
            Console.WriteLine(ar + br < d ? 0 : (ar < br && d < br - ar ? -2 : (br < ar && d < ar - br ? 2 : 1)));
        }
    }
}

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

int64_t GCD(int64_t A, int64_t B) {
  int64_t a = max(A, B);
  int64_t b = min(A, B);
  int64_t r = a % b;
  while ( r != 0 ) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int64_t LCM(int64_t A, int64_t B) {
  int64_t gcd = GCD(A, B);
  return (A/gcd) * B;
}

int64_t count_two(int64_t A) {
  int64_t count = 0;
  while ( A % 2 == 0 ) {
    count++;
    A = A / 2;
  }
  return count;
}

int main() {
  //input
  int64_t N;
  int64_t M;
  cin >> N >> M;
  vector<int64_t> b(N);
  int64_t a;
  rep(i,N) {
    cin >> a;
    b.at(i) = a / 2;
  }
  //calc
  int64_t lcm = b.at(0);
  int64_t c2 = count_two(lcm);
  bool has_target = true;
  for(int64_t i = 1; i < N; i++) {
    if ( count_two(b.at(i)) != c2 ) {
      has_target = false;
      break;
    }
    lcm = LCM(lcm, b.at(i));
  }
  int answer = 0;
  if ( has_target ) {
    int64_t candidate = M/lcm;
    answer = candidate % 2 == 0 ? candidate / 2 : (candidate + 1) / 2;
  }
  //output
  cout << answer << endl;
}

Measured memory_bytes: 1024
import collections

[n,k] = list(map(int, input().strip().split()))

counts = collections.Counter()
for i in range(k):
	d = int(input().strip())
	
	arr = list(map(int, input().strip().split()))
	for num in arr:
		counts[num] += 1

ans = 0

for i in range(1, n+1):
	if counts[i] == 0:
		ans += 1
		
print(ans)

Measured memory_bytes: 9456
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int n[] = new int [N];
    int cnt = 0;
    
    for(int i = 0; i<N; i++){
      n[i] = sc.nextInt();
      if(n[i] >= K){
        cnt++;
      }
    }
    System.out.println(cnt);
  }
}

Measured memory_bytes: 50980
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  int count1=0;
  int count2=0;
  
  for (int i=0; i<N; i++) {
    if (s[i] == 'R') {
      count1++;
    }
    else {
      count2++;
    }
  }
  if (count1 > count2) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int N;
    int[] A;

    scan(N);
    A = readln.split.to!(int[]);

    long ans;

    void dfs(int i, int even) {
        if (i == N) {
            if (!even) ans++;
            return;
        }

        dfs(i + 1, even * ((A[i] - 1) & 1));
        dfs(i + 1, even * (A[i] & 1));
        dfs(i + 1, even * ((A[i] + 1) & 1));
    }

    dfs(0, 1);

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

int64_t get_gcd(int a, int b) {
    if(a == 0) { return b; }
    return get_gcd(b%a, a);
}

int main(void) {
    int num, k;
    cin >> num >> k;
    vector<int> arr(num);
    cins(arr);

    int res = 0;
    int mmax = 0;
    for(int i = 0; i < num; i++) {
        int val = arr[i];
        mmax = max(val, mmax);
        if(res > val) swap(res, val);
        res = get_gcd(res, arr[i]);
    }
    debug("gcd: %d\n", res);
    bool flag = 0;
    if(k > mmax) {
        flag = false;
    } else {
        flag = ((mmax-k)%res == 0);
    } 

    cout << (flag ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return 0;
}

Measured memory_bytes: 3716
import collections
n = int(input())
S = []
for i in range(n):
    S.append(input())

c = collections.Counter(S)
d = c.most_common()
values, counts = zip(*d)
M = max(counts)

M_counts = counts.count(M)
ans = []
for i in range(M_counts):
    ans.append(values[i])

ANS = sorted(ans)
for i in ANS:
    print(i)

Measured memory_bytes: 61088
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, Npow, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
//***********//
int main() {
	cin >> H >> W;
	vll A(H, vl(W, 0));
	vll B(H, vl(W, 0));
	vll D(H+1, vl(W+1, 0));
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			cin >> B[i][j];
			D[i+1][j+1] = abs(A[i][j] - B[i][j]);
		}
	}
	ll M = (H + W) * 80;
	vector<vll> dp(H+1, vll(W+1, vl(M, 0)));
	dp[1][1][D[1][1]] = 1;
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			for (k = 0; k < M; k++) {
				if (i == H && j == W) continue;
				if (i != H) {
					if (k + D[i + 1][j] < M) dp[i + 1][j][k + D[i + 1][j]] |= dp[i][j][k];
					if (abs(k - D[i + 1][j]) < M) dp[i + 1][j][abs(k - D[i + 1][j])] |= dp[i][j][k];
				}
				if (j != W) {
					if (k + D[i][j + 1] < M) dp[i][j + 1][k + D[i][j + 1]] |= dp[i][j][k];
					if (abs(k - D[i][j + 1]) < M) dp[i][j + 1][abs(k - D[i][j + 1])] |= dp[i][j][k];
				}
			}
		}
	}
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			for (k = 0; k < M; k++) {
				//if(dp[i][j][k]) debug(i, j, k, dp[i][j][k]);
			}
		}
	}
	for (k = 0; k < M; k++) {
		if (dp[H][W][k]) { 
			cout << k; 
			exit(0);
		}
	}
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> a[3];
    rep(i, N) {
        rep(j, 3) {
            ll num;
            cin >> num;
            a[j].push_back(num);
        }
    }

    ll res = 0;
    rep(bit, 1 << 3) {
        vector<ll> b;
        rep(i, N) {
            ll tmp = 0;
            rep(j, 3) {
                if (bit & (1 << j)) tmp += a[j][i];
                else tmp -= a[j][i];
            }
            b.push_back(tmp);
        }
        sort(b.begin(), b.end(), greater<ll>());
        ll sum = 0;
        rep(i, M) sum += b[i];
        res = chmax(res, sum);
    }
    cout << res << endl;
}

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

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<pair<int,int>> war;
    int N,M;
    cin >> N >> M;

    for (int i = 0; i < M ; ++i) {
        int tmp1,tmp2;
        cin >> tmp1 >> tmp2;
        war.emplace_back(make_pair(tmp1,tmp2));
    }

    sort(war.begin(),war.end(),
         [](const pair<int,int>& x, const pair<int,int>& y){return x.second < y.second;}
    );

    for(auto x:war){
     //   cout << x.first << "  " << x.second << endl;
    }
    int ans =0;
    int line =0;
    for(auto x :war){
        if(x.first > line){
            line = x.second-1;
            ans++;
        }

    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <queue>
#define N 200005
using namespace std;

int n, a[N], d[N][20];
struct st {
	int x, y, l, r;
};

bool operator < (st p, st q) {
	return a[p.x] > a[q.x];
}
priority_queue<st> qu;
int mn(int p, int q) {return a[p] < a[q] ? p : q;}

void f(int p, int q) {
	int i, t1, t2;
	if (q - p <= 0) return;
	if (q - p == 1) {
		qu.push({p, q, p, q});
		return;
	}
	for (i = 1; 1<<i <= q-p+1; i++);
	i--;
	t1 = mn(d[p][i], d[q - (1 << i) + 1][i]);
	if (q - t1 == 1) {
		qu.push({t1, q, p, q});
		return;
	}
	for (i = 1; 1<<i <= q-t1; i++);
	i--;
	t2 = mn(d[t1 + 1][i], d[q - (1 << i) + 2][i]);
	qu.push({t1, t2, p, q});
}
int main()
{
	int i, j, k;
	st t;
	cin >> n;
	for (i = 0; i < n; i++) {
		scanf ("%d", &a[i]);
		d[i][1] = i;
	}
	for (j = 2; 1<<j <= n; j++) {
		k = 1<<(j-1);
		for (i = 0; i + k < n; i++) {
			d[i][j] = mn(d[i][j - 1], d[i + k][j - 1]);
		}
	}
	f(0, n - 1);
//	f(0, 1);
//	f(0, 3);
	while (!qu.empty()) {
		t = qu.top(); qu.pop();
		printf("%d %d ", a[t.x], a[t.y]);
		f(t.l, t.x -1);
		f(t.x + 1, t.y - 1);
		f(t.y + 1, t.r);
	}
    return 0;
}


Measured memory_bytes: 18676
//DPCoded
	//

#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef set<int> si;
typedef set<string> ss;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef pair<int, int> ii;

	//#define FILEINOUT
#ifdef FILEINOUT
ifstream In("Input.txt");
ofstream Out("Output.txt");
#else
#define In cin
#define Out cout
#endif

void print(vb v) {
	for (bool t : v) {
		if (t) Out << "W";
		else Out << "R";
	}
	Out << endl;
}

int main() {
	
	int n;
	In >> n;
	
	vb v;
	
	for (int i = 0; i < n; i++) {
		char c;
		In >> c;
		if (c == 'R') v.push_back(false);
		else v.push_back(true);
	}
	
	int l = 0;
	int r = n - 1;
	int ans = 0;
	
	while (l < r) {
		while (l < n - 1 && !v[l]) l++;
		while (0 <= r && v[r]) r--;
		
		if (l >= r) continue;
		
		//swap(v[l], v[r]);
		//print(v);
		ans++;
		l++;
		r--;
	}

	Out << ans << endl;
	
	
	return 0;
}


Measured memory_bytes: 3192
#include <cstdio>
#define MOD 100000
typedef long long ll;
ll dp[100][100][2][2];  // i,j,k,l---(i,j)ツ債。ツつ「ツづゥツ地ツ点ツ、kツ債カツつゥツづァツ０ツ可コツつゥツづァツ１ツ、l=ツ陳シツ前ツづ凝按つェツづつスツつゥ?1:0
int main() {
    for (int i=0; i<100; i++) {
        dp[0][i][0][0]=dp[i][0][1][0]=1;
    }
    for (int i=1; i<100; i++) {
        for (int j=1; j<100; j++) {
            dp[i][j][0][0]=(dp[i][j-1][0][0]+dp[i][j-1][0][1])%MOD;
            dp[i][j][0][1]=dp[i][j-1][1][0]%MOD;
            dp[i][j][1][0]=(dp[i-1][j][1][0]+dp[i-1][j][1][1])%MOD;
            dp[i][j][1][1]=dp[i-1][j][0][0]%MOD;
        }
    }
    int w, h;
    while (scanf("%d%d",&w,&h)) {
        if (!w&&!h) break;
        ll res=(dp[h-1][w-1][0][0]+dp[h-1][w-1][0][1]+dp[h-1][w-1][1][0]+dp[h-1][w-1][1][1])%MOD;
        printf("%lld\n",res);
    }
}

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

#define ll long long

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define repA(i,A)   for(auto i:A)

#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>

#define endl "\n"

const ll logN = 20;
const ll N = 100005;
const ll M = 1000000007;
#define PI 3.14159265

int main(){
  int n;
  cin>>n;
  vector<ll> a(n);
  rep(i, 0, n) cin>>a[i];
  ll dp[n+3][n+3];
  repb(l, n-1, 0){
    rep(r, l, n){
      if(l == r) dp[l][r] = a[l];
      else
      dp[l][r] = max(a[l]-dp[l+1][r], a[r]-dp[l][r-1]);
//      cout<<dp[l][r]<<" ";
    }
//    cout<<endl;
  }
  cout<<dp[0][n-1];
  return 0;
}


Measured memory_bytes: 46464
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
	int n;
	cin>>n;

	vi v(n),p(n),q(n);

	forn(i,0,n)
	{
		cin>>p[i];
		v[i] = i+1;
	}
        
	forn(i,0,n)
	{
		cin>>q[i];
	}        


	int a = -1,b = -1;

	int count = 0;
	do
	{
		if(v == p) a = count;
		if(v == q) b = count;
		count++;
	}while(next_permutation(all(v)));

	cout<<abs(a-b);







    return 0;
}		

Measured memory_bytes: 256
#include <iostream>

int maxSum(int *a, int n) {
	int sum, max = a[0];
	for (int i = 0; i < n; ++i) {
		sum = 0;
		for (int j = i; j < n; ++j) {
			sum += a[j];
			if (sum > max) { max = sum; }
		}
	}
	return max;
}

int main() {
	int n;
	int *a;
	for (;;) {
		std::cin >> n;
		if (n <= 0) { break; }
		a = new int[n];
		for (int i = 0; i < n; ++i) {
			std::cin >> a[i];
		}
		std::cout << maxSum(a, n) << '\n';
		delete [] a;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000


int main(){

	int N;
	cin>>N;
	
	vector<long long> A(N+1);
	A[0]=2;
	A[1]=1;
	
	for(int i=2;i<=N;i++){
		A[i] = A[i-1]+A[i-2];
	}
	
	cout<<A.back()<<endl;
	
    return 0;
}



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


int main()
{
    double x;
    ll k;
    double d;
    double ans;
    scanf("%lf %lld %lf",&x,&k,&d);
    if(x<0)
    {
        x=-x;
    }
    
    if(x/d>k)
    {
        ans=x-d*k;
    }
    else
    {

        double memo=floor(x/d);
        x=x-memo*d;
        k=k-memo;

        if(k%2==0)
        {
            ans=x;
        }
        else
        {
            ans=d-x;
        }
        
    }
    


    printf("%lld\n",(ll)ans);

    return 0;
}

Measured memory_bytes: 2268
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<LLI> a(X), b(Y), c(Z);
    REP(i, X) { cin >> a[i]; }
    RSORT(a);
    REP(i, Y) { cin >> b[i]; }
    RSORT(b);
    REP(i, Z) { cin >> c[i]; }
    RSORT(c);

    vector<LLI> v;
    for(int i = 0; i < X; i++) {
        for(int j = 0; j < Y; j++) {
            for(int k = 0; k < Z; k++) {
                if((i + 1) * (j + 1) * (k + 1) <= K)
                    v.push_back(a[i] + b[j] + c[k]);
                else break;
            }
        }
    }
    RSORT(v);
    REP(i, K) { cout << v[i] << endl; }

    return 0;
}

Measured memory_bytes: 1404
import Control.Monad
import qualified Data.List as L

main :: IO ()
main = do
    [n, m] <- map read . words <$> getLine :: IO [Int]
    roads <- L.group . L.sort . (++) [1..n] . concat
        <$> replicateM m (map read . words <$> getLine) :: IO [[Int]] 
    mapM_ print $ map (\l-> length l - 1) roads

Measured memory_bytes: 1020
N,M = map(int,input().split())
ABNs = [list(map(int,input().split())) for _ in range(N)]

ABNs = sorted(ABNs)

r = M
newABNs = []
for i in range(len(ABNs)):
	if ABNs[i][1] <= r:
		r -= ABNs[i][1]
		newABNs.append(ABNs[i])
	else:
		newABNs.append([ABNs[i][0],r])
		break
		
#print(newABNs)

ans = 0
for i in range(len(newABNs)):
	ans += (newABNs[i][0]*newABNs[i][1])
	
print(ans)

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

int main() {

    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int cnt = 0;

    for (int a = 0; a <= A; ++a) {
        for (int b = 0; b <= B; ++b) {
            for (int c = 0; c <= C; ++c) {
                if (500*a + 100*b + 50*c == X) cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve() 
{
	int n , m;
	
	cin >> n >> m;
	
	int a[n+1] {};
	
	int vis[n+1] {};
	
	for(int i = 0; i < m; ++i) {
		int x;
		
		cin >> x;
		
		vis[x] = 1;
	}
	
	a[0] = 1;
	
	for(int i = 0; i < n; ++i) {
		if(vis[i]) {
			continue;
		}
		
		if(a[i] == 0) {
			break;
		}
		
		if(!vis[i+1]) {
			a[i+1] = (a[i+1] + a[i]) % mod;
		}
		if(i+2 <= n && !vis[i+2]) {
			a[i+2] = (a[i+2] + a[i]) % mod;
		}
	}
	
	cout << a[n];
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 5188
#include<iostream>
#include<string>
using namespace std;
 
int main()
{
    string str1, str2;
    string command;
    int a, b;
    int q;
    int i,j,k;
     
    cin >> str1 >> q;
 
    for(i=0;i<q;i++){
        cin >> command;
        if(command=="replace"){
            cin >> a >> b >> str2;
            k=0;
            for(j=a;j<=b;j++){
                str1[j]=str2[k];
                k++;
            }
        }
        else if(command=="reverse"){
            cin >> a >> b;
            k=b-a;
            str2=str1.substr(a,b-a+1);
            for(j=a;j<=b;j++){
                str1[j]=str2[k];
                k--;
            }
        }
        else if(command=="print"){
            cin >> a >> b;
            str2=str1.substr(a,b-a+1);
            cout << str2 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

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

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }
	if (n == r) { return 1; }

	if (r > n / 2) { r = n / 2; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(llvec array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return -1LL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int main() {
	int a,b; cin>>a>>b;
	double amin=(a+0.08-1)*12.5,amax=(a+1)*12.5,bmin=(b+0.1-1)*10,bmax=(b+1)*10;
	for(int i=max(amin,bmin); i<amax&&i<bmax; i++) {
		if((int)(i*0.08)!=a||(int)(i*0.1)!=b) continue;
		cout<<i<<endl;
		return 0;
	}
	cout<<-1<<endl;
}


Measured memory_bytes: 256
N,M = [int(a) for a in input().split()]
edges = {i:[] for i in range(1,N+1)}
for i in range(M):
  a,b = [int(a) for a in input().split()]
  edges[a].append(b)
  edges[b].append(a)

def search(lst):
  if len(lst) == N:
    return 1
  else:
    a = lst[-1]
    next = [n for n in edges[a] if n not in lst]
    if len(next) == 0:
      return 0

    tot = 0
    for n in next:
      tot += search(lst + [n])
    
    return tot


ans = search([1])

print(ans)

      


Measured memory_bytes: 9032
#include<cstdio>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define reg register
typedef long long ll;
inline int read(){
	reg int x=0,f=1;reg char ch=getchar();
	for(;ch>'9'||ch<'0';f=ch=='-'?-1:1,ch=getchar());
	for(;ch<='9'&&ch>='0';x=(x<<3)+(x<<1)+(ch^48),ch=getchar());
	return x*f;
}
int buf[15];
inline void write(int x){
	reg int cnt=0;
	if(!x){puts("0");return;}
	while(x)buf[++cnt]=x%10+48,x/=10;
	while(cnt)putchar(buf[cnt--]);
	puts("");
}
const int maxn=2e5+5;
int n,a[maxn],cnt[maxn],s[maxn];
int main(){
	n=read();reg int ans=0,m=read();
	for(reg int i=1;i<=n;i++)cnt[a[i]=read()]++;
	for(reg int i=1;i<=n;i++)
		if(cnt[i])s[max(i-cnt[i]+1,1)]++,s[min(i+1,n+1)]--;
	for(reg int i=1;i<=n;i++)ans+=!(s[i]+=s[i-1]);
	while(m--){
		reg int x=read(),y=read(),t=a[x];a[x]=y;
		if(t>=cnt[t]&&t<=cnt[t]+n-1)ans+=!(--s[t-cnt[t]+1]);
		cnt[t]--;cnt[y]++;
		if(y>=cnt[y]&&y<=cnt[y]+n-1)ans-=!(s[y-cnt[y]+1]++);
		write(ans);
	}
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

// 各iについてf(i,*)のargminとminをペアで返す
template<typename T, typename F, typename Compare = less<T>>
vector<pair<ll,T>> monotone_minima(ll h, ll w, const F &f, const Compare &comp = Compare()) {
    vector<pair<ll,T>> dp(h);
    function<void(ll,ll,ll,ll)> dfs = [&](ll top, ll bottom, ll left, ll right) {
        if(top > bottom) return;
        ll line = (top + bottom) / 2;
        ll idx = left;
        T mi = f(line, left);
        for(ll i=left+1; i<=right; ++i) {
            T cost = f(line, i);
            if(comp(cost, mi)) {
                mi = cost;
                idx = i;
            }
        }
        dp[line] = make_pair(idx, mi);
        dfs(top, line-1, left, idx);
        dfs(line+1, bottom, idx, right);
    };
    dfs(0, h-1, 0, w-1);
    return dp;
}

int main(void) {
    ll s, n, m;
    cin >> s >> n >> m;
    vector<ll> x(s), t(n), p(n);
    REP(i, s) cin >> x[i];
    REP(i, n) cin >> t[i] >> p[i], p[i]--;

    vector<ll> v(n);
    REP(i, n) v[i] = t[i] - x[p[i]];
    sort(ALL(v));
    vector<ll> rui(n+1);
    REP(i, n) rui[i+1] = rui[i]+v[i];

    vector<ll> dp(n+1, INF);
    dp[0] = 0;
    REP(k, m) {
        auto f = [&](ll i, ll j) {
            return i<j ? INF : dp[j]+(i?v[i-1]:0)*(i-j)-(rui[i]-rui[j]);
        };
        auto ndp = monotone_minima<ll>(n+1, n+1, f); 
        REP(i, n+1) dp[i] = ndp[i].second;
        dump(k, dp);
    }
    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 3356
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe

solve :: Int -> Maybe (Int, [[Int]])
solve n = do
  k <- getK n
  return $ (k, map (((k-1):) . aSet k) [0..k-1])
  where
    aSet k p = [p0+1 .. p0+p] ++ [toSum (j-1) + p + 1 | j <- [p+1 .. k-1]]
      where p0 = toSum (p-1)

toSum x = x * (x+1) `div` 2

getK :: Int -> Maybe Int
getK n = let k = ceiling (sqrt (fromIntegral (2*n)))
         in if k*(k-1) == 2*n then Just k
            else if (k+1)*k == 2*n then Just (k+1)
                 else Nothing

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Maybe (Int, [[Int]])
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
  in solve n

outAnswer :: Maybe (Int, [[Int]]) -> IO ()
outAnswer Nothing = putStrLn "No"
outAnswer (Just (n, xs)) = do
  putStrLn "Yes"
  putStrLn (show n)
  putStr (unlines (map (unwords . map show) xs))

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 2172
/*#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,pair<int,int> >&a,pair<int,pair<int,int> >&b)
{
   return a.second.first<b.second.first;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}

int main()
{
    fast_cin;
    int t;
    cin>>t;
    int tc=0;
    while(t--)
    {
      int n,w;
      cin>>n>>w;
      vector<int> val,wt;
      for(int i=0;i<n;i++)
      {
          int u;
          cin>>u;
          val.pb(u);
      }
      for(int i=0;i<n;i++)
      {
          int u;
          cin>>u;
          wt.pb(u);
      }
      int ans=0;
      for(int i=0;i<n;i++)
      {
          int netwt=w;
          int j=i;
          while(j<n)
          {

          }
      }
    cout<<ans<<endl;
    }
    return 0;
}*/
#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,pair<int,int> >&a,pair<int,pair<int,int> >&b)
{
   return a.second.first<b.second.first;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}
void binary(int n)
{
    // array to store binary number
    int binaryNum[32];

    // counter for binary array
    int i = 0;
    while (n > 0) {

        // storing remainder in binary array
        binaryNum[i] = n % 2;
        n = n / 2;
        i++;
    }

    // printing binary array in reverse order
    for (int j = i - 1; j >= 0; j--)
        cout << binaryNum[j];
}
int main()
{
    fast_cin;
    int t;
    t=1;
    int tc=0;
    ll x=10000009;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        int dp[n];
        for(int i=0;i<n;i++)
        {
          if(i)
             dp[i]=INT_MAX;
          else
            dp[i]=0;
        }
        vector<int> v;
        for(int i=0;i<n;i++)
        {
            int u;
            cin>>u;
            v.pb(u);
        }
        for(int i=1;i<n;i++)
        {
            int j=1;
            while(j<=i&&j<=k)
            {
                dp[i]=min(dp[i],dp[i-j]+abs(v[i-j]-v[i]));
                j++;
            }
        }
        cout<<dp[n-1];
    }
    return 0;
}


Measured memory_bytes: 5060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
typedef long long ll;
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> x;
    cout << !x << "\n";
    return 0;
}

Measured memory_bytes: 3648
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0501
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	while (1) {
		int n; cin >> n;
		if (!n) break;
		map<char, bool> m1;
		map<char, char> m2;
		for (int i = 0; i < n;i++) {
			char c1, c2; cin >> c1 >> c2;
			m1[c1] = true;
			m2[c1] = c2;
		}
		int m; cin >> m;
		for (int i = 0; i < m;i++) {
			char c; cin >> c;
			if (m1[c]) { cout << m2[c]; continue; }
			else cout << c;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3148
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

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

int main() {
  int n, m;
  cin >> n >> m;
  if (n == m) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

vector<vector<int>> T;
int visit[100010] = {};
int dist_u[100010] = {};
int dist_v[100010] = {};
int max_dist_v[100010];

void calc_dist(int n,int now, int d[]){
  visit[n] = 1;
  d[n] = now;
  for(int next : T[n]){
    if(visit[next])continue;
    calc_dist(next, now+1, d);
  }
}

int calc_max_dist_v(int n){
  visit[n] = 1;
  max_dist_v[n] = dist_v[n];
  for(int next : T[n]){
    if(visit[next])continue;
    max_dist_v[n] = max(max_dist_v[n], calc_max_dist_v(next));
  }
  return max_dist_v[n];
}

int main(void){
  int n, u, v;
  scanf("%d %d %d", &n, &u, &v);
  --u;--v;
  T = vector<vector<int>>(n);
  for(int i = 0;i < n-1;++i){
    int a,b;
    scanf("%d %d", &a, &b);
    --a;--b;
    T[a].push_back(b);
    T[b].push_back(a);
  }
  fill(visit, visit+100010, 0);
  calc_dist(u, 0, dist_u);
  fill(visit, visit+100010, 0);
  calc_dist(v, 0, dist_v);
  fill(visit, visit+100010, 0);
  calc_max_dist_v(v);
  int res = 0;
  for(int i = 0;i < n;++i){
    if(dist_u[i] >= dist_v[i]){
      continue;
    }
    int cost = max_dist_v[i] - 1;
    res = max(res, cost);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 11136
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <chrono>

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 1e9 + 7;
const double eps = DBL_EPSILON;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef LOCAL_DEBUG
	freopen("input.txt", "r", stdin);
#endif
	ll n, d, a;
	cin >> n >> d >> a;
	vector <pll> v(n);
	for (pll& i : v) cin >> i.ff >> i.ss;
	sort(all(v));
	ll ans = 0;
	int ptr = 0;
	vector<pll> pl;
	vector<ll> pr;
	for (int i = 0; i < n; i++) {
		if (!pl.empty() && pl.back().ff >= v[i].ff) {
			int l = 0, r = pl.size() - 1;
			while (l < r) {
				int m = (l + r) / 2;
				if (pl[m].ff >= v[i].ff) r = m;
				else l = m + 1;
			}
			if (l == 0) v[i].ss -= pr.back();
			else v[i].ss -= pr.back() - pr[l - 1];
		}
		if (v[i].ss > 0) {
			ll c = v[i].ss / a + (v[i].ss % a != 0);
			ll r = (v[i].ff + 2 * d);
			ans += c;
			pl.push_back({ r, c * a });
			if (pr.empty()) pr.push_back(c * a);
			else pr.push_back(pr.back() + c * a);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11248
import sys
sys.setrecursionlimit(1000000)

def get_root(s):
    if s != root[s]:
        root[s] = get_root(root[s])
        return root[s]
    return s

def unite(s, t):
    root_s = get_root(s)
    root_t = get_root(t)
    if not root_s == root_t:
        if rank[s] == rank[t]:
            root[root_t] = root_s
            rank[root_s] += 1
        elif rank[s] > rank[t]:
            root[root_t] = root_s
        else:
            root[root_s] = root_t

def same(s, t):
    if get_root(s) == get_root(t):
        return True
    else:
        return False

n, q = map(int, input().split())
root = [i for i in range(n)]
rank = [1 for _ in range(n)]

for _ in range(q):
    t, u, v = map(int, input().split())
    if t == 0:
        unite(u, v)
    else:
        print(1 if same(u, v) else 0)

Measured memory_bytes: 100184
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
	long long N, K;
	int A[2001];
	int b[2001];
	int i, j;
	cin >> N >> K;
	long long t1, t2;
	t1 = 0;
	for (i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	for (i = 0; i < N; i++)
	{
		for (j = i + 1; j < N; j++)
		{
			if (A[i] > A[j])
			{
				t1++;
			}
		}
	}
	for (i = 0; i <= 2000; i++)
		b[i] = 0;
	for (i = 0; i < N; i++)
	{
		b[A[i]]++;
	}
	t2 = N * N;
	for (i = 0; i <= 2000; i++)
	{
		t2 -= b[i] * b[i];
	}
	t2 /= 2;
	long long s = 0;
	s = K * (K - 1) / 2;
	s %= 1000000007;
	s *= t2;
	s %= 1000000007;
	s += t1 * K;
	s %= 1000000007;
	cout << s << endl;
    return 0;
}



Measured memory_bytes: 256
w, h = map(int, input().split())
lst1 = sorted(map(int, input().split()))
lst2 = sorted(map(int, input().split()))

while lst1:
  num = lst1.pop()
  for i in range(-1, -num - 1, -1):
    lst2[i] -= 1
  lst2.sort()

if sum(lst2) == 0 and min(lst2) == 0:
  print(1)
else:
  print(0)


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

const int MOD = 1e9 + 7;

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

  long long p = 1;
  for (int i = 1; i <= n; i++) {
    p *= i;
    p %= MOD;
  }
  cout << p << '\n';
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

dic = {"R": [], "G": [], "B": []}

N = int(input())
S = list(input().rstrip())

for i, s in enumerate(S):
    dic[s].append(i)

Bs = set(dic["B"])

ans = 0
for nr in dic["R"]:
    for ng in dic["G"]:
        if nr < ng:
            d = ng - nr
            nos = [nr - d, ng + d]
        else:
            d = nr - ng
            nos = [ng - d, nr + d]
        
        if (nr-ng)%2 == 0:
            nos.append((nr+ng)//2)
        
        ans += len(Bs)
        for no in nos:
            if no in Bs:
                ans -= 1

print(ans)

Measured memory_bytes: 68536
gets
aa = gets.split.map(&:to_i).sort

a_count = Hash.new(0)
for a in aa
  a_count[a] = a_count[a] + 1
end

selection = []
for a, count in a_count
  if count >= 2
    selection << {"n" => a, "count" => count}
  end
end

if selection.size >= 2
  sorted_selection = selection.sort{|a1, a2| a1["n"] <=> a2["n"] }.reverse
  x = 0
  y = 0
  if sorted_selection[0]["count"] >= 4
    x = sorted_selection[0]["n"]
    y = sorted_selection[0]["n"]
  else
    x = sorted_selection[0]["n"]
    y = sorted_selection[1]["n"]
  end 
  puts x*y
else
  puts 0
end


Measured memory_bytes: 24552
import java.util.Scanner;

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

        for(int i = 0; i < s.length() - 1; i++) {
            if(s.charAt(i) != s.charAt(i + 1)) {
                System.out.println("Yes");
                return;
            }
        }

        System.out.println("No");
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
  // keyence 2019 C - Exam and Wizard
  // N個の試験に全て合格しないといけない
  // 現在A、必要なのはB以上
  int N; cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  priority_queue<ll> AB; //A-Bがプラスになるもののみを保持する
  ll m_sum = 0; int m_cnt = 0;
  REP(i, N){
    if(A[i] < B[i]){
      m_sum += B[i] - A[i];
      m_cnt++;
    }else if(A[i] > B[i]){
      AB.push(A[i] - B[i]);
    }
  }
  if(m_sum == 0){
    cout << 0 << endl;
    return 0;
  }
  int p_cnt = 0;
  while (!AB.empty()){
    m_sum -= AB.top(); AB.pop();
    p_cnt++;
    if(m_sum <= 0) break;
  }
  if(m_sum > 0){
    cout << -1 << endl;
  }else{
    cout << m_cnt + p_cnt << endl;
  }
}

Measured memory_bytes: 2428