akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cassert>
#include <queue>
#include <deque>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <cstdlib>
#include <string>
#include <unordered_map>
#include <sstream>
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef unsigned char byte;
typedef unsigned int uint;
typedef unsigned long long int ulli;

int A[200100], B[200100];

int main() {
    int i, v, n, r = 0;
    scanf("%d", &n);
    for (i=0; i<n; ++i) {
        scanf("%d", A+i);
    }
    for (i=0; i<n; ++i) {
        scanf("%d", B+i);
    }
    for (i = 28; i >= 0; --i) {
        int c = 0;
        v = (1 << (i+1)) - 1;
        for (int j=0; j<n; ++j) {
            A[j] &= v;
            B[j] &= v;
        }
        sort(B, B+n);
        v = 1 << i;
        for (int j=0; j<n; ++j) {
            if (A[j] < v) {
                c += lower_bound(B, B+n, 2 * v - A[j]) - lower_bound(B, B+n, v - A[j]);
            } else {
                c += lower_bound(B, B+n, 2 * v - A[j]) - lower_bound(B, B+n, 3 * v - A[j]) + n;
            }
            c &= 1;
        }
        r |= (c << i);
    }
    printf("%d\n", r);
    return 0;
}


Measured memory_bytes: 1664
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll x; cin >> x;
  if(x >= 2000){
    cout << 1 << endl;
    return 0;
  }
  
  else{
    rep(i,21){
      rep(j,21){
        rep(k,21){
          rep(l,21){
            rep(m,21){
              rep(n,21){
                if(100*i+101*j+102*k+103*l+104*m+105*n == x){
                  cout << 1 << endl;
                  return 0;
                }
              }
            }
          }
        }
      }
    }
  }
  
  cout << 0 << endl;
  
  
}

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

int main(){
	int h, w;
	while(true) {
		scanf("%d%d", &h, &w);
		if(h == 0 && w == 0) break;
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				if((i + j) % 2)
					printf(".");
				else
					printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
}



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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
int n;
ll x, a[maxn];
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n>>x;
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }
  ll ans = 0;
  for (int i=0; i+1<n; i++) {
    if (a[i] + a[i+1] > x) {
      ll need = a[i]+a[i+1]-x;
      ans += need;
      ll take = min(need, a[i+1]);
      a[i+1] -= take;
      need -= take;
      if (need > 0) {
	a[i] -= need;
      }
    }
  }

  cout<<ans<<endl;
  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    bitset<4000001> b;
    b.set(0);
    for (int i = 0; i < n; ++i) {
        b |= b << v[i];
    }
    int x = b.count(), cnt = 0;
    for (int i = 1; i < 4000001; ++i) {
        if(b[i]){
            if(cnt == (x-2)/2){
                cout << i << "\n";
                return 0;
            }
            cnt++;
        }
    }
    return 0;
}


Measured memory_bytes: 1664
N, K = map(int, input().split())
A = [0]*N
count = 0
for _ in range(K):
  d  = int(input())
  x = list(map(int, input().split()))
  for s in x:
    A[s-1]+=1

for x in A:
  if x == 0:
    count +=1
print(count)


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

int main() {
    int a, b, ans;
    scanf("%d %d", &a, &b);
    ans = a + b;
    ans = max(ans, a - b);
    ans = max(ans, a * b);
    printf("%d", ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <limits>

using namespace std;

template <typename T>
struct Dinic {
	struct edge {
		int to, rev;
		T cap;

		edge() {}
		edge(int to, int cap, int rev) :to(to), cap(cap), rev(rev) {}
	};

	const T INF = numeric_limits<T>::max();

	vector<vector<edge> > G;
	vector<int> level, iter;

	Dinic() {}
	Dinic(int n) :G(n), level(n), iter(n) {}

	void add_edge(int from, int to, T cap, bool directed = true) {
		G[from].emplace_back(to, cap, G[to].size());
		G[to].emplace_back(from, (directed ? 0 : cap), G[from].size() - 1);
	}

	void bfs(int s) {
		fill(level.begin(), level.end(), -1);
		queue<int> q;
		level[s] = 0;
		q.push(s);
		while (!q.empty()) {
			int v = q.front(); q.pop();
			for (auto& e : G[v]) {
				if (e.cap > 0 && level[e.to] == -1) {
					level[e.to] = level[v] + 1;
					q.push(e.to);
				}
			}
		}
	}

	T dfs(int v, int t, T f) {
		if (v == t) return f;
		for (int& i = iter[v]; i < G[v].size(); ++i) {
			edge& e = G[v][i];
			if (e.cap > 0 && level[v] < level[e.to]) {
				T d = dfs(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	T max_flow(int s, int t) {
		T flow = 0;
		while (true) {
			bfs(s);
			if (level[t] == -1) break;
			fill(iter.begin(), iter.end(), 0);
			while (true) {
				T f = dfs(s, t, INF);
				if (f == 0) break;
				flow += f;
			}
		}
		return flow;
	}
};

int main() {
	int V, E; cin >> V >> E;
	Dinic<int> G(V);
	for (int i = 0; i < E; ++i) {
		int u, v, c; cin >> u >> v >> c;
		G.add_edge(u, v, c);
	}
	cout << G.max_flow(0, V - 1) << endl;

	return 0;
}


/*
	created: 2019-10-23
	https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/6/GRL_6_A
*/


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

int main(){
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> ans;
  for (int i=1; i<=100; i++){
    if (A%i==0&&B%i==0){
      ans.push_back(i);
    }
  }
  cout << ans[ans.size()-K] << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<string.h>
#include<string>
#include<math.h>
#include <array>
#include <list>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;


template <class T>
class _Point{
public:
	T x;
	T y;
	int index;		//max 500000;
};

typedef int R;
typedef _Point<R> Point;

array< Point, 500000> A;
typedef pair<R,int> X_IDX;

int main(){
	std::istream & c_in = cin;

	int n;
	c_in >> n;
	for (int i = 0; i < n; ++i)
	{
		Point &p = A[i];
		c_in >> p.x >> p.y;
		p.index = i;
	}
	vector<X_IDX> LA;
	LA.resize(n);
	for (size_t j = 0; j < LA.size(); ++j)
	{
		LA[j] = X_IDX(A[j].x, A[j].index);
	}
	sort(LA.begin(), LA.end());

	
	int q;
	c_in >> q;

	vector<int> match_idx;
	match_idx.resize(LA.size());

	for (int j = 0; j < q; ++j)
	{
		R sx, tx, sy, ty;
		c_in >> sx >> tx >> sy >> ty;

		int size_of_match = 0;
		//for (vector<X_IDX>::iterator it = LA.begin(); it != LA.end(); ++it)
		X_IDX xx(sx, 0);
		vector<X_IDX>::iterator it = lower_bound(LA.begin(), LA.end(), xx);
		for (; it != LA.end(); ++it)
		{
			if (it->first < sx)
			{
				continue;
			}
			if (it->first > tx)
			{
				break;
			}
			int &y = A[it->second].y;
			if (sy <= y && y <= ty)
			{
				match_idx[size_of_match++] = it->second;
			}
		}
		sort(match_idx.begin(), match_idx.begin() + size_of_match);
		for (int k = 0; k < size_of_match;++k)
		{
			printf("%d\n", match_idx[k]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 14180
#include <bits//stdc++.h>
using namespace std;
int main(void){
    int a,b,c,i,j,k;
    string s;
    cin>>a>>b>>s;
    if(s[b-1]=='A')
    s[b-1]='a';
    else if(s[b-1]=='B')
    s[b-1]='b';
    else 
    s[b-1]='c';
    for(i=0;i<a;i++)
    cout<<s[i];
    cout<<endl;
   
}


Measured memory_bytes: 256
Printf.printf "%d\n" @@ Scanf.scanf "%d %d" @@ fun n x ->
  let rec f y z =
    if y mod z = 0 then 2*y - z else 2*z*(y/z) + f z (y mod z) in
  if n-x >= x then n + f (n-x) x else n + f x (n-x)

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

int cmpint(const void* n1, const void* n2)
{
    if (*(int*)n1 > * (int*)n2) {
        return -1;
    }
    else if (*(int*)n1 < *(int*)n2) {
        return 1;
    }
    else {
        return 0;
    }
}

int main() {
    int k, n;
    int h[200000] = {};
    long long ans;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++){
        scanf("%d", &h[i]);
    }
    qsort(h, n, sizeof(int), cmpint);
    for (int i = k; i < n; i++) {
        ans += h[i];
    }
    
    printf("%ld\n", ans);
    return 0;
}


Measured memory_bytes: 1788
N = int(input())
S = [input() for _ in range(N)]
A = [[0,1,2],[0,1,3],[0,1,4],[0,2,3],[0,2,4],[0,3,4],[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
chrs = {'M':0,'A':1,'R':2,'C':3,'H':4}
X = [0]*5
for i in S:
    if(i[0] in chrs):
        X[chrs[i[0]]] += 1
ans = 0
for i in A:
    ans += X[i[0]]*X[i[1]]*X[i[2]]
print(ans)


Measured memory_bytes: 9776
s = input()

for i in range(2**3):
    op = ["-", "-", "-"]
    for j in range(len(op)):
        if (i>>j) &1:
            op[len(op)-j-1] = "+"
    if eval(s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3])==7:
        print(s[0]+op[0]+s[1]+op[1]+s[2]+op[2]+s[3]+"=7")
        break

Measured memory_bytes: 9140
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ll N;
    cin >> N;
    if(N == 2){
        cout << 1 << endl;
        return 0;
    }
    ll cnt = 2;
    for(ll i=2; i*i<=N; i++){
        if(N%i == 1){
            cnt++;
        }
        if((N-1)%i == 0){
            if((N-1)/i != i){
                cnt++;
            }
        }
        if(N%i == 0){
            ll t = N;
            while(t%i == 0){
                t /= i;
            }
            if(t%i == 1) cnt++;
            if(i == N/i) continue;
            t = N;
            while(t%(N/i) == 0){
                t /= (N/i);
            }
            if(t%(N/i) == 1) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <string.h>
#include <sstream>
#include <cctype>
#include <climits>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <vector>
#include <iterator>
#include <algorithm>
#include <stack>
#define _clr(x,y) memset(x,y,sizeof(x))
#define _inf(x) memset(x,0x3f,sizeof(x))
#define pb push_back
#define mp make_pair
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
typedef long long LL;
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	#ifndef ONLINE_JUDGE
		//freopen("in.txt","r",stdin);
		//freopen("out.txt","w",stdout);
	#endif
	
	LL n,a,b,x[100000+5]={};
	LL ans=0;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++) cin>>x[i];
	for(int i=2;i<=n;i++)
	{
		ans+=min(b,a*(x[i]-x[i-1]));
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
use std::io::*;
use std::str::*;

fn read_from_stdin<T: FromStr>() -> T {
    let temp = stdin();
    let mut temp = temp.lock();
    read(&mut temp).unwrap()
}

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s.by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read_from_stdin();
    let mut array = Vec::new();
    for i in 1..n + 1 {
        let a: i64 = read_from_stdin();
        array.push(a - i as i64);
    }
    array.sort();

    if n % 2 == 0 {
        let (b_pre, b_suc) = (array[n / 2 - 1], array[n / 2]);
        let res_pre: i64 = array.iter().map(|x| (x - b_pre).abs()).sum::<i64>();
        let res_suc: i64 = array.iter().map(|x| (x - b_suc).abs()).sum::<i64>();
        println!("{}", std::cmp::min(res_pre, res_suc));
    } else {
        let b = array[n / 2];
        let res: i64 = array.iter().map(|x| (x - b).abs()).sum::<i64>();
        println!("{}", res);
    }
}


Measured memory_bytes: 6396
S=input()
ACGT=['A','C','G','T']
ans=0
tmp=0
for s in S:
  if tmp==0:
    if s in ACGT:
      tmp+=1
      if ans==0: ans=1
  else:
    if s in ACGT:
      tmp+=1
      if tmp>ans: ans=tmp
    else:
      tmp=0
print(ans)

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


int main() {
	long long A, B;
	cin >> A >> B;

	if (A == B) {
		cout << "Draw" << endl;
	}
	else if (A == 1) {
		cout << "Alice" << endl;

	}
	else if (B == 1) {
		cout << "Bob" << endl;

	}
	else if (A > B) {
		cout << "Alice" << endl;
	}
	else if (A < B) {
		cout << "Bob" << endl;

	}


	return 0;

}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  int n, m; cin >> n >> m;
  int64_t sum = 0;
  vector<tuple<int64_t, int64_t, int64_t>> data;
  rep(i, n) {
    int64_t x, y, z; cin >> x >> y >> z;
    data.emplace_back(x, y, z);
    //xsum += x, ysum += y, zsum += z;
    sum += x + y + z;
  }

  int64_t max_sum = 0;  

  for (int xf = -1; xf < 2; xf += 2)
  for (int yf = -1; yf < 2; yf += 2)
  for (int zf = -1; zf < 2; zf += 2) {
    const auto xyzsummer = [&](tuple<int64_t, int64_t, int64_t> const& t) {
      return get<0>(t) * xf + get<1>(t) * yf + get<2>(t) * zf;
    };
    sort(data.begin(), data.end(), [&](const auto& lhs, const auto& rhs) {
      return xyzsummer(lhs) > xyzsummer(rhs);
    });
    int64_t sum = 0;
    rep(i, m) {
      sum += xyzsummer(data[i]);
    }
    maximize(max_sum, sum);
  }
  cout << max_sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    vector<int> alpha(26, 0);
    string S;
    cin >> S;

    rep(i, S.size()) {
        alpha[S[i] - 'a']++;
    }

    int flag = false;
    rep(i, 26) {
        if (alpha[i] == 0) {
            char s = i + 'a';
            cout << s << endl;
            flag = true;
            break;
        }
    }

    if (!flag) cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

ll n, k;

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

    cin >> k >> n;

    if(k % 2 == 0) {
        cout << k / 2 << " ";
        FOR(i, 1, n) cout << k << " \n"[i == n - 1];
        return 0;
    }

    V<int> vec(n, k + 1 >> 1);
    int j = n;
    rep(i, n - i - 1) {
        if(--vec[--j] == 0) continue;
        while(++j < n)
            vec[j] = k;
    }

    rep(i, j) cout << vec[i] << " \n"[i == j - 1];

    return 0;
}

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

using namespace std;
#define rep(i,m,n) for(int i=m;i<n;++i)
#define llrep(i,m,n) for(ll i=m;i<n;++i)
#define inf 1000000000
#define llinf 1000000000000000000
#define mod 1000000007
#define mmod 998244353
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define all(v) v.begin(),v.end()

vector<ll>fac;
ll power(ll a, ll b, ll m);
ll combination(ll n, ll i);

int main() {
	ll n, m, k;
	cin >> n >> m >> k;
	fac.push_back(1);
	llrep(i, 1, n + 1) {
		fac.push_back((fac[i - 1] * i) % mmod);
	}
	ll ans = 0;
	llrep(i, 0, k + 1) {
		ll hoge = m * power(m - 1, n - 1 - i, mmod) % mmod;
		ans += hoge * combination(n, i) % mmod;
	}
	ans %= mmod;
	cout << ans << endl;
	return 0;
}

ll power(ll a, ll b, ll m) {
	ll ans = 1;
	ll hoge = a;
	while (b != 0) {
		if (b & 1) {
			ans = ans * hoge % m;
		}
		hoge = hoge * hoge % m;
		b >>= 1;
	}
	return ans;
}

ll combination(ll n, ll i) {
	ll hoge = power(fac[i], mmod - 2, mmod) * power(fac[n - 1 - i], mmod - 2, mmod) % mmod;
	return hoge * fac[n - 1] % mmod;
}

Measured memory_bytes: 5320
def warshall_floyd(graph):
    dist = [[1e9 for i in range(10)] for k in range(10)]
    for i in range(10):
        dist[i][i] = 0
    for i in graph:
        for k in range(9):
            dist[i][graph[i][k][0]] = graph[i][k][1]
    for i in range(10):
        for k in range(10):
            for j in range(10):
                dist[k][j] = min(dist[k][j],dist[k][i] + dist[i][j])
    return dist


h,w = map(int,input().split())
graph = dict()
for i in range(10):
    graph[i] = []

for i in range(10):
    temp = list(map(int,input().split()))
    for k in range(10):
        if i != k:
            graph[i].append([k,temp[k]])
dist = warshall_floyd(graph)
a = []
ans = 0
for i in range(h):
    temp = list(map(int,input().split()))
    for k in range(w):
        if temp[k] > 1 or temp[k] == 0:
            ans += dist[temp[k]][1]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll int64_t
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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


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

struct Node{
    int key;
    Node *prev,*next;
};

Node *nil;

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

Node* listSearch(int key){
    Node *cur = nil->next;
    while( cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t){
    if(t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
        if(cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d",cur->key);
        cur = cur->next;
    }
    printf("\n");
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    init();
    char com[21];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int key;
        scanf("%s",com);
        if(com[0]=='i'){
            scanf("%d",&key);
            insert(key);
        }
        else if(com[0]=='d'){
            if(strlen(com)>6){
                if(com[6]=='F')deleteFirst();
                if(com[6]=='L')deleteLast();
            }else{
                scanf("%d",&key);
                deleteKey(key);
            }
        }
    }
    Node *now=nil->next;
    while(now!=nil){
        printf("%d%c",now->key,now->next==nil?'\n':' ');
        now=now->next;
    }
    return 0;
}


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

#define ll long long
#define ar array

const int mxN=2e3;
int n, x, y, ans[mxN];

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

	cin >> n >> x >> y, --x, --y;
	for(int i=0; i<n; ++i) {
		for(int j=i+1; j<n; ++j) {
			int d=min(j-i, abs(i-x)+1+abs(j-y));
			++ans[d];
		}
	}
	for(int i=1; i<n; ++i)
		cout << ans[i] << "\n";
}

Measured memory_bytes: 256
import sys
import numpy as np

def judge(bef, aft):
    t, a, b = map(int, np.abs(aft-bef))
    if a+b <= t and (a+b)%2 == t%2:
        return True
    return False
    
def main():
    input = sys.stdin.readline
    n = int(input())
    bef = np.array([0, 0, 0])
    flag = True
    for i in range(n):
        aft = np.array([int(x) for x in input().split()])
        if judge(bef, aft):
            continue
        flag = False
    if flag:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 14548
#include <iostream>
#include <vector>
using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

int N, M;
Graph G;
vector<int> us, vs;

bool rec(int v, int p, int target, long long &path) {
    if (v == target) {
        path = 0;
        return true;
    }
    for (auto e : G[v]) {
        if (e.first == p) continue;
        if (rec(e.first, v, target, path)) {
            path |= (1LL<<e.second);
            return true;
        }
    }
    return false;
}

long long solve() {
    vector<long long> paths(M, 0);
    for (int i = 0; i < M; ++i) rec(us[i], -1, vs[i], paths[i]);
    long long res = 0;
    for (long long bit = 0; bit < (1<<M); ++bit) {
        long long val = 0;
        for (int i = 0; i < M; ++i) if (bit & (1LL<<i)) val |= paths[i];
        long long remnum = N-1 - __builtin_popcountl(val);
        if (__builtin_popcountl(bit) % 2 == 0) res += 1LL<<remnum;
        else res -= 1LL<<remnum;
    }
    return res;
}

int main() {
    cin >> N;
    G.assign(N, vector<Edge>());
    for (int i = 0; i < N-1; ++i) {
        int x, y; cin >> x >> y; --x, --y;
        G[x].emplace_back(y, i);
        G[y].emplace_back(x, i);
    }
    cin >> M;
    us.resize(M), vs.resize(M);
    for (int i = 0; i < M; ++i) {
        cin >> us[i] >> vs[i];
        --us[i], --vs[i];
    }
    cout << solve() << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int n;
int a[105];
int main()
{
	while(scanf("%d", &n) != EOF)
	{
		int sum = 0;
		for(int i = 1; i <= n; i++)
		{
			scanf("%d", &a[i]);
			sum += a[i];
		}
		if(sum % 10 != 0) printf("%d\n", sum);
		else
		{
			bool f = 0;
			sort(a + 1, a + n + 1);
			for(int i = 1; i <= n; i++)
			{
				if((sum - a[i]) % 10 != 0)
				{
					sum -= a[i];
					f = 1;
					break;
				}
			}
			if(f == 1) printf("%d\n", sum);
			else printf("0\n");
		}
		memset(a, 0, sizeof(a));
	}
	return 0;
}

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

int main()
{
	ll h, w, k;
	cin >> h >> w >> k;
	vector<string> S(h);
	for (auto &s : S)
		cin >> s;

	vector<vector<ll>> ANS(h, vector<ll>(w));

	{
		int now = 0;
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if(S[i][j]=='#')
				{
					ANS[i][j] = ++now;
				}
			}
		}
	}
	for(int i = 0;i<h;i++)
	{
		for(int j = 1;j<w;j++)
		{
			if(ANS[i][j]==0)ANS[i][j] = ANS[i][j-1];
		}
		for(int j = w-2;j>=0;j--)
		{
			if(ANS[i][j]==0)ANS[i][j] = ANS[i][j+1];
		}
	}
	
	for(int i = 0;i<w;i++)
	{
		for(int j = 1;j<h;j++)
		{
			if(ANS[j][i]==0)ANS[j][i] = ANS[j-1][i];
		}
		for(int j = h-2;j>=0;j--)
		{
			if(ANS[j][i]==0)ANS[j][i] = ANS[j+1][i];
		}
	}
	for(int i = 0;i<h;i++)
	{
		for(int j = 0;j<w;j++)
		{
			if(j)cout << ' ';
			cout << ANS[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 4484
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;

int main() {
	int i;
	long long int k;
	string s;

	cin >> s;
	cin >> k;

	if (k == 1) {
		cout << s[0];
	}
	else if (s[0] == '1') {
		for (i = 1; i < k - 1; i++) {
			if (s[i] != '1') {
				cout << s[i];
				break;
			}
		}
		if (i == k - 1)
			cout << s[i];
	}
	else {
		cout << s[0];
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		long D = scan.nextLong();
		long T = scan.nextLong();
		long S = scan.nextLong();
		String ans = (D>T*S)?"No":"Yes";
		System.out.println(ans);
	}
}

Measured memory_bytes: 26960
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<bitset>
#include<tuple>
#include<time.h>
#include<list>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

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



int h, n, a[10101], b[10101];
int dp[10101];
void solve(){
	cin >> h >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	
	fill(dp+1, dp+10101, INF);
	for(int i = 0; i < h; i++){
		for(int j = 0; j < n; j++){
			chmin(dp[min(h,i+a[j])], dp[i]+b[j]);
		}
	}
	cout << dp[h] << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    ll n, x, t;
    cin >> n >> x >> t;
    if(n % x == 0){
        cout << t * (n / x) << endl;
    }else{
        cout << t * ((n / x) + 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll k,n,maxn,pos;
double a[200005],b[200005],ans;
int main()
{
    //IOS;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        b[i]=b[i-1]+a[i];
    }
    for(int i=k; i<=n; i++)
    {
        if(b[i]-b[i-k]>maxn)
        {
            maxn=b[i]-b[i-k];
            pos=i-k+1;
        }
    }
    for(int j=pos; j<=k+pos-1; j++)
    {
        ans+=(((a[j]*(a[j]+1))/(double)2)/a[j]);
    }
    printf("%.12f",ans);
    return 0;
}
/*

*/


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll MOD = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    string s; cin>>s;
    ll n=s.size();
    ll ans=0,cnt=0;
    rep(i,n){
        if(s[i]=='A'||s[i]=='G'||s[i]=='T'||s[i]=='C'){
            cnt++;
        }else cnt=0;
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


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

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

  string o, e;
  cin >> o >> e;

  string ans = "";
  for (int i = 0; i < o.size(); i++) {
    ans += o[i];

    if (i >= e.size()) break;

    ans += e[i];
  }

  cout << ans << endl;

  return 0;
}

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

main(){
  int n,q;
  cin>>n;
  vector<int>v(n);
  r(i,n)cin>>v[i];
  cin>>q;
  while(q--){
    int a,l,r,s=0;
    cin>>l>>r>>a;
    for(;l<r;l++)s+=v[l]==a;
      cout<<s<<endl;
  }
}



Measured memory_bytes: 3100
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String res = "";
        switch (s.charAt(0)){
            case 'S':
                res = "Cloudy";
                break;
            case 'C':
                res = "Rainy";
                break;
            case 'R':
                res = "Sunny";
        }
        System.out.println(res);
        sc.close();
    }
}

class io{
    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }
}

class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


}



Measured memory_bytes: 19156
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n; string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < n-1; ++i) {
        if(s[i]+s[i+1] == 'O'+'X') {
            ans++;
            s[i] = s[i+1] = '?';
        }
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3320
import random

#--------粒　子　群　最　適　化------------------------------

#評価関数: z=-abs(total_yen-10000*x-5000*y-1000*(maisuu-x-y))
def criterion(x, y):
    z=-abs(total_yen-10000*x-5000*y-1000*(maisuu-x-y)) +min(0,maisuu-x-y)
    return z

#粒子の位置の更新を行う関数
def update_position(x, y, vx, vy):
    new_x = x + vx
    new_y = y + vy

    return new_x, new_y

#粒子の速度の更新を行う関数
def update_velocity(x, y, vx, vy, p, g, w=1, ro_max=0.14,v_max=5):
    #パラメーターroはランダムに与える
    ro1 =random.uniform(0, ro_max)
    ro2 =random.uniform(0, ro_max)
    #粒子速度の更新を行う
    new_vx = int((w * vx + ro1 * (p["x"] - x) + ro2 * (g["x"] - x)))
    new_vy = int((w * vy + ro1 * (p["y"] - y) + ro2 * (g["y"] - y)))
    if abs(new_vx)>v_max:
        new_vx=int(v_max*new_vx/abs(new_vx))
    if abs(new_vy)>v_max:
        new_vy=int(v_max*new_vy/abs(new_vy))

    #print(new_vx, new_vy)
    return new_vx, new_vy
    
def main():
    N = 2000  #粒子の数
    x_min, x_max = 0, total_yen//10000+1
    y_min, y_max = 0, 8
    #粒子位置, 速度, パーソナルベスト, グローバルベストの初期化を行う
    ps = [{"x": random.randint(x_min, x_max), 
        "y": random.randint(y_min, y_max)} for i in range(N)]
    vs = [{"x": 0, "y": 0} for i in range(N)]

    personal_best_positions = list(ps)
    personal_best_scores = [criterion(p["x"], p["y"]) for p in ps]

    best_particle = personal_best_scores.index(max(personal_best_scores))
    global_best_position = personal_best_positions[best_particle]

    T = 100  #制限時間(ループの回数)
    for t in range(T):
        for n in range(N):
            x, y = ps[n]["x"], ps[n]["y"]
            vx, vy = vs[n]["x"], vs[n]["y"]
            p = personal_best_positions[n]
            #粒子の位置の更新を行う
            new_x, new_y = update_position(x, y, vx, vy)
            ps[n] = {"x": new_x, "y": new_y}
            #粒子の速度の更新を行う
            new_vx, new_vy = update_velocity(
                new_x, new_y, vx, vy, p, global_best_position)
            vs[n] = {"x": new_vx, "y": new_vy}
            #評価値を求め, パーソナルベストの更新を行う
            score = criterion(new_x, new_y)
            if score > personal_best_scores[n]:
                personal_best_scores[n] = score
                personal_best_positions[n] = {"x": new_x, "y": new_y}
        #グローバルベストの更新を行う
        best_particle = personal_best_scores.index(max(personal_best_scores))
        global_best_position = personal_best_positions[best_particle]
#        print(max(personal_best_scores), global_best_position["x"], global_best_position["y"])

    #最適解
    return max(personal_best_scores), global_best_position["x"], global_best_position["y"]


#--------------------------------------------------------------

maisuu,total_yen =[int(i) for i in input().split()]
best=-100000000
xx=0
yy=0
for i in range(1):
    kouho_best, kouho_x, kouho_y=main()
    if best<kouho_best:
        best=kouho_best
        xx=kouho_x
        yy=kouho_y
if best<0 or xx<0 or yy<0 or maisuu-xx-yy<0:
    print(-1,-1,-1)
else:
    print(xx,yy,maisuu-xx-yy)



Measured memory_bytes: 5480
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >>N;
  
  for(int i=0; i<N; i++){
    string S;
    cin >>S;
    
    if(S=="Y"){
      cout <<"Four"<<endl;
      break;
    }
    
    if(i==N-1){
      cout <<"Three"<<endl;
    }
    
  }
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}


template <typename T>
class Seg_Tree{
public: // 0-index
  vector<T> dat;
  T initial,M;
  int n;
  T unite(T a,T b){//
    return min(a,b);
  }
  Seg_Tree(int n0_=1,T initial_=1,T M_=1){
    initsize(n0_,initial_,M_);
  }
  void initsize(int n0,T initial_,T M_){
    M = M_;
    initial = initial_;
    int k=1;
    while(1){
      if(n0<=k){
        n=k;
        dat.resize(2*n-1);
        for(int i=0;i<2*n-1;i++)dat[i]=initial;
        break;
      }
      k*=2;
    }
  }
 
  //i banme wo x nisuru
  void update(int i,T x){
    i += n-1;
    dat[i] = x;
    while(i>0){
      i = (i-1) / 2;
      dat[i] = unite(dat[i*2+1],dat[i*2+2]);
    }
  }
 
  //[a,b)
  T query0(int a,int b,int k,int l,int r){
    if(r<=a || b<=l)return initial;
    if(a<=l && r<=b)return dat[k];
    else{
      T vl = query0(a,b,k*2+1,l,(l+r)/2);
      T vr = query0(a,b,k*2+2,(l+r)/2,r);
      return unite(vl,vr);
    }
  }
 
  //return [a,b)
  T query(int a,int b){
    return query0(a,b,0,0,n);
  }
};

class UnionFind{
public:
	vector<int> par;
	int Components;
	//0-indexed
	void init(int n = 1){
		Components = n;
		par.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i;
	}
	int root(int x = 1){
		if(par[x]==x)return x;
		return par[x] = root(par[x]);
	}
	void unite(int x = 1,int y = 1){
		x = root(x);
		y = root(y);
		if(x==y)return;
		par[x] = y;
		Components--;
	}
	int setsize(){
		return Components;
	}
};

int main(){
	ll N,K;
	cin >> N >> K;
	vector<ll> p(N);
	for(auto &&x:p) cin >> x;

	Seg_Tree<ll> sg_min(N,N+1,MOD),sg_max(N,N+1,MOD);//RMQ
	
	FOR(i,0,N){
		sg_min.update(i,+p[i]);
		sg_max.update(i,-p[i]);
	}

	vector<ll> to(N);
	to[N-1] = N-1;
	FORR(i,0,N-1){
		if(p[i]<p[i+1]){
			to[i] = to[i+1];
		}else{
			to[i] = i;
		}
	}

	int r = -1;
	UnionFind uf;
	uf.init(N-K+1);
	FOR(i,0,N-K){
		if(((sg_min.query(i,i+K)==p[i]) && (sg_max.query(i+1,i+K+1)==-p[i+K]))){
			uf.unite(i,i+1);
		}
	}
	FOR(i,0,N-K+1){
		if(to[i]>=i+K-1){
			if(r>-1){
				uf.unite(i,r);
			}else{
				r = i;
			}
		}
	}
	cout << uf.setsize() << endl;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int mod=998244353;
const int maxn=100010;
int k,n,N,tmp,ans,jc[maxn],iv[maxn],ivjc[maxn],cnt;
int C(int x,int y) {
	if (x<y||y<0) return 0;
	return (ll)jc[x]*ivjc[x-y]%mod*ivjc[y]%mod;
}
void update(int &x,int y) {
	x+=y; if (x>=mod) x-=mod;
}
int main() {
	
	read(k); read(n);
	jc[0]=iv[0]=ivjc[0]=jc[1]=iv[1]=ivjc[1]=1;
	for (int i=2;i<=10000;i++) {
		jc[i]=(ll)jc[i-1]*i%mod;
		iv[i]=(ll)(mod-mod/i)*iv[mod%i]%mod;
		ivjc[i]=(ll)ivjc[i-1]*iv[i]%mod;
	}
	for (int m=2;m<=2*k;m++) {
		cnt=0;
		for (int i=1;i<=k;i++)
			if (i<=m-i&&m-i<=k) cnt++;
		ans=0;
		for (int i=0;i<=cnt;i++) {
			N=n-i*2;
			if (N<0) break;
			tmp=(ll)C(N+k-1,k-1)*C(cnt,i)%mod;
			if (i&1^1) update(ans,tmp);
			else update(ans,mod-tmp);
		}
		printf("%d\n",ans);
	}
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    vll cnt(100001, 0);
    rep(i, n){
        cin >> a[i];
        cnt[a[i]]++;
    }
    ll types = 0;
    rep(i, 100001){
        types += (cnt[i] >= 1);
    }
    ll ans = (types % 2 ? types : types - 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

a, b = MAP()

if a*b <= 0:
	print("Zero")
elif (b-a+1)%2 and b < 0:
	print("Negative")
else:
	print("Positive")

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

int main(){
    string S;
    cin>>S;
    if(S[6]>='5'||S[5]=='1')                               cout<<"TBD"<<endl;
    else if(S[5]=='0'&&S[8]=='3'&&S[9]=='1')    cout<<"TBD"<<endl;
    else                                        cout<<"Heisei"<<endl;                                       
    return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <iostream>

using namespace std;

int main() {
    int a, b;
    while (~scanf("%d %d", &a, &b)) {
        if (a % 2 && b % 2) {
            printf("Yes\n");
        } else
            printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;
ll INF = 1e10;

int main()
{
	int i = 1;
	vector<int> x;
	while (true)
	{
		int tmp;
		cin >> tmp;
		if (tmp == 0)break;
		else x.push_back(tmp);
	}
	rep(i, x.size()) co("Case " << i + 1 << ": " << x[i]);
	return 0;
}



Measured memory_bytes: 3196
package main

import (
	"fmt"
)

func main() {
	// Code for D - Line++
	var n, x, y int
	fmt.Scanf("%d %d %d", &n, &x, &y)

	c := map[int]int{}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				continue
			}

			r := Min([]int{
				Abs(j - i),
				Abs(x - 1 - j) + Abs(y - 1 - i) + 1,
				Abs(x - 1 - i) + Abs(y - 1 - j) + 1,
			})

			k, ok := c[r]
			if ok {
				c[r] = k + 1
			} else {
				c[r] = 1
			}
		}
	}

	for k := 1; k <= n-1; k++ {
		s, ok := c[k]
		if ok {
			fmt.Println(s / 2)
		} else {
			fmt.Println(0)
		}
	}
}

func Abs(x int) int {
	if x < 0 {
		return - x
	}

	return x
}

func Min(l []int) int {
	m := l[0]
	for _, x := range l {
		if x < m {
			m = x
		}
	}

	return m
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
	int r,c;
	while (cin >> r >> c){
		if (!(r | c)) break;
		for (int i=0;i<r;i++){
			cout << '#';
			for (int j=0;j<c-2;j++){
				cout << ((i == 0 || i == r - 1) ? '#' : '.');
			}
			cout << '#';
			cout << endl;
		}
		cout << endl;
	}
}


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

using namespace std;

long long inf=1000000007;

int main(){
	long long n,k;
	cin>>n>>k;
	vector<long long> tower(n);
	vector<long long> tallest(n,-1);
	for(long long i=0;i<n;i++){
		cin>>tower.at(i);
		tallest.at(i)=max(tallest.at(max((long long)0,i-1)),tower.at(i));
	}

	long long ans=inf*1000;

	for(long long tmp=0;tmp<(1<<n);tmp++){
		bitset<15> bits=tmp;
		long long cnt=0;
		for(long long i=0;i<n;i++){
			if(bits.test(i)) cnt++;
		}
		if(cnt!=k) continue;

		long long pre=0;
		vector<long long> high=tallest;
		for(long long i=0;i<n;i++){
			if(!bits.test(i)) continue;

			if(i==0 || high.at(i-1)<tower.at(i)){
				pre+=0;
			}else{
				pre+=high.at(i)-tower.at(i)+1;

				long long now=high.at(i)+1;
				for(long long j=i;j<n;j++){
					high.at(j)=max(high.at(j),now);
				}
			}
		}

		ans=min(ans,pre);
	}

	cout<<ans<<endl;

	return 0;
}


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

int main(){

    int a;
    int x,y,z;

    cin>>a;

    x=a%10;//1の位
    y=(a-x)%100/10;//10の位
    z=(a-x-y*10)%1000/100;//100の位


    cout<<x+y+z<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i,4){
        if(s[i] == '+')ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
cnt = 0
for i in range(X,N+1):
    if i in A:
        cnt += 1
cntmin = cnt
cnt = 0
for i in range(X,-1,-1):
    if i in A:
        cnt += 1
cntmin = min(cntmin,cnt)
print(cntmin)

Measured memory_bytes: 38288