akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=1e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e6+10;
	//------------------FIXED------------------
	int a[N];
	void main()
	{
		int k=qread(),n=qread();
		if(k%2==0){ write1(k/2);fo(i,2,n) write1(k);return; }
		int m=(k+1)/2;a[n]=m;int ln=1;
		fd(i,n-1,1)
		{
			a[i]=m;ln++;
			if((n-i)&1)
			{
				if(a[i+ln-1]==1) ln--;
				else {a[i+ln-1]--;while(i+ln-1<n) ln++,a[i+ln-1]=k;}
			}
		}fo(i,1,ln) write1(a[i]);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

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

#define max(x,y)  (x > y) ? x:y
#define min(x,y)  (x < y) ? x:y

int main(){
  int n;
  int maxv,minv;
  int i;
  int *R;

  scanf("%d",&n);
  R = (int *)malloc(sizeof(int) * n);

  for (i = 0;i < n;i++)
    scanf("%d",&R[i]);

  maxv = R[1] - R[0];
  minv = R[0];

  for (i = 1;i < n;i++){
    maxv = max(maxv,R[i] - minv);
    minv = min(minv,R[i]);
  }

  printf("%d\n",maxv);
  free(R);
  
  return 0;
}



Measured memory_bytes: 2284
#include <iostream>
#include <string>

int main() {

    std::uint16_t k = 0;
    std::cin >> k;
    std::string s;
    std::cin >> s;

    if(s.size() <= k) std::cout << s;
    else std::cout << s.substr(0, k) << "...";

    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    double w, h, x, y;
    cin >> w >> h >> x >> y;

    printf("%.10f", h*w / 2.0);
    if(x == w/2.0 && y == h/2.0)cout << " 1" << endl;
    else cout << " 0" << endl;
}

Measured memory_bytes: 3788
// AtcoderTemplate.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include "bits/stdc++.h"
using namespace std;

int main()
{
	vector<int> v(3);
	cin >> v[0] >> v[1] >> v[2];
	sort(v.begin(), v.end());
	cout << v[2] * 10 + v[1] + v[0] << endl;



    return 0;
}



Measured memory_bytes: 256
///////////////////// author : TrEbLeCleF /////////////////////
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
#define FOr(i, a, b) for (int i=a; i<(b); i++)
#define For(i, a) for (int i=0; i<(a); i++)
#define FOrr(i,a,b) for (int i = (b)-1; i >= a; i--)
#define Forr(i,a) for (int i = (a)-1; i >= 0; i--)
/////////////////////////// ..... ///////////////////////////
#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() { cerr << "]\n";}
template<typename T, typename ...Args> void DBG(T first, Args... args){
cerr << first; if(sizeof...(args))cerr<<", "; DBG(args...); }
/////////////////////////// ..... ///////////////////////////
#define int ll
#define pb(x) push_back(x)
#define print(v,s,e) for(int i = s; i < e; i++)cout << v[i]<<" ";cout<<"\n";
#define INF 1e17
#define PI 3.14159265358979323846 
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
/////////////////////////// GLOBAL ///////////////////////////
const int N = 101;
int a[N],b[N];
/////////////////////////// GLOBAL ///////////////////////////
void solve(){
	int n,W; cin >> n >> W;
	For(i,n)cin >> a[i] >> b[i];
	int dp[n][W+1];
	memset(dp,0,sizeof(dp));
	dp[0][a[0]] = b[0];
	For(i,n){
		For(j,W+1){
			if(i+1 < n && j+a[i+1] < W+1)
			dp[i+1][j+a[i+1]] = max(dp[i+1][j+a[i+1]], b[i+1] + dp[i][j]);
			if(i+1 <n)
			dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
		
		}
	}
	cout << *max_element(dp[n-1],dp[n-1]+W+1) <<"\n";
}
int32_t main(){ 
	#ifndef ONLINE_JUDGE
		clock_t tStart = clock();
		freopen("TC", "r", stdin);
		//freopen("output.txt","w",stdout);
	#endif 
    ios_base:: sync_with_stdio(false); 
   	cin.tie(0); 
	int t=1;
	//cin >> t;
	for(int tt=1;tt<=t;tt++){
		//cout << "Case #"<<tt<<": ";
		solve();
	}
	#ifndef ONLINE_JUDGE
    	cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
    #endif
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 2019;

int mod(int x) {
    x %= MOD;
    if (x < 0) { x += MOD; }
    return x;
}

// O(log(p))
int mpow(int x, int p) {
    if (p == 0) { return 1; }
    if (p % 2 == 1) { return mod(x * mpow(x, p - 1)); }
    int sub = mpow(x, p / 2);
    return mod(sub * sub);
}

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

    string s;
    cin >> s;

    vll x(s.size() + 1, 0);
    ll num = 0;

    rep(i, 0, (int)s.size()) {
        num = mod(num * 10 + ll(s[i] - '0'));
        x[i + 1] = num;
    }

    // O(n * log(MOD))
    vll fac(s.size() + 1), inv(s.size() + 1);
    fac[0] = 1;
    rep(i, 1, (int)s.size() + 1) { fac[i] = mod(fac[i - 1] * 10); }

    vll dp(2019, 0);
    rep(i, 0, (int)s.size() + 1) { dp[mod(x[i] * fac[(int)s.size() - i])]++; }

    ll ans = 0;
    for (ll cnt : dp) { ans += cnt * max(cnt - 1, (ll)0) / 2; }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8376
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const double inf=1e8;	
int main(){
	int n,m,r;
	cin>>n>>m>>r;
	vi a(m);
	rep(i,m)cin>>a[i];
	map<int,int>ma;
	rep(i,m)ma[a[i]]=i+1;
	vvi in(n,vi(r));
	rep(i,n)rep(j,r)cin>>in[i][j];
	int N=1<<m;
	vi dp(N,inf);
	dp[N-1]=0;
	queue<int>q;
	q.push(N-1);
	while(!q.empty()){
		int b=q.front();q.pop();
		rep(k,r){
			int w=0;
			rep(i,m)if(b&1<<i&&ma[in[a[i]-1][k]])w|=1<<(ma[in[a[i]-1][k]]-1);
			if(dp[w]>dp[b]+1){
				dp[w]=dp[b]+1;
				q.push(w);
			}
		}
	}
/*	for(int i=N-1;i>0;i--)if(dp[i]!=inf)rep(k,r){
		vi t;
		rep(j,m)if(i&1<<j)t.pb(a[j]);
		rep(j,t.size())if(t[j])t[j]=in[t[j]-1][k];
		int w=0;
		rep(j,t.size())if(ma[t[j]])w|=1<<(ma[t[j]]-1);
		dp[w]=min(dp[w],dp[i]+1);
	}
	*/
	cout<<dp[0]<<endl;
}

Measured memory_bytes: 3452
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }

int main() {
  string s;
  cin >> s;

  vector<int> line;
  auto current = s[0];
  ull result = 0;
  ull zero = 0;
  ull one = 0;
  bool switched = false;
  each(i, s.size()) {
    if (s[i] == '0')
      zero++;

    if (s[i] == '1')
      one++;
  }

  result = (min(zero, one) * 2);
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int w,a,b;
  cin >> w >> a >> b;
  if(a > b){
    int temp = a;
    a = b;
    b = temp;
  }
  int answer = b -(a + w);
  if(answer < 0) answer = 0;
  cout << answer << endl;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,k;cin>>n>>k;
    char a;
    vector<char> arr;
    for (int i=0;i<k;i++){
        cin>>a;
        arr.emplace_back(a);
    }bool pos;string x;
    while (1){
        x=to_string(n);
        pos=true;
        for (int i=0;i<x.size();i++){
            for (int j=0;j<arr.size();j++){
                if (arr[j]==x[i]){
                    pos=false;
                    break;
                }
            }if (!pos)break;
        }if (pos)break;
        else n++;
    }cout<<n<<endl;
    return 0;

}


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


int negative(int* number, int m, int N, int minIdx, pair<int, int>* operation) {
	for (int i = N - 1; i >= 0; --i) {
		while (number[i] > number[i + 1]) {
		    if (number[minIdx] > number[i]) {
		    	minIdx = i;
		    }
			number[i] += number[minIdx];
			operation[m] = make_pair(minIdx + 1, i + 1);
			++m;
			if (number[minIdx] > number[i]) {
		    	minIdx = i;
		    }
		}
	}
	return m;
}

int positive(int* number, int m, int N, int maxIdx, pair<int, int>* operation) {
	for (int i = 1; i < N; ++i) {
		while (number[i] < number[i - 1]) {
		    if (number[maxIdx] < number[i]) {
		    	maxIdx = i;
		    }
			number[i] += number[maxIdx];
			operation[m] = make_pair(maxIdx + 1, i + 1);
			++m;
			if (number[maxIdx] < number[i]) {
		    	maxIdx = i;
		    }
		}
	}
	return m;
}

int main() {
	int N;
	cin >> N;
	int* save = new int[N];
	int* number = new int [N];
	int maxIdx = 0;
	int minIdx = 0;
	for (int i = 0; i < N; ++i) {
		cin >> number[i];
		save[i] = number[i];
		if (number[maxIdx] < number[i]) {
			maxIdx = i;
		}
		if (number[minIdx] > number[i]) {
			minIdx = i;
		}
	}
	int m = 0;
	pair<int, int>* operation = new pair<int, int>[2 * N];
	
	if (number[minIdx] < 0 && number[maxIdx] > 0) {
		if (-number[minIdx] > number[maxIdx]) {
			for (int i = 0; i < N; ++i) {
				if (number[i] > 0) {
					number[i] += number[minIdx];
					operation[m] = make_pair(minIdx + 1, i + 1);
					++m;
				}
			}
			// all is negative
			m = negative(number, m, N, minIdx, operation);
		} else {
			for (int i = 0; i < N; ++i) {
				if (number[i] < 0) {
					number[i] += number[maxIdx];
					operation[m] = make_pair(maxIdx + 1, i + 1);
					++m;
				}
			}
			//all is positive
			m = positive(number, m, N, maxIdx, operation);
		}
	} else if (number[maxIdx] <= 0) {
		//all is negative
		m = negative(number, m, N, minIdx, operation);
	} else if (number[minIdx] >= 0) {
		// all is positive
		m = positive(number, m, N, maxIdx, operation);
	}
	cout << m << endl;	
	for (int i = 0; i < m; ++i) {
		cout << operation[i].first << " " << operation[i].second << endl; 
	}
	
	return 0;
}

Measured memory_bytes: 384
#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(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(1){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
return 0;}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

char mat[10][10];
signed main(){
  ios::sync_with_stdio(false);cin.tie(0);

  int r , c , K;
  cin >> r >> c >> K;

  for(int i = 0; i < r; i++) {
    for(int j = 0; j < c; j++) {
      cin >> mat[i][j];
    }
  }

  int ans = 0;
  for(int M1 = 1; M1 < (1 << r); M1++) {
    for(int M2 = 1; M2 < (1 << c); M2++) {
      int black = 0;
      for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
          if( (M1 & (1 << i) ) && (M2 & (1 << j)) && mat[i][j] == '#' ) {
            black++;
          }
        }
      }
      if(black == K) {
        ans++;
      }
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3140
#include<stdio.h>
int main(void)
{
int c1,c5,c10,c50,c100,c500;
scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
if(c1*1+c5*5+c10*10+c50*50+c100*100+c500*500>=1000){
	printf("%d\n",1);
}
else{
	printf("%d\n",0);
}
return 0;
}



Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, a=0, b=0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n; ++i) {
        if (s[i]=='#') {
            a++;
        }
        else if (s[i]=='.' && a>0){
            b++;
            a--;
        }
    }
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
            var N = items[0];
            var K = items[1];
            var A = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();

            var work = Enumerable.Range(0, K).Select(elem => (long)A[elem]).Sum();
            foreach (var i in Enumerable.Range(0, N))
            {
                if (i < K)
                {
                    ;
                }
                else
                {
                    Console.WriteLine(A[i - K] < A[i] ? "Yes" : "No");
                }
            }
        }
    }
}


Measured memory_bytes: 46732
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}

const int N = 10010;
char s[N], p[N];
int n, m, k;
ll dp[2][N];
ll a[N];
ll f[N];
ll rf[N];
ll C[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	f[0] = 1;
	for (int i = 1; i < N; i++)
		f[i] = mult(f[i - 1], i);

	scanf("%s", s);
	scanf("%s", p);
	m = strlen(s);
	n = k = 0;
	for (int i = 0; i < m; i++) {
		if (s[i] == '0') continue;
		if (p[i] == '1')
			n++;
		else
			k++;
	}

	dp[0][0] = 1;
	if (k == 0)
		a[0] = 1;
	for (int i = 0; i < n + k; i++) {
		for (int j = 0; j <= k; j++)
			dp[1][j] = 0;
		for (int j = 0; j <= k; j++) {
			if (j < k)
				dp[1][j + 1] = add(dp[1][j + 1], dp[0][j]);
			if (i - j < n)
				dp[1][j] = add(dp[1][j], mult(dp[0][j], j));
		}
		for (int j = 0; j <= k; j++)
			dp[0][j] = dp[1][j];
		if (i >= k - 1)
			a[i + 1 - k] = dp[0][k];
	}

	C[0] = 1;
	for (int i = 1; i <= n + k; i++) {
		for (int j = i; j > 0; j--)
			C[j] = add(C[j], C[j - 1]);
	}

	ll ans = 0;
	for (m = 0; m <= n; m++)
		ans = add(ans, mult(a[m], mult(f[n - m], C[n - m])));
	ans = mult(ans, mult(f[n], mult(f[k], f[k])));
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 512
"use strict";

const main = arg => {
    const inputList = arg.trim().split("\n");
    // 回答を記述
    const A = parseInt(inputList[0].split(" ")[0]);
    const V = parseInt(inputList[0].split(" ")[1]);
    const B = parseInt(inputList[1].split(" ")[0]);
    const W = parseInt(inputList[1].split(" ")[1]);
    const T = parseInt(inputList[2].split(" ")[0]);

    // WがV以上だった場合、追いつけない
    if (V <= W) {
        console.log("NO");
    } else {
        const pointDiff = Math.abs(A - B);
        const speedDiff = V - W;
        if ((pointDiff / speedDiff <= T)) {
            console.log("YES");
        } else {
            console.log("NO");
        }
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29624
#include <bits/stdc++.h>
#define MAXN 2000005
using namespace std;

const long long M=1e9+7;

int a,b,c,d;
long long inv[MAXN],fac[MAXN],invfac[MAXN],ans;

inline void fadd(long long &a,long long b){a+=b;if (a>=M) a-=M;return ;}

inline long long C(int n,int m)
{
	return fac[n]*invfac[m]%M*invfac[n-m]%M;
}

int main()
{
	inv[0]=inv[1]=invfac[0]=fac[0]=1LL;
	for (int i=1;i<MAXN;i++) fac[i]=fac[i-1]*i%M;
	for (int i=2;i<MAXN;i++) inv[i]=(M-M/i)*inv[M%i]%M;
	for (int i=1;i<MAXN;i++) invfac[i]=invfac[i-1]*inv[i]%M;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	for (int i=b;i<=d;i++)
	{
		long long t=C(i+c+1,i+1);
		fadd(t,M-C(i+a,i+1));
		fadd(ans,t);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 47232
import java.util.*
/**
 * Created by nosan on 2017/04/22.
 */
fun main(args: Array<String>) {
//    0≦A,B≦23
    //24 時間表記 (0:00〜23:59) で A 時ちょうどであり、コンテストがちょうど B 時間後に始まります。
    //コンテストの開始時刻は、24 時間表記で何時ちょうどでしょうか?
    //
//    入力
//    入力は以下の形式で標準入力から与えられる。
//    A B
    val scanner = Scanner(System.`in`)
    val A = scanner.nextLong()
    val B = scanner.nextLong()
    var C=A+B
    if(A+B>=24){
        C-=24
    }
    println(C)
}

Measured memory_bytes: 21544
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<tuple<string, int, int> > v(n);
    for(int i=0; i<n; ++i){
        string s;
        int p;
        cin >> s >> p;
        v[i] = make_tuple(s, -p, i+1);
    }

    sort(v.begin(), v.end());
    for(int i=0; i<n; ++i)
        cout << get<2>(v[i]) << endl;

    return 0;
}


Measured memory_bytes: 256
N, M = list(map(lambda x: int(x), input().split(' ')))
X = list(map(lambda x: int(x), input().split(' ')))

if M <= N:
    print(0)

else:
    X.sort()
    diffs = [X[i+1] - X[i] for i in range(M-1)]
    diffs.sort(reverse=True)
    n = N-1
    ans = sum(diffs[n:])
    print(ans)




Measured memory_bytes: 56360
class UnionFind:
    def __init__(self,n):
        self.table = [-1]*n

    def root(self,x):
        stack = []
        tbl = self.table
        while tbl[x]>=0:
            stack.append(x)
            x = tbl[x]
        for y in stack:
            tbl[y] = x
        return x

    def find(self,x,y):
        return self.root(x)==self.root(y)
    def union(self,x,y):
        r1 = self.root(x)
        r2 = self.root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -=1
        else:
            self.table[r1] = r2
if __name__=='__main__':
    N,M = map(int,input().split())
    AB = [list(map(int,input().split())) for _ in range(M)]
    uf = UnionFind(N)
    for i in range(M):
        uf.union(AB[i][0]-1,AB[i][1]-1)
    r = [0]*N
    for i in range(N):
        r[uf.root(i)] = r[uf.root(i)] + 1
    print(max(r))

Measured memory_bytes: 51548
#!/usr/bin/env python
# coding: utf-8

# In[1]:


N, K = map(int, input().split())


# In[2]:


A = [int(x) for x in input().split()]


# In[11]:


ones = [0] * 40
for a in A:
    s = format(a, '040b')
    for i in range(40):
        ones[i] += int(s[i])
    


# In[12]:


kb = format(K, '040b')
flag = False
ret = []
for i in range(40):
    if flag:
        if ones[i] >= N / 2:
            ret.append(0)
        else:
            ret.append(1)
    else:
        if kb[i] == '0':
            ret.append(0)
        else:
            if ones[i] >= N / 2:
                ret.append(0)
                flag = True
            else:
                ret.append(1)


# In[13]:


ans = 0
for i in range(40):
    if ret[i] == 0:
        ans += 2 ** (39 - i) * ones[i]
    else:
        ans += 2 ** (39 - i) * (N - ones[i])


# In[14]:


print(ans)


# In[ ]:





# In[ ]:





# In[ ]:






Measured memory_bytes: 69264
#include<stdio.h>
int main(){
  int a,b,c=0;
  scanf("%d %d",&a,&b);
  int d[a];
  for(int i=0; i<a; i++){
    scanf("%d",&d[i]);
  }
  for(int i=a-1; 0<i; i--){
    for(int j=0; j<i; j++){
      if(d[j]<d[j+1]){
        int e=d[j];d[j]=d[j+1];d[j+1]=e;
      }
    }
  }
  for(int i=0; i<b; i++){
    c+=d[i];
  }
  printf("%d",c);
  return 0;}


Measured memory_bytes: 128
// CPP program for finding number of divisor 
#include<iostream>
// #include <bits/stdc++.h> 
using namespace std; 
#define ll long long 


// driver program 
int main() 
{ 
    ll int n, i, c0 = 0, c1 = 0 ,c2 = 0 ,c3 = 0;
    cin >> n;
    string s;
    for(i=0;i<n;i++)
    {
        cin >> s;
        if(s[0] == 'A')
        c0++;
        else if(s[0] == 'W')
        c1++;
        else if(s[0] == 'T')
        c2++;
        else if(s[0] == 'R')
        c3++;
    }
    printf("AC x %lld\nWA x %lld\nTLE x %lld\nRE x %lld",c0, c1, c2, c3);
	return 0; 
} 


Measured memory_bytes: 3676
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
int p[21];
int q[21];

int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	for(int i=0;i<a;i++)scanf("%d",q+i);
	int ret=0;
	for(int i=0;i<a;i++)ret+=max(0,p[i]-q[i]);printf("%d\n",ret);
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	string S=in<string>(),T=in<string>();
	ll A=1;
	for(int i=0;i<N;){
		if(S[i]==T[i]){
			if(i==0){
				A *= 3;
			}
			else{
				if(S[i-1]==T[i-1]){
					A *= 2;
					A %= atcoder_mod;
				}
			}
			i++;
		}
		else{
			if(i==0){
				A *= 6;
			}
			else{
				if(S[i-1]==T[i-1]){
					A *= 2;
					A %= atcoder_mod;
				}
				else{
					A *= 3;
					A %= atcoder_mod;
				}
			}
			i+=2;
		}
	}
	out(A);
	return 0;
}


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

using namespace std;

const auto MOD = (long long) 1e9 + 7;

long long dp[100005][13] = {0};

int main() {
    string S;
    cin >> S;

    dp[0][0] = 1;
    for (int i = 0; i < S.size(); i++) {
        int c;
        if (S[i] == '?') {
            c = -1;
        } else {
            c = S[i] - '0';
        }

        for (int j = 0; j < 10; j++) {// 上からi+1桁目の数字
            if (c == -1 || c == j) {
                for (int k = 0; k < 13; k++) {// 上i桁を13で割った余り
                    dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
                }
            }
        }
        for (int j = 0; j < 13; j++) {
            dp[i + 1][j] %= MOD;
        }
    }

    cout << dp[S.size()][5] << endl;
    return 0;
}

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

int main() {
	string weather[] = {"Sunny", "Cloudy", "Rainy"} ;
	string S ;
	cin >> S ;
	for(int i = 0 ; i < 3 ; i++) {
		if( S == weather[i] ) {
			cout << weather[(i+1)%3] << endl ;
			break ;
		}
	}

	return 0;
}


Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
s = gets.chomp

res = 0

lr = 0
rl = 0

s.length.times do |i|
  next if i >= s.length - 1
  res += 1 if s[i] == s[i + 1]
  lr += 1 if s[i] != s[i + 1] and s[i] == 'L'
  rl += 1 if s[i] != s[i + 1] and s[i] == 'R'
end

sw = [lr, rl, k].min

k -= sw
res += sw * 2
lr -= sw
rl -= sw

if lr+rl > 0 and k > 0
  res += 1
end

puts res

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

using namespace std;

#define ll long long int
#define ld long double
#define pii pair<int,int>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define bit(a,b) ((a>>b)&1)
#define IOS ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

const ll mx = 1e6+1, Mod = 1e9+7;

int n;

int main()
{
    string s;
    cin >> s;
    if(s[0]!='A')
        return cout << "WA", 0;
    int c=0;
    for(int i=2;i<s.size()-1;i++)
        if(s[i]=='C')
            c++, s[i]='c';
    if(c!=1)
        return cout << "WA", 0;
    for(int i=1;i<s.size();i++)
        if(s[i]<'a')
            return cout << "WA", 0;
    cout << "AC";
    return 0;
}












Measured memory_bytes: 256
/**
  * @brief atcoder
  * @author yao
  */
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#define ft first
#define sd second
#ifdef DBG
#   define dbg_pri(x...) fprintf(stderr,x)
#else
#   define dbg_pri(x...) 0
#   define NDEBUG
#endif //DBG
#include <cassert>

typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;

#define N 128

int a[N];

int main()
{
    int n;
    lli k=1000, s=0;
    scanf("%d", &n);
    for(int i=0;i<n;++i) scanf("%d", &a[i]);
    for(int i=0;i<n;++i)
    {
        if(a[i] > a[i+1]) k += s*a[i], s = 0;
        else s += k/a[i], k%=a[i];
    }
    printf("%lld\n", k);
    return 0;
}


Measured memory_bytes: 1732
a,b,h,m = map(int,input().split())
import math
alp = 0.5*(h*60+m)/180*math.pi
be = 6*m/180*math.pi
if abs(alp-be) <= math.pi:
    s = abs(alp-be)
else:
    s = 2*math.pi - abs(alp-be)
l = (a**2+b**2 - 2*a*b*math.cos(s))**(1/2)
print(l)

Measured memory_bytes: 9508
import itertools
s = input()
a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])

l = [0] * 8
l[0] = a + b + c + d
l[1] = a + b + c - d
l[2] = a + b - c + d
l[3] = a + b - c - d
l[4] = a - b + c + d
l[5] = a - b + c - d
l[6] = a - b - c + d
l[7] = a - b - c - d

if l[0] == 7:
  print('{}+{}+{}+{}=7'.format(a, b, c, d))
elif l[1] == 7:
  print('{}+{}+{}-{}=7'.format(a, b, c, d))
elif l[2] == 7:
  print('{}+{}-{}+{}=7'.format(a, b, c, d))
elif l[3] == 7:
  print('{}+{}-{}-{}=7'.format(a, b, c, d))
elif l[4] == 7:
  print('{}-{}+{}+{}=7'.format(a, b, c, d))
elif l[5] == 7:
  print('{}-{}+{}-{}=7'.format(a, b, c, d))
elif l[6] == 7:
  print('{}-{}-{}+{}=7'.format(a, b, c, d))
elif l[7] == 7:
  print('{}-{}-{}-{}=7'.format(a, b, c, d))

Measured memory_bytes: 3064
M=998244353
n,m,k=map(int,input().split())
p,c=[m]*n,[1]*n
for i in range(1,n):
  p[i]=p[i-1]*(m-1)%M
  c[i]=c[i-1]*(n-i)*pow(i,M-2,M)%M
print(sum(p[n-i-1]*c[i]%M for i in range(k+1))%M)

Measured memory_bytes: 24576
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,j,n,wt,tot=0;
	int v[100009],w[100009];
	cin>>n>>wt;
	for(i=0;i<n;i++)
	{
		cin>>w[i]>>v[i];
		tot+=v[i];
	}
	long long int dp[n+1][tot+1];
	for(i=0;i<=n;i++)
	{
		dp[i][0]=0;
		for(j=1;j<=tot;j++)
			dp[i][j]=INT_MAX;
	}
	for(i=1;i<=n;i++)
	{
		for(j=0;j<=tot;j++)
			dp[i][j]=dp[i-1][j];
		for(j=v[i-1];j<=tot;j++)
		{
			if(dp[i][j]==INT_MAX && dp[i-1][j-v[i-1]]==INT_MAX)
				continue;
			else
				dp[i][j]=min(dp[i][j],dp[i-1][j-v[i-1]]+w[i-1]);
		}
	}

	int ans=-1;
	for(j=tot;j>=0;j--)
	{
		if(dp[n][j]<=wt)
		{
			ans=j;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 79104
# ABC131
# B Bite Eating
N, L = map(int, input().split())
A = 0
a = 1000
for i in range(1,N+1):
    x = L + i - 1
    A += x
    if abs(x) < a:
        a = abs(x)
if A >= 0:
    print(A-a)
else:
    print(A+a)


Measured memory_bytes: 9172
// J4180449 三宅亮輔
// 問題名
// - Breadth First Search
// 問題URL
// - https://onlinejudge.u-aizu.ac.jp/#/problems/ALDS1_11_C
// 所要時間
// -
// 学んだこと
//
//
//

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n, d[100];

vector<int> v[100];

queue<int> q;

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        d[i] = -1;
        int u, k;
        cin >> u >> k;
        u--;
        for(int j = 0; j < k; j++) {
            int x;
            cin >> x;
            x--;
            v[u].push_back(x);
        }
    }

    d[0] = 0;
    q.push(0);

    while(!q.empty()) {
        int vi = q.front();
        q.pop();

        for(int i = 0; i < v[vi].size(); i++) {
            int next = v[vi][i];
            if(d[next] == -1) {
                d[next] = d[vi] + 1;
                q.push(next);
            }
        }
    }

    for(int i = 0; i < n; i++) {
        cout << i + 1 << " " << d[i] << endl;
    }
}


Measured memory_bytes: 3160
#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; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#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() {
    init();
    string S;
    cin >> S;
    ll ans, N;
    ans = N = S.size();
    repe(i, 1, N){
        if (S[i - 1] != S[i]) chmin(ans, max(i, N - i));
    }

    cout << ans << endl;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

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


Measured memory_bytes: 3612
program answer2
 implicit none
 
 integer :: i, j, N, K, m
 integer, allocatable :: p(:)
 
 read(*,*) N, K
 allocate(p(N))
 read(*,*) p
 
 do j =1, N-1
   do i = 1, N-1
   if(p(i)>p(i+1)) then
     m=p(i)
     p(i)=p(i+1)
     p(i+1)=m
   end if
   end do
 end do
 
 m=0
 do i =1, K
   m= m+p(i)
 end do
 
 write(*,*) m
 deallocate(p)
 stop
end program answer2
 


Measured memory_bytes: 2812
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    if (!S.contains("1") || !S.contains("0")) {
      System.out.println(S.length() / 2);
      return;
    } else {
      // int one = 0;
      // int zero = 0;
      // for (int i = 0; i < S.length(); i++) {
      // if (S.charAt(i) == '0')
      // zero++;
      // else
      // one++;
      // }
      // int min = Math.min(zero, one);
      // System.out.println(Math.abs(min - S.length() / 2));
      char first = S.charAt(0);
      int count = 0;
      if (first == '1') {
        for (int i = 1; i < S.length(); i += 2) {
          if (S.charAt(i) != '0')
            count++;
        }

        for (int i = 0; i < S.length(); i += 2) {
          if (S.charAt(i) != '1')
            count++;
        }
      } else {
        for (int i = 1; i < S.length(); i += 2) {
          if (S.charAt(i) != '1')
            count++;
        }

        for (int i = 0; i < S.length(); i += 2) {
          if (S.charAt(i) != '0')
            count++;
        }
      }

      System.out.println(count);

    }
  }
}

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

using namespace std;

long long i,n,t,ans,sum;
long long a[1000007];
map<long long, long long> mem;

int main() {
	scanf("%lld",&n);
	for (i=0 ; i<n ; i++) {
		scanf("%lld",&a[i]);
	}
	
	mem[0] = 1;
	
	for (i=0 ; i<n ; i++) {
		sum += a[i];
		ans += mem[sum];
		mem[sum]++;
	}
	
	printf("%lld\n",ans);
}


Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;
int main(){
    string s;
    cin >> s;
    int c_s=0;
  //  int c_t=0;
    int c=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='S'){
            c_s++;
        }else{
            if(c_s!=0){
                c++;
                c_s--;
            }
        }
    }
    cout<<s.size()-c*2<<endl;
}

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

using namespace std;

inline void add(int &x,int y) {
  ((x+=y)>=MOD)?x-=MOD:0;
}

char str[300005];
int f[300005][7];

const int trans[7][2]={{1,2},{3,0},{4,6},{1,1},{5,2},{4,4},{6,6}};

int main() {
  scanf("%s",str+1);
  int n=strlen(str+1);
  f[0][0]=1;
  for(int i=1;i<=n;i++)
    for(int j=0;j<7;j++)
      if (f[i-1][j]) {
      	if (str[i]!='1') add(f[i][trans[j][0]],f[i-1][j]);
      	if (str[i]!='0') add(f[i][trans[j][1]],f[i-1][j]);
	  }
  printf("%d\n",(f[n][2]+f[n][6])%MOD);
  return 0;
}

Measured memory_bytes: 8704
n = int(input())

p = list(map(int, input().split()))

ans = 0
for i in range(n - 1):
    if i == 0:
        continue
    else:
        line = sorted([p[i - 1], p[i], p[i + 1]])
        if line[1] == p[i]:
            ans += 1

print(ans)

Measured memory_bytes: 3060
d,m=1e9+7,p[10001][200]={1};i,j,k,x,I;char s[11111];main(L){for(scanf("%s%d",s,&d);s[i];i+=++j/2,j%=2)for(x=L=j?9:s[i]-48,k=0;~x;x-=++k/d,k%=d)p[i+1][I=(j|x<L)*d+(k+x)%d]+=p[i][j*d+k],p[i+1][I]%=m;printf("%d",(*p[i]+p[i][d]-1+m)%m);}

Measured memory_bytes: 7936
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

r = load()

print(2 * r * math.pi)

Measured memory_bytes: 9456
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, x;
    cin >> a >> b >> x;
    if (a == 0) {
        cout << b / x + 1 << endl;
    } else {
        cout << b / x - (a - 1) / x << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n;cin>>n;
    string ans="";
    while(n!=0){
        if(abs(n)%2==0){
            n=-1*n/2;
            ans="0"+ans;
        }else{
            n=-1*(n-1)/2;
            ans="1"+ans;
        }
    }
    if(ans==""){
        cout<<0<<endl;
    }else{
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;



int main(){
    
ll a,b,c,d;
cin>>a>>b>>c>>d;
//ループは無理、演算でいく

ll x,y,z;
//a=x*(a/c)+a%cとするとｘは1以上A以下のCの倍数の個数
x=b/c-a/c;
//Aより大きくB以下のCの倍数の個数
if(a%c==0)x++;

y=b/d-a/d;
//AからBまでのなかのDの倍数の個数
if(a%d==0)y++;
//ここからCとDの最小公倍数LCMを求めて引く
//LCM=c*d/GCD
//つまり最大公約数GCDがわかればいい
//ユークリッドの互除法をつかう

ll p=max(c,d);
ll q=min(c,d);
ll r=p%q;

//p=q*[]+r、q=r*[]+r`,...の繰り返し
  
while(r>0){
   p=q;
   q=r;
   r=p%q;

}

ll gcd=q;
ll lcm=(c*d)/gcd;

z=b/lcm-a/lcm;
if(a%lcm==0)z++;
  
ll ans=(b-a+1)-(x+y-z);

cout<<ans<<endl;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		char[] a = s.toCharArray();

		String ans;

		if(!(a[0] == a[1] && a[0] == a[2] && a[0] == a[3]) && ((a[0] == a[2] && a[1] == a[3]) || (a[0] == a[3] && a[1] == a[2]) || (a[0] == a[1] && a[2] == a[3])))
ans = "Yes";
else
	ans = "No";

		System.out.println(ans);
	}

}


//import java.util.Scanner;
//
//public class Main {
//
//	public static void main(String[] args){
//		Scanner in = new Scanner(System.in);
//		int n = in.nextInt();
//
//		for(int i = 0; i < n; i++)
//
//		System.out.println(ans);
//	}
//
//}

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

struct UnionFind {
  vector<int> p;

  UnionFind(int N) : p(N) {
    for(int i=0; i<N; i++)
      p[i] = i;
  }

  int root(int x) {
    if (p[x] == x)
      return x;
    return p[x] = root(p[x]);
  }

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
      return;
    p[rx] = ry;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int N,K,L,i,p,q;
  cin >> N >> K >> L;
  UnionFind r(N), t(N);
  map<pair<int,int>,int> m;

  for(i=0; i<K; i++) {
    cin >> p >> q;
    r.unite(p-1,q-1);
  }
  for(i=0; i<L; i++) {
    cin >> p >> q;
    t.unite(p-1,q-1);
  }

  for(i=0; i<N; i++) {
    pair<int,int> p = make_pair(r.root(i), t.root(i));
    if(m.count(p))
      m.at(p)++;
    else
      m[p] = 1;
  }

  for(i=0; i<N; i++)
    cout << m.at(make_pair(r.root(i), t.root(i))) << " ";
  cout << endl;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string s;
    cin >> s;
    ll ans = INF;
    for(char c = 'a'; c <= 'z'; c++) {
        ll tmp = 0, con = 0;
        rep(j, 0, (ll)s.size()) {
            if(s[j] == c) {
                chmax(tmp, con);
                con = 0;
            } else {
                con++;
            }
        }
        chmax(tmp, con);
        chmin(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define sort(a) sort(a.begin(), a.end())
#define loop(n) for(ll i = 0; i<n; i++)
using namespace std;


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

int main(){
    ll a, b;
    cin>>a>>b;
    ll ans = gcd(a,b);
    ans = a*b/ans;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
mod = 10**9+7

if abs(n-m)>1:
    print(0)
else:
    ans=1
    for i in range(1,n+1):
        ans=ans*i%mod
    for j in range(1,m+1):
        ans=ans*j%mod
    if n==m:
        ans=ans*2%mod
    print(ans)

Measured memory_bytes: 3060