akhauriyash/Code-Regression huggingface dataset:
global cmt                                                     
cmt = 0                                                        
def Merge(left, right):                                        
    global cmt                                                 
    lst = []                                                   
    i, j = 0, 0                                                
    while i < len(left) and j < len(right):                    
        if left[i] <= right[j]:                                
            lst.append(left[i])                                
            i += 1                                             
        else:                                                  
            lst.append(right[j])                               
            j += 1                                             
    lst += left[i:]                                            
    lst += right[j:]                                           
    cmt += len(lst)                                            
                                                               
    return lst                                                 
                                                               
def MergeSort(A):                                              
    if len(A) == 1: return A                                   
    mid = len(A) / 2                                           
    left = MergeSort(A[:mid])                                  
    right = MergeSort(A[mid:])                                 
    #print left, right                                         
    sortedList = Merge(left, right)                            
    return sortedList                                          
                                                               
n = raw_input()                                                
print ' '.join(map(str,MergeSort(map(int, raw_input().split()))
))                                                             
print cmt

Measured memory_bytes: 55608
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<map>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const int mod=1000000007;
const llint big=1e18+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-9;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}//a>b
class in_t{public:
	int a;in_t(){cin>>a;}
	operator int() {return a;}
};
class ld_t{public:
	long double a;ld_t(){cin>>a;}
	operator long double() {return a;}
};
int main(void){
	int n,l,q,i,j;cin>>n;
	//ダブリング、留年
	vector<int>bas(n);
	vector<vector<int>>go(n);
	
	for(i=0;i<n;i++){cin>>bas[i];go[i].res(20);}
	cin>>l>>q;
	int now=0;
	for(j=0;j<n;j++){
		while(now+1<n&&bas[now+1]<=bas[j]+l){now++;}
		go[j][0]=now;
	}
	for(i=1;i<20;i++){
		for(j=0;j<n;j++){
			go[j][i]=go[go[j][i-1]][i-1];
		}
	}
	for(i=0;i<q;i++){
		int a,b,ans=0;
		cin>>a>>b;a--;b--;
		if(a>b){swap(a,b);}
		for(j=19;j>=0;j--){
			if(go[a][j]<b){a=go[a][j];ans+=(1<<j);}
		}
		ans++;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 14592
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){
    //建物定義
    int build[4][3][10];
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                build[i][j][k] = 0;    
            }

        }   

    }
    //建物

    int n; scanf("%d",&n);
    int b, f, r, v;

    for (int i = 0; i < n; i++)
    {
        scanf("%d %d %d %d",&b, &f, &r, &v);
        build[b-1][f-1][r-1] += v;
    }

    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                printf(" %d",build[i][j][k]);
            }
            printf("\n");
            
        }
        if (i<3)
        {
            printf("####################\n");
        }
        
        
    }
    
    

}



Measured memory_bytes: 3208
n = int(input())
 
f = True
for i in range(n):
  t,x,y = map(int,input().split())
  et = t
  exy = x+y
  et-=exy
  
  if(et>=0):
    if(et%2==0):
      continue
    else:
      f = False
      break
  else:
    f = False
    break
 
if (f):
  print('Yes')
else:
  print('No')

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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(10)





void solve() {

	int m, n;
	cin >> m >> n;
	if(m == n) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	solve();

	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(){
        int n, flag=1;
        scanf("%d", &n);
        for(int i=1;i<10;i++){
                if(n%i==0 && n/i<10){
                        flag=0;
                        puts("Yes");
                        break;
                }
        }
        if(flag) puts("No");
        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)

int main()
{
  int N;
  cin >> N;
  
	if(N==0)cout<<1<< endl;
  else cout<<0<< endl;
}


Measured memory_bytes: 3592
#include<iostream>
#include<cmath>
#include<cassert>
#include<iomanip>
#include<vector>
#include<utility>
#include<algorithm>

const auto pi = std::acos(-1.0);

struct vec {
	double x, y;
	vec(double dx = 0, double dy = 0 ) :x{dx}, y{dy} {}
	auto operator+(const vec&v)const{
		return vec{ x + v.x, y + v.y }; 
	}
	auto& operator+=(const vec&v) {
		return *this = *this + v;
	}
	
	auto operator*(double d)const {
		return vec{ x*d,y*d };
	}
	auto& operator*=(double d) {
		*this = *this*d;
		return *this;
	}

	auto operator*(const vec&v)const {
		return vec{ x*v.x, y*v.y };
	}
	auto& operator*=(const vec&v) {
		return *this = *this * v;
	}

	auto operator-(const vec&v)const {
		return vec{ x - v.x, y - v.y };
	}
	auto& operator-=(const vec&v) {
		return *this = *this - v;
	}

	auto operator/(double d)const {
		assert(std::abs(d) > 0.000001);
			//std::assert();
		return vec{ x / d,y / d };
	}
	auto& operator/=(double d) {
		return *this = *this / d;
	}
	
	friend auto operator<<(std::ostream&os, const vec&v)->std::ostream& {
		return os << v.x << " " << v.y << "\n";
	}

	auto rotated(double rad)const{
		vec tmp{};
		tmp.x = (x*std::cos(rad) - y*std::sin(rad));
		tmp.y = (x*std::sin(rad) + y*std::cos(rad));
		return tmp;
	}
	auto& rotate(double rad) {
		return *this = rotated(rad);
	}
};


double tab[] = { 0,1/3,-1/3, 0 };

void koch(std::vector<vec> *const vp, int deg) {
	if (deg == 0)return;

	auto &v   = *vp;
	auto init = v.front();
	auto end  = v.back();
	auto unit = (end - init) / 3;
	auto mid  = (end - init) / 2;

	vec vtab[4]{ {}, unit,mid,unit * 2 };
	
	auto tmp  = std::move(v);v.clear();
	unsigned dn = deg * 4 - 3;
	if(v.capacity()<dn )
		v.reserve(deg * 4 - 3);

	for (auto&e : tmp) {
		e /= 3;
	}
	auto up = tmp; //tmp.pop_back();
	auto down = tmp;
	auto tmp2 = tmp;

	auto b = tmp.back();
	for (auto&e : up) {
		e.rotate( 1.0 / 3 * pi);
		e += b;
	}b = up.back();
	
	for (auto&e : down) {
		e.rotate(-1.0 / 3 * pi);
		e += b;
	}b = down.back();
	
	for (auto&e : tmp2) {
		e += b;
	}


	std::vector<std::vector<vec>*> vps{ &tmp,&up,&down,&tmp2 };

	for (unsigned int i{}; i < 4; i++) {
		auto& here = *vps[i];
		//std::cout << here.size();
		v.insert(std::end(v), std::begin(here), std::end(here)-1);
	}
	v.push_back(end);
	/*
	auto p = init;

	std::cout << p;

	p += unit.rotated(0);
	std::cout << p;
	
	p += unit.rotated(pi / 3);
	std::cout << p;

	p += unit.rotated( -1*pi/3 );
	std::cout << p ;

	p += unit.rotated( 0 );// .rotated(pi / 3);
	std::cout << p;
	*/
}

int main() {
	int n;// = 1;
	std::cin >> n;
	std::cout << std::fixed << std::setprecision(5);
//	std::cout << vec{ 10,0 }.rotated(pi / 4);
	
	std::vector<vec> v{ {0, 0}, {100,0}};
	//koch(0, 100, 1);
	for (int i{}; i < n; i++) {
		koch(&v, n);
	}
	for (const auto&e : v) {
		std::cout << e;
	}

	return 0;
}


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

int main(){
  int N, A;
  cin >> N >> A;
  
  int L = A;
  int R = A + N - 1;
  
  int eat;
  
  if (R <= 0) eat = R;
  else if (L > 0) eat = L;
  else eat = 0;
  
  int answer = N * (L + R)/2 - eat;
  
  cout << answer;
}

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

using namespace std;


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

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

  int H, W;
  cin >> H >> W;
  vector<string> ss(H);
  for(int i=0;i<H;i++){
    string s;
    cin >> s;
    ss.at(i) = s;
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(ss[i][j] == '.') continue;
      int cnt = 0;
      for(int k=0;k<4;k++){
	int nx = i+dx[k];
	int ny = j+dy[k];
	if(nx < 0 || H <= nx || ny < 0 || W <= ny) continue;
	// cout << "(" << nx << "," << ny << ")" << ss[nx][ny];
	if(ss[nx][ny] == '#'){
	  cnt++;
	  break;
	}
      }
      // cout << endl;
      if(cnt == 0){
	cout << "No" << endl;
	return 0;
      }
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    
    int n,i;
    cin>>n>>i;
    cout<<n-i+1<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define f(i,l,h) for(ll i=l;i<h;i++)
#define fr(i,h,l) for(ll i=h;i>=l;i--)

using namespace std;

typedef pair<ll,ll> pll;
const ll INF=(ll)(1e9+7);
typedef vector<ll> vll;

int main()
{
    //cout << "Hello world!" << endl;
    ll h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;

    ll temp=(h2-h1)*60+m2-m1;
    cout<<temp-k<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N,Q;
LL A[100001];
LL X[100001];
LL S[100001];
LL T[100001];
LL SS[100001];

LL biparate(LL x){
	int lb=-1;
	int ub=N;
	while(ub-lb>1){
		int mid=(ub+lb)/2;
		if(x<=A[mid]){
			ub=mid;
		}else{
			lb=mid;
		}
	}
	return ub;
}

bool check(LL x,LL a){
	if(A[x]<a)return true;
	LL now=A[x];
	LL y=a-(now-a);
	int b=biparate(y);
	int c=x-b+1;
	int d=N-1-x;
	//cout<<x<<" xx "<<b<<"bb "<<c<<" cc"<<d<<" dd"<<endl;
	if(c<=d){
		return true;
	}
	return false;
	
}

int main(){
	cin>>N>>Q;
	REP(i,N){
		cin>>A[i];
		if(i==0){
			S[0]=A[0];
			SS[0]=A[0];
			T[0]=0;
		}else if(i%2==1){
			S[i]=S[i-1];
			SS[i]=SS[i-1]+A[i];
			if(i==1){
				T[1]=A[1];
			}else{
				T[i]=T[i-1]+A[i];
			}
		}else{
			S[i]=A[i]+S[i-1];
			SS[i]=SS[i-1]+A[i];
			T[i]=T[i-1];
		}
	}
	REP(i,Q){
		cin>>X[i];
	}
	/*
	REP(i,N){
		cout<<S[i]<<" "<<SS[i]<<endl;
	}*/
	REP(i,Q){
		int ub=N-1;
		int lb=-1;
		while(ub-lb>1){
			int mid=(ub+lb)/2;
			if(check(mid,X[i])){
				lb=mid;
			}else{
				ub=mid;
			}
		}
		//cout<<"lb"<<lb<<endl;
		int c=N-1-lb;
		//cout<<c<<endl;
		LL ans=0;
		if(c<=lb){
			ans=SS[N-1]-SS[lb];
			//ans=SS[lb]-SS[lb-c];
			if((lb-c)%2==1){
				ans+=T[lb-c];
			}else{
				ans+=S[lb-c];
			}
		}else{
			ans=SS[N-1]-SS[lb];
			//ans=SS[lb];
		}
		cout<<ans<<endl;
	}

}

Measured memory_bytes: 5632
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAX 100001

int main() {
    int N, Q;
    string S;
    int l, r;
    cin >> N >> Q;
    cin >> S;

    int t[MAX], cnt=0;
    for(int i=0; i<N-1; i++) {
        if(S[i] == 'A' && S[i+1] == 'C') cnt ++;
        t[i+1] = cnt;
    }

    for(int i=0; i<Q; i++) {
        cin >> l >> r;
        cout << (t[r-1] - t[l-1]) << endl;
    }
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <unordered_map>
// #include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x)  if(DEBUG_Switch) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%d%c", arr[i], i == n ? '\n' : ' ');}}
void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%lld%c", arr[i], i == n ? '\n' : ' ');}}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
#define DEBUG_Switch 0
int main()
{
#if DEBUG_Switch
    freopen("C:\\code\\input.txt", "r", stdin);
#endif
    //freopen("C:\\code\\output.txt","r",stdin);
    int n = readint();
    int k = readint();
    int base = k;
    int l = 1;
    int r = k + 1;
    while (base--)
    {
        if (l >= r)
        {
            l = k + 2;
            r = 2 * k + 1;
        }
        printf("%d %d\n", l, r );
        l++;
        r--;
    }
    return 0;
}




Measured memory_bytes: 3708
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int H, W; std::cin >> H >> W;
  int N; std::cin >> N;
  std::vector<int> a(N); rep(i,N) std::cin >> a[i];

  std::vector<int> ans(H*W);
  int color = 1;
  int c = 0;
  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      if ( i % 2 == 0 ) ans[i*W+j] = color;
      else              ans[i*W+(W-1-j)] = color;
      c++;
      if ( c == a[color-1] ) {
        c = 0;
        color++;
      }
    }
  }

  rep(i,H) {
    rep(j,W) std::cout << ans[i*W+j] << " ";
    std::cout << std::endl;
  }
  return 0;
}


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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

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

    ll s,w;
    cin >> s >> w;

    string ans = "safe";
    if(s <= w)ans = "unsafe";

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

Measured memory_bytes: 3608
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

int MOD_BIG = 1000000007;
int MOD_BIG2 = 998244353;
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

//////////////////////////////////////

//////////////////////////////////////

int main() {
    
    int A, B;
    cin >> A >> B;
    
    cout << A*B << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3636
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

ll floor_sum(ll n, ll q, ll t) {
	ll d = n % q;
	ll res = (n / q) * (t + 1LL);
	if (t <= d) {
		return (n / q) * (t + 1LL);
	}
	t -= d + 1;

	ll a = t / q;
	res -= a * (a + 1LL) / 2LL * q;
	res -= (a + 1LL) * (t % q + 1LL);

	return res;
}

int solve() {
	ll n , k;
	cin >> n >> k;

	if (k == 0) {
		cout << n * n << endl;
		return 0;
	}

	ll res = 0;
	res += (n - k) * (n - k + 1LL) / 2LL;

	for (ll q = 1; q * (k + 1LL) + k <= n; ++q) {
		ll l = (n - q) / (q + 1LL);
		res -= (k + l) * (l - k + 1LL) / 2LL;
		res += floor_sum(n, q, l) - floor_sum(n, q, k - 1LL);
	}

	cout << res << endl;

	return 0;
}

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

	solve();

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll = long long;                    // seq 1 128 | factor   100333 ~2^16.61
using ld = long double;                  //   | grep -v ' .* '  1300111 ~2^20.31
using vl = vector<ll>;                   //                    10300777 ~2^23.30
using vvl = vector<vl>;                  //                   100400999 ~2^26.58
using pll = pair<ll,ll>;                 //                  1300400999 ~2^30.28
using vpll = vector<pll>;                //                 10200500333 ~2^33.25
using vb = vector<bool>;                 //                100200400777 ~2^36.54
using vs = vector<string>;               //               1200300700111 ~2^40.13
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      //              10200300500777 ~2^43.21
const ld eps = 1e-9;                     //             100200300400777 ~2^46.51
#define sz(c) ll((c).size())             //            1200300400600999 ~2^50.09
#define all(c) begin(c),end(c)           //           10200300400600111 ~2^53.18
#define mp make_pair                     //          100200300400600333 ~2^56.48
#define mt make_tuple                    //         1200300400500800999 ~2^60.06
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

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

	ll n; cin >> n;
	vl as(n); FOR(i,0,n) cin >> as[i];
	vvl dp(n, vl(n, 0));

	FOR(i,0,n) dp[i][i] = as[i];

	FOR(i,1,n) {
		for (ll x = 0; x+i < n; x++) {
			dp[x][x+i] = max(as[x] - dp[x+1][x+i], as[x+i] - dp[x][x+i-1]);
		}
	}

	cout << dp[0][n-1] << "\n";

	return 0;
}


Measured memory_bytes: 72704
import sys

sys.setrecursionlimit(10**6)

def solve(n,a):
    wa=0
    for i in range(n):
        if(i%2==0):
            wa+=a[i]
    kotae=wa
    for i in range(n//2):
        wa+=a[(n//2-i-1)*2+1]
        wa-=a[(n//2-i-1)*2]
        if(wa>kotae):
            kotae=wa
    return kotae

def dfs(n,a,k):
    global zen
    zen.append([n,k])
    if(k==1):
        return max(a)
    ari=a[n-1]+dfs(n-2,a[:n-2],k-1)
    if(n==k*2-1):
        return ari
    nasi=dfs(n-1,a[:n-1],k)
    return max(ari,nasi)

n=int(input())

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

if(n%2==0):
    print(solve(n,a))
else:
    data=[[a[0],a[0]],[max(a[:2]),max(a[:2])]]
    #data.append([max(a[:3]),sum(a[:3])-min(a[:3])])
    data.append([max(a[:3]),a[0]+a[2]])
    for i in range(3,n):
        if(i%2==1):
            ari=a[i]+data[i-2][0]
            nasi=data[i-1][1]
            saiyo=max(ari,nasi)
            data.append([saiyo,saiyo])
        else:
            ooi=a[i]+data[i-2][1]
            nasi=data[i-1][1]
            ari=a[i]+data[i-2][0]
            sukunai=max(ari,nasi)
            data.append([sukunai,ooi])
    print(data[n-1][0])

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

#define mp      make_pair

int par[101010];

int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }

int main() {
        int n;
        scanf("%d", &n);
        set<int> g[101010];
        queue<pair<int, int>> both;
        for (int i = 0; i < n; i ++) par[i] = i;
        for (int i = 0; i < 2 * n - 2; i ++) {
                int a, b;
                scanf("%d%d", &a, &b);
                a --, b --;
                if (g[a].count(b)) { 
                        both.emplace(a, b);
                        //cout << "both.emplace(" << a << ", " << b << ")" << endl;
                } else { 
                        g[a].insert(b);
                        g[b].insert(a);
                }
        }
        int ans = 0;
        while (!both.empty()) {
                ans ++;
                int a, b;
                tie(a, b) = both.front();
                both.pop();
                a = find(a), b = find(b);
                //if (g[a].size() < g[b].size()) swap(a, b);
                a = par[a], b = par[b];
                if (a == b) continue;
                par[b] = a;
                g[a].erase(b);
                g[b].erase(a);
                for (auto c : g[b]) {
                        g[c].erase(b);
                        if (g[a].count(c)) { 
                                both.emplace(a, c);
                        } else { 
                                g[a].insert(c);
                                g[c].insert(a);
                        }
                }
                g[b].clear();
        }
        puts(ans == n - 1 ? "YES" : "NO");
        return 0;
}



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

int main(){
  int n, i, j, u, k, v;
  int m[100][100];

  scanf("%d",&n);
  if(n < 1 || 100 < n) exit(1);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      m[i][j]=0;
    }
  }
 
  for(i=0; i<n; i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0; j<k; j++){
      scanf("%d",&v);
      m[u-1][v-1]=1;
    }
  }
  
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      printf("%d", m[i][j]);
      if(j < n-1) printf(" ");
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2104
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <string.h>
#include <cmath>
using namespace std;
using ll = long long;
typedef pair <int, int> pii;

int main()
{

	int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	//cout << LONG_MAX << endl;
	//long long n, A[1000000000];
	//ll n, m, q;
	cin >> a;
	cin >> b;
	int p[100005] = {};
	int m[100005] = {};
	vector<int> x[100005];
	int memo[100005] = {};
	for (ll i = 1; i <= b; i++)
	{
		cin >> p[i];
		cin >> m[i];
		x[p[i]].push_back(m[i]);
		memo[p[i]]++;
	}
	for (ll i = 1; i <= 100000; i++)
	{
		if (memo[i] != 0)
		{
			sort(x[i].begin(), x[i].end());
		}
	}
	for (ll i = 1; i <= b; i++)
	{
		printf("%06d", p[i]); // "0012"（ゼロ埋め）
		e = lower_bound(x[p[i]].begin(), x[p[i]].end(), m[i]) - x[p[i]].begin();
		
		printf("%06d\n", e + 1); // "0012"（ゼロ埋め）
		//cout<<lower_bound(x[p[i]], x[p[i]] + memo[i], m[i])<<;

	}
	//cout << x[1][0] << endl;
	//cout << x[1][1] << endl;
	//cout << x[2][0] << endl;




	//cout << e + 1 << endl;
	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//lower_bound(A, A + n, d)//配列のなかからd以上の最小値を探して配列番号を返す関数
//cin >> a;
//cin >> b;
//cin >> c;
//double z[1003];
//for (ll i = 0; i < a; i++)
//{
//	cin >> z[i];
//}
//d = 100000000;
//for (ll i = 0; i < a; i++)
//{
//	if (abs(z[i]*0.006+b-c)<d)
//	{
//		d = abs(z[i] * 0.006 + b - c);
//		e = i;
//	}
//}

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

#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-funroll-loops")
#pragma GCC target("avx,sse4")

#define mms(a,n) memset(a,0,sizeof((a)[0])*(n))
#define mmp(a,b,n) memcpy(a,b,sizeof((b)[0])*(n))
#define lowbit(x) ((x)&-(x))
#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
#define fd(i,r,l) for(register int i=r,_lim_=l;i>=_lim_;i--)
#define fos(i,l,r,d) for(register int i=l,_lim_=r;i<=r;i+=d)
#define fol(i,l,r) for(register ll i=l,_lim_=r;i<=_lim_;i++)
#define fdl(i,r,l) for(register ll i=r,_lim_=l;i>=_lim_;i--)
#define fosl(i,l,r,d) for(register ll i=l,_lim_=r;i<=r;i+=d)
#define Clear(a) memset(a,0,sizeof(a))
#define Copy(a,b) memcpy(a,b,sizeof(b))
#define ALL(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ldb;
typedef double db;
typedef pair<int,int> pi;

int x,y;

int main(){
	cin>>x>>y;
	cout<<(x%y?x:-1);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

class MathLib{
    public static long divCeil(long a, long b){
        return (a+b-1)/a;
    }

    public static long gcd(long a, long b){
        if(a<b) return gcd(b,a);
        if(b==0) return a;
        if(a%b==0) return b;
        return gcd(b,a%b);
    }
    public static long lcm(long a, long b){
        return (a/gcd(a,b))*b;
    }

    public static LinkedList<Long> divisors(long N){
        LinkedList<Long> ans = new LinkedList<>();
        for(long n = (long)(Math.sqrt(N)+2); n>0; n--){
            if(n*n>N) continue;
            else if(n*n==N) ans.add(n);
            else if(N%n==0){
                ans.addFirst(n);
                ans.addLast(N/n);
            }
        }
        return ans;
    }
}
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N+1];
        for(int n=1; n<=N; n++) A[n]=sc.nextInt();

        int[] balls = new int[N+1];
        Arrays.fill(balls,0);

        TreeSet<Integer> ans = new TreeSet<>();

        for(int n=N; n>0; n--){
            if(balls[n]%2!=A[n]){
                ans.add(n);
                for(long d:MathLib.divisors(n)) balls[(int)d]++;
            }
        }

        System.out.println(ans.size());
        while(!ans.isEmpty()){
            System.out.print(ans.pollFirst());
            if(ans.isEmpty()) System.out.println();
            else System.out.print(" ");
        }

    }
}


Measured memory_bytes: 93532
// ABC071B - Not Found

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

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

	int alpha[26];
	for (int i = 0; i < 26; i++) {
		alpha[i] = 0;
	}
	for (int i = 0; i < S.size(); i++) {
		alpha[S[i] - 'a']++;
	}

	for (int i = 0; i < 26; i++) {
		if (alpha[i] == 0) {
			printf("%c\n", i + 'a');
			return 0;
		}
	}

	printf("None\n");

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main(){
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  rep(i,a+1){
    rep(j,b+1){
      rep(k,c+1){
        if(500*i + 100*j + 50*k == x) ans++;
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#A
S = str(input())
N = len(S)
T = str(input())

flag = True
for i in range(N):
    s = S[i]
    t = T[i]
    if s != t:
        flag = False
        
if flag:
    if len(T) == N+1:
        print("Yes")
    else:
        print("No")
else:
    print("No")



Measured memory_bytes: 8932
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  int N, l;
  cin >> N;
  int ans = 0;
  vector<int> vec(N*2);

  for (int i = 0; i < N*2; i++){
    cin >> l;
    vec.at(i) = l;
  }
  sort(vec.begin(), vec.end());

  int cnt = N*2;
  while (cnt > 1){
    ans += min(vec.at(cnt-1), vec.at(cnt-2));
    cnt -= 2;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pi;

#define fi first
#define se second

int read() {
  int res = 0, w = 1; char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') c = getchar(), w = -1;
  while (isdigit(c)) res = (res << 1) + (res << 3) + c - '0', c = getchar();
  return res * w;
}

const int N = 2e5 + 10;

int n, L, x[N];
pi y[N];
vector <pair<pi, pi> > a, b;

ll calc(vector<pi> & s) {
  ll ans = 0, sum = 0;
  for (int i = L - 1, j = 0; i < (signed) s.size(); i++, j++) {
    sum += s[j].first;
    ans += s[i].second * sum;
  }
  return ans;
}

int main() {
#ifdef dream_maker
//  freopen("tst.in", "r", stdin);
#else
  //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);
#endif
  n = read(), L = read();
  for (int i = 1; i <= n; i++) {
    x[i] = read();
    y[i] = make_pair(x[i], i);
  }
  sort(y + 1, y + n + 1);
  ll ans = n;
  int val = 0, cur = 1;
  while (1) {
    if (a.empty()) {
      if (cur > n) break;
      else val = y[cur].first;
    } else {
      ++val;
    }
    while (val == y[cur].first) {
      a.emplace_back(pi(y[cur].second, y[cur].second), pi(1, 1));
      cur++;
    }
    b.clear();
    sort(a.begin(), a.end());
    for (int l = 0, r; l < (signed) a.size(); l = r + 1) {
      r = l;
      while (r + 1 < (signed) a.size() && a[r + 1].first.first == a[r].first.second + 1) r++;
      int len = r - l + 1, cnt = len / L;
      if (cnt) {
        vector<pi> now, pos, val;
        for (int k = l; k <= r; k++) now.push_back(a[k].second);
        ans += calc(now);
        for (int k = 0; k < cnt; k++) {
          pos.emplace_back(a[l].first.first + k, (k == cnt - 1) ? a[r].first.second : a[l].first.first + k);
          val.emplace_back(0, 0);
        }
        for (int k = l; k <= r; k++) {
          int tl = k - l + 1, tr = r - k + 1;
          if (tl >= L) val[tl / L - 1].second += a[k].second.second;
          if (tr >= L) val[cnt - tr / L].first += a[k].second.first;
        }
        ans -= calc(val);
        for (int k = 0; k < cnt; k++) b.emplace_back(pos[k], val[k]);
      }
    }
    a = b;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n), B(n);
  rep(i, n) {
    cin >> A[i];
    A[i]--;
  }
  rep(i, n) {
    cin >> B[i];
    B[i]--;
  }
  vector<int> posA(n, -1), posB(n, -1);
  rep(i, n) {
    if(i == n-1 || i == 0 || A[i] != A[i+1]) {
      posA[A[i]] = i+1;
    }
  }
  rep(i, n) {
    if(i == 0 || B[i-1] != B[i]) {
      posB[B[i]] = i;
    }
  }
  int mx = 0;
  rep(i, n) {
    if(posA[i] != -1 && posB[i] != -1) {
      chmax(mx, posA[i]-posB[i]);
    }
  }
  vector<int> C(n);
  rep(i, n) C[(i+mx)%n] = B[i];
  bool ok = true;
  rep(i, n) if(A[i] == C[i]) ok = false;
  if(ok) {
    cout << "Yes" << endk;
    rep(i, n) cout << C[i]+1 << ' ';
    cout << endk;
  } else {
    cout << "No" << endk;
  }
  return 0;
}


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

#define MAX_P 1000001

int main(){
	bool prime[MAX_P];
	prime[0] = false;
	prime[1] = false;
	for( int i = 2; i < MAX_P; i++ ) prime[i] = true;
	for( int i = 2; i < MAX_P; i++ ){
		if( prime[i] ){
			for( int j = 2*i; j < MAX_P; j += i ){
				prime[j] = false;
			}
		}
	}
	int n, x;
	while( cin >> n >> x, n || x ){
		vector<bool> dp(x+1);
		for( int i = 0; i <= x; i++ ) dp[i] = false;
		vector<int> p(n);
		for( int i = 0; i < n; i++ ){
			cin >> p[i];
		}
		dp[0] = true;
		int max = 0;
		for( int i = 0; i < n; i++ ){
			for( int j = p[i]; j <= x; j++ ){
				if( dp[j-p[i]] ){
					dp[j] = true;
					if( prime[j] && max < j ) max = j;
				}
			}
		}
		if( max > 0 ) cout << max << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 2296
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) v.erase(unique(ALL(v)), v.end())
#define bit(i) (1LL<<i)
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  int N,M;
  while(cin >> N >> M){
    vector<vector<int>> s(M);
    REP(i,M){
      int k; cin >> k;
      s[i] = vector<int>(k); cin >> s[i];
    }

    vector<int> p(M); cin >> p;

    int ans = 0;
    REP(i,1<<N){
      bool b = true;
      REP(j,M){
	int c = 0;
	for(auto k : s[j]) c += (i>>(k-1)) & 1;
	if(p[j] != c%2){
	  b = false;
	  break;
	}
      }
      
      if(b) ++ans;
    }
   
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
		}
		long ans = 0;
		
		for(int i = 1; i < n; i++) {
			if(a[i-1] > a[i]) {
				ans += a[i-1] - a[i];
				a[i] = a[i-1];
			}
		}
		
		System.out.println(ans);
		

	}

}


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

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


int main() {
    bool sosu[100001];
    rep(i,0,100001) sosu[i] = true;
//    fill(sosu,sosu+100001,1);
    sosu[0] = sosu[1] = false;
    rep(i,2,100001){
        if(sosu[i]){
            for(int j = i * 2; j < 100001; j+=i){
                sosu[j] = false;
            }
        }
    }
    int rui[100001] = {};
    rep(i,0,100001){
        if(sosu[i] && sosu[(i+1)/2]) rui[i]++;
    }
    rep(i,1,100001){
        rui[i] += rui[i-1];
    }
    int Q;
    cin >> Q;
    rep(i,0,Q){
        int l,r;
        cin >> l >> r;
        cout << rui[r] - rui[l-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
//#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 2000000000;
//const ll INF64 = 9223372036854775807ll;
const ll INF64 = 9223372036854775ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
//std::vector<vector<int>> g;
int main(){
    int n;
    std::cin >> n;
    int a,b;
    std::cin >> a>>b;
    int c=0,cc=0,ccc=0;
    VEC(int,v,n);
    rep(i,n){
        if(v[i]<=a)c++;
        else if(v[i]<=b)cc++;
        else ccc++;
    }
    std::cout << min({c,cc,ccc}) << std::endl;
}

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

int main(){
    int n, m;
    multiset<int> ms;
    cin>>n;
    for(int i=0; i<n; i++){
        int d;
        cin>>d;
        ms.insert(d);
    }
    int t[200000];
    cin>>m;
    for(int i=0; i<m; i++) cin>>t[i];
    bool ans=true;
    for(int i=0; i<m; i++){
        auto it=ms.find(t[i]);
        if(it==ms.end()){
            ans=false;
            break;
        }
        ms.erase(it);
    }
    if(ans) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


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

int main(int argc, char **argv)
{
	ll n, k, q;
	cin >> n >> k >> q;

	vector<ll> a(q);
	for (int i = 0; i < q; ++i)
	{
		cin >> a[i];
		--a[i];
	}

	vector<ll> v(n, 0);

	for (int i = 0; i < q; ++i)
	{
		int &&right = a[i];
		++v[right];
	}

	for (int i = 0; i < n; ++i)
	{
		std::cout << (q < k + v[i] ? "Yes" : "No") << std::endl;
	}
}

Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdlib>
using namespace std;
int n,x,y,ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		ans+=y-x+1;
	}
	cout<<ans<<endl;
 	return 0;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	int X = max(N, M);
	int Z = 1 << X;
	vector<vector<int> > V(Z, vector<int>(Z));
	V[0][0] = 0;
	for (int i = 0; i < X; i++) {
		for (int j = 0; j < 1 << i; j++) {
			for (int k = 0; k < 1 << i; k++) {
				V[j + (1 << i)][k] = V[j][k + (1 << i)] = V[j][k];
				V[j + (1 << i)][k + (1 << i)] = 1 - V[j][k];
			}
		}
	}
	vector<vector<int> > ANS(Z - 1, vector<int>(Z - 1, 0));
	for (int i = 0; i < Z - 1; i++) {
		for (int j = 0; j < Z - 1; j++) {
			ANS[i][j] = (V[i][j] + V[i][j + 1] + V[i + 1][j] + V[i + 1][j + 1]) % 2;
		}
	}
	for (int i = 0; i < (1 << N) - 1; i++) {
		for (int j = 0; j < (1 << M) - 1; j++) {
			cout << ANS[i][j];
		}
		cout << endl;
	}
}

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

int main() {

	int i = 0;

	int a, b;
	char op;

	char ops[3000];
	int nums[2][3000];

	while (true) {
		cin >> a >> op >> b;

		if (op == '?') break;

		nums[0][i] = a;
		nums[1][i] = b;
		ops[i] = op;

		i++;
	}

	for (int j = 0; j < i; j++) {
		switch (ops[j]) {
		case '+': cout << nums[0][j] + nums[1][j] << endl; break;
		case '-': cout << nums[0][j] - nums[1][j] << endl; break;
		case '*': cout << nums[0][j] * nums[1][j] << endl; break;
		case '/': cout << nums[0][j] / nums[1][j] << endl; break;
		default: break;
		}
	}

	return 0;
}


Measured memory_bytes: 3100