akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

struct Edge {
	int to, cap, rev;
};

#define INF 1e9

bool used[1000];
vector< vector<Edge> > G;

void add_edge(int from, int to, int cap) {
	G[from].push_back( (Edge){to, cap, G[to].size()} );
	G[to].push_back( (Edge){from, 0, G[from].size()-1} );
}
int dfs(int s, int t, int f) {
	if (s == t) return f;
	used[s] = true;
	for (int i = 0; i < G[s].size(); ++i) {
		Edge& e = G[s][i];
		if ( !used[e.to] && e.cap > 0 ) {
			int 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;
}

int max_flow(int s, int t) {
	int res = 0;
	while (1) {
		fill(used, used+1000, false);
		int f = dfs(s, t, INF);
		if ( f == 0 ) break;
		res += f;
	}
	return res;
}

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}

int main() {
	int M, N;
	while ( cin >> M >> N, M || N ) {
		vector<int> v1(M), v2(N);
		for (int i = 0; i < M; ++i) {
			cin >> v1[i];
		}
		for (int i = 0; i < N; ++i) {
			cin >> v2[i];
		}
		int s = M+N, t = M+N+1;
		G.clear(); G.resize(t+1);
		for (int i = 0; i < M; ++i) {
			for (int j = 0; j < N; ++j) {
				if (gcd(v1[i], v2[j]) > 1) {
					add_edge(i, M+j, 1);
				}
			}
		}
		for (int i = 0; i < M; ++i) {
			add_edge(s, i, 1);
		}
		for (int i = 0; i < N; ++i) {
			add_edge(M+i, t, 1);
		}
		cout << max_flow(s, t) << endl;
	}
}

Measured memory_bytes: 5524
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string S;
  cin >> S;
  
  int size = S.size();
  int num = 0;
  bool ok = false;

  
  size = (size-1) / 2 * 2;
 
  for (int i = size; i > 0; ) {
  	int count = 0;
    
    for (int j = 0; j < i/2; j++) {
      if(S[j] != S[i/2 + j])
        break;
      if(j == i/2 - 1 && S[j] == S[i/2 + j])
        ok = true;
    }
    
    if(ok == true){
      num = i;
      break;
    }
    
    i = i - 2;
  }
  
  cout << num << endl;
  
  /*
  if(num > 0){
    cout << num << endl;
  }else {
    num = 1;
    cout << num << endl;
  }*/
  
 
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d))
    {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String u, nl = System.getProperty("line.separator");
		StringBuilder 
			p = new StringBuilder(1024),
		  	d = (new StringBuilder(128)).append("."),
		  	s = (new StringBuilder(128)).append("#"),
		  	k = new StringBuilder(128);
		Scanner r = new Scanner(System.in);
		int h, w, ww = 0x10;
		while (0 != (ww >>= 1)) {
			d.append(d);
			s.append(s);
		}
		ww = d.length();
		while (0 != ((h = r.nextInt()) | (w = r.nextInt()))) {
			while (w > ww) {
				d.append(d);
				s.append(s);
				ww = d.length();
			}
			p.append(u = s.substring(0, w)).append(nl);
			k.setLength(0);
			k.append(d.substring(0, w)).append(nl)
			.replace(0, 1, "#").replace(w - 1, w, "#");
			while (2 != h--) {
				p.append(k);
			}
			p.append(u).append(nl).append(nl);
		}
		System.out.print(p);
	}
}

Measured memory_bytes: 18376
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,m]=i2()
e=[[] for i in range(n+100)]
for i in range(m):
 [a,b]=i2()
 e[a].append(b)
 e[b].append(a)

import sys
sys.setrecursionlimit(10**6)
d=[0 for i in range(n+100)]
dd=[]
def dfs1(v):
   d[v]=1
   for i in e[v]:
      if d[i]==0:
         dd.append(i)
         dfs1(i)
         break
ddd=[]
def dfs2(v):
   d[v]=1
   for i in e[v]:
      if d[i]==0:
         ddd.append(i)
         dfs2(i)
         break
dfs1(1)
dfs2(1)
l=ddd[::-1]+[1]+dd
print(len(l))
print(*l)


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

using namespace std;

void solve() {
    vector<string> S(3);
    cin >> S[0] >> S[1] >> S[2];
    int player, next_player;
    player = 0;
    while(1)
    {
        if (S[player].length() == 0)
        {
            if (player == 0)
            {
                cout << "A" << endl;
            }
            else if (player == 1)
            {
                cout << "B" << endl;
            }
            else
            {
                cout << "C" << endl;
            }
            return;
        }
        
        if(S[player][0] == 'a')
        {
            next_player = 0;
        }
        else if (S[player][0] == 'b')
        {
            next_player = 1;
        }
        else
        {
            next_player = 2;
        }
        S[player].erase(0,1);
        player = next_player;
        
    }
}

int main() {
    solve();
    return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w;
    cin >> n >> w;
    ll arr[n][2];
    for(ll i=0;i<n;i++){
        cin >> arr[i][0] >> arr[i][1];
    }
    ll dp[n+1][w+1];
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=w;j++){
            if(i==0 || j==0){
                dp[i][j]=0;
            }else if(arr[i-1][0]<=j){
                dp[i][j] = max( arr[i-1][1] + dp[i-1][j-arr[i-1][0]] , dp[i-1][j] );
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[n][w];

    return 0;
}


Measured memory_bytes: 79232
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int n, m;

int is_matched(const vector<string> _a, const vector<string> _b, int _i, int _j) {
    for (int k=0; k<m; k++) {
        for (int l=0; l<m; l++) {
            if (_a[_i+k][_j+l] != _b[k][l])
                return 0;
        }
    }

    return 1;
}

int matching(const vector<string> _a, const vector<string> _b) {
    for (int i=0; i<n-m+1; i++) {
        for (int j=0; j<n-m+1; j++) {
            if (is_matched(_a, _b, i, j))
                return 1;
        }
    }

    return 0;
}



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

    vector<string> a;
    for (int i=0; i<n; i++) {
        string input;
        cin >> input;
        a.push_back(input);
    }

    vector<string> b;
    for (int j=0; j<m; j++) {
        string input;
        cin >> input;
        b.push_back(input);
    }

    if (matching(a, b)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,0,-1};
const static int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

struct Star {
  int x;
  int y;
  int brightness;
  Star(int x,int y,int brightness) 
    : x(x), y(y), brightness(brightness) {}
  bool operator>(const Star& s) const {
    return brightness > s.brightness;
  }
};

int main(){
  int total_stars;
  int brightness_limit;
  while(~scanf("%d %d",
               &total_stars,
               &brightness_limit)){

    priority_queue<Star,vector<Star>,greater<Star> > que;
    for(int star_i = 0; star_i < total_stars; star_i++){
      int x;
      int y;
      int brightness;
      scanf("%d %d %d",&x,&y,&brightness);
      que.push(Star(x,y,brightness));
    }

    int lower_idx = 0;
    vector<Star> stars;

    multiset<int> xs;
    multiset<int> ys;

    ll res = 0;
    while(!que.empty()){
      Star s = que.top();
      que.pop();

      while(lower_idx < stars.size()
            && s.brightness - stars[lower_idx].brightness > brightness_limit){
        xs.erase(xs.find(stars[lower_idx].x));
        ys.erase(ys.find(stars[lower_idx].y));
        lower_idx++;
      }
      xs.insert(s.x);
      ys.insert(s.y);
      stars.push_back(s);

      res = max(res,(ll)(*(--xs.end()) - *xs.begin()) * (ll)(*(--ys.end()) - *ys.begin()));
    }
    printf("%lld\n",res);
  }
}

Measured memory_bytes: 25124
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;

int main(){
	int T,X;
	cin>>T>>X;
	cout<<(double)T/X<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define HAIRETU(N,A) for(int i=0;i<N;i++) cin >>A[i]
using namespace std;

int ptr, ctr, res;

int main() {
    int N;
    cin >> N;
    
    int A[100050] = {};
    HAIRETU(N, A);
    
    sort(A, A+N);
    
    while (ptr < N) {
        int cc=A[ptr], f=0;
        while(ptr < N && A[ptr] == cc){
            f++;
            ptr++;
            
        }
        res+=f%2;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int A,B,C;
    cin>>A>>B>>C;
    if(A == 5 && B == 5 && C ==7 ){
        cout << "YES" <<endl;
    }else if(A == 5 && B == 7 && C ==5 ){
        cout << "YES" <<endl;
        }else if(A == 7 && B == 5 && C ==5 ){
        cout << "YES" <<endl;
        }else{
            cout << "NO" <<endl;
        }
     
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

//map
int main()
{
    int N;
    cin >> N;
    vector <double> v(N);
	REP(i,N)
	{
		cin >> v[i];
	}
	sort(v.begin(),v.end());

	double moto = v[0];
	for(int i = 1; i < N; ++i)
	{
		moto += v[i];
		moto /= 2.0;
	}

    cout << moto << endl;

    return 0;
}

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

int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    int A;
    for(int i=0; i<M; i++)
    {
        scanf("%d", &A);
        N-=A;
    }
    if(N<0)
    {
        N=-1;
    }
    printf("%d", N);
    return 0;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;

#define pb push_back
#define F  first
#define S  second
#define int ll
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

const int MOD = 1e9 + 7, N = 5e5 + 10;
const ll LINF = LLONG_MAX;


int32_t main() {
    fast();
	int n;
	cin >> n;
	int sum=0,c=1;
	while(n>0){
		sum+=c;
		c*=2;
		n/=2;
	}
	cout<<sum;


    return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N, X, M;
    cin >> N >> X >> M;

    vl used(M, 0);
    ll st = 0, now = X, T = 0, stcnt = 0;
    rep(i, N){
        if(used[now]){
            T = i + 1 - used[now];
            stcnt = i - T;
            break;
        }
        st += now, used[now] = i + 1;
        now = now * now % M;
    }

    ll sum = 0;
    rep(t, T){
        sum += now;
        now = now * now % M;
    }
    st -= sum;

    if(T == 0 or used[0] > 0){
        cout << st + sum << endl;
        return 0;
    }

    st += (N - stcnt) / T * sum;
    rep(i, (N - stcnt) % T){
        st += now;
        now = now * now % M;
    }

    cout << st << endl;
}

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

int main(){
	vector<int> v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k; cin>>k;
	cout<<v[k-1]<<endl;
}

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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i = (int)m; i < (int)n; i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPM(i,m,n) for(int i = (int)m; i >= (int)n; i--)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

//------------------------------------------------------

const ll MAX_N = 1000010;
ll fact[MAX_N];
ll fact_inv[MAX_N];

ll bin_pow_mod(ll x, ll y) { //x^y mod
    if (x == 0) return 0;
    ll prod = 1;
    while (y > 0) {
        if (y % 2 == 1) prod = (prod * x) % MOD;
        x = (x * x) % MOD;
        y /= 2;
    }
    return prod % MOD;
}

void init_fact() {
    fact[0] = fact_inv[0] = 1;

    REP(i, 1, MAX_N) {
        fact[i] = (fact[i - 1] * i) % MOD;
        fact_inv[i] = bin_pow_mod(fact[i], MOD - 2);
    }
}

ll comb_mod(ll n, ll r) {
    if (n < r) return 0;
    else return ((fact[n] * fact_inv[n - r]) % MOD * fact_inv[r]) % MOD;
}

int main() {
    int n;
    cin >> n;
    ll a[n + 1];
    rep(i, n + 1) cin >> a[i];
    map<int, bool> mp;

    int two_num;

    rep(i, n + 1) {
        if (mp[a[i]]) two_num = a[i];
        else mp[a[i]] = true;
    }

    bool middle = false;
    int side = 0;

    rep(i, n + 1) {
        if (a[i] == two_num) {
            middle = !middle;
            continue;
        }
        if (!middle) side++;
    }

    init_fact();

    rep2(i, n + 1) {
        cout << (comb_mod(n + 1, i) - comb_mod(side, i - 1) + MOD) % MOD << endl;
    }

    return 0;
}



Measured memory_bytes: 22272
text = list(input())
atcoder_char = ['A', 'C', 'G', 'T']
for i, char in enumerate(text):
    if char not in atcoder_char:
        text[i] = ''

max_count = 0
count = 0
for char in text:
    if char in atcoder_char:
        count += 1
    else:
        if max_count < count:
            max_count = count
            count = 0

print(max_count) if max_count >= count else print(count)

Measured memory_bytes: 38384
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from functools import reduce

def main():
  n = int(input())
  la = list(map(int, input().strip().split()))
  x = reduce(lambda x, y: x ^ y, la)
  print(' '.join([str(x ^ a) for a in la]))

if __name__=='__main__':
  main()


Measured memory_bytes: 34080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define sqr(int) (int * int)
#define sqr3(int) (int * int * int)
#define pi M_PI
#define nl "\n"




void solve(){
	int a,sum=0;
	cin >> a;
	for(int i = 1; i<=3; i++){
		sum += pow(a,i);
	}
	cout << sum;

}







    

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




Measured memory_bytes: 4024
# C - Tsundoku
from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = map(int, open(0).read().split())
    cum_A, cum_B = accumulate(AB[:N], initial=0), tuple(accumulate(AB[N:]))
    candidates = [0]
    for i, a in enumerate(cum_A):
        if a > K:
            break
        candidates.append(i + bisect(cum_B, K - a))
    print(max(candidates))


if __name__ == "__main__":
    main()


Measured memory_bytes: 55316
// C - 100 to 105
// https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_c
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, x, w, ans = 0, count1 = 0, count2 = 0, count3 = 0, count4 = 0, count5 = 0, count6 = 0;
  string s, t;
  cin >> x;
  a = x / 100;
  repe(i, 0, a)
  {
    b = x - i * 100;
    if (b <= 5 * i)
    {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
} 

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

int main() {
	int n, a[200000];
	int max, semimax;
	cin >> n;

	cin >> a[0] >> a[1];
	max = (a[0] > a[1]) ? a[0] : a[1];
	semimax = (max == a[0]) ? a[1] : a[0];

	for (int i = 2; i < n; ++i) {
		cin >> a[i];
		if (a[i] > max)
			max = a[i];
		else if (a[i] == max)
			semimax = a[i];
		else if (a[i] > semimax)
			semimax = a[i];
	}

	for (int i = 0; i < n; ++i) {
		if (a[i] == max)
			cout << semimax << endl;
		else
			cout << max << endl;
	}
	return 0;
}

Measured memory_bytes: 2432
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
/*================Header Template==============*/
int main() {
	map<int,int>cnt;
	int n,x;
	read(n);
	while(n--) {
		read(x);
		cnt[x]++;
	}
	int ans=0;
	for(map<int,int>::iterator it=cnt.begin();it!=cnt.end();it++)
		if((it->second)<(it->first))
			ans+=it->second;
		else
			ans+=(it->second)-(it->first);
	printf("%d\n",ans);
}

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

int32_t main(){
	int n;
	cin >> n;
	vector<int> h(n+1);
	for(int i=1; i<=n; i++){
		cin >> h[i];
	}
	map<int, int> hash;
	int res = 0;
	for(int j=1; j<=n; j++){
		if(hash.find(j-h[j]) != hash.end()){
			res += hash[j-h[j]];
		}
		hash[j+h[j]]++;
	}
	cout << res << "\n";
}

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

int check(vector<int> character, int i, int color)
{
  if(character[i] == color) return character.size();

  character[i] = color;
  vector<int>::iterator it;
  while( 1 ){
    it = search_n(character.begin(), character.end(), 4, color);
    while(it!=character.end() && *it==color) it = character.erase(it);
    if(it==character.end())break;
    color = *it;
  }

  return character.size();
}

int main()
{
  int N, M;
  while(cin>>N, N){
    vector<int> character(N);
    for(int i=0; i<N; i++) cin>>character[i];

    M = 100000;
    for(int i=0; i<N; i++){
      for(int color=1; color<=3; color++){
        M = min(M, check(character, i, color));
      }
    }
    cout<<M<<endl;
  }
}

Measured memory_bytes: 1296
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int x = sc.nextInt(), y = sc.nextInt(), z = sc.nextInt();
		System.out.println(z + " " + x + " " + y);
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}

Measured memory_bytes: 21332
N, A, B = [int(_) for _ in input().split()]
mod = 10**9 + 7
c = [1, N]
for i in range(1, B + 1):
    c += [c[-1] * (N - i) * pow(i + 1, mod - 2, mod) % mod]
ans = pow(2, N, mod) - c[A] - c[B] - 1
ans %= mod
print(ans)


Measured memory_bytes: 16740
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Card {
  String suit;
  int value;
  int storedNo;

  public Card( String suit, int value, int storedNo ) {
    this.suit  = suit;
    this.value = value;
    this.storedNo = storedNo;
  }
  public Card( Card card ) {
    this(card.suit, card.value, card.storedNo);
  }

  @Override
  public String toString() {
    return suit + String.valueOf(value);
  }
}

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      Card[][] cards = new Card[2][n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++) {
        cards[0][i] = new Card(
          line[i].substring(0, 1),
          Integer.parseInt(line[i].substring(1)),
          i );
        cards[1][i] = new Card(cards[0][i]);
      }

      bubbleSort(cards[0], n);
      dispIntArray(cards[0]);
      System.out.println(isStableSorted(cards[0], n) ? "Stable" : "Not stable");
      selectionSort(cards[1], n);
      dispIntArray(cards[1]);
      System.out.println(isStableSorted(cards[1], n) ? "Stable" : "Not stable");
    }
  }

  static int bubbleSort(Card[] a, int n) {
    int count=0;
    Card t;

    for(int i=0,f=1; f==1 || i<n; i++ ) {
      f=0;
      for(int j=n-1; j>0; j-- ) {
        if( a[j].value < a[j-1].value) {
          t = a[j]; a[j] = a[j-1]; a[j-1] = t;
          count++;
          f=1;
        }
      }
    }

    return count;
  }

  static int selectionSort(Card a[], int n) {
    int count = 0;
    Card t;

    for(int i=0,min; i<n-1; i++ ) {
      min = i;
      for(int j=i+1; j<n; j++ ) {
        if( a[min].value > a[j].value) min = j;
      }
      if( min != i ) {
        t = a[i]; a[i] = a[min]; a[min] = t;
        count++;
      }
    }

    return count;
  }

  static boolean isStableSorted(Card[] sorted, int n) {
    boolean ret = true;

    for (int i=0, max=n-1; i < max; i++) {
      if( sorted[i].value == sorted[i+1].value
        && sorted[i].storedNo > sorted[i+1].storedNo )
        ret = false;
    }

    return ret;
  }

  public static void dispIntArray(Card[] a) {
    StringBuilder s = new StringBuilder();

    for (Card c : a) { s.append(c.toString()).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 24428
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]) {
	//char a,b;
	std::string a,b,c;
	//std::getline(std::cin, buf);

	

	std::cin >>a;
	b = "ABC";
	c = "ARC";

	if (b.compare(a)==0) {
		std::cout << "ARC" << std::endl;
	}
	else if (c.compare(a)==0) {
		std::cout << "ABC" << std::endl;
	}
	

	//printf("%d\n", d);
	//std::cout <<d<< std::endl;
	return 0;
}

Measured memory_bytes: 3628
import java.io.*;

public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        int K = Integer.parseInt(br.readLine());
        int X = Integer.parseInt(br.readLine());
        int Y = Integer.parseInt(br.readLine());

        int in = 0;
        int out = 0;
        in = X*K;
        out = Y*(N-K);
        if(out <= 0){
            out = 0;
            in = X*N;
        }
        System.out.println(in+out);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

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


struct Solver {
  long n;
  std::vector<std::array<long, 2>> xs;
  Solver() {
    S002 reader;
    reader >= n;
    long m = n - 1;
    reader >m>= xs;
  }
  std::vector<long> neighbours[112345];
  bool visited[112345];
  long dfs(long i) {
    visited[i] = true;
    long even = 0, odd = 0;
    long max = 0;
    for(long next : neighbours[i]) {
      if( visited[next] ) continue;
      long t = dfs(next);
      if( t % 2 == 0 ) {
        even += 1;
      }
      else {
        odd += 1;
      }
      max = std::max(max, t);
    }
    if( odd >= 2 ) {
      puts("First");
      exit(0);
    }
    if( i == 1 and odd == 0 ) {
      puts("First");
      exit(0);
    }
    if( odd == 1 ) {
      return 2;
    }
    else {
      return 1;
    }
  }
  void solve() {
    for(auto x : xs) {
      neighbours[x[0]].push_back(x[1]);
      neighbours[x[1]].push_back(x[0]);
    }
    for(long i = 0; i < 112345; ++i) {
      visited[i] = false;
    }
    dfs(1);
    puts("Second");
  }
  ~Solver() { fprintf(stderr, "--end--\n"); }
};
 
int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}



Measured memory_bytes: 8320
fn main() {
    let mut _s = String::new();
    std::io::stdin().read_line(&mut _s).unwrap();

    let mut a = String::new();
    std::io::stdin().read_line(&mut a).unwrap();
    let a: Vec<i32> = a
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();

    let mut ans = true;
    let mut tmp_max = -1;
    for &i in a.iter() {
        tmp_max = if i > tmp_max { i } else { tmp_max };

        if i < tmp_max - 1 {
            ans = false;
            break;
        }
    }

    if ans {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 6396
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    ll mina = 1000, maxa = 0;
    for(int i = 0; i < n; ++i){
        ll ai;
        cin >> ai;
        mina = min(mina, ai);
        maxa = max(maxa, ai);
    }
    cout << maxa - mina << endl;
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	int p[15];
	int i;
	for(i=0; i<N; ++i) cin >> p[i];
	int S=0;
	int j=0;
	for(i=1; i<N; ++i) if(p[i]>p[j]) j=i;
	for(i=0; i<N; ++i)
	{
	    if(i==j) S = S + p[i]/2;
	    else S = S + p[i];
	}
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	ll A, B, C; cin >> A >> B >> C;

	rep(i, 0, 10000) {
		if (i*A % B == C) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

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

int main() {
    int n, m;
    while(cin >> n >> m, n){
        int masu[1005], ans = -1, pos = 0;
        for(int i=0;i<n;i++){
            cin >> masu[i];
        }
        for(int i=0;i<m;i++){
            int x;
            cin >> x;
            pos += x;
            if(pos < n) pos += masu[pos];
            if(pos >= n-1 && ans < 0) ans = i+1;
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3084
import math
import sys
a=int(input())
List=list(map(int,input().split()))
s=sum(List)
r=1
count=0
for i in range(a+1):
  count+=r
  r-=List[i]
  s-=List[i]
  if r<0:
    print(-1)
    sys.exit()
  r=min(s,2*r)
print(count)



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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int cnt=0;
	char c='a';
	map<string,int>mp;
	string s,w="abcdefghijklmnopqrstuvwxyz";
	cin>>s;
	for(int i=0;i<s.length();i++){
		mp[s.substr(i,1)]++;
	}
	for(auto p:mp){
		auto a=p.first;
		if( a!=w.substr(cnt,1)){
			cout<<w.substr(cnt,1);
			return 0;
		}
		cnt++;
	}
	if(cnt!=26){
		cout<<w.substr(cnt,1)<<endl;
	}else{
		cout<<"None"<<endl;
	}
}


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

using namespace std;
typedef long long ll;

int n;
pair<pair<string, int>, int> rs[105];

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> rs[i].first.first >> rs[i].first.second;
        rs[i].first.second *= -1;
        rs[i].second = i + 1;
    }
    sort(rs, rs + n);
    for (int i = 0; i < n; i++) {
        cout << rs[i].second << '\n';
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n;
int a[100006];
int main()
{
	cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	if(a[0]==0)
	{
		rep(i,n)
		{
			if(i!=0)
			{
				if((int)((i+1)/2)*2!=a[i])
				{
					cout<<0<<endl;
					return 0;
				}
			}
		}
	}
	else if(a[0]==1)
	{
		rep(i,n)
		{
			if(i%2==0)
			{
				if(a[i]!=i+1)
				{
					cout<<0<<endl;
					return 0;
				}
			}
			else
			{
				if(a[i]!=i)
				{
					cout<<0<<endl;
					return 0;
				}
			}
		}
	}
	else
	{
		cout<<0<<endl;
		return 0;
	}
	int k=(a[n-1]+1)/2;
	int t=1;
	rep(i,k)
	{
		t*=2;
		t%=1000000007;
	}
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>

char ji[55]={};
char ou[55]={};

int main()
{
	int j=0,o=0,p=0;
	scanf("%s",ji);
	scanf("%s",ou);
	while((ji[j]!='\0')||(ou[o]!='\0'))
	{
		p++;
		if(p%2==1)
		{
			printf("%c",ji[j]);
			j++;
		}
		else
		{
			printf("%c",ou[o]);
			o++;
		}
	}
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<stack>
#include<vector>


int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    char a[n+1][n+1],b[m+1][m+1];
    int i,j,si,sj;
    for(i=0;i<=n-1;i++)scanf("%s",a[i]);
    for(i=0;i<=m-1;i++)scanf("%s",b[i]);
    
    int ans=0;
    
    for(si=0;si<=n-m;si++)for(sj=0;sj<=n-m;sj++){
        int flag=0;
        for(i=si;i<=si+m-1;i++)for(j=sj;j<=sj+m-1;j++){
            if(a[i][j]!=b[i-si][j-sj])flag=1;
        }
        if(flag==0)ans=1;
    }
    
        if(ans==0)printf("No");
        else printf("Yes");
    
    return 0;
}


Measured memory_bytes: 128
import sys
import re
import queue
import collections
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []


def main():
	N,X,M=i_map()

	Y = X

	went_array = []
	for i in range(0,M):
		went_array.append(-1)

	loop_flag = False
	first = -1
	second = -1
	value = -1
	for i in range(0,N):

		if(went_array[Y] != -1):
			loop_flag = True
			first = went_array[Y]
			second = i
			value = Y
			break

		went_array[Y] = i
		Y = (Y*Y) % M

	if(loop_flag == False):
		Z = X
		sum = 0

		for i in range(0,N):
			sum += Z
			Z = (Z*Z)%M

		print(sum)

	else:
		Z = X
		sum1 = 0
		for i in range(0,first):
			sum1 += Z
			Z = (Z*Z)%M

		Z = value
		cum = []
		cum.append(Z)
		Z = (Z*Z) %M
		for i in range(1,second-first):
			cum.append(cum[i-1]+Z)
			Z = (Z*Z) %M

		sum2 = ((N-first)//(second-first))*cum[second-first-1]

		if((N-first)%(second-first) == 0):
			print(sum1 + sum2)
		else:
			sum3 = cum[((N-first)%(second-first)-1)]
			print(sum1 + sum2 + sum3)


	return

if __name__ == '__main__':
	main()

Measured memory_bytes: 15240
import java.util.Arrays;

public class Main {


  private static void solve() {
    int n = ni();
    int k = ni();
    long[] a = nal(n);
    
    long[] b = new long[n * (n + 1) / 2];
    int ptr = 0;
    for (int i = 0; i < n; i ++) {
      long sum = 0;
      for (int j = i; j < n; j ++) {
        sum += a[j];
        b[ptr ++] = sum;
      }
    }

    long[] c = new long[b.length];

    long ret = 0;
    for (int i = 50; i >= 0; i --) {
      long m = 1L << i;
      
      int cnt = 0;
      for (long v : b) {
        if ((v & m) == m) {
          c[cnt ++] = v;
        }
      }
      if (cnt >= k) {
        ret |= m;
        long[] tmp = b;
        b = Arrays.copyOf(c, cnt);
        c = tmp;
      }
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

using namespace std;

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        if (i < n - i) ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int main(void)
{
	int i,sum,x;
	sum=0;
	for(i=0;i<5;i++)	{
		scanf("%d",&x);
		if(x<40)	x=40;
		sum+=x;
	}
	printf("%d\n",sum/5);
	return 0;
}


Measured memory_bytes: 1028
#include <iostream>
#include <stack>

int main(){
    int in;
    std::stack<int> st;

    while(std::cin >> in){
        if(in == 0){
            std::cout << st.top() << std::endl;
            st.pop();
        }else{
            st.push(in);
        }
    }

    return 0;
}

Measured memory_bytes: 3004
let readInt() = stdin.ReadLine() |> int
let readIntArray() = stdin.ReadLine().Split(' ') |> Array.map (fun x -> int x)

let ab = readIntArray()

let getStrength n =
    if n = 1 then 14 else n

match (getStrength ab.[0], getStrength ab.[1]) with 
| x, y when x > y -> "Alice" 
| x, y when x < y -> "Bob"
| _ -> "Draw"
|> printfn "%s"

Measured memory_bytes: 13916
#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<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll  MOD = 1000000007;

int main() {
	ll n, k;
	cin >> n >> k;
	vector<bitset<50>> a(n);
	rep(i, n) {
		ll x;
		cin >> x;
		bitset<50> y(x);
		a.at(i) = y;
	}
	if (k == 0) {
		ll s = 0;
		rep(i, n) s += k ^ a.at(i).to_ullong();
		cout << s;
		return 0;
	}
	bitset<50> K(k);
	ll mx = 49;
	while (!(K.test(mx))) mx--;
	bitset<50> ans1;
	for (ll i = 49; i >= 0; i--) {
		ll cnt = 0;
		rep(j, n) if (a.at(j).test(i)) cnt++;
		if (cnt < n - cnt && i <= mx) ans1.set(i);
	}
	bitset<50> ans2 = ans1;
	ans2.set(mx, 0);
	ans1.set(mx);
	vector <bitset<50>> ans;
	ans.push_back(ans2);
	for(ll i = mx; i >= 0; i--) {
		if (ans1.test(i)) {
			if (K.test(i)) {
				if (k >= ans1.to_ullong()) ans.push_back(ans1);
			}
			else {
				ans1.set(i, 0);
			}
		}
		else {
			if (K.test(i)) {
				if (k >= ans1.to_ullong()) ans.push_back(ans1);
			}
			else {
				if (k >= ans1.to_ullong()) ans.push_back(ans1);
			}
		}
	}
	ans.push_back(ans1);
	ll s = 0;
	for(auto i : ans) {
		ll t = 0;
		rep(j, n) {
			t += a.at(j).to_ullong() ^ i.to_ullong();
		}
		if (s < t) s = t;
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

const ll INF = 1e15;
const double eps = 1e-6;
const ll MOD = 1000000007;

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

int main() {
	ll X, Y;
	cin >> X >> Y;
	if (X % Y == 0)
		cout << -1 << endl;
	else
		cout << X * Y - X << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
lia,lib,lic,lid = [],[],[],[]
count = 0
for i in range(n):
    lib.append(int(input()))
    for j in range(lib[i]):
        lid.append([int(s) for s in input().split()])
    lic.append(lid)
    lid = []
for i in range(2**n):
    b = "0"*(n-len(bin(i))+2)+bin(i)[2:]
    li = [int(b[s]) for s in range(n)]
    f = 1
    for j in range(n):
        for k in range(lib[j]):
            if li[j] == 1:
                if li[lic[j][k][0]-1] != lic[j][k][1]:
                    f = 0
    if f == 1:
        lia.append(li)
        count += 1
for i in range(count):
    lia[i] = sum(lia[i])
print(max(lia))

Measured memory_bytes: 50652
n = int(input())
numbs = list(map(int,input().split()))
print(' '.join(map(str,numbs)))
for i in range(1,len(numbs)):
    key = numbs[i]
    j = i-1
    while j >=0 and numbs[j] > key:
        numbs[j+1] = numbs[j]
        j -= 1
    numbs[j+1] = key
    print(' '.join(map(str,numbs)))

Measured memory_bytes: 5596
#include <stdio.h>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;

map<ll, vector<ll> > M;
ll a[222222], t[222222];

int main(void)
{
	ll n, i;

	scanf("%lld", &n);
	for (i = 1; i <= n; i++)
	{
		scanf("%lld", &a[i]);
		t[i] = i - a[i];
	}

	for (i = 1; i <= n; i++)
		if (t[i] > 0)
			M[t[i]].push_back(i);

	ll ans = 0;
	for (i = 1; i <= n; i++)
	{
		ll p = i + a[i];

		ll it = upper_bound(M[p].begin(), M[p].end(), i) - M[p].begin();

		ans += M[p].size() - it;
	}

	printf("%lld", ans);
	return 0;
}

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

typedef pair<int, int> ii;
typedef long long ll;
const int mod = 1000000007;

int mul(int x, int y) {
  return (ll)x * y % mod;
}
int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
int sub(int x, int y) {
  x -= y;
  if (x < 0) x += mod;
  return x;
}
int mpow(int x, int y) {
  if (y == 0) return 1;
  int ret = mpow(x, y / 2);
  ret = mul(ret, ret);
  if (y & 1) ret = mul(ret, x);
  return ret;
}
int inv(int x) {
  return mpow(x, mod - 2);
}
int two[200005];

struct X {
  int a, b, c;
  X() {}
  X(int x, int y, int z): a(x), b(y), c(z) {}
};

int n;
vector<int> v[200005];
int sz[200005];

deque<X> pl[200005];
deque<X> *dq[200005];

int cnt;
deque<X>* newd() {
  return &pl[cnt ++];
}

deque<X>* merge(deque<X>* d1, deque<X>* d2, int &ssz) {
  if (d1->size() < d2->size()) swap(d1, d2);
  deque<X> &p = *d1;
  deque<X> &q = *d2;

  ssz = max(ssz, (int)q.size());
  for (int i = 0; i < (int)q.size(); i ++) {
    // X tmp(add(mul(p[i].a, q[i].b), mul(p[i].b, q[i].a)), mul(p[i].b, q[i].b));
    p[i].a = add(mul(p[i].a, q[i].b), mul(p[i].b, q[i].a));
    p[i].b = mul(p[i].b, q[i].b);
    p[i].c = add(p[i].c, q[i].c);
  }
  d2->clear();
  return d1;
}

void dfs(int x) {
  if (v[x].size() == 0) {
    dq[x] = newd();
    dq[x]->push_back(X(1, 1, 1));
    return;
  }
  dq[x] = nullptr;
  int ssz = 0;

  for (int i = 0; i < (int)v[x].size(); i ++) {
    int y = v[x][i];
    dfs(y);

    if (dq[x] == nullptr) dq[x] = dq[y];
    else {
      dq[x] = merge(dq[x], dq[y], ssz);
    }
  }

  auto &d = *dq[x];
  for (int i = 0; i < ssz; i ++) {
    // d[i].a = mul(d[i].a, d[i].b);
    d[i].b = sub(two[d[i].c], d[i].a);
    // d[i].a = mul(d[i].a, inv(d[i].b));
  }
  d.push_front(X(1, 1, 1));
}

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

  two[0] = 1;
  for (int i = 1; i <= n + 1; i ++) {
    two[i] = mul(two[i - 1], 2);
  }

  for (int i = 1; i <= n; i ++) {
    int pi;
    scanf("%d", &pi);
    v[pi].push_back(i);
  }

  dfs(0);

  int ans = 0;
  for (X x : *dq[0]) {
    int tmp = mul(x.a, two[n + 1 - x.c]);
    ans = add(ans, tmp);
  }
  printf("%d\n", ans);
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int n, k; cin >> n >> k;
    vector<ll> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    vector<ll> dp(n, 1LL << 60);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k; j++){
            if(i + j < n){
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
            }
        }
    }
    cout << dp[n - 1] << endl;
}


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

int main() {
	// your code goes here
	int n,k,ans=0;
	cin>>n>>k;
	vector<int>arr(n);
	for(int i=0;i<n;i++){
		cin>>arr[i];
		if(arr[i]>=k){
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3672