akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

#define int long long int

constexpr int INF = std::numeric_limits<int>::max();

int one[64];

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;


    vector<int> A(N);
    for (int &a:A) {
        cin >> a;
    }

    for (int a:A) {
        int i = 0;
        while (a != 0) {
            one[i] += a % 2;
            i++;
            a = a >> 1;
        }
    }

    int x = 0;
    bool sagari = false;
    for (int i = 62; i >= 0; i--) {
        // cout << one[i] << " ";
        x = x << 1;
        int o = (K >> i) % 2;
        if (o == 1) {
            if (one[i] < N - one[i]) {
                x = x | 0x01;
            } else {
                x = x | 0x00;
                sagari = true;
            }
        } else { // o == 0
            if (sagari) {
                if (one[i] < N / 2) {
                    x = x | 0x01;
                } else {
                    x = x | 0x00;
                }
            }
        }
    }
    // cout << endl;

    // cout << x << endl;

    int ans = 0;
    for (int a : A) {
        ans += x ^ a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define y1 y3

using namespace std;

int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

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

	return ans;
}


int maze[5001][5001];
int X1[300000],Y1[300000],X2[300000],Y2[300000];
int main() {
	int H,W;cin>>H>>W;
	int cnt=0;
	REP(i,H){
		REP(j,W)cin>>maze[i][j];
	}
	REP(i,H){
		if(i%2==0){
			REP(j,W){
				if(maze[i][j]%2==1){
					if(j==W-1){
						if(i==H-1)break;
						X1[cnt]=i;Y1[cnt]=j;
						X2[cnt]=i+1;Y2[cnt]=j;
						maze[i+1][j]++;
						cnt++;
						continue;
					}
					else{
					    X1[cnt]=i;Y1[cnt]=j;
				    	X2[cnt]=i;Y2[cnt]=j+1;
				    	maze[i][j+1]++;
				    	cnt++; 
					}
				}
			}
		}
		if(i%2==1){
					REPR(j,W-1){
						if(maze[i][j]%2==1){
							if(j==0){
								if(i==H-1)break;
								X1[cnt]=i;Y1[cnt]=j;
								X2[cnt]=i+1;Y2[cnt]=j;
								maze[i+1][j]++;
								cnt++;
								continue;
							}
							else{
							    X1[cnt]=i;Y1[cnt]=j;
							    X2[cnt]=i;Y2[cnt]=j-1;
							    maze[i][j-1]++;
							    cnt++;
							}
						}
					}
				}
	}
	cout<<cnt<<endl;
	REP(i,cnt){
		cout<<X1[i]+1<<" "<<Y1[i]+1<<" "<<X2[i]+1<<" "<<Y2[i]+1<<endl;
	}
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
vector<int> g[maxn];
ll fact[maxn],invfac[maxn];
int n,sz[maxn];
ll dp[maxn],invdp[maxn],ans[maxn];
inline ll quickpow(ll base,ll ind)
{
	ll ans=1;
	while(ind>0)
	{
		if(ind&1)ans=ans*base%MOD;
		ind>>=1;
		base=base*base%MOD;
	}
	return ans;
}
void dfs(int x,int fa)
{
	sz[x]=1;
	dp[x]=1;
	for(int i=0;i<g[x].size();i++)
	{
		int to=g[x][i];
		if(to==fa)continue;
		dfs(to,x);
		sz[x]+=sz[to];
		dp[x]=dp[x]*1ll*invfac[sz[to]]%MOD;
		dp[x]=dp[x]*1ll*dp[to]%MOD;
	}
	dp[x]=dp[x]*1ll*fact[sz[x]-1]%MOD;
	invdp[x]=quickpow(dp[x],MOD-2);
//	cout<<x<<' '<<dp[x]<<' '<<invdp[x]<<endl;
}
void dfs2(int x,int fa)
{
	ans[x]=dp[x];
	dp[x]=dp[x]*1ll*invfac[n-1]%MOD;
//	cout<<x<<" "<<dp[x]<<endl;
	for(int i=0;i<g[x].size();i++)
	{
		int to=g[x][i];
		if(to==fa)continue;
		
		
		dp[to]=dp[to]*1ll*invfac[sz[to]-1]%MOD;
		dp[to]=dp[to]*1ll*fact[n-1]%MOD;
		
		dp[to]=dp[to]*1ll*dp[x]%MOD;
		dp[to]=dp[to]*1ll*invdp[to]%MOD;
		dp[to]=dp[to]*1ll*fact[n-sz[to]-1]%MOD;
		dp[to]=dp[to]*1ll*invfac[n-sz[to]]%MOD;
		dp[to]=dp[to]*1ll*fact[sz[to]]%MOD;
		
		dfs2(to,x);
		
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	fact[0]=1;
	for(int i=1;i<=n;i++)
		fact[i]=fact[i-1]*1ll*i%MOD;
	invfac[n]=quickpow(fact[n],MOD-2);
	for(int i=n-1;i>=0;i--)
		invfac[i]=invfac[i+1]*1ll*(i+1)%MOD;
	dfs(1,0);
	dfs2(1,0);
	for(int i=1;i<=n;i++)
	{
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 22516
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    cout << abs(n-2)*abs(m-2) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << ( a + b ) * h / 2 << endl;
    return 0;
}


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

int main(){
  int a,b,c,d,e,k;
int count=0;
  cin>>a>>b>>c>>d>>e>>k;
  if(b-a<=k){
    if(c-b<=k&&c-a<=k){
     if(d-c<=k&&d-b<=k&&d-a<=k){
      if(e-d<=k&&e-c<=k&&e-b<=k&&e-a<=k){
        cout<<"Yay!"<<endl;
        count++;
  }
   }
    }
       }
   if(count==0) cout<<":("<<endl;
 
}


Measured memory_bytes: 256
#include<stdio.h>
int a[200010];
double p[200010];
int main()
{
	int n,k,i,j;scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		for(j=1;j<=a[i];j++)
		    p[i]+=j;
		p[i]/=a[i];    
	}
	int l=1,r=1,cnt=0;double sum=0,max=0;
	while(1)
	{
		while(r<=n&&cnt<k)
		    sum+=p[r++],cnt++;
		if(sum>max)max=sum;
		sum-=p[l++],cnt--;   
		if(r>n)break; 
	}
	printf("%.12lf\n",max);
}

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

if N == 1:
    a = 0
elif N != 1:
    a = 10 **(N-1)

for i in range(a,10**N):
    count = 0
    str_i = str(i)
    for j in range(M):
        if str_i[sc[j][0]-1] == str(sc[j][1]):
            count += 1
    if count == M:
        print(i)
        exit()
print(-1)


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


int main(){
	char α ='0';

	std::string text_A = "A";
	std::string text_a = "a";

	std::cin >> α;

	//あえて文字列文字コードで指定Z=0x5A
	if ('A'<=α && α<='Z') {
		std::cout << text_A << std::endl;
		return 0;
	}
	std::cout << text_a << std::endl;
	return 0;
}


Measured memory_bytes: 2984
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define F first
#define S second
#define _READ freopen("input.txt","r", stdin);
#define _FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
    lli n,w;
    cin>>n>>w;
    vector<pair<lli,lli>> v(n);
    for(auto &i:v)
        cin>>i.F>>i.S;
    const lli MAXI=1e10;
    vector<lli> dp(100001,MAXI);
    //(weight, value)
    //dp[i]--> min weight acquired satisfying the i unit of price
    dp[0]=0;
    for(lli i=0;i<n;i++)//iterate over all items one by one
    {
        
        lli weight=v[i].F,price=v[i].S;
        for(lli j=100000;j-price>=0;j--)
            dp[j]=min(dp[j],dp[j-price]+weight);
      	// wight= weight excluding this item + including this item's weight   
    }
    lli ans=0;
    for(lli i=0;i<100001;i++)
        if(dp[i]<=w)
            ans=i;
    cout<<ans<<"\n";
}
int main()
{
    solve();
    return 0;
}

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

bool comp(int w1,int h1,int w2,int h2){
    if(w1*w1+h1*h1==w2*w2+h2*h2)return h1 < h2;
    else return w1*w1+h1*h1 < w2*w2+h2*h2;
}

signed main (){
    int H,W;
    while(cin>>H>>W && H && W){
        int answ=1000,ansh=1000;
        for(int h=1;h<151;h++){
            for(int w=h+1;w<151;w++){
                if(comp(W,H,w,h) && comp(w,h,answ,ansh)){
                    answ=w;
                    ansh=h;
                }
            }
        }
        cout<<ansh<<" "<<answ<<endl;
    }


}
    
/*
*/



Measured memory_bytes: 3080
from collections import deque
h, w = map(int, input().split())
inf = int(1e9)
g = []
whites = 0
for _ in range(h):
  g.append(input())
  for c in g[-1]:
    whites += c == '.'
if (g[0][0] == '#' or g[-1][-1] == '#'):
    print(-1)
    exit()
d = [[inf for _ in range(w)] for _ in range(h)]
d[0][0] = 1
offsets = [(-1, 0), (0, 1), (0, -1), (1, 0)]
q = deque()
q.append((0, 0))
while q:
    i, j = q.popleft()
    for di, dj in offsets:
        ii = i + di
        jj = j + dj
        if (min(ii, jj) >= 0 and min(h-ii, w-jj) > 0 and g[ii][jj] == '.' and d[ii][jj] > d[i][j] + 1):
            d[ii][jj] = d[i][j] + 1
            q.append((ii, jj))
if d[-1][-1] == inf:
    print(-1)
else:
    print(whites - d[-1][-1])

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

typedef long long ll;

int main(void)
{
    int n,s, val, i;
    cin >> n >> s;
    vector <int> v;
    for(i = 0; i < n; i++)
    {
        cin >> val;
        v.push_back(val);
    }
    sort(v.begin(), v.end());

    int sum = 0;
    for(i = 0; i < s; i++)
    {
        sum += v[i];
    }
    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  map<ll, ll> mp;
  rep(i, n) {
    mp[a[i]]++;
  }

  map<int, pair<ll, ll>> mp2;
  ll sum = 0;
  for (auto& p : mp) {
    ll tmp1 = 0; ll tmp2 = 0;
    if (p.second >= 2) {
      tmp1 = (p.second * (p.second - 1)) / 2;
    }
    if (p.second >= 3) {
      tmp2 = ((p.second - 1) * (p.second -2)) / 2;
    }
    mp2[p.first] = make_pair(tmp1, tmp2);
    sum += tmp1;
  }

  for (auto& v : a) {
    auto p = mp2[v];
    cout << sum - p.first + p.second << endl;
  }

  return 0;
}


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

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define db(...) 42
#endif

using ll = long long;

int main() {
  string a, b;
  cin >> a >> b;
  if (a.size() > b.size()) {
    cout << "GREATER" << '\n';
  } else if (a.size() < b.size()) {
    cout << "LESS" << '\n';
  } else {
    for (int i = 0; i < (int)a.size(); i++) {
      if (a[i] > b[i]) {
        cout << "GREATER" << '\n';
        return 0;
      }
      if (a[i] < b[i]) {
        cout << "LESS" << '\n';
        return 0;
      }
    }
    cout << "EQUAL" << '\n';
  }
  return 0;
}


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

ll calc(ll x){
    if (x <= 9) return x;
    ll res = 0;
    ll y = x;
    ll cnt = 10;
    while (cnt <= x) {
        res *= 2;
        res += x % cnt;
        cnt *= 10;
    }
    res += x;
    while (y > 0){
        y /= 10;
        res += calc(y);
    }
    
    return res;
}

int main(){
    ll S;
    cin >> S;
    cout << calc(S) << endl;
    return 0;
}

Measured memory_bytes: 256
/***************************************************************
	File name: C.cpp
	Author: ljfcnyali
	Create time: 2019年08月04日 星期日 19时58分04秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 
typedef long long LL;

int a[100010], n;

int main()
{
    scanf("%d", &n);
    int sum = 0;
    REP(i, 1, n) scanf("%d", &a[i]);
    for ( int i = n; i >= 2; -- i )
    {
        if ( a[i] < a[i - 1] ) -- a[i - 1];
    }
    REP(i, 1, n - 1) if ( a[i] > a[i + 1] ) { puts("No\n"); return 0; }
    puts("Yes");
    return 0;
}

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

int main(int argc, char const *argv[])
{
    int h,w;
    cin >>h>>w;
    vector<string> vec_s{};
    string s;
    for (int i=0;i<h;++i){
        cin >>s;
        vec_s.push_back(s);
    }
    for(int i=0;i<2*h;++i){
        cout << vec_s[i/2] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000
using namespace std;
//65 - 90
int main()
{
    int n;
    while (cin >> n, n)
    {
        int table[100] = {};
        char ch, ans;
        int max_fi = 0, max_sec = 0;
        int pos;
        bool flag = false;
        rep(i, n)
        {
            //cout << max_fi << " " << max_sec << endl;
            cin >> ch;
            table[(int)ch]++;
            if (table[(int)ch] > max_sec)
            {
                if (table[(int)ch] > max_fi)
                {
                    max_fi = table[(int)ch];
                    ans = ch;
                    //cout << ans << endl;
                }
                else
                {
                    max_sec = table[(int)ch];
                }
            }
            if (max_fi > (n - i - 1) + max_sec && flag == false)
            {
                pos = i + 1;
                flag = true;
            }
        }
        int cnt_flag = 0;
        for (int i = 65; i <= 90; i++)
        {
            if (table[i] == max_fi)
                cnt_flag++;
        }
        if (cnt_flag > 1)
        {
            cout << "TIE" << endl;
        }
        else
        {
            cout << ans << " " << pos << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3096
class Baseball():
    def __init__(self, runner, score, out):
        self.runner = runner
        self.score = score
        self.out = out


for i in range(int(input())):
    inning = Baseball(0,0,0)
    while True:
        event = input()
        if event == 'HIT':
            if inning.runner == 3:
                inning.score += 1
            else:
                inning.runner += 1
        elif event == 'HOMERUN':
            inning.score += inning.runner +1
            inning.runner = 0
        elif event == 'OUT':
            inning.out += 1
            if 2 < inning.out:
                break
        else:
            pass
    print(str(inning.score))


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

#define LL long long
const int N = 1e5 + 5;
int f[N], n, m, x, y, a[N], ans;

inline int F(int x) {return (f[x] == x ? x : f[x] = F(f[x]));}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        f[i] = i;
    }      

    while(m--) {
        cin >> x >> y;
        f[F(x)] = F(y);
    }

    for(int i = 1; i <= n; i++) ans += F(i) == F(a[i]);
    cout << ans;
}

Measured memory_bytes: 4288
using System;
using System.Linq;
using System.Collections.Generic;

public class Prime{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
         
        var primeFactors = PrimeFactors(n);
         
        string output = primeFactors.Count() == 0 
                        ? n.ToString() 
                        : string.Join(" ", primeFactors.Select (f => f.ToString()).ToArray()); //AOJ??¨
                        //:string.Join(" ", primeFactors);
        Console.WriteLine("{0}: {1}", n, output);
    }
     
    public static IEnumerable<int> PrimeFactors(int n)
    {
        int i = 2;
        int tmp = n;
         
        while (i <= tmp)
        {
            if(tmp % i == 0){
                tmp /= i;
                yield return i;
            }else if(i*i > n){
                i = int.MaxValue; //???????????????
                yield return tmp;
			}else{
                i++;
            }
        }
    }
}

Measured memory_bytes: 5976
#include <cstdio>
#include <algorithm>

struct Node{
    int parent;
    int depth;
    int height;
    int degree;
    int left;
    int right;
    int sibling;
};

Node node[100000];

void setDepth(int num) {
    if(node[num].parent == -1) {
        node[num].depth = 0;
        return;
    }

    if(node[num].depth == -1){
        setDepth(node[num].parent);
        node[num].depth = node[node[num].parent].depth + 1;
    }
}

void setHeight(int num) {
	int h_left = 0;
	int h_right = 0;
    
    if (node[num].left != -1) {
        setHeight(node[num].left);
        h_left = node[node[num].left].height + 1;
    }
    if (node[num].right != -1) {
        setHeight(node[num].right);
        h_right = node[node[num].right].height + 1;
    }

    node[num].height = std::max(h_left, h_right);
}

void init() {
    for (int i; i < 100000; i++) {
        node[i].parent = -1;
        node[i].depth = -1;
        node[i].height = 0;
        node[i].degree = -1;
        node[i].left = -1;
        node[i].right = -1;
        node[i].sibling = -1;
    }
}

int main(){
	init();
    int n;
    scanf("%d", &n);
    int id, L, R = 0;

    for (int i = 0; i < n; i++) {
    	scanf("%d %d %d", &id, &L, &R);
        if(L != -1) {
            node[id].left = L;
            node[L].parent = id;
    	}

        if(R != -1) {
            node[id].right = R;
            node[R].parent = id;
        }

        if(L != -1 && R != -1) {
        	node[L].sibling = R;
        	node[R].sibling = L;
        }
        node[id].degree = (R!=-1) + (L!=-1);
    }

    for (int i = 0; i < n; i++) {
    	printf("node %d: parent = %d, sibling = %d, degree = %d, ",i,node[i].parent, node[i].sibling, node[i].degree);
        setDepth(i);
        setHeight(i);
        printf("depth = %d, height = %d, ",node[i].depth, node[i].height);

        if(node[i].parent == -1) printf("root\n");
        else if(node[i].degree != 0) printf("internal node\n");
        else printf("leaf\n");
    }

    return 0;
}




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

#define maxn 100002
#define FOR(i, l, r) for (int i=l; i<=r; ++i)
#define FORD(i, r, l) for (int i=r; i>=l; --i)
#define REP(i, r) for (int i=0; i<(int)r; ++i)
#define REPD(i, r) for (int i=(int)r-1; i>=0; --i)
#define fi first
#define se second
#define mk make_pair
#define nil NULL
#define y0 y902
#define y1 y232
#define x0 x92
#define x1 x899
#define next asdfa
#define sz size
#define Debug(X) {cerr << #X << " = " << X << '\n';}
#define PR(A, n) {cerr << #A << " = "; FOR(i, 1, n) cerr << A[i] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; REP(i, n) cerr << A[i] << ' '; cerr << '\n';}
typedef long long ll;
typedef double db;
typedef pair<db, db> dd;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int inf = 1e9;
const ll MOD = 1000000007;
template<class T> int getbit(T x, int pos) {return (x>>(pos-1)) & 1;}
template<class T> void turn_on(T &x, int pos) {x = x | ((T)1<<(pos-1));}
template<class T> void turn_off(T &x, int pos) {x = x & ~((T)1<<(pos-1));}
template<class T> T sqr(T a) {return a*a;}

int n, m;
ll fact[maxn];

int main() {
    //freopen("animal.inp", "r", stdin);
    //freopen("", "w", stdout);
    //ios::sync_with_stdio(0); cin.tie(0);
    scanf("%d%d", &n, &m);
    fact[0] = 1;
    FOR(i, 1, max(n, m)) fact[i] = fact[i-1]*i%MOD;
    if (abs(m-n)>1) printf("0");
    else if (n%2==m%2) {
        printf("%I64d", fact[n]*fact[m]*2%MOD);
    }
    else {
        printf("%I64d", fact[max(n, m)]*fact[min(m, n)]%MOD);
    }
}



Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_D&lang=jp

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    n = input()
    numbers = [int(x) for x in input().split()]
    print(min(numbers), max(numbers), sum(numbers))


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 8812
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int n;
vector<int>now;
vector<int>loop[16];
vector<int>loop1[16];
int ans;
void solve(int index)
{
  if(index==n)
  {
    bool ka=false;
    int nowi=0;
    for (int i = 0; i < now.size(); ++i)
    {
      if(now[i]==1)
      {
        nowi++;
        for (int j = 0; j < loop[i].size(); ++j)
        {
          if(now[loop[i][j]]==1){ka=true;break;}
        }
        for (int j = 0; j < loop1[i].size(); ++j)
        {
          if(now[loop1[i][j]]!=1){ka=true;break;}
        }
      }
      if(ka)break;
    }
    if(!ka)ans=max(ans,nowi);
    return;
  }
  now.pb(1);
  solve(index+1);
  now.pop_back();
  now.pb(0);
  solve(index+1);
  now.pop_back();
}
int main()
{
  //flash;
  cin>>n;
  for (int i = 0; i < n; ++i)
  {
    int yo;
    cin>>yo;
    for (int doi = 0; doi < yo; ++doi)
    {
      int sol,kol;
      cin>>sol>>kol;
      if(!kol)
      {
        loop[i].pb(sol-1);
      }
      else loop1[i].pb(sol-1);
    }
  }
  solve(0);
  cout<<ans;
  return 0;
}
//code the AC sol !
// BS/queue/map


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let mut n = read::<i128>();
    let mut ans = 0i64;
    let mut primes = vec![];
    for i in 1.. {
        if i * i > n {
            primes = get_primes(2 * i + 1);
            break;
        }
    }

    for p in primes {
        let mut coef = p;
        while n % coef == 0 {
            n /= coef;
            ans += 1;
            if coef * p > n || coef / 1000 * p > n {
                break;
            }
            coef *= p;
        }
        while n % p == 0 {
            n /= p;
        }
    }
    if n != 1 {
        ans += 1;
    }
    println!("{}", ans);
}

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()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn get_primes(n: i128) -> Vec<i128> {
    let mut is_prime = vec![true; n as usize + 1];
    let mut primes = Vec::new();
    is_prime[0] = false;
    is_prime[1] = false;

    for i in 2..n + 1 {
        if is_prime[i as usize] {
            primes.push(i);
            let mut j = 2 * i;
            while j < n {
                is_prime[j as usize] = false;
                j += i;
            }
        }
    }
    primes
}


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

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

    if (a>=3200)
        cout << s;
    else
        cout <<"red";

    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import core.stdc.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
int readint(){
    return readln.chomp.to!int;
}
int[] readints() {
    return readln.split.to!(int[]);
}

string[] a;

void main() {
    int[] hw = readints();
    int h = hw[0], w = hw[1];
    a = new string[h];
    int white;
    foreach(i; 0..h) {
        a[i] = readln.chomp;
        white += count(a[i], '.');
    }

    // BFS
    auto d = new int[][](h, w);
    foreach(dd; d) fill(dd, -1);
    int[][] Q; // x, y, dist
    Q ~= [0, 0, 0];
    d[0][0] = 0;
    while (Q.length) {
        auto t = Q[0]; Q = Q[1..$];
        int cx = t[0], cy = t[1], dist = t[2];
        foreach(dx, dy; zip([1,0,-1,0], [0,1,0,-1])) {
            int nx = cx + dx, ny = cy + dy;
            if (nx<0 || ny<0 || nx>=w || ny>=h) continue;
            if (d[ny][nx] != -1 || a[ny][nx] != '.') continue;
            Q ~= [nx, ny, dist + 1]; d[ny][nx] = dist + 1;
        }
    }
    if (d[h-1][w-1] == -1) {
        writeln(-1);
    }
    else {
        writeln(white - d[h-1][w-1] - 1);
    }
}

Measured memory_bytes: 636
from itertools import accumulate
n=int(input())
size=1005
sheet=[[0for i in range(size)] for i in range(size)]
for i in range(n):
    a,b,c,d=map(int,input().split())
    sheet[b][a]+=1
    sheet[b][c]-=1
    sheet[d][a]-=1
    sheet[d][c]+=1
for i in range(size):
    sheet[i]=list(accumulate(sheet[i]))
mx=max(sheet[0])
for i in range(1,size):
    for j in range(size):
        sheet[i][j]+=sheet[i-1][j]
    mx=max(mx,max(sheet[i]))
print(mx)




Measured memory_bytes: 46232
N = input()
A = input()
B = input()
C = input()
cnt = 0
for a,b,c in zip(A,B,C):
    if a == b and b == c and b == a:
        continue
    elif a != b and b != c and c != a:
        cnt += 2
    elif a == b and b != c:
        cnt += 1
    elif b == c and c != a:
        cnt += 1
    elif c == a and a != b:
        cnt += 1
    
print(cnt)

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

int main() {
    unsigned long N;
    cin >> N;
    vector<long> A(N);
    for (auto &i : A)cin >> i;
    cout << accumulate(A.cbegin(), A.cend(), 0L, [](auto a, auto b) { return abs(a) + abs(b); }) -
            (1 & count_if(A.cbegin(), A.cend(), [](auto a) { return a < 0; }) ?
             abs(*min_element(A.cbegin(), A.cend(), [](auto a, auto b) { return abs(a) < abs(b); })) * 2 : 0) << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<int, int>;

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

    int h, w;
    cin >> h >> w;
    vector< string > field(h);
    rep (i, h) cin >> field[i];

    int ans = 0;
    rep (i, h)
    {
        rep (j, w)
        {
            if (field[i][j] != '#')
            {
                vector< vs32 > d(h, vs32(w, 1e9));
                queue< P > q;
                q.push(P{i, j});
                d[i][j] = 0;
                while (!q.empty())
                {
                    P p = q.front(); q.pop();
                    int y = p.first;
                    int x = p.second;
                    int dy[] = {-1, 0, 1, 0};
                    int dx[] = {0, -1, 0, 1};
                    rep (k, 4)
                    {
                        int ny = y + dy[k];
                        int nx = x + dx[k];
                        if (IN(0, h, ny) && IN(0, w, nx) && field[ny][nx] != '#' && d[ny][nx] > d[y][x] + 1)
                        {
                            d[ny][nx] = d[y][x] + 1;
                            q.push(P{ny, nx});
                        }
                    }
                }
                int temp = 0;
                rep (ii, h) rep (jj, w) if (field[ii][jj] != '#') temp = MAX(temp, d[ii][jj]);
                ans = MAX(ans, temp);
            }
        }
    }

    cout << ans << "\n";
    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() {
  string s;
  cin >> s;
  int ans = 0;
  int c = 0;
  rep(i, s.size()) {
    if (s[i] == 'T') ++c;
    else --c;
    ans = max(ans, 2 * c);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> arr(n, 0);
  for (int i = 0; i < q; ++i) {
    int a; cin >> a;
    ++arr[a - 1];
  }
  for (int i = 0; i < n; ++i) {
    cout << (arr[i] > q - k ? "Yes" : "No") << endl;
  }
}


Measured memory_bytes: 1024
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		Console.WriteLine(Console.ReadLine().Count(c => c == '1'));
	}
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
using namespace std;

int main(){
  string N; cin>>N;
  if(N.length()==1){
    cout<<N<<endl;
    return 0;
  }

  ll sum=0;
  for(char i:N) sum+=i-'0';
  if(sum==N.length()*9){
    cout<<sum<<endl;
    return 0;
  }

  cout<<max(sum, (ll)(N[0]-'1'+9*N.length()-9))<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28; // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> aSet(n + 1, true);
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        aSet[a] = false;
    }

    vector<ll> dp(n + 1);
    dp[0] = 1;
    dp[1] = (aSet[1]) ? 1 : 0;
    for (int i = 2; i <= n; i++) {
        dp[i] = (aSet[i]) ? (dp[i - 1] + dp[i - 2]) % MOD : 0;
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
	"log"
)

func main() {
	var n, x, t int
	if _, err := fmt.Scan(&n, &x, &t); err != nil {
		log.Fatal(err)
	}

	result := ((n + x - 1) / x) * t
	fmt.Println(result)
}


Measured memory_bytes: 1836
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 55
#define M 2500
#define P 100
#define inf 0x3f3f3f3f
using namespace std;
struct Ahri
{
	int v,n;
}e[M];
int head[N],cnt;
inline void add(int u,int v)
{
	e[++cnt].v=v;
	e[cnt].n=head[u];
	head[u]=cnt;
}
bool f[P+5][N][N];
int dis[N],n,m,A,B,C;
int da[N],db[N],dc[N];
void getf()
{
	int i,j,k,l;
	for(i=1;i<=n;i++)f[0][i][i]=1;
	for(k=1;k<=P;k++)
		for(j=1;j<=n;j++)
			for(i=head[j];i;i=e[i].n)
				for(l=1;l<=n;l++)
					f[k][l][e[i].v]|=(f[k-1][l][j]);
}
queue<int>q;
void bfs()
{
	while(!q.empty())q.pop();
	memset(dis,-1,sizeof dis);
	memset(da,0,sizeof da);
	memset(db,0,sizeof db);
	memset(dc,0,sizeof dc);
	
	int i,u;
	q.push(n),dis[n]=0;
	
	while(!q.empty())
	{
		u=q.front(),q.pop();

		for(i=1;i<=n;i++)if(dis[i]==-1)
		{
			if(!da[i]&&f[A][i][u])da[i]=dis[u]+1;
			if(!db[i]&&f[B][i][u])db[i]=dis[u]+1;
			if(!dc[i]&&f[C][i][u])dc[i]=dis[u]+1;
			if(da[i]&&db[i]&&dc[i])
				dis[i]=max(da[i],max(db[i],dc[i])),q.push(i);
		}
	}
}

int main()
{
//	freopen("test.in","r",stdin);
	int i,j,k;
	scanf("%d%d%d%d%d",&n,&m,&A,&B,&C);
	while(m--)
	{
		scanf("%d%d",&i,&j);
		add(i,j);
	}
	getf();
	bfs();
	if(dis[1]==-1)puts("IMPOSSIBLE");
	else printf("%d\n",dis[1]);
	
	return 0;
}

Measured memory_bytes: 1516
#include<bits/stdc++.h>
#include<atcoder/dsu>
using namespace std;
using namespace atcoder;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int x,q;
    cin>>x>>q;
    dsu d(x);
    for (int i=0; i<q; i++)
    {
        int t,r,l;
        cin>>t>>l>>r;
        if (t==0)
            d.merge(l,r);
        else
        {
            if (d.same(l,r))
                cout<<1<<endl;
            else
                cout<<0<<endl;
        }
    }
    return 0;
}


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

using namespace std;

struct tort {long long x, y, z; int poz;} a[1002], b[1002];
long long n, sol, m, nr;
int semn[2] = {1, -1};
int v[10][5];

bool cmp (tort p, tort q) {
  return p.x + p.y + p.z > q.x + q.y + q.z;
}

int main()
{
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y >> a[i].z;
  }
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++)
      for (int k = 0; k < 2; k++) {
        nr++;
        v[nr][0] = semn[i], v[nr][1] = semn[j], v[nr][2] = semn[k];
      }
  for (int k = 1; k <= 8; k++) {
    for (int i = 1; i <= n; i++) {
      b[i].x = v[k][0] * a[i].x;
      b[i].y = v[k][1] * a[i].y;
      b[i].z = v[k][2] * a[i].z;
      b[i].poz = i;
    }
    sort (b + 1, b + n + 1, cmp);
    long long sumx = 0, sumy = 0, sumz = 0;
    for (int i = 1; i <= m; i++)
      {sumx += a[b[i].poz].x; sumy += a[b[i].poz].y; sumz += a[b[i].poz].z;}
    sol = max(sol, abs(sumx) + abs(sumy) + abs(sumz));
  }
  cout << sol;
  return 0;
}


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

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

const int MX = 500, WORDS = (MX * MX + 63) >> 6;

pair<int, int> bit(int x, int y) {
	int f = max(MX - 1 - x, MX - 1 - y);
	int z = f * f;
	if (MX - 1 - x == f) z += MX - 1 - y;
	else z += f + 1 + MX - 1 - x;
	return {z >> 6, z & 63};
}

char s[MX][MX + 1];
uint64_t reach[MX + 1][WORDS];
uint64_t mask[WORDS][4];

int main() {
	int n;
	ignore = scanf("%d", &n);
	for (int i = 0; i < n; i++) ignore = scanf(" %s", s[i]);
	//for (int i = 0; i < n; i++) fill(s[i], s[i] + n, '7');
	
	for (int x = 0; x < n; x++)
		for (int y = 0; y < n; y++) {
			if (s[x][y] == '#') continue;
			int a = s[x][y] - '0', p, q;
			tie(p, q) = bit(x, y);
			for (int k = 0; k < 4; k++) {
				mask[p][k] |= ((a >> k) & 1ULL) << q;
			}
		}
	
	long long ans = 0;
	for (int d = 2 * (n - 1); d >= 0; d--) {
		for (int x = 0, y = d; x <= d; x++, y--) {
			if (y >= n || x >= n || s[x][y] == '#') {
				if (x < n) memset(reach[x], 0, sizeof reach[x]);
				continue;
			}
			
			int sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0;
			uint64_t* r1 = reach[x];
			uint64_t* r2 = reach[x + 1];
			for (int i = 0; i < WORDS; i++) {
				r1[i] |= r2[i];
				if (r1[i] > 0) {
					sum0 += __builtin_popcountll(r1[i] & mask[i][0]);
					sum1 += __builtin_popcountll(r1[i] & mask[i][1]);
					sum2 += __builtin_popcountll(r1[i] & mask[i][2]);
					sum3 += __builtin_popcountll(r1[i] & mask[i][3]);
				}
			}
			
			ans += (sum0 + sum1 * 2 + sum2 * 4 + sum3 * 8) * (s[x][y] - '0');
			
			int p, q;
			tie(p, q) = bit(x, y);
			reach[x][p] |= (1ULL << q);
		}
	}
	
	printf("%lld\n", ans);
	
	return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int x, a, b;
  cin >> x >> a >> b;
  if (abs(x - a) > abs(x - b)) {
    cout << 'B' << endl;
  } else {
    cout << 'A' << endl;
  }

  return 0;
}


Measured memory_bytes: 256
while 1:
    m,d=map(int,input().split())
    if m==0:break
    print(['Wednes', 'Thurs', 'Fri', 'Satur', 'Sun', 'Mon', 'Tues'][([0,31,60,91,121,152,182,213,244,274,305,335][m-1]+d)%7]+'day')

Measured memory_bytes: 7532
#include <bits/stdc++.h>
#include <map>
using namespace std;
#define int long long
#define loop(i,a,b) for(i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define vct vector
#define stk stack
#define qu queue
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define br break
#define con continue
#define re return
#define tc(t) int t; cin>>t; while(t--)
#define q(q) int q; cin>>q; while(q--)
#define subs substr
#define er erase
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;
signed main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        /*int te;
        cin>>te;
        while(te--)*/{
                int W,s,max_sum=0,temp_sum=0,even=0,odd=0,color=1,oka=5,okb=0,inda=-1,indb=-1,n,maxf=INT_MAX,y,index=0,d,z,p=1,i,j,k,x=1,l,sum=0,ans=0,count=LONG_MAX,count2=0,count1=0,count3=0,ans1,ans2,berry=0,straw=0,berry1=0,straw1=0,berry2=0,straw2=0;
                cin>>n>>W;
                vct<int> w(n+1),v(n+1);
                loop(i,1,n+1){
                        cin>>w[i]>>v[i];
                }
                int t[n+1][W+1]={0};
                memset(t,0,sizeof(t));
                for(i=1;i<=n;i++){
                        for(j=0;j<=W;j++){
                                if(w[i]>j)
                                t[i][j]=t[i-1][j];
                                else
                               t[i][j]=max(v[i]+t[i-1][j-w[i]],t[i-1][j]); 
                        }
                }
                cout<<t[n][W];
        }
        return 0;
}


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

int main(){
    unsigned long N, ans{0};
    cin >> N;
    ++N;
    for(unsigned long i = 0, j = 1, p = 1; i < 10; ++i){
        j *= 10;
        j = min(N, j);
        if(~i & 1)ans += j - p;
        p = j;
    }
    cout << ans << endl;
}

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

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	c = c - (a - b);
	if (c < 0) c = 0;
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
 
module Main
  ( main
  )
where
 
import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
 
parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine
 
main = do
  [s, t] <- words <$> getLine
  putStrLn $ t ++ s


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int > pp;
typedef long long ll;
 
#define sz(x) (int)x.size() 
int const N=3e5+10,oo=1e9;
ll const OO=2e18;
double const eps=1e-8,PI=acos(-1);
int mod=oo+7;

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin>>s;
  int n=sz(s);
  int a1=0,a2=0;
  for(int i=0;i<n;i++){
  	a1+=s[i]-'0'!=i%2;
  	a2+=s[i]-'0'!=(i+1)%2;
  }
  cout<<min(a1,a2);
  return 0;
}






Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import sys
import math
# sys.setrecursionlimit(10000)


def main():
    # 入力処理
    N = int(input())

    # アルゴリズム本体
    y = math.factorial(N) % (10**9+7)

    # 出力
    print(y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3980
#pragma GCC target ("avx2") 
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define fast_az_fuk ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long 
#define int ll 
#define ull unsigned ll
#define ld long double 
#define pb push_back 
#define pf push_front
#define dll deque<ll> 
#define vll vector<ll> 
#define pll pair<ll,ll> 
#define mapll map<ll,ll>
#define endl "\n" 
#define all(v) v.begin(),v.end() 
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
void swap(auto*,auto*);
const ll N=1e5; vll adj[N+1]; bool visited[N+1];
void bfs(ll node){
    visited[node]=1; queue<ll> q;
    q.push(node);
    while(!q.empty()){
        node=q.front(); q.pop();
        for(ll x:adj[node]){
            if(visited[x]) continue;
             visited[x]=1; q.push(x);
        }
    }
}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast_az_fuk
    ll n,m; cin>>n>>m;
    for(ll i=1;i<=m;i++){
        ll u,v; cin>>u>>v; adj[u].pb(v); adj[v].pb(u);
    }
    ll c=0; ms(visited,0);
    for(ll i=1;i<=n;i++){
        if(visited[i]) continue;
        bfs(i); c++;
    }
    cout<<c-1;
    return 0;
}
void swap(auto &a,auto &b)
{
    auto temp=a; a=b; b=temp;
}

Measured memory_bytes: 9732
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=5*1e5+10;
char s[N];
int a[N],n,m,ans,sum[N];
int main()
{
	scanf("%d%d%s",&n,&m,s+1);
	s[0]='0';
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+(a[i]=(s[i]-'0')^(s[i-1]-'0'));
	for(int i=1,k=a[1];i<=n;i++,k^=a[i])
		ans=max(ans*1l,upper_bound(sum,sum+1+n,m*2-(!k)+sum[i])-sum-i);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define call(x) (x).cbegin(), (x).cend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) {if (b<a) {a=b; return 1;} return 0;}
const int INF = INT_MAX;
const int MOD = 1000000007;
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main() {
    int N;
    cin >> N;
    vs W(N);
    rep(i, N) cin >> W[i];
    set<string> dict;
    bool ok = true;
    rep(i, N) {
        if (i == 0) {
            dict.insert(W[i]);
            continue;
        }
        if (dict.count(W[i])) {
            ok = false;
            break;
        }
        if (W[i-1][W[i-1].size() - 1] != W[i][0]) {
            ok = false;
            break;
        }
        dict.insert(W[i]);  
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256