akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <climits>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast64_t;
using uint64 = std::uint_fast64_t;
uint32 k;
std::vector<uint32> a;

bool cmax(uint32 m) {
	rep(i, 0, k) {
		m = m - m%a[i];
	}
	if (m <= 2) return true;
	return false;
}
bool cmin(uint32 m) {
	rep(i, 0, k) {
		m = m - m%a[i];
	}
	if (m >= 2) return true;
	return false;
}

int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cin >> k;
	a = std::vector<uint32>(k);
	rep(i,0,k)
		std::cin >> a[i];
	uint32 min, max;
	uint32 ok = 1,ng = 1 << 60;
	while (ng - ok > 1) {
		uint32 mid = ok + (ng - ok) / 2;
		if (cmax(mid)) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}
	max = ok;
	ok = 1 << 60;
	ng = 1;
	while (ok - ng > 1) {
		uint32 mid = ng + (ok - ng) / 2;
		if (cmin(mid)) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}
	min = ok;
	if (min > max) {
		std::cout << "-1\n";
	}
	else {
		std::cout << min << " " << max << "\n";
	}
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <set>
using namespace std;
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d%d", &x, &y);
int main() {
  scii(a,b) sci(c)
  set<int>st;
  st.insert(a);
  st.insert(b);
  st.insert(c);
  printf("%d\n",(int)st.size());
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int M = 3e5 + 5;
const int mod = 1e9 + 7;

int power(int a, int b)
{
	int res = 1;
	while(b > 0)
	{
		if(b & 1) 
			res = (res * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return res % mod;
}

int inverseMod(int a, int b)
{
	return power(a, b);
}

int solve(int n, int r)
{
	int res = 1;
	if(r > n - r)
		r = n - r;
	for(int i = 0; i < r; i++)
	{
		res = (res * (n - i)) % mod;
		res = (res * inverseMod(i + 1, mod - 2)) % mod;
	}
	return res;
}

// (n - 1)!/(n - k)! * (k - 1)!

// (n - 2)!(n - k - 1)! * (k - 1)!

int32_t main()
{	
	ios_base::sync_with_stdio(0);   cin.tie(0);     cout.tie(0);
	int n, k;			cin >> n >> k;
	int a[n + 1];
	for(int i = 0; i < n; i++)	cin >> a[i];
	sort(a, a + n);
	int nCr = solve(n - 1, k - 1), ans = 0;
	for(int i = n - 1; i >= 0; i--)
	{
		ans += (nCr * a[i]) % mod;
		ans %= mod;
		nCr = (nCr * inverseMod(i, mod - 2)) % mod;
		nCr = (nCr * (i + 1 - k)) % mod;
	}
	nCr = solve(n - 1, k - 1);
	for(int i = 0; i < n; i++)
	{
		ans -= (nCr * a[i]) % mod;
		ans += mod;
		ans %= mod;
		nCr = (nCr * inverseMod(n - i - 1, mod - 2)) % mod;
		nCr = (nCr * (n - k - i)) % mod;
	}
	cout << ans;
	return 0; 
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

ll gcd(ll x, ll y){ return y==0? x: gcd(y, x%y); }

int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, x;
	cin >>n >>x;
	VI a(n);
	rep(i, n) cin >>a[i];
	ll ans = 0;
	rep(i, n-1){
		if(a[i] + a[i+1] > x ){
			int tb = a[i+1] + min( 0, a[i] - x);
			ans += a[i] + a[i+1] - x;
			a[i+1] -= tb;
		}
	}
	cout << ans <<endl;
	
	return 0;
}

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

#define ll long long

using namespace std;

ll INF = (ll) 1e20;
int iINF = (int) 1e20;
ll mod = (ll) 1e9 + 7;

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
    ll n, m, k;
    cin >> n >> m >> k;
    string tb[n];
    for(int i = 0; i < n; ++i) {
        cin >> tb[i];
    }
    int ans = 0;
    for(int i = 0; i < (1 << n); ++i) {
        for(int j = 0; j < (1 << m); ++j) {
            ll now = 0;
            for(int a = 0; a < n; ++a) {
                for(int b = 0; b < m; ++b) {
                    if((i & (1 << a)) || (j & (1 << b)))
                        continue;
                    now += (tb[a][b] == '#');
                }
            }
            ans += (now == k);
        }
    }
    cout << ans;
}

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

int main(){
    int A, B, M;
    cin >> A >> B >> M;
    int a[A], b[B], c[M], x[M], y[M];
    for(int i=0; i<A; i++){
        cin >> a[i];
    }
    for(int i=0; i<B; i++){
        cin >> b[i];
    }
    for(int i=0; i<M; i++){
        cin >> x[i] >> y[i] >> c[i];
    }

    int payment, payment2, amin=a[0], bmin=b[0];
    for(int i=1; i<A; i++){
        if(a[i]<amin){
            amin=a[i];
        }
    }
    for(int i=1; i<B; i++){
        if(b[i]<bmin){
            bmin=b[i];
        }
    }
    payment= amin + bmin;
    // cout << payment << endl;

    for(int i=0; i<M; i++){
        // payment2= a[x[i]-1]+b[y[i]-1]-c[i];
        if(a[x[i]-1]+b[y[i]-1]-c[i]<payment){
            payment= a[x[i]-1]+b[y[i]-1]-c[i];
        }
        // cout << payment << endl;
    }
    cout << payment << endl;
    return 0;
}

Measured memory_bytes: 2176
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

typedef pair<ll, int> ll_i;
vector<ll_i> g[2][100000];
vector<ll> dijkstra(int num, int start, int t) {
  priority_queue<ll_i, vector<ll_i>, greater<ll_i> > que;
  vector<ll> dp(num, 1e18);
  dp[start] = 0;
  que.push(make_pair(0, start));
  while (!que.empty()) {
    ll_i v = que.top();
    que.pop();
    if (dp[v.second] < v.first) continue;
    for (auto u : g[t][v.second]) {
      if (dp[v.second] + u.first < dp[u.second]) {
        dp[u.second] = dp[v.second] + u.first;
        que.push(make_pair(dp[u.second], u.second));
      }
    }
  }
  return dp;
}

int main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--, t--;
  for (int i = 0; i < m; ++i) {
    int u, v;
    ll a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    g[0][u].push_back(make_pair(a, v));
    g[0][v].push_back(make_pair(a, u));
    g[1][u].push_back(make_pair(b, v));
    g[1][v].push_back(make_pair(b, u));
  }
  vector<ll> ans1 = dijkstra(n, s, 0);
  vector<ll> ans2 = dijkstra(n, t, 1);
  vector<ll> ans(n + 1, 2e18);
  for (int i = n - 1; i >= 0; --i) {
    ans[i] = min(ans[i + 1], ans1[i] + ans2[i]);
  }
  for (int i = 0; i < n; ++i) {
    cout << (ll)1e15 - ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 19140
#include <bits/stdc++.h>
using namespace std;
#define _K ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld long double
#define ll long long
#define pb push_back
#define Pb pop_back
#define pi acos(-1)
#define eps 1e-7
#define F first
#define S second
#define X real()
#define Y imag()
#define cross(a,b) (conj(a)*(b)).X
#define dot(a,b) (conj(a)*(b)).Y
#define all(f) (f).begin(),(f).end()
#define allr(f) (f).rbegin(),(f).rend()
const int mod = 1e9+7 , A = 1e5 ;
typedef complex <ld> point ;
typedef vector <point> polygon ;
typedef tuple <int , int , int> line ;
//====================================
ll memo[3005][3005] , ans = 0 ;
string s , t ;
bool done = 0 ;
ll solve(ll i , ll j)
{
	if (i >= s.size() || j >= t.size())
		return 0 ;
	if (memo[i][j] != -1)
		return memo[i][j] ;

	ll val = 0 ;
	{
		if (s[i] == t[j])
		{
			val = solve(i + 1 , j + 1) + 1 ;
		}
		else
		{
			val = max (val , solve(i + 1 , j)) ;
			val = max (val , solve(i , j + 1)) ;
		}
	}
	memo[i][j] = val ;
	return val ;
}
void check(ll i , ll j)
{
	if (i >= s.size() || j >= t.size())
		return ;
	{
		if (s[i] == t[j])
		{
			done = 1 ;
			cout << s[i] ;
			check(i + 1 , j + 1) ;
		}
		else
		{
			if (solve(i + 1 , j) == memo[i][j])
				check(i + 1 , j) ;
			else
				check(i , j + 1) ;
		}
	}
}
int main()
{
	_K
	cin >> s >> t ;
	memset (memo , -1 , sizeof memo) ;
	ans = solve(0 , 0) ;
	check(0 , 0) ;
	if (done == 0)
		cout << ' ' ;
	return 0 ;
}

Measured memory_bytes: 71040
// need
#include <iostream>
#include <algorithm>
// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
//#include <deque>
#include <valarray>
#include <unordered_map>
#include <array>
// stream
//#include <istream>
#include <sstream>
//#include <ostream>
#include <fstream>
// etc
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#define INF 100000
//#include <chrono>
using namespace std;

int main()
{
  int  a, b, c;
  cin >> a >> b >> c;
  if(b/a < c)
    cout << b/a << endl;
  else
    cout << c << endl;
  return 0;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

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

    vector<ll>cnt(5);
    rep(i,n){
        string s;
        cin>>s;

        if(s[0]=='M'){
            cnt[0]++;
        }
        if(s[0]=='A'){
            cnt[1]++;
        }
        if(s[0]=='R'){
            cnt[2]++;
        }
        if(s[0]=='C'){
            cnt[3]++;
        }
        if(s[0]=='H'){
            cnt[4]++;
        }
    }

    ll ans=0;

    for(int i=0;i<3;i++){
        for(int j=i+1;j<4;j++){
            for (int k=j+1;k<5;k++) {
                ans+=cnt[i]*cnt[j]*cnt[k];
            }
        }
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
using namespace std;
using ll =long long;
int main() {






	
	double L;
	cin >> L;
	
	
	cout << fixed<<pow(L/3,3);


}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

double pow(int n,int P) {
    double ans = 1.0 / P;
    double x = 0.5;
    while(n) {
        if(n&1) {
            ans *= x;
        }
        n >>= 1;
        x *= x;
    }

    return ans;
}

int main(void) {
    int N,K;
    double ans = 0.0;
    cin>>N>>K;

    if(K == 1) {
        cout<<1.0<<endl;

        return 0;
    }

    for(int i = 1;i <= min(N,K-1);i++) {
        int ret = ceil(log2(K) - log2(i));
        ans += pow(ret,N);
    }
    if(N > K) {
        ans += ((double)(N - K + 1.0))/N;
    }

    printf("%.10f\n",ans);

    return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 200005

ll t[4*MAXN], dp[MAXN]={0};
void build(ll node, ll start, ll end){
    if(start == end){
        t[node] = dp[start];
        ret;
    }
    ll mid = (start+end)/2;
    build(2*node, start, mid);
    build(2*node+1, mid+1, end);
    t[node] = max(t[2*node], t[2*node+1]);
}

void update(ll node, ll start, ll end, ll idx, ll val){
    if(start == end){
        t[node] = val;
        dp[idx] = val;
        return;
    }
    ll mid = (start+end)/2;
    if(idx<=mid && idx>=start){
        update(2*node, start, mid, idx, val);
    }
    else {
        update(2*node+1, mid+1, end, idx, val);
    }
    t[node]=max(t[2*node], t[2*node+1]);
}

ll query(ll node, ll start, ll end, ll l, ll r){
    if(end<l || start>r){
        return -inf;
    }
    else if(start>=l && end<=r){
        return t[node];
    }
    ll mid = (start+end)/2;
    ll p1 = query(2*node, start, mid, l, r);
    ll p2 = query(2*node+1, mid+1, end, l, r);
    return max(p1, p2);
}

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

    ll n;
    cin>>n;
    ll h[n+1], a[n+1];
    loop(i,1,n+1) {
        cin>>h[i];
    }
    loop(i,1,n+1) cin>>a[i];
    build(1, 1, n);
    for(ll i=1; i<=n; i++){
        ll x = query(1, 1, n, 1, h[i]-1);
        if(h[i]==1) x=0;
        x += a[i];
        update(1, 1, n, h[i], x);
    }

    ll ans = INT_MIN;
    loop(i,1,n+1){
        ans = max(ans, dp[i]);
    }
    print(ans);

    
}



Measured memory_bytes: 9472
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//void chmin(ll &a,ll b){if(a>b) a = b ;}

int main(){
	ll n ; cin >> n ;
	vector<pll> a(100100),b(100100) ;
	for(int i=0;i<a.size();i++){
		a.at(i).first = b.at(i).first = 0 ;
		a.at(i).second = b.at(i).second = i ;
	}
	for(int i=0;i<n;i++){
		ll c ; cin >> c ;
		if(i&1) b.at(c).first++ ;
		else a.at(c).first++ ;
	}
	sort(all(a)) ; reverse(all(a)) ;
	sort(all(b)) ; reverse(all(b)) ;
	if(a.at(0).second!=b.at(0).second) cout << n-a.at(0).first-b.at(0).first << endl ;
	else cout << min(n-a.at(0).first-b.at(1).first,n-a.at(1).first-b.at(0).first) << endl ;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdlib>

using namespace std;

int comp(const void *_a, const void *_b){
	char *a, *b;
	a = (char*)_a;
	b = (char*)_b;
	if(a[1] != b[1]) return a[1] - b[1];
	else return a[0]-b[0];
}

bool makeset(char c[][2], int n){
	for(int i = 0; i < n-2; i++){
		for(int j = i+1; j < n-1; j++){
			for(int k = j+1; k < n; k++){
				if(c[i][1] == c[k][1]){
					if(c[i][0] == c[k][0] || (c[i][0]+1 == c[j][0] && c[j][0]+1 == c[k][0])){
						if(n == 3) return true;
						else{
							char _c[n-3][2];
							int idx = 0;
							int _idx = 0;
							while(idx < n){
								if(idx != i && idx != j && idx != k){
									_c[_idx][0] = c[idx][0];
									_c[_idx][1] = c[idx][1];
									_idx++;
								}
								idx++;
							}
							if(makeset(_c, n-3)) return true;
						}
					}
				}
			}
		}
	}
	return false;
}

int main(){
	int t;
	cin >> t;
	while(t--){
		char c[9][2];
		for(int i = 0; i < 9; i++) cin >> c[i][0];
		for(int i = 0; i < 9; i++) cin >> c[i][1];
		qsort(c,9,sizeof(c[0]),comp);
		cout << (int)makeset(c,9) << endl;
	}
}

Measured memory_bytes: 0
// ====================================
//   author: M_sea
//   website: https://m-sea-blog.com/
// ====================================
#include <bits/stdc++.h>
#define file(x) freopen(#x".in","r",stdin); freopen(#x".out","w",stdout)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;

int read() {
	int X=0,w=1; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
	while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
	return X*w;
}

const int N=100000+10;

int n,x,a[N];

int main() {
	n=read(),x=read();
	for (int i=1;i<=n;++i) a[i]=read();
	ll ans=0;
	for (int i=2;i<=n;++i) {
		if (a[i-1]+a[i]>=x) {
			int dlt=a[i-1]+a[i]-x; ans+=dlt;
			if (a[i]>=dlt) a[i]-=dlt;
			else a[i]=0,a[i-1]-=dlt-a[i];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4056
#include <iostream>

using namespace std;

long long f(long long n, long long x);

int main(void) {
	long long ans;
	long long i;
	long long a, b, x;
	// get input ----------------------------------
	cin >> a >> b >> x;
	// calc ---------------------------------------
	ans = f(b, x) - f(a - 1, x);
	// disp answer ---------------------------------
	cout << ans << endl;
	return 0;
}

long long f(long long n, long long x) {
	if (n == -1) {
		return 0;
	}
	return n / x + 1;
}


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

struct theSieveOfEratosThenes {
	vector<bool> prm;

	theSieveOfEratosThenes(int n) {
		prm = vector<bool>(n + 1, true);
		prm[0] = prm[1] = false;
		for (int i = 2; i * i <= n; ++i) {
			if (prm[i]) {
				for (int j = 2 * i; j <= n; j += i) prm[j] = false;
			}
		}
	}

	bool isPrimeNumber(int a) {
		return prm[a];
	}
};

int main() {
	int n;
	theSieveOfEratosThenes tsoet(999999);
	while (cin >> n) {
		int ans = 0;
		for (int i = 2; i <= n; ++i) {
			if (tsoet.isPrimeNumber(i)) ++ans;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
inline int add(int a, int b) { return (a+b)%mod;}
inline int sub(int a, int b) { return (a-b+mod)%mod;}
inline int mul(int a, int b) { return 1LL*a*b%mod;}

struct warp
{
        int sx, sy, tx, ty;
        bool operator<(const warp &w) const {
                if(sx != w.sx) return sx < w.sx;
                return sy < w.sy;
        }
};

int extgcd(int a, int b, int &x, int &y)
{
        int g = a; x = 1; y = 0;
        if(b != 0) g = extgcd(b,a%b,y,x), y -= a/b*x;
        return g;
}
int inv(int a) {
        int x, y; extgcd(a,mod,x,y);
        return (mod+x%mod)%mod;
}
int fact[200010];
inline int nck(int n, int k) { return mul(mul(fact[n], inv(fact[n-k])), inv(fact[k]));}


int n, m, k, dp[100010];
// dp[i] := i番目のワープホールの入り口までの場合の数
vector<warp> warps;

inline int calc(int sx, int sy, int tx, int ty)
{
        if(tx < sx or ty < sy) return 0;
        return nck(tx-sx+ty-sy, tx-sx);
}

int solve()
{
        memset(dp,0,sizeof(dp));
        sort(begin(warps),end(warps));
        warps.push_back((warp){n,m, n+1, m+1});
        for (int i = 0; i <= k; i++) {
                dp[i] = nck(warps[i].sx+warps[i].sy, warps[i].sy);
                for (int j = 0; j < i; j++) {
                        dp[i] = add(dp[i], mul(dp[j], sub(calc(warps[j].tx, warps[j].ty, warps[i].sx,warps[i].sy),
                                                          calc(warps[j].sx, warps[j].sy, warps[i].sx,warps[i].sy))));
                }
        }
        return dp[k];
}

bool input()
{
        warps.clear();
        cin >> n >> m >> k;
        n--; m--;
        int a, b, c, d;
        for (int i = 0; i < k; i++) {
                cin >> a >> b >> c >> d;
                warps.push_back((warp){a-1,b-1,c-1,d-1});
        }
        return n+1 or m+1 or k;
}

int main()
{
        fact[0] = 1;
        for (int i = 0; i < 200000; i++) fact[i+1] = mul(fact[i], i+1);
        while(input()) cout << solve() << endl;
        return 0;
}



Measured memory_bytes: 4256
#include <stdio.h>
#include <stdlib.h>
#pragma GCC optimize ("O3")

inline static int gl(void){
    int x = 0;
    for(;;){
        unsigned int c = getchar_unlocked() - 48;
        if(c < 10){
            x = x*10 + c;
        }else{
            break;
        }
    }
    return x;
}

inline static void pl(unsigned int s){
    char str[9];
    int pos=9;
    if(s==0){
        putchar_unlocked('0');
        return;
    }
    do{
        pos--;
        str[pos]=s%10+48;
        s/=10;
    }while(s!=0);
    for(; pos<9; pos++){
        putchar_unlocked(str[pos]);
    }
}


int main(void){
    static unsigned short out[1000000];
    static char a[501];
    const int h=gl(), w=gl();
    int pos=0;
    char haveCoin = 0;
    short old_y, old_x;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            int t = getchar_unlocked() - 48;
            getchar_unlocked();
            a[j] = t;
        }
        if(i%2==1){
            for(int j=1; j<=w; j++){
                if(haveCoin){
                    out[4*pos+0]=old_y;
                    out[4*pos+1]=old_x;
                    out[4*pos+2]=i;
                    out[4*pos+3]=j;
                    pos++;
                }
                haveCoin ^= a[j]&1;
                old_y = i;
                old_x = j;
            }
        }else{
            for(int j=w; j>0; j--){
                if(haveCoin){
                    out[4*pos+0]=old_y;
                    out[4*pos+1]=old_x;
                    out[4*pos+2]=i;
                    out[4*pos+3]=j;
                    pos++;
                }
                haveCoin ^= a[j]&1;
                old_y = i;
                old_x = j;
            }
        }
    }
    pl(pos); putchar_unlocked('\n');
    for(int i=0; i<pos; i++){
        pl(out[4*i+0]); putchar_unlocked(' ');
        pl(out[4*i+1]); putchar_unlocked(' ');
        pl(out[4*i+2]); putchar_unlocked(' ');
        pl(out[4*i+3]); putchar_unlocked('\n');
    }
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include <cstdio>
using namespace std;
int main(){
    double r;
    double area,length;
    cin>>r;
    area=r*r*3.141592653589;
    length=2.0*r*3.141592653589;
    printf("%lf %lf\n",area,length);
    return 0;
    
}


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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
char chlit(char c){return c+32;}
char chbig(char c){return c-32;}

int main(){
  int h[1000],w[1000];
  rep(i,1000){
    cin >> h[i] >> w[i];
    if(h[i] == 0&&w[i] == 0)break;
  }
  for(int k=0;k<1000;k++){
    if(h[k] == 0&&w[k] ==0 )break;
    for(int i=0;i<h[k];++i){
      for(int j=0;j<w[k];++j){
        if(i%2==0){
          if(j%2==0)cout << "#";
          else cout << ".";
        } else {
          if(j%2==0)cout << ".";
          else cout << "#";
        }    
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
using namespace std;
map <int,int> mp;
typedef pair<int, int> P;
typedef long long ll;
static const int MAX=100000;
static const int NMAX=100;

int main(){
    int N; string s; cin>>N>>s;
    int cunt=0,max_cunt=0;
    for(int i=0;i<N;i++){
        if(s[i]=='I') cunt++;
        else cunt--;
        max_cunt=max(cunt,max_cunt);
    }
    cout<<max_cunt<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	string str;
	int N, b = 0, r = 0;
	cin >> N >> str;

	for (int i = 0; i < N; i++)
	{
		if (str[i] == 'R') r++;
		else b++;
	}

	if (r > b) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int nmax = max(A, max(B, C));
	int ans = 3 * nmax - A - B - C;
	if (1 == ans % 2) {
		ans += 3;
	}
	ans /= 2;
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;
  if (s.size() == 3) {
    reverse(s.begin(), s.end());
  }

  cout << s << '\n';
  return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;

int d, n, m, k, s, e, mid, ans;
int p[200000];

int main(){
	while(scanf("%d", &d),d){
		ans = 0;
		scanf("%d%d", &n, &m);
		rep(i,n-1) scanf("%d", &p[i]);
		p[n-1] = 0; p[n] = d; p[n+1] = d+1;
		sort(p,p+n+2);
		rep(i,m){
			scanf("%d", &k);
			s = 0; e = n+1;
			while(true){
				mid = (s+e)/2;
				if(e-s == 1) break;
				if(p[mid] <= k) s = mid;
				else e = mid;
			}
			ans += min(k-p[s],p[e]-k);
		}
		printf("%d\n", ans);
	}
}

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

int main(){

  const int INF = 100000000;

  int n;
  cin >> n;
  vector<int> h_v(n);

  for(int i=0; i<n; ++i) cin >> h_v[i];

  vector<int> dp(n,INF);

  dp[0] = 0;
  dp[1] = abs(h_v[1] - h_v[0]);
  for(int i=2; i<n; ++i){
    dp[i] = min(dp[i-1] + abs(h_v[i]-h_v[i-1]), dp[i-2] + abs(h_v[i]-h_v[i-2]));
  }
  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  string s;
  cin >> s;
  rep(i, s.size())
  {
    if (s[i] == ',')
      s[i] = ' ';
  }
  cout << s << endl;
  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 N;
	vector<int64> a;
	cin >> N;
	a.resize(N);
	REP(i, N) cin >> a[i];
	sort(all(a));
	int64 res = a[0];
	REP(i, N-1){
		if(abs(a[N-1]-a[i]*2) < abs(a[N-1]-res*2))
			res = a[i];
	}
	cout << a[N-1] << " " << res << endl;
}

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

unsigned int my_gcd(int a, int b) {
	unsigned int r;
	if (a < 0) a *= -1;
	if (b < 0) b *= -1;
	if (a < b) my_gcd(b, a);
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main() {
	int n, init, gcd;
	cin >> n >> init;
	vector<int> x(n);
	for (int i = 0; i < n; i++) {
		cin >> x.at(i);
		x.at(i) -= init;
	}
	if (n != 1)
		gcd = my_gcd(x[0], x[1]);
	else {
		cout << abs(x[0]) << endl;
		return 0;
	}
	for (int i = 2; i < n; i++)
		gcd = my_gcd(gcd, x[i]);
	cout << gcd << endl;
}

Measured memory_bytes: 640
from itertools import product
n, m, x = map(int, input().split())
c = []
a = []

for i in range(n):
    a.append(list(map(int, input().split())))
    c.append(a[-1].pop(0))

l = list(product([0, 1], repeat=n))
ans = [] * len(l)

for t in range(len(l)):
    s = [0] * m
    for i in range(n):
        for j in range(m):
            s[j] += l[t][i]*a[i][j]
    if min(s) >= x:
        ans_n = 0
        for i in range(n):
            ans_n += l[t][i]*c[i]
        ans.append(ans_n)

if len(ans) > 0:
    print(min(ans))
else:
    print(-1)

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

int n;
vector<int> x;

int main() {
    while (scanf("%d", &n) == 1) {
        x.assign(n, 0);
        for (int i = 0; i < n; i++) scanf("%d", &x[i]);
        
        vector<int> l(n, 0), r(n, 0);
        for (int i = 0; i < n; i++) l[i] = (i ? l[i - 1] : 0) ^ x[i];
        for (int i = n - 1; i >= 0; i--) r[i] = (i < n - 1 ? r[i + 1] : 0) ^ x[i];

        vector<int> a(n, 0);
        for (int i = 0; i < n; i++)
            a[i] = (i ? l[i - 1] : 0) ^ (i < n - 1 ? r[i + 1] : 0);

        for (auto &x : a) printf("%d ", x);
        printf("\n");
    }
}


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

long long MinY(long long a,long long b)
{
    long long min, max;
    long long r;
    max=a>b?a:b;
    min=a<b?a:b;
    if(max%min==0)
        return max;
    while(max%min!=0)
    {
        r=max%min;
        max=min;
        min=r;
    }
    return a*b/min;
}


int main() {
    // insert code here...
    //cout<<"ffe"<<endl;
    long long n,m;
    cin>>n>>m;
    string s,t;
    cin>>s;
    cin>>t;
    long long re=MinY(n, m);
    long long un=re/n;
    long long ln=re/m;
    int ok=1;
    for(int i=0;i<=n;i++)
    {
        long long pz=un*i;
        if(pz%ln==0)
        {
            long long pzt=pz/ln;
            if(s[i]!=t[pzt])
            {
                ok=0;
                break;
            }
        }
    }
    if(ok)
        cout<<re<<endl;
    else
        cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 512
/////////////////////////////
//* Code By: SANSKAR SETH *//
/////////////////////////////


/*----------HEADER FILES AND TEMPLATES----------*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define pob pop_back
#define pf pop_front()
#define puf push_front()
#define mp make_pair
#define loop(i,a,b) for(int i=a ; i<b ; ++i)
#define rloop(i,a,b) for(int i=a ; i>=b ; --i)
#define ip(a) int a; cin>>a
#define ip2(a,b) int a,b; cin>>a>>b
#define ip3(a,b,c) int a,b,c; cin>>a>>b>>c
#define ipv(v,n) vi v(n); loop(i,0,n) cin>>v[i]
#define pv(v) loop(i,0,v.size()) cout<<v[i]<<" "
#define ips(s) string s; cin>>s
#define F first
#define S second
#define si(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define coutfl(l,p) fixed << setprecision(p) << l

typedef pair<int, int> pii;
typedef unordered_set<int> usi;
typedef set<int> si;
typedef map<int, int>   mii;
typedef map<char, int>  mci;
typedef vector<int>    vi;
typedef vector<char>   vc;
typedef vector<pii>    vpii;
typedef vector<vi>     vvi;

const int mod = 1000000007;
const int N = 5e5;

/*----------SOLUTION----------*/

void solve()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	vi A;

	A.pb(a * c);
	A.pb(a * d);
	A.pb(b * c);
	A.pb(b * d);
	if ((a <= 0 && b >= 0) || (c <= 0 && d >= 0)) A.pb(0);

	sort(all(A));

	cout << A[A.size() - 1] << endl;


}

/*----------MAIN FUNCTION----------*/
int32_t main()
{
	fastIO;

	/*----MAIN PART----*/

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

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class25
    {
        static void Main()
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = NM[0], M = NM[1];
            int n = N - M, m = M;
            long ntime = n * 100;
            long mtime = m * 1900;
            long a = 1;
            for (int i = 0; i < M; i++)
                a *= 2;
            Console.WriteLine((ntime + mtime) * a);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define stpn setprecision
using namespace std;
typedef long long ll;
int temp,n,i;
bool b;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>temp;
		if (temp%2==0)
		{
			if (temp%3!=0&&temp%5!=0)
			{
				cout<<"DENIED";
				return 0;
			}
		}
	}
	cout<<"APPROVED";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  int i;
  cin>>s>>t;
  for(i=0;i<s.size();i++)
  if(s[i]!=t[i]){
    cout<<"No";
    return 0;
  }
  if(s.size()+1==t.size()) cout<<"Yes";
  else cout<<"No";
  return 0;
}


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

int main(){ 
    int n;
    cin>>n;
    int a=0;
    int b=0;
    for(int i=21;i<n+1;i+=2){
        for(int j=2;j<i;j++){
            if(i%j==0){
                a++;
            }
        }
        if(a==6){
            b++;
        }
        a=0;
    }
    cout<<b;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
S = str(input())
ans = 0

for slash in range(N - 1):
    ctr = 0
    S_r_dic = dict()
    S_l = S[: slash + 1]
    S_r = S[slash + 1 :]
    for s in S_r:
        if s not in S_r_dic and s in Counter(S_l):
            ctr += 1
            S_r_dic[s] = 1
    ans = max(ctr, ans)

print(ans)

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

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());

    if (s < t)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int,int>;
 
int main(){
  ll H, W; cin >> H >> W;
  ll count = 0;
  rep(i, H) {
    if (i % 2 == 0){
      count += (W + 1) / 2;
    } else {
      count += W / 2;
    }
  }
  if (H == 1 || W == 1) count = 1;
  cout << count << endl;
  return 0;
}

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

int main(){
  const int INF = 1001001001;
  int n,m;
  cin >> n >> m;
  vector<int> to[100005];
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  queue<int> q;
  vector<int> dist(n,INF);
  vector<int> pre(n,-1);
  dist[0] = 0;
  q.push(0);
  while(!q.empty()){
    int v = q.front();
    q.pop();
    for(int u : to[v]){
      if(dist[u]!=INF) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }

  cout << "Yes" << endl;
  rep(i,n){
    if(i==0) continue;
    cout << pre[i] + 1 << endl;;
  }

  return 0;
}

Measured memory_bytes: 10572
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1] * (n+1)
        self.rnk = [0] * (n+1)
        
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if (x == y):
            return
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
                
    def isSameGroup(self,x,y):
        return self.Find_Root(x) == self.Find_Root(y)
    
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

N,M,K = map(int,input().split())
t = UnionFind(N)

ans = [-1] * (N+1)
for i in range(M):
    a,b = map(int,input().split())
    ans[a] -= 1
    ans[b] -= 1
    t.Unite(a,b)

for i in range(N):
    ans[i+1] += t.Count(i+1)

for i in range(K):
    c,d = map(int,input().split())
    if t.isSameGroup(c,d):
        ans[c] -= 1
        ans[d] -= 1

del ans[0]
print(' '.join(map(str,ans)))

Measured memory_bytes: 15636
def mdist(a, b):
    return abs(a[0]-b[0]) + abs(a[1]-b[1])

n = int(input())
data = [[0, 0, 0]] + [[int(d) for d in input().split(' ')] for _ in range(n)]

for d1, d2 in zip(data[:-1], data[1:]):
    dt = d2[0] - d1[0]
    dist = mdist(d1[1:], d2[1:])
    if not ((dt >= dist) and ((dt%2)==(dist%2))):
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 22628
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>

using namespace std;
#define REP(m,n) for(int i=m;i<n;++i)
#define REPj(m,n) for(int j=m;j<n;++j)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair

int main() {
	int h, w, c=0;
	cin >> h >> w;
	int ans = 0, ansa = 0;
	vector<int>v(30, 0);
	REP(0, h) {
		string tmp;
		cin >> tmp;
		REPj(0, w) {
			v[(int)tmp[j] - (int)'a']++;
		}
	}
	if (h % 2 == 1) {
		c += w/2;
	}
	if (w % 2 == 1) {
		c += h/2;
	}
	REP(0, v.size()) {
		if (v[i] % 4 == 2) {
			ans++;
		}
		if (v[i] % 2 == 1) {
			ansa++;
		}
	}
	if (ans > c || ansa > 1) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
    using System.Text;
    using System.Collections.Generic;
    using static System.Math;
    using System.Linq;
    using static System.Array;
    
    namespace ConsoleApp2
    {
    class Program
    {
        static long H;
        static long W;
        static String[] map;
        static void Main(string[] args)
        {

            var HW = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            H = HW[0];
            W = HW[1];
            map = new string[H];
            for (int i = 0; i < H; i++)
            {
                map[i] = Console.ReadLine();
            }
            var tmp = Cul();
            var ans = Cul2(tmp);

            for (int i = 0; i < ans.Length; i++)
            {
                Console.WriteLine(String.Join("",ans[i]));
            }
            
        }

        static char[][] Cul2(List<string> inp)
        {
            var num = inp.Count();
            var ans = new List<char>[num];
            for (int i = 0; i < num; i++)
            {
                ans[i] = new List<char>();
            }
            for (int i = 0; i < W; i++)
            {
                var flg = true;
                for (int j = 0; j < num; j++)
                {
                    if(inp[j][i] == '#')
                    {
                        flg = false;
                        break;
                    }
                }

                if (!flg)
                {
                    for (int j = 0; j < num; j++)
                    {
                        ans[j].Add(inp[j][i]);
                    }
                }
            }
            var tmp = new char[num][];
            for (int i = 0; i < num; i++)
            {
                tmp[i] = ans[i].ToArray();
            }

            return tmp;
        }


        static List<string> Cul()
        {
            var ans = new List<string>();
            for (int i = 0; i < H; i++)
            {
                if (map[i].Contains("#"))
                {
                    ans.Add(map[i]);
                }
            }
            return ans;
        }
    }

}


Measured memory_bytes: 13524
#include<bits/stdc++.h>
using namespace std;
int n,a[100001],b[100001],ans;
map <int,int> c;
int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+1+n);
	for(int i=1;i<=n;++i){
		c[b[i]]=i;
	}
	for(int i=1;i<=n;++i){
		if(abs(i-c[a[i]])%2==1)ans++;
	}
	cout<<ans/2;
}

Measured memory_bytes: 7808
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String s=sc.next();
		String str="";
		String temp="";
		
		for(int i=1;i<=s.length();i++){
				
				if(s.charAt(i-1)=='0'){
					str+="0";
					
				}else if(s.charAt(i-1)=='1'){
					str+="1";
					
				}else if(s.charAt(i-1)=='B'){
					
					for(int j=0;j<str.length()-1;j++){
						temp+=str.charAt(j);
					}
					str=temp;
					temp="";
				}
		}
		
		sc.close();
		System.out.print(str);
	}
}

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

int main()
{
    string x, y;
    cin >> x >> y;
    if(x < y)
    {
        cout << "<" << endl;
    }
    else if(x > y)
    {
        cout << ">" << endl;
    }
    else
    {
        cout << "=" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using ll = long long;
using namespace std;

int main() {
    ll R, G, B, N;
    cin >> R >> G >> B >> N;
    // r + g + b == N
    // r, g, b >= 0
    ll ans = 0;
    for (int i = 0; i <= N/R; ++i) {
        for (int j = 0; j <= N/G; ++j) {
            int v = N - i * R - j * G;
            if (v >= 0 && v % B == 0)
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
require 'matrix'
class Matrix
  # v2.3 では代入不可
  def []=(i, j, x)
    @rows[i][j]=x
  end
end
h, w = gets.split.map(&:to_i)
cm = Matrix.build(h + 2, w + 2){0}
que = []
a = []
1.upto(h) do |i|
  s = gets.chomp
  1.upto(w) do |j|
    if s[j - 1] == '.'
      cm[i, j] = -1
      a << [i, j]
    end
  end
end
ans = 0
a.each do |b|
  dm = Marshal.load(Marshal.dump(cm))
  que.push(b[0], b[1], 0)
  dm[b[0], b[1]] = 0
  while que.size > 0
    y = que.shift
    x = que.shift
    r = que.shift
    ans = r + 1 if ans < r + 1
    if dm[y + 1, x] == -1
      dm[y + 1, x] = r + 1
      que.push(y + 1, x, r + 1)
    end
    if dm[y - 1, x] == -1
      dm[y - 1, x] = r + 1
      que.push(y - 1, x, r + 1)
    end
    if dm[y, x - 1] == -1
      dm[y, x - 1] = r + 1
      que.push(y, x - 1, r + 1)
    end
    if dm[y, x + 1] == -1
      dm[y, x + 1] = r + 1
      que.push(y, x + 1, r + 1)
    end
  end
end
puts ans - 1

Measured memory_bytes: 4348
import java.util.Scanner;

public class Main {

	static int mincost(int i, int[] ar, int[] dp) {

		if (i >= ar.length)
			return 0;

		if (i == ar.length - 1)
			return 0;

		if (dp[i] != -1)
			return dp[i];

		int left = Math.abs(ar[i] - ar[i + 1]) + mincost(i + 1, ar, dp);
		
		int right = Integer.MAX_VALUE;
		
		if(i + 2 < ar.length)
			right = Math.abs(ar[i] - ar[i + 2]) + mincost(i + 2, ar, dp);

		return dp[i] = Math.min(left, right);
	}

	public static void main(String args[]) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ar[] = new int[n];
		int dp[] = new int[n];

		for (int i = 0; i < n; i++) {
			ar[i] = sc.nextInt();
			dp[i] = -1;
		}

		System.out.println(mincost(0, ar, dp));
	}

}

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

#ifdef LOCAL_PC
	#define debug(args...) { cout.flush(); fflush(stdout); fprintf(stderr, args); }
#else
	#define debug(args...) ; /*  */
#endif
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class Ty> Ty rnd(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }

template<class num> inline void rd(num &x) {
	char c; while(isspace(c = getchar()));
	bool neg = false;
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar()))
		x = (x << 3) + (x << 1) + c - '0';
	if (neg) x = -x;
} template <class T, class... Args> inline void rd(T& x, Args&... args) { rd(x); rd(args...); }

const int MAXN = 2e5 + 5, INF = 0x3f3f3f3f;

int main() {
	ios::sync_with_stdio(false); cin.tie(NULL);
	int n, k; cin >> n >> k;
	map<int, int> f;
	for (int i = 0; i < k; i++) {
		int x; cin >> x;
		while(x--) {
			int y; cin >> y;
			f[y]++;
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; i++) ans += f[i] == 0;
	cout << ans << endl;

}



Measured memory_bytes: 3620
#[allow(unused_imports)]
use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

const MOD : i32 = 1_000_000_007;

  

fn main() {
    let nm = read_vec::<usize>();
    let n = nm[0];
    let m = nm[1];
    let s = read_vec::<u32>();
    let t = read_vec::<u32>();

    let answer = solve(n, m, &s, &t);
    println!("{}", answer);
}

fn solve(n: usize, m: usize, s: &[u32], t: &[u32]) -> i32 {
    let mut dp: Vec<Vec<i32>> = vec![vec![0; m+1]; n+1];
    let mut sum: Vec<Vec<i32>> = vec![vec![0; m+1]; n+1];

    dp[0][0] = 0;
    sum[0][0] = 1;

    for i in 1..n + 1 {
        dp[i][0] = 0;
        sum[i][0] = 1;
    }

    for j in 1..m + 1 {
        dp[0][j] = 0;
        sum[0][j] = 1;
    }

    for i in 1..n + 1 {
        for j in 1..m + 1 {
            if s[i - 1] == t[j - 1] {
                dp[i][j] = sum[i - 1][j - 1];
            }
            sum[i][j] = sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1] + dp[i][j];
            sum[i][j] %= MOD;
        }
    }

    let mut answer = sum[n][m];
    if answer < 0 {
        answer += MOD;
    }

    return answer;
}


Measured memory_bytes: 37116
def inpl(): return [int(i) for i in input().split()]
def burger(x):
    if not x:
        return 1
    return 3 + 2*burger(x-1)
def pate(n,x):
    if not n or not x:
        return [0, 1][x == 1]
    result = 0
    if x == burger(n):
        return 2**(n+1)-1
    if x == 2 + burger(n-1):
        return 2**n-1 + 1
    elif x > (burger(n)+1)//2:
        result += 2**n-1 + 1
        x -= (burger(n-1)+2)
    else:
        x -= 1
    return result + pate(n-1,x)      
N, X = inpl()
print(pate(N, X))

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {




            var a = Console.ReadLine().GroupBy(x => x);
            bool j = true;
            foreach (var item in a)
            {
                if (item.Count() != 2)
                {
                    j = false;
                }
            }

            if (a.Count() != 2)
            {
                j = false;
            }
            Console.WriteLine(j ? "Yes" : "No");
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll A[200002],B[200002];

int main()
{
    ll n,m,k,i,j,ans;
    cin>>n>>m>>k;
    for(i=1; i<=n; i++)
    {
        scanf("%lld",&A[i]);
        A[i]+=A[i-1];
    }
    for(i=1; i<=m; i++)
    {
        scanf("%lld",&B[i]);
        B[i]+=B[i-1];
    }
    A[n+1]=B[m+1]=2e9;
    ans=0;
    for(i=0; i<=n; i++)
    {
        if(A[i]>k)break;
        j=lower_bound(B+1,B+m+1,k-A[i])-B;
        if(B[j]>k-A[i])j--;
        ans=max(ans,i+j);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6888