akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

string S;
int N,A,B,C,D,tmp;
bool dfs(int node, int goal){
    //cout << node << ' ' << goal << endl;
    if(node>=N || S[node]=='#' || node==tmp){
        return false;
    }else if(node==goal){
        return true;
    }
    for(int i=1; i<=2; i++){
        if(dfs(node+i, goal)){
            return true;
        }
    }
}

int main(){
    cin >> N >> A >> B >> C >> D;
    A--;B--;C--;D--;
    cin >> S;
    tmp=-1;

    if(C<D){
        if(dfs(B,D)){
            B=D;
        }else{
            cout << "No" << endl;
            return 0;
        }
        if(dfs(A,C)){
            cout << "Yes" << endl;
            return 0;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }

    while(S[B-1]=='#' || S[B+1]=='#'){
        for(int i=0; i<2; i++){
            B++;
            if(S[B]=='.')break;
        }
        //cout << B << endl;
        if(S[B]=='#' || B>D){
            cout << "No" << endl;
            return 0;
        }
    }
    tmp=B;
    if(dfs(A,C)){
        A=C;
        tmp=-1;
    }else{
        cout << "No" << endl;
        return 0;
    }
    if(dfs(B,D)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 4228
s=int(input())
se={s}
for i in range(10000000):
    if s%2==0:
        s=s//2
        if s in se:
            print(i+2)
            exit()
        else:
            se.add(s)
    else:
        s=s*3+1
        if s in se:
            print(i+2)
            exit()
        else:
            se.add(s)

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

using namespace std;

const int maxn=1e5+5;
const int MOD=1e9+7;

int main(){
	string s;
	cin>>s;
	int n=s.length();
	vector<int> dp(13,0);
	dp[0]=1;
	int pow[maxn];
	pow[0]=1;
	for(int i=1;i<maxn;i++){
		pow[i]=(pow[i-1]*10)%13;
	}
	for(int i=0;i<n;i++){
		vector<int> new_dp(13,0);
		if(s[i]!='?'){
			int cur=s[i]-'0';
			for(int j=0;j<13;j++){
				new_dp[(j+cur*pow[n-1-i])%13]+=dp[j];
				new_dp[(j+cur*pow[n-1-i])%13]%=MOD;
			}
		}
		else{
			for(int j=0;j<10;j++){
				for(int k=0;k<13;k++){
					new_dp[(k+j*pow[n-1-i])%13]+=dp[k];
					new_dp[(k+j*pow[n-1-i])%13]%=MOD;
				}
			}
		}
		swap(new_dp,dp);
	}
	printf("%d\n",dp[5]);
	return 0;
}

Measured memory_bytes: 896
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int h, w, ans;
string s[22];
bool vis[20][20];

bool gun(int x, int y, int u, int v)
{
	if (x < 0 || x >= h) return false;
	if (y < 0 || y >= w) return false;
	if (x != u && y != v) return false;
	return true;
}

int fun(int x, int y, int u, int v)
{
	int cnt = 0;
	memset(vis, 0, sizeof(vis));
	queue<pair<int, int> > qu;
	qu.push({ x, y });
	vis[x][y] = true;
	pair<int, int> lst = { x, y };
	while (!qu.empty()) {
		auto cur = qu.front();
		qu.pop();
		if (cur == make_pair(u, v)) {
			return cnt;
		}
		for (int i = cur.fi - 1; i <= cur.fi + 1; i++) {
			for (int j = cur.se - 1; j <= cur.se + 1; j++) {
				if (gun(i, j, cur.first, cur.second)) {
					if (s[i][j] == '.' && !vis[i][j]) {
						qu.push({ i, j });
						vis[i][j] = true;
					}
				}
			}
		}
		if (cur == lst && !qu.empty()) {
			cnt++;
			lst = qu.back();
		}
	}
	return 0;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			for (int ii = 0; ii < h; ii++) {
				for (int jj = 0; jj < w; jj++) {
					if (s[i][j] == '.' && s[ii][jj] == '.') ans = max(ans, fun(i, j, ii, jj));
				}
			}
		}
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

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

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int n;
    cin>>n;
    vector<int>a,b;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        a.push_back(x+y);
        b.push_back(x-y);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int ans=max(abs(a[0]-a[n-1]),abs(b[0]-b[n-1]));
    cout<<ans<<endl;
}


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

int main() {
    int n, m, q;
    scanf("%d %d %d", &n, &m, &q);
    int table[n][n + 1];
    std::fill(table[0], table[n - 1]+n+1, 0);
    for (int i = 0; i < m; i++) {
        int l, r;
        scanf("%d %d", &l, &r);
        table[l - 1][r]++;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= n; j++) {
            table[i][j] += table[i][j - 1];
        }
    }
    for (int i = 0; i < q; i++) {
        int p, q;
        scanf("%d %d", &p, &q);
        int count = 0;
        for (int i = p - 1; i < q; i++) {
            count += table[i][q] - table[i][p - 1];
        }
        printf("%d\n", count);
    }
    return 0;
}


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

int dp[200010];
int main() {
	int N, p[200010];
	cin >> N;
	for(int i=0; i<N; ++i){
	    cin >> p[i];
	    dp[p[i]]=dp[p[i]-1]+1;
	}
	int mx=0;
	for(int i=1; i<=N; ++i) mx=max(mx, dp[i]);
	cout << N-mx << endl;
	return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (long long i = 0; i < (long long) (n); ++i)
#define pb emplace_back
#define endl '\n'

template<typename T> void _dbg(const char*_s,T _h) { cerr<<_s<<" = "<<_h<<"\n"; }

template<typename T, typename... Ts> void _dbg(const char*_s,T _h,Ts... _t) {
    for(int _b=0;((_b+=*_s=='(')-=*_s==')')!=0||*_s!=',';)cerr<<*_s++;
    cerr<<" = "<<_h<<",";_dbg(_s+1,_t...);
}

#define int long long

#ifdef LOCAL
    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
    #define dbg(...)
#endif

const int N = 500 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
int u, v;
int cnt[N];

bool read() {
    if (!(cin >> n >> u >> v))
        return false;

    return true;
}

void solve(int id = 0) {
    for (int i = 1; i <= n; ++i)
        for (int j = i + 1; j <= n; ++j) {
            int dist = abs(i - j);
            dist = min(dist, abs(i - u) + 1 + abs(v - j));
            dist = min(dist, abs(i - v) + 1 + abs(u - j));
            ++cnt[dist];
        }

    for (int i = 1; i <= n - 1; ++i)
        cout << cnt[i] << ' ';

    cout << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    //cin >> T;

    while (read())
        solve(T++);

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int A, B, C, D, E;
	cin >> A >> B >> C >> D >> E;
	int ans = C * 60 + D - A * 60 - B - E;

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

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

// 抽象化したセグメント木
template<class Monoid> struct SegTree {
    using Func = function<Monoid(Monoid, Monoid)>;
    const Func F;
    const Monoid UNITY;
    int SIZE_R;
    vector<Monoid> dat;
    
    SegTree(int n, const Func f, const Monoid &unity): F(f), UNITY(unity) { init(n); }
    void init(int n) {
        SIZE_R = 1;
        while (SIZE_R < n) SIZE_R *= 2;
        dat.assign(SIZE_R * 2, UNITY);
    }
    
    /* set, a is 0-indexed */
    void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
    void build() {
        for (int k = SIZE_R - 1; k > 0; --k)
            dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    
    /* update a, a is 0-indexed */
    void update(int a, const Monoid &v) {
        int k = a + SIZE_R;
        dat[k] = v;
        while (k >>= 1) dat[k] = F(dat[k*2], dat[k*2+1]);
    }
    
    /* get [a, b), a and b are 0-indexed */
    Monoid get(int a, int b) {
        Monoid vleft = UNITY, vright = UNITY;
        for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
            if (left & 1) vleft = F(vleft, dat[left++]);
            if (right & 1) vright = F(dat[--right], vright);
        }                                                                                                              
        return F(vleft, vright);
    }
    inline Monoid operator [] (int a) { return dat[a + SIZE_R]; }
    
    /* debug */
    void print() {
        for (int i = 0; i < SIZE_R; ++i) {
            cout << (*this)[i];
            if (i != SIZE_R-1) cout << ",";
        }
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
    vector<long long> h(N), a(N);
    for (int i = 0; i < N; ++i) cin >> h[i];
    for (int i = 0; i < N; ++i) cin >> a[i];

    // セグメント木 (区間取得を max としたもの)
    SegTree<long long> dp(N+1,
                          [](long long a, long long b) { return max(a, b); },
                          0);

    // 更新
    long long res = 0;
    for (int i = 0; i < N; ++i) {
        // 値取得
        long long A = dp.get(0, h[i]);

        // 更新
        if (dp.get(h[i], h[i]+1) < A + a[i]) {
            dp.update(h[i], A + a[i]);
            res = max(res, A + a[i]);
        }
    }
    cout << res << endl;
}   


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

int main() {
  	long long int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  cout  << max({
    a*c,
    a*d,
    b*c,
    b*d
  }) << endl;
	return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    ll sum = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        sum += a[i];
        if (sum > x) {
            cout << i << endl;
            return 0;
        } else if (sum == x) {
            cout << i + 1 << endl;
            return 0;
        }
        ans = i;
    }
    cout << ans << endl;
    return 0;
}

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

int n,pd,a[2010][2010],ji;
int main()
{
	scanf("%d",&n);
	for(int i=1;i*(i-1)<=2*n;++i)
	{
		if(i*(i-1)==2*n)
		{
			pd=i;
			break;
		}
	}
	if(pd==0)
	printf("No\n");
	else
	{
		printf("Yes\n");
		printf("%d\n",pd);
		for(int i=1;i<=pd-1;++i)
		a[1][i]=i;
		ji=pd-1;
		for(int i=2;i<=pd;++i)
		{
			for(int j=1;j<i;++j)
			a[i][j]=a[j][i-1];
			for(int j=i;j<=pd-1;++j)
			a[i][j]=++ji;
		}
		for(int i=1;i<=pd;++i)
		{
			printf("%d ",pd-1);
			for(int j=1;j<=pd-1;++j)
			printf("%d ",a[i][j]);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

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

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();

    int a, b;
    cin>>a>>b;
    int x=b*10;
    for (int i=x;i<=x+9;i++)
    {
        double y=i*0.08;
        if (floor(y)==a)
        {
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
    return 0;
}

Measured memory_bytes: 3620
H,W=map(int,input().split())

a=[]
place=[]

count=0

for i in range(H):
  a.append(list(map(int,input().split())))
 
  if i>=1:
    for j in range(W):
      if a[i-1][j]%2==1:
        count+=1
        a[i][j]+=1
        place.append([i,j+1,i+1,j+1])
  
  if i==H-1:
    for j in range(W):
      if j>=1 and a[i][j-1]%2==1:
        count+=1
        a[i][j]+=1
        place.append([i+1,j,i+1,j+1])

print(count)

for i in range(len(place)):
  print(place[i][0],place[i][1],place[i][2],place[i][3])


'''
count=0
answer=0
anslist=[]

while(count!=(doubleN//2)):
  
  if place[2*count][0]==place[2*count+1][0] and place[2*count][1]==place[2*count+1][1]:
    count+=1
    continue;
  
  answer+=1 
  if place[2*count][0]==place[2*count+1][0]:
    if place[2*count][1]<place[2*count+1][1]:
      anslist.append([place[2*count][0],place[2*count][1],place[2*count][0],place[2*count][1]+1])
      place[2*count][1]+=1
      continue;
    else:
      anslist.append([place[2*count][0],place[2*count][1],place[2*count][0],place[2*count][1]-1])
      place[2*count][1]-=1
      continue;
      
  else:
    anslist.append([place[2*count][0],place[2*count][1],place[2*count][0]+1,place[2*count][1]])
    place[2*count][0]+=1
    continue;


print(answer)

for i in range(len(anslist)):
  print(anslist[i][0],anslist[i][1],anslist[i][2],anslist[i][3])
  
for i in range(len(place)//2):
  print(place[2*i][0],place[2*i][1],place[2*i+1][0],place[2*i+1][1])
'''

Measured memory_bytes: 30212
n=int(raw_input())
a=[int(raw_input()) for _ in xrange(n)]
mxlba=0
for i in xrange(n):
    mxlba=max(mxlba,len(bin(a[i])[2:]))

exist=[False]*(mxlba+1000)
for i in xrange(n):
    bit=bin(a[i])[2:]
    lb=len(bit)
    for j in xrange(lb-1,-1,-1):
        if bit[j]=="1":
            exist[lb-1-j]=True
            break

axor=0
for i in xrange(n):
    axor^=a[i]
if axor==0:
    print(0)
    exit()
axor=bin(axor)[2:]
la=len(axor)
ans=0
i=0
while i<la:
    if axor[i]=="1":
        if not exist[la-i-1]:
            print(-1)
            exit()
        else:
            ans+=1
            if la-i-1==0:
                break
            tmp=int("1"*(la-i-1),2)
            axor=int(axor,2)^tmp
            axor=bin(axor)[2:]
    i+=1

print(ans)


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

int N, T, A;
int x = 0;
  
int main() {
  int data[1000];
  float diff = 100000;
  cin >> N;
  cin >> T >> A;
  for (int i = 0; i < N; i++) cin >> data[i];
  for (int i = 0; i < N; i++) {
    double temp = T - data[i] * 0.006;
    float d = abs(A - temp);
    if (diff > d) {
        diff = d;
        x = i;
     }
  }
  cout << x+1 << endl;
}

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

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll post[n];
   ll mod = 1000000007;
    for(int i=0;i<n;i++)cin>>a[i];

    post[n-1]=a[n-1];

    for(int i=n-2;i>=0;i--)
    {
        post[i]=(post[i+1]%mod+a[i]%mod)%mod;
    }

    ll ans=0;

    for(int i=0;i<n-1;i++)
    {
        ans = (ans%mod+((a[i]*post[i+1])%mod))%mod;
    }

    cout<<ans<<endl;




}


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

using namespace std;

struct interval
{
    int a, b;
};

interval v[100005];

interval intersect (interval a, interval b)
{
    interval ans;

    if(a.a < b.a)
        ans.a = b.a;
    else
        ans.a = a.a;


    if(a.b < b.b)
        ans.b = a.b;
    else
        ans.b = b.b;

    return ans;
}

bool comp_interv (interval a, interval b)
{
    return a.a < b.a;
}

bool is_voidinteresction (interval a)
{
    return a.a>=a.b;
}

int main()
{
    /*freopen("d.in","r",stdin);
    freopen("d.out","w",stdout);*/
    int n, m, bridgecount = 0;
    interval intersection;

    scanf("%d %d\n", &n, &m);
    for(int i=1; i<=m; i++)
        scanf("%d %d\n", &v[i].a, &v[i].b);

    sort(v+1, v+m+1, comp_interv);
    /*for(int i=1; i<=m; i++)
    {
        printf("%d %d\n", v[i].a, v[i].b);
    }*/


    intersection.a = v[1].a;
    intersection.b = v[1].b;

    for(int i=2; i<=m; i++)
    {
        if(is_voidinteresction(intersect(intersection, v[i]))) //If the intersection is void
        {
            bridgecount++;

            intersection.a = v[i].a;
            intersection.b = v[i].b;
        }

        else //If the intersection is not void
        {
            intersection.a = intersect(intersection, v[i]).a;
            intersection.b = intersect(intersection, v[i]).b;
        }
    }

    bridgecount++;

    printf("%d", bridgecount);
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    string S;
    ll K;
    cin >> S >> K;
    int pnt = 0;
    char res;
    for (int i = 0; i < S.size(); ++i) {
        if (S.at(i) == '1') {
            pnt = i + 1;
        } else {
            res = S.at(i);
            break;
        }
    }

    cout << ((K <= pnt) ? '1' : res) << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
a = list(map(int, input().split()))

h = [0] + h
a = [0] + a

bit = [0] * (n+1)
def update(a, w):
    x = a
    while x <= n:
        bit[x] = max(bit[x], w)
        x += x & -x

def solve(a):
    res = 0
    x = a
    while x > 0:
        res = max(res, bit[x])
        x -= x & -x
    return res

for i in range(1, n+1):
    ma = solve(h[i]-1)
    update(h[i], ma + a[i])

print(max(bit))

Measured memory_bytes: 35972
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};


int main(){
  int N;
  cin>>N;
  vector<pair<int,int>> red(N),blue(N);
  for(int i=0;i<N;i++){
    cin>>red[i].first>>red[i].second;
  }
  for(int i=0;i<N;i++){
    cin>>blue[i].first>>blue[i].second;
  }
  sort(red.rbegin(),red.rend());

  int ans=0;
  vector<bool> used(N,false);
  for(int i=0;i<N;i++){
    int place=-1;
    int miny=1000;
    for(int j=0;j<N;j++){
      if(!used[j]&&red[i].first<blue[j].first&&red[i].second<blue[j].second&&blue[j].second<miny){
        place=j;
        miny=blue[j].second;
      }
    }
    if(place==-1) continue;
    ans++;
    used[place]=true;

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



Measured memory_bytes: 256
use std::io;
use std::io::prelude::*;

fn main() {
    let mut stdin = io::stdin();
    let mut buf = String::new();
    let _ = stdin.read_to_string(&mut buf);
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();
    let mut h: Vec<u32> = iter.map(|x| x.parse().unwrap()).collect();

    h.sort();
    println!("{}", (0..(n - k + 1)).map(|i| h[i + k - 1] - h[i]).min().unwrap());
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

int main(){
    int n, m;   cin >> n >> m;
    vector<bool> sw(n);
    vector<vector<bool>> light(m, vector<bool>(n, false));
    REP(i, m){
        int k;  cin >> k;
        REP(j, k){
            int x;  cin >> x;
            x--;
            light[i][x] = true;
        }
    }
    vector<ll> p(m);
    REP(i, m)   cin >> p[i];

    ll res=0;
    REP(i, 1<<n){
        bool flag=true;
        
        REP(j, m){
            int cnt=0;
            REP(bit, n){
                if(i & 1<<bit){
                    if(light[j][bit]) cnt += 1;
                }
            }
            if(cnt%2!=p[j]) flag=false; 
        }
        if(flag) res += 1;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
n = gets.chop.to_i
a = $stdin.read.chomp.split.map { |e| e.to_i }
lcm = a[0]
1.upto(a.size-1) do |i|
  lcm = lcm.lcm(a[i])
end
res = 0
a.each do |e|
  res += lcm / e
end
puts res % (10**9 + 7)


Measured memory_bytes: 63524
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

use std::cmp::Ordering;
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

impl<T: Copy> Copy for Rev<T> {}

struct UnionFind {
    data: Vec<usize>,
    size: Vec<usize>,
    groupes: usize,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut data = vec![0; n];
        for i in 0..data.len() {
            data[i] = i;
        }
        let mut size = vec![1; n];
        UnionFind {
            data: data,
            size: size,
            groupes: n,
        }
    }

    fn unite(&mut self, a: usize, b: usize) {
        let mut a = self.find(a);
        let mut b = self.find(b);
        if a == b {
            return;
        }

        if self.size[a] < self.size[b] {
            std::mem::swap(&mut a, &mut b);
        }

        self.groupes -= 1;
        self.size[a] += self.size[b];
        self.data[b] = a;
    }

    fn find(&mut self, x: usize) -> usize {
        let t = self.data[x];
        if t != x {
            let p = self.find(t);
            self.data[x] = p;
        }
        self.data[x]
    }
}

use std::collections::HashSet;

fn main() {
    input! {
        n: usize, m: usize,
        xyz: [(usize1, usize1, usize); m]
    }

    let mut uf = UnionFind::new(n);
    for (x, y, z) in xyz {
        if z % 2 == 0 {
            uf.unite(x, y);
        } else {
            uf.unite(x, y);
        }
    }

    let ans = uf.groupes;
    println!("{}", ans);
}


Measured memory_bytes: 12540
/*{{{*/
//#define HOME
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define F first
#define S second

template<class T> void _R(T &_x) { cin >> _x; }
void _R(int &_x) { scanf("%d", &_x); }
void _R(int64_t &_x) { scanf("%" SCNd64, &_x); }
void _R(double &_x) { scanf("%lf", &_x); }
void _R(char &_x) { scanf(" %c", &_x); }
void _R(char *_x) { scanf("%s", _x); }
template<class T, class U> void _R(pair<T, U> &_x) {_R(_x.F); _R(_x.S);}
void R() {}
template<class T, class... U> void R(T &_head, U &... _tail) { _R(_head); R(_tail...); }

template<class T> void _W(const T &_x) { cout << _x; }
void _W(const int &_x) { printf("%d", _x); }
void _W(const int64_t &_x) { printf("%" PRId64, _x); }
void _W(const double &_x) { printf("%.16f", _x); }
void _W(const char &_x) { putchar(_x); }
void _W(const char *_x) { printf("%s", _x); }
template<class T, class U> void _W(const pair<T, U> &_x) {_W(_x.F); putchar(' '); _W(_x.S);}
template<class T> void _W(const vector<T> &_x) { for (auto i = _x.begin(); i != _x.end(); _W(*i++)) if (i != _x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &_head, const U &... _tail) { _W(_head); putchar(sizeof...(_tail) ? ' ' : '\n'); W(_tail...); }
template<class T, class... U> void DB(const T &_head, const U &... _tail) {
#ifdef HOME
    W('#', _head, _tail...);
#endif
}

#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define RAN(x,n) (x).begin(), (x).begin()+(n)
#define UNIQUE(x) {sort(ALL(x)); (x).erase(unique(ALL(x)), (x).end());}

#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
//#define ITER(i,t) for (auto i = t.begin(); i != t.end(); ++i)
#define IT3(i,st,ed) for (auto i = st; i != ed; ++i)
#define IT2(i,range) IT3(i,range)

#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define MS(X, v) memset((X), (v), sizeof((X)))

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

inline int LG (const unsigned int &_x) { return 31-__builtin_clz(_x); }  // floor: LG(x), ceil: LG(x-1)+1
/*}}}*/

ll n;

int main(){
    R(n);
    ll ans = n;
    for(ll i=1; i*i <= n; ++i){
        if(n % i != 0) continue;
        ans = min(ans, i + n / i - 2);
    }
    W(ans);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

// lcm ここから
// gcd ここから
template <typename T>
T gcd(T a, T b) {
	if(a < b) {
		swap(a, b);
	}

	T r = a % b;
	while(r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}
// gcd ここまで

template <typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b); // オーバーフロー注意
}
// lcm ここまで

int main() {
        int n;
        scanf("%d", &n);
        VI a(n);
        EACH(e, a){
                scanf("%d", &e);
        }
        int result = 1;
        REP(i, n){
                result = lcm(result, a[i]);
        }
        printf("%d\n", result);
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  int d[n];
  for(int i=0; i<n; i++) cin >> d[i];
  int sum = 0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      sum += d[i]*d[j];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define S 1000001
#define M 1000000007
#define nl cout<<"\n";
#define er  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define Y cout<<"YES\n";
#define N cout<<"NO\n";
#define print(x)                 cout<<#x<<": "<<x<<endl;
#define print2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define print3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define print4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define print5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define print6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;

int main()
{
    fast
    // test
    {
        lli n,ans=0;
        cin>>n;
        lli arr[n+11]={0};
        for(lli i=1;i<=n;i++)
        {
            cin>>arr[i];
            if(i%2&&arr[i]%2)
            {
                ans++;
            }
        }
        cout<<ans;
    }
}
//a+b=a?b+2?(a&b)
//__builtin_popcount(number)
//cout<<fixed<<setprecision(8)<<output<<"\n";




Measured memory_bytes: 3648
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> xs(n); cin >> xs;
    auto x2 = xs;
    sort(x2.begin(), x2.end());
    int n1 = x2[n / 2 - 1], n2 = x2[n / 2];
    for(int i = 0; i < n; i++){
        cout << (xs[i] <= n1 ? n2 : n1) << '\n';
    }
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n;
    std::cout.precision(10);
    int yes=0;
  cin>>n;
  ll p=n+(n*n) +(n*n*n);
  cout<<p;
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3556
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

int ans;
bool ok[3][3][2010][2010],f[3][3][4010];
string s[3];

inline bool check(int x,int y,int posx,int posy){
	if(s[x][posx]=='?'||s[y][posy]=='?'||s[x][posx]==s[y][posy]) return true;
	return false;
} 

inline void calc(int x,int y,int z)
{
	for(int i=0;i<=s[x].size();i++){
		for(int j=i;j<=max(i+s[y].size(),s[x].size());j++){
			bool flag1=(i>=s[x].size()||f[x][y][i+s[y].size()-1]);
			bool flag2=(j>=s[x].size()||f[x][z][j+s[z].size()-1]);
			bool flag3=(j>=i+s[y].size()||f[y][z][j-i+s[z].size()-1]);
			if(flag1&&flag2&&flag3){
				int val=max(s[x].size(),max(i+s[y].size(),j+s[z].size()));
				ans=min(ans,val);
			}
		}
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>s[0]>>s[1]>>s[2];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++) if(j!=i){
			for(int ii=0;ii<s[i].size();ii++){
				for(int jj=0;jj<s[j].size();jj++){
					ok[i][j][ii][jj]=check(i,j,ii,jj);
				}
			}
		}
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++) if(j!=i){
			for(int k=0;k<s[i].size()+s[j].size()-1;k++){
				f[i][j][k]=1;
				for(int l=0;l<s[i].size();l++){
					if(s[j].size()-k-1+l<0) continue;
					if(s[j].size()-k-1+l>=s[j].size()) continue;
					f[i][j][k]&=ok[i][j][l][s[j].size()-k-1+l];
				}
			}
		}
	}
	ans=s[0].size()+s[1].size()+s[2].size();
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++) if(j!=i){
			for(int k=0;k<3;k++) if(k!=i&&k!=j){
				calc(i,j,k);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 28928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14

int main(){
    ll t, n; cin >> t;
    REP(i,t){
        cin >> n;
        vector<ll> a(n);
        REP(k,n) cin >> a[k];
        string s; cin >> s;
        vector<ll> nl={0};
        bool jud = true;
        FORD(j,n-1,0){
            if (s[j]=='0'){
                ll x = a[j];
                REP(k,nl.size()){
                    x = min(x^nl[k],x);
                }
                REP(k,nl.size()){
                    nl[k]=min(nl[k]^x,nl[k]);
                }
                nl.pb(x);
            }
            else{
                ll x = a[j];
                REP(k,nl.size()){
                    x = min(x^nl[k],x);
                }
                if (x!=0){
                    jud = false;
                    break;
                }
            }
            /*cout << j << endl;
            REP(i,nl.size()) cout << nl[i] << " ";
            cout << endl;*/
        }
        if (jud) cout << 0 << endl;
        else cout << 1 << endl;
    }
}

Measured memory_bytes: 3648
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = in.nextInt();
        int m = in.nextInt();
        int[] a = new int[m];
        for(int i = 0; i<m; i++){
            a[i] = in.nextInt();
        }
        shuffle(a);
        Arrays.sort(a);
        int[] d = new int[m-1];
        for(int i = 0; i<m-1; i++){
            d[i] = a[i+1]-a[i];
        }
        long sum = 0;
        shuffle(d);
        Arrays.sort(d);
        for(int i = 0; i<m-1-(n-1); i++) sum += d[i];
        out.println(sum);
        out.close();
    }
    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

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

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



Measured memory_bytes: 44836
//Wrong answer on test inf.
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
#define y1 y1___
using namespace std;
char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
ll read(){
	char ch=gc();ll x=0;int op=1;
	for (;!isdigit(ch);ch=gc()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=gc()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
ll n,now;
double cal(ll x){
	ll y=x,ret=0;
	while (x) ret+=x%10,x/=10;
	return 1.*y/ret;
}
bool ok(ll x){
	ll t=1;
	while (t<=x){
		if (cal(x+t)<cal(x)) return 0;
		t*=10;
	}
	return 1;
}
int main(){
	n=read();
	while (n--){
		ll t=1;
		while (1)
			if (ok(now+t)){now+=t;break;}
			else t*=10;
		printf("%lld\n",now);
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int ans=0;
  string s="CODEFESTIVAL2016",t;
  cin >> t;
  for(int i=0; i<16; i++) {
    if(s[i]!=t[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    bool yes=false;
    if(n%7==0 && n/7>=1){
        yes=true;
        cout<<"Yes"<<endl;
    }
    else if(n%4==0 && n/4>=1){
        yes=true;
        cout<<"Yes"<<endl;
    }
    else{
        for(int i=7;i<=n;i=i+7){
            int temp=n-i;
            if(temp%4==0 && temp/4>=1){
                yes=true;
                cout<<"Yes"<<endl;
                break;
            }
        }
    }
    if(yes==false){
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	int s[1000],ss[1000]={0};
	int max=0 , r[2000];
	for( int i=0 ; i<n ; i++ )
		cin >> s[i] ;
	int x;
	for( int i=0 ; i<m ; i++ ){
		cin >> x;
		max=0;
		for( int j=0 ; j<n ; j++ ){
			if( x>=s[j] && s[j]>=max ){
				ss[j]++;
				max=s[j];
			}
		}
	}
	max=0;
	int maxi;
	for( int i=0 ; i<n ; i++ ){
	//	cout <<"   "<< ss[i] ;
		if( max<ss[i] ){
			max=ss[i];
			maxi=i+1;
		}
	}
	//cout << endl << endl;
	cout << maxi << endl;
}

Measured memory_bytes: 3092
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

class UnionFind {
public:
  int N;
  int* root;
  int* rank;

  UnionFind(int n) : N(n) {
    root = new int[N];
    rank = new int[N];
    for (auto i = 0; i < N; ++i) {
      root[i] = i;
      rank[i] = 0;
    }
  }

  ~UnionFind() {
    delete[] root;
    delete[] rank;
  }

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

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      root[x] = y;
    } else {
      root[y] = x;
      if (rank[x] == rank[y]) ++(rank[x]);
    }
  }

  bool same(int x, int y) {
    return (find(x) == find(y));
  }
};


int main () {
  int n, q;
  cin >> n >> q;
  UnionFind uf(n);
  for (auto i = 0; i < q; ++i) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      uf.unite(x, y);
    } else {
      if (uf.same(x, y)) {
        cout << "1" << endl;
      } else {
        cout << "0" << endl;        
      }
    }
  }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

vi G[2005];

int dfs(int u, int p, int d) {
	int ret = 1;
	for(int v:G[u]) if(v != p && d)
		ret += dfs(v, u, d-1);
	return ret;
}

signed main()
{
	IO_OP;
	
	int n, k;
	cin >> n >> k;
	for(int i=0;i<n-1;i++) {
		int u, v;
		cin >> u >> v;
		G[u].PB(v);
		G[v].PB(u);
	}	
	if(k % 2 == 0) {
		int mx = -1;
		for(int i=1;i<=n;i++)
			mx = max(mx, dfs(i, -1, k/2));
		cout << n - mx << endl;
	} else {
		int mx = -1;
		for(int i=1;i<=n;i++)
			for(int j:G[i])
				mx = max(mx, dfs(i, j, k/2) + dfs(j, i, k/2));
		cout << n - mx << endl;
	}
	
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 998244353
#define EPS 1e(-9);
using namespace std;
typedef long long ll;

struct BIT
{
  vector<ll> bit;
  int M;
  BIT(int n){
    M = n;
    bit.resize(M+1);
    rep(i, bit.size()){bit[i]= 0;}
  }

  void add(int a, ll x) { // aを +x  aは 1-indexed
    if (a > M) return;
    bit[a] += x;
    add(a+(a&-a), x); //真上の階層すべてに足す
  }

  ll sum(int a) { // [1,a] 1-indexed
    if (!a) return 0; // 0 のときは0
    return bit[a] + sum(a-(a&-a)); //(a&-a) 最後の1のビットだけ立つ 区間の長さに等しい
  } // 左上のものをすべて足す

  ll sum(int a,int b){ // [a,b] 1-indexed
    return sum(b) - sum(a-1);
  }

  ll get(ll k){ // k-th number 1-indexed 二分探索
    //k-1までが全部入るresの1つ後を求める。
    ll res=0; // kがたまるまでresを増やす。
    ll N=1; while(N <= M) N*=2;
    for(int i=N/2; i>0; i/=2 ){
      if(res + i <= M and bit[res+i] <k){
        k = k-bit[res+i];
        res+=i;
      }
    }
    return res+1; // 1-indexed resまでは新kまでが全部入る
  }

};

ll modpow(ll a, ll n, ll mod=MOD){ // a^n % MOD の計算
  ll res = 1;
  while (n > 0){
    if(n & 1) res = res * a % mod;
    a = a * a  % mod;
    n >>= 1;
  }
  return res;
}


void Main(){

  ll N; cin>>N;

  vector<pair<ll,ll>> ve(N);

  rep(i,N){
    cin>>ve[i].first>>ve[i].second;
  }

  SORT(ve);

  vector<ll> x(N);
  vector<ll> y(N);

  rep(i,N){
    x[i]=ve[i].first;
    y[i]=ve[i].second;
  }

  vector<ll> xcomp,ycomp; //圧縮後のx,y
  vector<ll> valx=x,valy=y;//VALSにaをコピー
  SORT(valx);
  SORT(valy);
  rep(i,N){
    xcomp.emplace_back(lower_bound(ALL(valx), x[i]) -valx.begin());
    ycomp.emplace_back(lower_bound(ALL(valy), y[i]) -valy.begin());
  }

  ll ans=0;

  BIT bis(N+1); //小さい方から。x< かつy<を調べる
  BIT bib(N+1); //大きい方から。

  rep(i,N){
    bib.add(i+1,1);
  }

  ll xs[N],xb[N],ys[N],yb[N];

  rep(i,N){
    // 点ごとに見る。 iがそれ以下かつyがそれ以下から1個以上 逆からも1個以上のときカウント modpow(2, 数1)*modpow(2, 数2) + modpow(2, N-1)
    xs[i]=bis.sum(ycomp[i]);
    xb[i]=i-xs[i];

    bis.add(ycomp[i]+1,1);

    ys[i]=bib.sum(ycomp[i]);
    yb[i]=(N-i-1)-ys[i];

    bib.add(ycomp[i]+1,-1);
  }

  rep(i,N){

    ll A=( (modpow(2,xs[i]) - 1 ) * (modpow(2,yb[i]) -1)%MOD);
    ll B=( (modpow(2,xb[i]) - 1 ) * (modpow(2,ys[i]) -1)%MOD);

    ans=(ans+(A*modpow(2,xb[i]+ys[i])%MOD) + (B*modpow(2,xs[i]+yb[i])%MOD)-(A*B%MOD)+MOD)%MOD;

  }

  ans=(ans+N*modpow(2,N-1))%MOD;

  cout<< ans <<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

using namespace std;

int main()
{
    int N, K;
    int i, j;
    long long int cnt = 0;
    scanf("%d %d",&N, &K);

    for(j=K+1;j<=N;j++){
        int A = N/j; int B = max(N - (K + N/j*j) + 1,0);
        int chk = (j-K);
        cnt += chk * A + B;
    }

    printf("%lld",cnt - (K==0?N:0));

    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() {
    int K;
    cin >> K;
    string S = "ACL";
    string res;
    rep(i, K) res += S;
    cout << res << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
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; }

int main(){
  int n;
  cin >> n;
  vector<string> d = {"AC","WA","TLE","RE"};
  vl cnt(4,0);
  rep(i,n){
    string s;
    cin >> s;
    rep(j,4){
      if(s == d[j]){
        cnt.at(j)++;
      }
    }
  }
  rep(i,4){
    cout << d[i] << " x " << cnt.at(i) << endl;
  }
}

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

int main(){

	int a,b,c,d,l,x,y,z;
	cin >> l >> a >> b >> c >> d;

	if( a%c > 0 ){
		x = a/c+1;
	}
	else{
		x = a/c;
	}
	if( b%d > 0 ){
		y = b/d+1;
	}
	else{
		y = b/d;
	}

	z = max( x , y );
	
	cout << l-z << endl;

	return 0;
}


Measured memory_bytes: 3052