akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <map>
#include <bitset>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+" ";
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
constexpr const ll INF = 1e15;
constexpr const ll MOD = 1000000007;
constexpr const ll MAX = 15;
constexpr int nx[4] = {1,0,-1,0};
constexpr int ny[4] = {0,1,0,-1};
typedef pair<ll,ll> P;
ll LCA(string x,string y){
    ll a = x.length();
    ll b = y.length();
    vector<vector<ll>> dp(a+1,vector<ll>(b+1,0));
    rep(i,a){
        rep(j,b){
            if (x[i] == y[j]) dp[i+1][j+1] = dp[i][j]+1;
            else dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
        }
    }
    return dp[a][b];
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll q;
    cin >> q;
    rep(i,q){
        string x,y;
        cin >> x >> y;
        PRINT(LCA(x,y));
    }
}



Measured memory_bytes: 10836
while True:
   n = int(input())
   if n == 0:
      break

   s = list(map(int, input().split()))
   
   m = sum(s) / n
   b = 0
   for i in range(n):
      b += (s[i] - m) ** 2
   
   ans = (b / n) ** 0.5
   print(ans)

   


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

int main(){
    string s,t;
    cin >> s;
    cin >> t;
    if((s.at(0)==t.at(2) && s.at(1)==t.at(1)) && s.at(2)==t.at(0))
    cout << "YES" << endl;
    else 
    cout << "NO" << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> mins(N, 1), maxs(N, 1);

    int max = 0;
    for (int i = 0; i < N; ++i) {
        int t;
        cin >> t;
        if (t > max) max = mins[i] = t;
        maxs[i] = t;
    }

    vector<int> A(N, 0);
    for (int i = 0; i < N; ++i) cin >> A[i];
    max = 0;
    for (int i = N - 1; i >= 0; --i) {
        if (A[i] > max) {
            if (A[i] < mins[i] or A[i] > maxs[i]) {
                cout << 0 << endl;
                return 0;
            }
            max = mins[i] = A[i];
        }
        if (A[i] < maxs[i]) maxs[i] = A[i];
    }

    long mod = 1000000007;
    long results = 1;
    for (int i = 0; i < N; ++i) {
        results *= (maxs[i] - mins[i] + 1);
        results %= mod;
    }
    cout << (results % mod) << endl;
    return 0;
}

Measured memory_bytes: 1408
def calc(i, j, B1, len_b):
    extra = 0
    d = j - i

    # i < j < k
    k1 = d + j
    if k1 < len_b:
        extra += B1[k1]

    # k < i < j
    k2 = i - d
    if 0 <= k2 and k2 < len_b:
        extra += B1[k2]

    # i < k < j
    s = i + j
    if s % 2 == 0:
        k3 = s // 2
        if k3 < len_b:
            extra += B1[k3]
    return extra

def main():
    N = int(input())
    S = input()
    R, G, B = [], [], []
    RGB = {'R': R, 'G': G, 'B': B}
    for i in range(N):
        RGB[S[i]].append(i)
    num_r, num_g, num_b = len(R), len(G), len(B)
    if num_r == 0 or num_g == 0 or num_b == 0:
        print(0)
        return

    len_b = (B[-1] + 1)
    B1 = [0]*len_b
    for b in B:
        B1[b] = 1
    # print(R, G, B)
    ans = num_r * num_g * num_b
    for i in R:
        for j in G:
            ans -= calc(min(i, j), max(i, j), B1, len_b)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9340
#include<iostream>
#include<cstdio>
using namespace std;
int main(void){
    int w[30],a,b,tmp,d,n;
    char c;
    cin >> d >> n;
    for(int i=0; i<d; i++)
        w[i] = i+1;
    for(int i=0; i<n; i++){
        cin >> a >> c >> b;
        tmp = w[a-1]; w[a-1] = w[b-1]; w[b-1] = tmp;
    }
    for(int i=0; i<d; i++)
        cout << w[i] << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

const int MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int dp[252521];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout<<setprecision(10)<<fixed;
	int n, c[252521];
	cin>>n;
	REP(i, n){
		cin>>c[i];
	}
	vi cc;
	cc.push_back(c[0]);
	REP(i, n-1){
		if(c[i]!=c[i+1]){
			cc.push_back(c[i+1]);
		}
	}
	n=(int)cc.size();
	dp[cc[0]]=1;
	FOR(i, 1, n){
		dp[cc[i]]=(dp[cc[i]]+dp[cc[i-1]])%MOD;
	}
	cout<<dp[cc[n-1]]<<'\n';
	return 0;
}


Measured memory_bytes: 2804
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

const ll INF = 1e16;

int main(){
    int N;cin >> N;
    vector<int> a(N);
    rep(i,N)cin >> a[i];
    vector<ll> sum(N+1);
    for(int i=0;i<N;i++){
        sum[i+1] = sum[i]+a[i];
    }
    ll res = INF;
    for(int i=1;i<N;i++){
        res = min(res,abs(sum[i]-(sum[N]-sum[i])));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2560
import sys
readline = sys.stdin.readline

N, M = map(int, readline().split())
L = [[] for i in range(N+1)]
R = [[] for i in range(N+1)]
for i in range(M):
    l, r, a = map(int, readline().split())
    L[l-1].append((r, a))

INF = 2**31-1

LV = (N).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [0]*(2*N0)

I = []; K = []
for x in range(N0+1):
    y = N0 + x
    z = (y // (y & -y)) >> 1
    K.append(z)
    r = []
    while z:
        r.append(z)
        z >>= 1
    r.reverse()
    I.append(r)
I.append([])

J = []
for x in range(N0+1):
    y = N0 + x + 1
    z = (y // (y & -y)) - 1
    J.append(z-1 if z else 0)

def propagates(ids):
    for i in ids:
        v = lazy[i-1]
        if not v:
            continue
        lazy[2*i-1] += v; lazy[2*i] += v
        data[2*i-1] += v; data[2*i] += v
        lazy[i-1] = 0

# update [0, r)
def update(r, x):
    #propagates(I[r])

    i = r
    while i:
        v = J[i-1]
        lazy[v] += x; data[v] += x
        i -= (i & -i)

    k = K[r]
    while k:
        data[k-1] = max(data[2*k-1], data[2*k]) + lazy[k-1]
        k >>= 1

# update[k, k+1)
def update1(k, x):
    #propagates(I[k])
    k += N0
    data[k-1] += x
    while k:
        k >>= 1
        data[k-1] = max(data[2*k-1], data[2*k]) + lazy[k-1]


# query [0, r)
def query(r):
    return max(map(data.__getitem__, qquery(r)))

def qquery(r):
    propagates(I[r])

    while r:
        yield J[r-1]
        r -= (r & -r)

# query [k, k+1)
def query1(k, x):
    propagates(I[k])
    return data[k + N0 - 1]


for i in range(N):
    for r, a in L[i]:
        update(i+1, a)
        R[r].append((i, a))
    for l, a in R[i]:
        update(l+1, -a)
    v = query(i+1)
    update1(i+1, v)
for l, a in R[N]:
    update(l+1, -a)
sys.stdout.write("%d\n" % query(N+1))

Measured memory_bytes: 162680
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  int h,n,x=0;
  
  cin >>h>>n;
  vector<int> a(n);
  
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  
  for(int j=0;j<n;j++){
    x += a.at(j);
  }
  
  if(x>=h){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-


def main():
    s = input()

    koho_list = ["dream", "dreamer", "erase", "eraser"]

    flg = True
    while len(s) > 0:
        for koho in koho_list:
            if len(s) >= len(koho) and s[-len(koho):] == koho:
                s = s[:-len(koho)]
                break
        else:
            flg = False
            break

    if flg:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
n = int(input())
a_list = list(map(int, input().split()))

cnt = 0

al = False
for i, a in enumerate(a_list):
    if i == 0:
        pre = a
    else:
        if a == pre:
            if not al:
                al = True
                cnt += 1
            else:
                al = False
        else:
            al = False
            
        pre = a
        
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
  
int main() {
 int heya[4][3][10];
  for (int a=0;a<4;a++){
    for (int b=0;b<3;b++){
      for (int c=0;c<10;c++){
     	heya[a][b][c]=0;
      }}}
    
  int n;cin>>n;
  for(int i=0;i<n;i++){
    int b,f,r,v;
  	cin>>b>>f>>r>>v;
    heya[b-1][f-1][r-1]+=v;
  }
  
  for (int a=0;a<4;a++){
    for (int b=0;b<3;b++){
      for (int c=0;c<10;c++){
  		cout<<" "<<heya[a][b][c];
      }
      	cout<<endl;
    }
    if(a<=2) cout<<"####################"<<endl;
  }
}
 


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

bool coloring(int c, int v, vector<int> &color,vector<vector<int>> &g){
    if(color[v] == -c) return false;
    if(color[v] != 0) return true;
    color[v] = c;
    for(int to : g[v]){
        if(!coloring(-c,to,color,g)) return false;
    }
    return true;
}

int main(){
    int n,m;
    while(cin>>n>>m, n|m){
        vector<vector<int>> g(n);
        rep(i,m){
            int v,u;
            cin>>v>>u;
            v--, u--;
            g[u].push_back(v);
            g[v].push_back(u);
        }

        vector<int> color(n);
        if(!coloring(1,0,color,g)){
            cout<<0<<endl;
            continue;
        }
        int red = 0, black = 0;
        rep(i,n){
            if(color[i] == 1) red++;
            else black++;
        }

        set<int> res;
        if(red % 2 == 0) res.insert(red/2);
        if(black % 2 == 0) res.insert(black/2);
        cout<<res.size()<<endl;
        for(int p : res){
            cout<<p<<endl;
        }

    }
    return 0;
}



Measured memory_bytes: 3160
object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val h, w = sc.nextInt
	val s = Array.fill(h)(sc.next.toArray) map (_ map (_ == '.'))
	
	def bfs(sx: Int, sy: Int): Int = {
		val a = Array.tabulate(h)(s(_).clone) map (_ map (if (_) 0 else -1))
		
		def inner(seq : Seq[(Int, Int)]): Int = seq match {
			case Seq() => a.flatten.max
			case (x, y) :: tail => {
				val ds = Seq( (x-1, y), (x+1, y), (x, y-1), (x, y+1) ).filter { case (i, j) =>
					(i, j) != (sx, sy) && 0 <= i && i < w && 0 <= j && j < h && a(j)(i) == 0
				}
				ds foreach {case (q, p) => a(p)(q) = a(y)(x) + 1}
				inner(tail ++ ds)
			}
		}
		
		inner(Seq((sx, sy)))
	}
	
	println((for (x <- 0 until w; y <- 0 until h if s(y)(x)) yield bfs(x, y)).max)
}

Measured memory_bytes: 72488
N = int(input())
robots, count = [], 0
for x in range(N):
    X, L = map(int, input().split())
    robots.append((X+L, X-L))
robots.sort()
node = -10**12
for end, start in robots:
    if start >= node:
        node = end
        count += 1
print(count)

Measured memory_bytes: 16988
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
 
int main() {
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    ll m = t.size();
 
    vvl dp(n+1, vl(m+1));  // dp[i][j] : sのi文字目までとtのj文字目までのLCSの長さ
    rep(i, n) {
        rep(j, m) {
            chmax(dp[i+1][j+1], max(dp[i+1][j], dp[i][j+1]));
            if(s[i] == t[j]) {
                chmax(dp[i+1][j+1], dp[i][j] + 1);
            }
        }
    }
 
    string ans = "";
    ll i = n-1, j = m-1;
    while(i >= 0 && j >= 0) {
        if(dp[i+1][j+1] == dp[i][j+1]) {
            i--;
        }
        else if(dp[i+1][j+1] == dp[i+1][j]) {
            j--;
        }
        else if(dp[i+1][j+1] == dp[i][j] + 1) {
            ans = s[i] + ans;
            i--;  j--;
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 74004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int main () {
  int N;
  cin >> N;
  vector<int> p(N), q(N);
  rep(i,N) {
    cin >> p[i];
    q[i] = p[i];
  }

  sort(all(q));

  int c = 0;
  rep(i,N) {
    if(p[i] != q[i]) c++;
  }

  cout << (c == 0 || c == 2 ? "YES" : "NO") << endl;

  return 0;
}


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

using namespace std;

int main() {
	//freopen("input.txt", "r", stdin);
	int n, m;
	cin >> n >> m;
	string arr[n];
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int cnt = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (arr[i][j] == '#')
				cnt++;
	if (cnt != m + n - 1) {
		cout << "Impossible" << endl;
		return 0;
	}
	int a = 0, b = 0;
	while (a < n - 1 && b < n - 1) {
		if (b < m - 1) {
			if (arr[a][b + 1] == '#')
				b++;
			else if (a < n - 1) {
				if (arr[a + 1][b] != '#') {
					cout << "Impossible" << endl;
					return 0;
					break;
				}
				else
					a++;
			}
			else {
				cout << "Impossible" << endl;
				return 0;
				break;
			}
		}
		else if (arr[a + 1][b] != '#') {
			cout << "Impossible" << endl;
			return 0;
		}
		else
			a++;
	}
	cout << "Possible" << endl;
	return 0;
}

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

struct RollingHash {
  const int h = 1000000007;
  const int b = 10007;
  vector<int> ha;
  vector<int> po;
  RollingHash(const string &s) {
    int n = (int) s.size();
    ha.assign(n + 1, 0);
    po.assign(n + 1, 1);
    for (int i = 0; i < n; i++) {
      ha[i + 1] = ((long long) ha[i] * b + s[i]) % h;
      po[i + 1] = ((long long) po[i] * b) % h;
    }
  }
  int get(int l, int r) {
    return (ha[r] + h - ((long long) ha[l] * po[r - l]) % h) % h;
  }
};

struct UnionFind {
  vector<int> data;
  UnionFind(int n) {
    data.assign(n, -1);
  }
  int root(int k) {
    if (data[k] < 0) return k;
    return data[k] = root(data[k]);
  }
  bool unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }
  int size(int k) {
    return -data[root(k)];
  }
};

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  string ss = s;
  while (ss.size() < t.size()) {
    ss += s;
  }
  ss += ss;
  RollingHash sh(ss), th(t);
  auto uf = UnionFind(n);
  for (int i = 0; i < n; i++) {
    if (sh.get(i, i + t.size()) == th.get(0, t.size())) {
      int x = i % n;
      int y = (i + t.size()) % n;
      if (!uf.unite(x, y)) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, uf.size(i) - 1);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (A[A[i]-1] == i+1) {
      ans++;
    }
  }
  cout << ans/2 << endl;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int		main(void)
{
	int n,d,x;
	int i,j;
	int count = 0;
	cin >> n >> d >> x;
	int A[n];
	for (i = 0; i < n; i++)
		cin >> A[i];
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < d; j++)
		{
			if ((j * A[i]) + 1 <= d)
				count++;
			else
				break ;
		}
	}
	cout << count + x << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repd(i,x,y) for (int i=x; i>=y; --i)
using namespace std;

typedef long long LL;
const int p=1000000007;
int n,m,f[33000],cnt[20][33000];
bool map[20][20];

int power(int x,int k)
{
    int ret=1;
    for (; k; k>>=1,x=LL(x)*x%p)
        if (k&1)
            ret=LL(ret)*x%p;
    return ret;
}

int main()
{
    scanf("%d%d",&n,&m);
    repu(i,1,m)
    {
        int u,v;
        scanf("%d%d",&u,&v),map[u-1][v-1]=1;
    }
    repu(i,0,n-1)
        repu(j,0,(1<<n)-1)
        {
            cnt[i][j]=1;
            repu(k,0,n-1)
                if ((j&(1<<k)) && map[i][k])
                    (cnt[i][j]*=2)%=p;
            --cnt[i][j];
            repu(k,0,n-1)
                if ((j&(1<<k)) && map[k][i])
                    (cnt[i][j]*=2)%=p;
        }
    f[0]=1;
    repu(i,0,(1<<n)-1)
        if (f[i])
        {
            int s=(1<<n)-1-i;
            for (int j=s; j; j=(j-1)&s)
                if ((j&1)==((j>>1)&1))
                {
                    int w=f[i];
                    repu(k,0,n-1)
                        if ((i>>k)&1)
                            w=LL(w)*cnt[k][j]%p;
                    (f[i^j]+=w)%=p;
                }
        }
    printf("%d\n",(power(2,m)-f[(1<<n)-1]+p)%p);
    return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int N=205;
int n;
int a[N][N];
int col[N];
void dfs(int u,int color)
{
	if(col[u]!=-1)
	{
		if(col[u]!=color)
		{
			printf("-1");
			exit(0);
		}
		return;
	}
	col[u]=color;
	for(int v=1;v<=n;v++)
		if(a[u][v]) dfs(v,color^1);
	return;
}
int f[N][N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			scanf("%1d",&a[i][j]);
	memset(col,-1,sizeof(col));
	dfs(1,0);
	memset(f,63,sizeof(f));
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(a[i][j]) f[i][j]=a[i][j];
	for(int i=1;i<=n;i++)
		f[i][i]=0;
	for(int k=1;k<=n;k++)
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
	int ans=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			ans=max(ans,f[i][j]+1);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 4136
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/* Coding space */
vt<string> vs;
const int vec[] = {1,0,-1,0,1};
int main(){
  int h,w; cin >> h >> w;
  rep(i,h){
    string in; cin >> in;
    vs.pb(in);
  }
  bool used[51][51] = {};
  int ans = 0;
  rep(i,h)rep(j,w)if(vs[i][j] == '.') ans++;
  using Data = tuple<int,int,int>; // y,x,score;
  queue<Data> q;
  q.push(Data{0,0,0});
  while(!q.empty()){
    int a,b,c; tie(a,b,c) = q.front(); q.pop();
    if(used[a][b] == 1) continue;
    used[a][b] = 1;
    //cerr << a << " " << b << endl;
    if(a == h-1 && b == w - 1){
      cout << ans - c - 1 << endl;
      exit(0);
    }else{
      rep(i,4)
        if(a + vec[i] >= 0 && a + vec[i] < h && b + vec[i+1] >= 0 && b + vec[i+1] < w && vs[a+vec[i]][b+vec[i+1]] != '#')
          q.push(Data{a+vec[i],b+vec[i+1],c+1});
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

#define POS(cnt,L,R) (((cnt)*(n+1)+(L))*(n+1)+(R))

void run(void){
  char *s=(char *)calloc(301,sizeof(char));
  scanf("%s",s);
  const int n=strlen(s);
  int k;
  scanf("%d",&k);
  int *dp=(int *)calloc((n+1)*(n+1)*(k+1),sizeof(int));
  for(int cnt=0;cnt<=k;cnt++){
    for(int l=0;l<n;l++){
      dp[POS(cnt,l,l+1)]=1;
    }
    for(int len=2;len<=n;len++){
      for(int l=0;l+len<=n;l++){
	if(s[l]==s[l+len-1]){
	  dp[POS(cnt,l,l+len)]=dp[POS(cnt,l+1,l+len-1)]+2;
	} else {
	  int a=cnt>0?dp[POS(cnt-1,l+1,l+len-1)]+2:0;
	  int b=dp[POS(cnt,l+1,l+len)];
	  int c=dp[POS(cnt,l,l+len-1)];
	  dp[POS(cnt,l,l+len)]=MAX(a,MAX(b,c));
	}
      }
    }
  }
  printf("%d\n",dp[POS(k,0,n)]);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 106752
using System;


    public static class Program
    {
        static void Main()
        {
        
            var data1 = int.Parse(Console.ReadLine().Trim());
        var time1 = data1/(60*60);
        var time2 = (data1 % (60 * 60)) / 60;
        var time3 = (data1%(60*60)) % 60;

        Console.WriteLine(time1 + ":" + time2 + ":" + time3);

    }
        
        }
            
        




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

class Timer {
	std::chrono::high_resolution_clock::time_point m_start;
public:
	Timer() 
	: m_start(std::chrono::high_resolution_clock::now()) {}

	~Timer() {
		auto end = std::chrono::high_resolution_clock::now();
  		auto duration_s = std::chrono::duration<double>(end - m_start).count();
  		cerr << "Completed in " << duration_s << endl;
  	}
};

template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
struct debug {
#ifdef LOCAL
	~debug() { cerr << endl; }
	template < class c > typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) { cerr << boolalpha << i; return *this; }
	template < class c > typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) { return *this << range(begin(i), end(i)); }
	template < class c, class b > debug & operator <<(pair < b, c > d) {
	  return * this << "(" << d.first << ", " << d.second << ")";
	}
	template < class c > debug & operator <<(rge<c> d) {
	  *this << "[";
	  for (auto it = d.b; it != d.e; ++it)
	    *this << ", " + 2 * (it == d.b) << *it;
	  return * this << "]";
	}
#else
	template < class c > debug & operator <<(const c&) { return * this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int INF = 1e9 + 5;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#include <iostream>

void solve() {
	int n;
	cin >> n;
	Timer timer;

	int sum = 0;
	int temp, prev;
	cin >> temp;
	prev = temp;
	sum += temp;
	for (int i = 1; i < n - 1; ++i) {
		cin >> temp;
		sum += min(temp, prev);
		prev = temp;
	}
	sum += temp;

	cout << sum << endl;
}

int main() {
	FAST
	int t = 1;
	// cin >> t;

	for (int i = 0; i < t; ++i) {
		solve();
	}
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353 
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
ll k,a[200005],rui[200005],ans;
map<ll,int>M;

int main(){
	cin>>n>>k;if(k==1){cout<<0<<endl;return 0;}
	repn(i,n){
		cin>>a[i]; a[i]--;
	}
	M[0]++;
	rui[0] = 0;
	repn(i,n) rui[i] = (rui[i-1]+a[i])%k;
	repn(i,n){
		ans += M[rui[i]]++;
		if(i+1-k >= 0) M[rui[i+1-k]]--;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 15872
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

const int kMaxN = 105;

int n;
int a[kMaxN], b[kMaxN], c[kMaxN], d[kMaxN];
vector<int> g[kMaxN];
int vis[kMaxN], tim, lk[kMaxN];

inline void Link(int u, int v) {
  g[u].push_back(v);
}

int Find(int x) {
  for (int nxt : g[x]) {
    if (vis[nxt] != tim) {
      vis[nxt] = tim;
      if (!lk[nxt] || Find(lk[nxt])) {
        lk[nxt] = x;
        return true;
      }
    }
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> b[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> c[i] >> d[i];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (a[i] < c[j] && b[i] < d[j])
        Link(i, j);
    }
  }
  int ans = 0;
  tim = 0;
  for (int i = 1; i <= n; ++i) {
    ++tim;
    ans += Find(i);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let k = scan "%d" id

let rec gcd  a b =
  if b = 0 then a
  else gcd b (a mod b)

let () =
  let memo = Array.make_matrix (succ k) (succ k) 0 in
  ListL.iter (1++k) ~f:(fun i ->
      ListL.iter (1++k) ~f:(fun j ->
          memo.(i).(j) <- gcd i j
        )
    );
  ListL.map (1++k) ~f:(fun i ->
      ListL.map (1++k) ~f:(fun j ->
          ListL.map (1++k) ~f:(fun m ->
              memo.(memo.(i).(j)).(m)
            ) |> List.sum
        ) |> List.sum
    )|>List.sum
  |> Printf.printf "%d\n"


Measured memory_bytes: 8300
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }
vector<pair<ll, ll>> primeFac(ll n) {
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
}  // namespace my
////////////////////////

int main() {
  int k, l, rem;
  cin >> k;
  if (k % 7 == 0)
    l = 9 * k / 7;
  else
    l = 9 * k;

  int ans;
  bool flag = false;
  for (int i = 1; i <= 1e8; i++) {
    if (i == 1)
      rem = 10 % l;
    else
      rem = (rem * 10) % l;
    if (rem == 1) {
      ans = i;
      flag = true;
      break;
    }
  }

  if (!flag) ans = -1;
  cout << ans << endl;
}

Measured memory_bytes: 3580
const solve = (n, k, s) => {
  const num = k * 2 + 1
  let lenMap = []
  let currLen = 1
  let curr = s[0]
  for (var i = 1; i < s.length; i++) {
    if (curr == s[i]) {
      currLen++
    } else {
      // lenMap[curr].push(currLen)
      lenMap.push({
        flg: curr,
        len: currLen
      })
      currLen = 1
      curr = s[i]
    }
  }
  let result = 0
  let cache = {}
  let beforeMinus = undefined
  let before = undefined
  lenMap.push({ flg: curr, len: currLen })
  // console.log(lenMap)
  for (var i = 0; i < lenMap.length; i++) {
    let tg = lenMap[i]
    if (tg.flg == 1) {
      result = Math.max(result, tg.len)
      continue
    }
    let r = 0
    let last = k * 2 + i - 1
    if (before === undefined) {
      let start = i
      if (0 < i) {
        start--
      }

      for (var j = start; j <= last; j++) {
        if (lenMap[j]) {
          r += lenMap[j].len
        }
      }
    } else {
      // console.log("======")
      // console.log(before, beforeMinus, lenMap[i])
      r = before - beforeMinus

      // console.log(r, last)
      if (lenMap[last]) {
        r += lenMap[last].len
      }
      if (lenMap[last - 1]) {
        r += lenMap[last - 1].len
      }
    }
    let c = lenMap[i].len
    if (lenMap[i - 1]) {
      c += lenMap[i - 1].len
    }
    before = r
    beforeMinus = c
    result = Math.max(result, r)
  }

  return result
}
const main = (input) => {
  const [head, s] = input.split("\n")
  const [n, k] = head.split(" ")

  return solve(n, k, s.split("").map(Number))
}

if (process.env.NODE_ENV !== "test") {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(main(input.trim()))
}


Measured memory_bytes: 17996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod=1e9+7;
 
int main(){
  int n;cin>>n;
  vector<int> p[n];
  map<string,int> a;
  rep(i,n){
    string s;cin>>s;
    int tmp[10];
    rep(j,10)tmp[j]=s[j]-'a';
    sort(tmp,tmp+10);
    string t;
    rep(j,10)t.push_back('a'+tmp[j]);
    a[t]++;
  }
  ll ans=0;
  for(auto i=a.begin();i!=a.end();++i){
    ll tmp=i->second;
    ans+=tmp*(tmp-1)/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 15104
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const PRIME_SIZE: usize = 1000000;
#[allow(dead_code)]
struct Eratosthnes {
    n: usize,
    bprime: Vec<bool>,
    prime: Vec<usize>,
}
#[allow(dead_code)]
impl Eratosthnes {
    fn new(n: usize) -> Eratosthnes {
        let mut bprime = vec![true; PRIME_SIZE + 1];
        let mut prime = vec![];
        bprime[0] = false;
        bprime[1] = false;
        for i in 2..n+1 {
            if !bprime[i] { continue; }
            prime.push(i);
            if i * i > n { continue; }
            let mut j = i * i;
            while j <= n {
                bprime[j] = false;
                j += i;
            }
        }
        Eratosthnes {
            n: n,
            bprime: bprime,
            prime: prime,
        }
    }
}

fn main() {
    let n = 1e+5 as usize + 10;
    let era = Eratosthnes::new(n as usize);
    let mut sums = vec![0; n];
    for i in 1..n {
        if era.bprime[i] && era.bprime[(i + 1) / 2] { sums[i] += 1; }
        sums[i] += sums[i - 1];
    }
    let q: usize = read();
    for _ in 0..q {
        let l: usize = read();
        let r: usize = read();
        println!("{}", sums[r] - sums[l - 1]);
    }
}

Measured memory_bytes: 4732
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

const MOD: usize = 1e9 as usize + 7;

fn main() {
    input! {
        h: usize,
        w: usize,
        a: usize,
        b: usize,
    }

    let mut v = vec![vec![0; w]; h];
    for y in 0..b {
        for x in 0..a {
            v[y][x] = 0;
        }
        for x in a..w {
            v[y][x] = 1;
        }
    }

    for y in b..h {
        for x in 0..a {
            v[y][x] = 1;
        }
        for x in a..w {
            v[y][x] = 0;
        }
    }

    for y in 0..h {
        for x in 0..w {
            print!("{}", v[y][x]);
        }
        println!()
    }
}


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

int main(void){
	int n;
	cin >> n;
	vector<int> h(n+1), a(n+1,0);
	for(int i = 0; i < n; ++i){
		cin >> h[i];
	}
	h[n] = 1000000001;
	for(int i = 0; i < n; ++i){
		if(h[i] >= h[i+1]){
			a[i+1] = a[i] + 1;
		}else{
			a[i+1] = 0;
		}
	}
	int ans = 0;
	for(int i = 0; i < n; ++i){
		ans = max(ans,a[i]);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
	int t; cin >> t;
	for (int i = 0; i < t; ++i) {
		ll n, m, a, b; cin >> n >> m >> a >> b;
		cout << floor_sum(n, m, a, b) << endl;
	}
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	long long p;
	double n,ans;
	cin>>n>>p;
	vector <long long > v,v1;
	for(int i=1;i*1ll*i<=p;i++)
	  {
	  	  if(i*1ll*i==p)
	  	    {
	  	    	v.push_back(i);
	  	    }
	  	  else if(p%i==0)
	  	    {
	  	    	v.push_back(i);
	  	    	v.push_back(p/i);
	  	    }
	  }
	 sort(v.begin(),v.end());
	if(n==1)
	  {
	  	cout<<p<<'\n';
	  	return 0;
	  }
	//vector <long long > v1;
	double i=1;
	while(1)
	  {	 ans=pow(i,n);
	  	 v1.push_back(ans);
	  	 if(ans>p)
	  	   {
	  	   	 break;
	  	   }
	  	 ++i;
	  }
	 
	for(int i=0;i<v1.size();i++)
	  {  
	  	 if(binary_search(v.begin(),v.end(),v1[i])==true)
	  	   ans=(i+1);
	  }
	 cout<<ans<<'\n'; 
	// your code goes here
	return 0;
}

Measured memory_bytes: 8940
s = input()
ans = 0
if len(s) > 1:
    k = s[1]
    if s[0] == '0' and s[1] == '0':
        k ='1'
    elif s[0] == '1' and s[1] == '1':
        k = '0'
for i in range(1,len(s)):
    if i%2 == 0 and s[i] != s[0]:
        ans+=1
    elif i%2 != 0 and s[i] != k:
        ans+=1

print (ans)




Measured memory_bytes: 3188
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	static InputStream is = System.in;
	static String INPUT = "";

	public static void main(String[] args) throws Exception
	{
		int n = ni();
		int M = 1000001;
		int W = (M>>>6)+1;
		long[] f1 = new long[W];
		long[] f2 = new long[W];
		long[] ex = new long[W];
		for(int i = 0;i < n;i++){
			int v = ni();
			if(f1[v>>>6]<<~v>=0){
				f1[v>>>6] |= 1L<<v;
			}else{
				f2[v>>>6] |= 1L<<v;
			}
		}
		for(int i = 1;i <= M;i++){
			if((f1[i>>>6]&~ex[i>>>6])<<~i<0){
				for(int j = i*2;j < M;j+=i){
					ex[j>>>6] |= 1L<<j;
				}
			}
		}
		int ans = 0;
		for(int i = 0;i < W;i++){
			ans += Long.bitCount((f1[i]^f2[i])&~ex[i]);
		}
		System.out.println(ans);
	}
	
	private static byte[] inbuf = new byte[1024];
	static int lenbuf = 0, ptrbuf = 0;
	
	private static int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
//	private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); }
	private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private static double nd() { return Double.parseDouble(ns()); }
	private static char nc() { return (char)skip(); }
	
	private static String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private static char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private static char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private static int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private static int ni()
	{
		int num = 0, b;
//		boolean minus = false;
//		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
//		if(b == '-'){
//			minus = true;
//			b = readByte();
//		}
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9')));
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return num;
//				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}


Measured memory_bytes: 34000
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
#define ll long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define PB push_back
//以下、素集合と木は同じものを表す
class UnionFind {
public:
    vector<ll> parent; //parent[i]はiの親
    vector<ll> siz; //素集合のサイズを表す配列(1で初期化)
    map<ll,vector<ll>> group;//素集合ごとに管理する連想配列(keyはそれぞれの素集合の親、valueはその素集合の要素の配列)

    //コンストラクタ
    UnionFind(ll n):parent(n),siz(n,1){ 
        //全ての要素の根が自身であるとして初期化
        for(ll i=0;i<n;i++){parent[i]=i;}
    }

    //データxの属する木の根を取得(経路圧縮も行う)
    ll root(ll x){
        if(parent[x]==x) return x;
        return parent[x]=root(parent[x]);//代入式の値は代入した変数の値なので、経路圧縮できる
    }

    //xとyの木を併合
    void unite(ll x,ll y){
        ll rx=root(x);//xの根
        ll ry=root(y);//yの根
        if(rx==ry) return;//同じ木にある時
        //小さい集合を大きい集合へと併合(ry→rxへ併合)
        if(siz[rx]<siz[ry]) swap(rx,ry);
        siz[rx]+=siz[ry];
        parent[ry]=rx;//xとyが同じ木にない時はyの根ryをxの根rxにつける
    }

    //xとyが属する木が同じかを判定
    bool same(ll x,ll y){
        ll rx=root(x);
        ll ry=root(y);
        return rx==ry;
    }

    //xの素集合のサイズを取得
    ll size(ll x){
        return siz[root(x)];
    }

    //素集合をそれぞれグループ化
    void grouping(ll n){
        //経路圧縮を先に行う
        REP(i,n)root(i);
        //mapで管理する(デフォルト構築を利用)
        REP(i,n)group[parent[i]].PB(i);
    }
};
signed main(){
    int n,m,a,b;
    cin>>n>>m;
    UnionFind uf(n);
    while(cin>>a>>b)
        uf.unite(--a,--b);
    int ans=0;
    for(int i=0;i<n;i++)
        ans=max(ans,uf.size(i));
    cout<<ans<<endl;
}


Measured memory_bytes: 6336
//Name: Shopping in JOI Kingdom
//Level: 3
//Category: グラフ,Graph,最短経路
//Note:

/*
 * とりあえず道の途中に家があるときのことは考えず，各頂点についてショッピングモールからの
 * 最短距離を求める．
 * これは各ショッピングモールを始点としたダイクストラで求められる．
 * ただしナイーブにやると最大ケースで死にそうなので，ダイクストラの途中で他のショッピングモールに
 * ぶつかった場合はそこで枝刈りするようにした．
 *
 * ある2頂点があって，それぞれのショッピングモールへの最短距離がaとbで距離lの辺でつながっているとき，
 * この辺上での最遠点では
 * a+ul == b+(1-u)l
 * が成立しているはずであるから，各aとbの組について方程式を解いてulを求め，最大のa+ulを選べばそれが解となる．
 * (最短距離の定義より，min(a,b)+l >= max(a,b)であることに注意)
 */
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>

using namespace std;

struct Road {
    int from, to;
    int len;

    Road() {}
    Road(int f, int t, int l) : from(f), to(t), len(l) {}
};

vector<Road> roads_of[3000];
bool is_shopping_mall[3000];
int min_dist[3000];

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

    int N, M, K;
    cin >> N >> M >> K;
    for(int i = 0; i < M; ++i) {
        int a, b, l;
        cin >> a >> b >> l;
        --a; --b;
        roads_of[a].push_back(Road(a, b, l));
        roads_of[b].push_back(Road(b, a, l));
    }
    fill_n(is_shopping_mall, N, false);
    for(int i = 0; i < K; ++i) {
        int a;
        cin >> a;
        --a;
        is_shopping_mall[a] = true;
    }
    fill_n(min_dist, N, INT_MAX);

    static int memo[3000];
    fill_n(memo, N, INT_MAX);
    for(int start = 0; start < N; ++start) {
        if(!is_shopping_mall[start]) continue;
        priority_queue<pair<int, int> > q;
        q.push(make_pair(0, start));
        memo[start] = 0;
        while(!q.empty()) {
            int cost = -q.top().first;
            int pos = q.top().second;
            q.pop();
            if(memo[pos] < cost) continue;
            min_dist[pos] = min(min_dist[pos], cost);

            for(vector<Road>::iterator it = roads_of[pos].begin(); it != roads_of[pos].end(); ++it) {
                if(is_shopping_mall[it->to]) continue;

                int nc = cost + it->len;
                if(memo[it->to] > nc) {
                    memo[it->to] = nc;
                    q.push(make_pair(-nc, it->to));
                }
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < N; ++i) {
        int d = 0;
        const int a = min_dist[i];
        // a+ul == b+vl, u+v == 1
        // a+ul == b+(1-u)l
        // 2ul == b-a+l
        // ul == (b-a+l)/2
        for(vector<Road>::iterator it = roads_of[i].begin(); it != roads_of[i].end(); ++it) {
            const int b = min_dist[it->to];
            if(b >= a) {
                int ul = (b-a+it->len) / 2;
                if((b-a+it->len) % 2 == 1) ++ul;
                d = max(d, min_dist[i] + ul);
            }
        }
        ans = max(ans, d);
    }

    cout << ans << endl;
    return 0;
}

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


int main()
{
    int k,a,b,d;
    cin>>k>>a>>b;
    d=a/k;
    while(d*k<=b)
    {
        if(d*k>=a and d*k<=b)
        {
            cout<<"OK"<<endl;
            return 0;
        }
        d++;
    }
    cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;

signed main(){
    ll h,w;
    cin>>h>>w;
    ll a,b;
    if(w%2==0) a=w/2;
    else a=w/2+1;
    b=w/2;
    ll ans=0;
    if(h%2==1)ans+=a*(h/2+1);
    else ans+=a*(h/2);
    ans+=b*(h/2);
    if(h==1||w==1) cout<<1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s=="MON")cout<<6<<endl;
  else if(s=="TUE")cout<<5<<endl;
  else if(s=="WED")cout<<4<<endl;
  else if(s=="THU")cout<<3<<endl;
  else if(s=="FRI")cout<<2<<endl;
  else if(s=="SAT")cout<<1<<endl;
  else if(s=="SUN")cout<<7<<endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	int N, M; cin >> N >> M;
	map<char, int>mp;
	mp[0] = 'W';
	mp[1] = 'B';
	mp[2] = 'R';
	vector<vector<int>>nums(N, vector<int>(3));
	for (int i = 0; i < N; ++i) {
		string st; cin >> st;
		for (int j = 0; j < 3; ++j) {
			nums[i][j] = count(st.begin(), st.end(), mp[j]);
		}
	}
	int ans = N*M;
	for (int u = 1; u < N-1; ++u) {
		
		for (int d = u + 1; d < N; ++d) {
			int nans = 0;
			for (int y = 0; y < u; ++y) {
				nans += nums[y][1] + nums[y][2];
			}
			for (int y = u; y < d; ++y) {
				nans += nums[y][0] + nums[y][2];
			}
			for (int y = d; y < N; ++y) {
				nans += nums[y][0] + nums[y][1];
			}
			ans = min(ans, nans);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3188