akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

    int n, m;
    cin >> n >> m;

    vector< LLP > v;
    rep(i, n){
        lint a, b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }

    sort(v.begin(), v.end(), [&](LLP a, LLP b){ return a.first != b.first ? a.first< b.first : a.second > b.second; });

    priority_queue<lint> que;
    lint ans = 0;
    int j = 0;
    rrep(i, m){
        while(j < n && v[j].first + i <= m){
            que.push(v[j].second);
            ++j;
        }
        if(!que.empty()){
            ans += que.top();
            que.pop();
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3696
#include <stdio.h>
int main()
{
 int a,b;
 char op;

 for( ; ;)                                                  
 { 
     scanf("%d %c %d" , &a,&op,&b );     //char????????????????????????%c
     if(op == '+') printf("%d\n",a+b);     //char?????\???????????????single quote???'?????§??????
     else if(op == '-') printf("%d\n",a-b);
     else if(op == '/') printf("%d\n",a/b);
     else if(op == '*') printf("%d\n",a*b);    
    else if(op == '?') break;   

 }

return 0;
    
}

Measured memory_bytes: 600
#include<stdio.h>
int getDiv(long long a) {
    int c = 0;
    while(1){
        if(a%2 == 0){
            c++;
            a= a/2;
        }
        else
            break;
    }
    return c;
}
int main(){
    int n,val;
    scanf("%lld",&n);
    val = n;
    int max = 0,div;
    for(int i=2; i<=n; i+=2){
        div = getDiv(i);
        if(div > max) {
            max = div;
            val = i;
        }
    }
    printf("%d ",val);
    return 0;
}


Measured memory_bytes: 128
n = int(input())
A = [list(map(int, input().split())) for i in range(n-1)]

for i in range(n-1) :
    t = A[i][1] + A[i][0]
    for j in range(i+1,n-1) :
        if t <= A[j][1] :
            t = A[j][1] + A[j][0]
        elif t%A[j][2] == 0 :
            t += A[j][0]
        else :
            t += (A[j][2] - t%A[j][2]) + A[j][0]
        #print(t)
    print(t)
print(0)
    


Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
#define RI register int
#define CI const int&
using namespace std;
const int N=200005;
int n,c; long long ans; char s[N];
int main()
{
	RI i; scanf("%s",s+1); n=strlen(s+1);
	for (i=1;i<=n;++i) if (s[i]=='B') ++c; else ans+=c;
	return printf("%lld",ans),0;
}

Measured memory_bytes: 1924
#NTL_1_A
l = []
f = 3
n = int(input())
print(n,end='')
print(':',end=' ')
while n%2 == 0:
    l.append(2)
    n = n//2
while f <= n**(1/2):
    if n%f == 0:
        l.append(f)
        n = n//f
    else:
        f += 2
if n != 1:
    l.append(n)

print(' '.join(map(str,l)))


Measured memory_bytes: 5640
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main(){
  string s; cin >> s;
  int n = s.size();
  string ans = "yes";
  for(int i = 0; i < n; i++){
    for(int j=i+1; j < n; j++){
      if(s[i] == s[j]) ans = "no";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pp() pop_back()
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 /*int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }*/
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int a){
	par= vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0)
      return a;
    else
      return par[a]=find(par[a]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
int gcm(int a,int b){
    if(b==0)
        return a;
    return gcm(b,a%b);
}
int lcm(int a,int b){
    return a/gcm(a,b)*b;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
/*struct dfs(){

}*/
signed main(){
  int a;
  cin>>a;
  int b;
  b=0;
  fo(i,26){
    if((a-4*i)%7==0&&(a-4*i)>=0)
      b=1;
  }
  if(b)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#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 <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int H, W;
	cin >> H >> W;
	for (int i = 1; i <= W + 2; i++) {
		cout << '#';
	}
	cout << endl;
	for (int i = 0; i < H; i++) {
		cout << '#';
		for (int j = 0; j < W; j++) {
			char c;
			cin >> c;
			cout << c;
		}
		cout << "#" << endl;
	}
	for (int i = 1; i <= W + 2; i++) {
		cout << '#';
	}
	cout << endl;
}


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

class UnionFind {
private:
	int siz;
	vector<int> rank, par;
public:
	UnionFind(){}
	UnionFind(int n):siz(n), rank(n, 1), par(n, 0) {
		iota(par.begin(), par.end(), 0);
	}
	int find(int x) {
		return (x == par[x] ? x : par[x] = find(par[x]));
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rank[x] < rank[y]) swap(x, y);
		rank[x] += rank[y];
		par[y] = x;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n, q;
	cin >> n >> q;
	UnionFind u(n);
	while(q--) {
		int p, a, b;
		cin >> p >> a >> b;
		if(p == 0) u.unite(a, b);
		else puts(u.same(a, b) ? "1" : "0");
	}
	return 0;	
}



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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		100050

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

int N;
V used;
int ans;

void dfs(int x){
	if(x >= N){ans = min(ans,x);return;}
	for(int itr : used){
		if(x==0 && itr==0)continue;
		dfs(x*10 + itr);
	}
}


//
int main(){
	int K;cin>>N>>K;
	V D(10,1);
	REP(i,K){
		int d;cin>>d;
		D[d] = 0;
	}
	
	REP(i,10){
		if(D[i])used.push_back(i);
	}

	ans = INF;
	dfs(0);

	cout << ans << endl;

	return 0;
}




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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   ll n;
   cin>>n;
   ll a[n],s=0,ts=0;
   for(int i=0;i<n;i++)
   {
       ll x;
       cin>>x;
       a[i]= 2*x;
       ts+=(a[i]);
       if(i%2==1)
       {
           s+= (2*a[i]);
       }
   }
   //cout<<ts<<" "<<s<<"\n";
   ll pr= ts-s;
   pr/=2;
   cout<<pr<<" ";
  for(int i=0;i<n-1;i++)
   {
      pr= a[i]-pr;
     cout<<pr<<" ";
   }

}


Measured memory_bytes: 4392
from collections import deque
s,q=deque([*input()]),int(input())
judge=False
for i in range(q):
  t=input().split()
  if len(t)==1:
    judge = not judge
  else:
    t,f,c=t
    if not judge and f=='1': s.appendleft(c)
    elif not judge and f=='2': s.append(c)
    elif judge and f=='1': s.append(c)
    else: s.appendleft(c)
if judge: s.reverse()
print(*s,sep='')

Measured memory_bytes: 16304
#include <bits/stdc++.h>
using namespace std;
#define ll long
ll dp[100005];
int main(){
  ll i,j,n,k;
  cin>>n>>k;
  ll arr[n];
  for(i=0;i<n;i++)cin>>arr[i];
  sort(arr,arr+n);
  for(i=0;i<arr[0];i++)
   dp[i]=2;
  for(;i<=k;i++){
   dp[i]=2;
   for(j=0;j<n&&i-arr[j]>=0&&dp[i]!=1;j++)
    if(dp[i-arr[j]]==2)dp[i]=1;
  }
  // for(i=0;i<=k;i++)cout<<dp[i]<<" ";
  (dp[k]==1)?cout<<"First":cout<<"Second";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin >> n;
	if (n == 0) printf("0\n");
	else {
		string res;
		while (n) {
			int got = bool(n % (-2));
			res += string(1, '0' + got);
			n -= bool(got); n /= -2;
		}
		reverse(res.begin(), res.end());
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 256
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int a[5]={},b[5]={},ans=inf,cnt;
  for(int i=0; i<5; i++) {
    cin >> a[i];
    b[i]=i;
  }
  do{
    cnt=0;
    for(int i=0; i<5; i++) {
      cnt=(cnt+9)/10*10;
      cnt+=a[b[i]];
    }
    ans=min(ans,cnt);
  }while(next_permutation(b,b+5));
  cout << ans << endl;
}

Measured memory_bytes: 256
class BinarySearchTree
	attr_accessor :key, :parent, :left, :right
	@@root = nil
	def initialize(key, parent, left, right)
		self.key = key
		self.parent = parent
		self.left = left
		self.right = right
	end
	
	def self.insert(key)
		if @@root == nil
			@@root = BinarySearchTree.new(key, -1, nil, nil)
		else
			val = @@root
			while true
				if key < val.key
					if val.left
						val = val.left
					else
						val.left = BinarySearchTree.new(key, val.key, nil, nil)
						break
					end
				else
					if val.right
						val = val.right
					else
						val.right = BinarySearchTree.new(key, val.key, nil, nil)
						break
					end
				end
			end
		end
	end
	
	def self.find(key)
		val = @@root
		while true
			if val.key == key
				puts "yes"
				return
			end
			if val.key < key
				if val.right
					val = val.right
				else
					puts "no"
					return
				end
			else
				if val.left
					val = val.left
				else
					puts "no"
					return
				end
			end
		end
	end
	
	def self.posto(val=@@root)
		Kernel.print " #{val.key}"
		self.posto(val.left) if val.left != nil
		self.posto(val.right) if val.right != nil
	end
	
	def self.ino(val=@@root)
		self.ino(val.left) if val.left != nil
		Kernel.print " #{val.key}"
		self.ino(val.right) if val.right != nil
	end
	
	def self.print
		ino
		Kernel.print "\n"
		posto
		Kernel.print "\n"
	end
	
end


m = gets.chomp.to_i
commands = []
m.times do
	commands.push(gets.chomp)
end
commands.each do |cmd|
	opn, opnd = cmd.split(" ")
	if opnd
		BinarySearchTree.send(opn, opnd.to_i)
	else
		BinarySearchTree.send(opn)
	end
end


Measured memory_bytes: 92476
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        var cn = new int[,] { { 0, 0, 0 }, { 0, 0, 255 },{ 0, 255, 0 } ,{ 0, 255, 255 },{ 255, 0, 0 },{ 255, 0, 255 }
                                    ,{255,255,0 },{255,255,255 } };
        var color = new string[] { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };
        while (true)
        {
            var s = Console.ReadLine().Trim();
            if (s == "0") break;
            var r = Convert.ToInt32(s.Substring(1, 2), 16);
            var g = Convert.ToInt32(s.Substring(3, 2), 16);
             var b = Convert.ToInt32(s.Substring(5, 2), 16);
            var d2a = new int[8];
            for (int i = 0; i < 8; i++)
                d2a[i] = (int)Math.Pow(r - cn[i, 0], 2) + (int)Math.Pow(g - cn[i, 1], 2) + (int)Math.Pow(b - cn[i, 2], 2);
            var d2amin = d2a.Min();
            for (int i = 0; i < 8; i++) 
                if (d2a[i] == d2amin) { Console.WriteLine(color[i]); break; }
        }
    }
}

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

int main() {
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
  int N;
  cin>>N;
  string S;
  cin>>S;
  int answer=0;
  if(N%2 == 0){
    rep(i,N/2){
      if(S[i] != S[i+N/2]){
        answer=1;
        break;
      }
    }
  }
  else
    answer=1;
  if(answer==0)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = Integer.parseInt(stdin.nextLine());
        int[] p = Pattern.compile(" ").splitAsStream(stdin.nextLine()).mapToInt(Integer::parseInt).toArray();

        int ans = 0;
        for (int i = 0; i < n - 2; i++) {
            int[] q = IntStream.of(p[i], p[i + 1], p[i + 2]).sorted().toArray();
            if (p[i + 1] == q[1]) ans++;
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 28372
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <math.h>
#include <string.h>
#include <map>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#define INF 100000
#define MAX 500
using namespace std;
#define For(i, a, b) for ( int i = (a); i < (b); i++ )
#define Fors(i, sz) for ( size_t i = 0; i < sz.size (); i++ )
#define Set(a, s) memset (a, s, sizeof (a))
 #define EXPLORED 2
#define VISITED 1
#define UNVISITED 0
 typedef pair<int,int> ii;
 typedef vector<ii> vii;
 typedef vector <int > vi;
 vector<vii> adj(MAX);
 vi dfs_num,dfs_parent,dfs_low,articulation_vertex;
int dfsNumberCounter=0,dfsRoot,rootChildren=0;
vii bridge;

void articulationPointAndBridge(int u)
{

  dfs_num[u]=dfs_low[u]=dfsNumberCounter++;
  for(int i=0;i<adj[u].size();i++)
  {
    ii v=adj[u][i];
    if(dfs_num[v.first]==UNVISITED)
    {
      dfs_parent[v.first]=u;
      if(u==dfsRoot) rootChildren++;
      articulationPointAndBridge(v.first);
      if(dfs_low[v.first]>=dfs_num[u])
        articulation_vertex[u]=1;
      if(dfs_low[v.first]>dfs_num[u])
        bridge.push_back(ii(u,v.first));
      dfs_low[u]=min(dfs_low[u],dfs_low[v.first]);
    }
    else if(v.first!=dfs_parent[u])
      dfs_low[u]=min(dfs_low[u],dfs_num[v.first]);
  }
}

int main()
{
 //  freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
 int v,e,x,y;
 cin>>v>>e;
 dfsNumberCounter=0;
 dfs_num.assign(v,0);
 dfs_low.assign(v,0);
 dfs_parent.assign(v,0);
 articulation_vertex.assign(v,0);

for(int i=0;i<e;i++)
{
cin>>x>>y;
x--;y--;
adj[x].push_back(ii(y,1));
adj[y].push_back(ii(x,1));
}
for(int i=0;i<v;i++)
{
  if(dfs_num[i]==UNVISITED)
  {
    dfsRoot=i;
    rootChildren=0;
    articulationPointAndBridge(i);
    //if(rootChildren<2)
      //articulation_vertex[dfsRoot]=0;
  }
}
// cout<<"Articulation points :"<<endl;
// for(int i=0;i<v;i++)
// {
// if(articulation_vertex[i]==1)
//  cout<<i<<" ";
// }
cout<<(int)bridge.size()<<endl;

return 0;

}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	int out=0;
	rep(i,s.size())if(s[i]=='1')out++;
	cout<<out<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int check[8]={0};
double length(int a,int b,int c,int d){
    return sqrt((a-b)*(a-b) + (c-d)*(c-d));
}
int fact(int n)
{
    int ans;
    
    if(n==1) return 1;
    ans=n*fact(n-1);
    
    return ans;
}
double ans[40320]={0};
int root[8]={0};
int num = 0;
int x[8],y[8];
void calc(int N,int layer){
    if(layer==N){
        for(int i=1;i<N;i++){
            ans[num] += length(x[root[i-1]],x[root[i]],y[root[i-1]],y[root[i]]);
        }
        num++;
    }else{
        for(int i=0;i<N;i++){
            if(check[i]==0){
                check[i] = 1;
                root[layer] = i;
                calc(N,layer+1);
                check[i] = 0;
                root[layer] = 0;
            }
        }
    }
}
int main(void){
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d%d",&x[i],&y[i]);
    }
    calc(N,0);
    double sum = 0;
    for(int i=0;i<fact(N);i++){
        sum += ans[i];
    }
    printf("%.10f\n",sum/fact(N));
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int n,sum;
	scanf("%d%d",&n,&sum);
	if(sum%1000||sum<1000*n||sum>10000*n){
		printf("-1 -1 -1\n");
		return 0;
	}
	sum/=1000;
	int d1=sum/10,d2=(sum%10)/5;
	int d3=sum%10-d2*5;
	int sumn=n-d1-d2-d3;
	if(sumn<0){
		printf("-1 -1 -1\n");
		return 0;
	}
	for(int i=0;i<=d1;i++)
		for(int j=0;j+i<=d1;j++)
			for(int k=0;k<=d2+i;k++)
				if(i+j*9+k*4==sumn){
					printf("%d% d% d\n",d1-i-j,d2-k+2*i,d3+j*10+5*k);
					return 0;
				}
	printf("-1 -1 -1\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v));
#define MP make_pair
#define X first
#define Y second

using namespace std;

const double EPS = 1e-8;

typedef pair<int, int> P;
typedef long long ll;

template<class T> inline T sq(T a){return a*a;}
template<class T> T gcd(T m, T n){return n?gcd(n, m%n):m;}

const int N = 210;
int par[N];

void init(){
	rep(i, N) par[i] = i;
}

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

void unite(int x, int y){
	par[find(x)]=find(y);
}

struct edge{
	int from, to, cost;
	edge(){}
	edge(int f, int t, int c):from(f), to(t), cost(c){}
	bool operator<(const edge &r) const{
		return cost < r.cost;
	}
};

int h[N];
edge E[N*N];
bool used[N*N];
int G[N][N];

int main(){
	int n, m;
	while(cin >> n >> m, n|m){
		init();
		rep(i, n) cin >> h[i];
		MEMSET(G, 0);
		MEMSET(used, 0);
		rep(i, m){
			int a, b, c;
			cin >> a >> b >> c;
			a--, b--;
			E[i] = edge(a, b, c);
			G[a][b] = G[b][a] = 1;
		}

		priority_queue<P> q;
		rep(i, n) q.push(MP(h[i], i));
		bool ok[N] = {};
		int ans = 0;
		sort(E, E+m);

		int num = 0;
		int cnt = 1;
		while(!q.empty()){
			int x = q.top().first;
			while(!q.empty() && x == q.top().first){
				num++;
				ok[q.top().second] = 1;
				q.pop();
			}
			rep(i, m){
				int f = E[i].from, t = E[i].to;
				if(!used[i] && ok[f] && ok[t]){
					if(find(f) == find(t)) continue;
					unite(f, t);
					cnt++;
					ans += E[i].cost;
					used[i] = 1;
				}
			}
			if(cnt != num){
				init();
				MEMSET(used, 0);
				ans = 0;
				cnt = 1;
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e13;
typedef pair<ll,ll> P;
int main(){
    int n;
    cin >> n;
    int a[100001];
    rep(i,n){
        cin >> a[i];
    }
    ll color[3] = {0};
    ll ans = 1;
    ll c;
    ll check = 0;
    rep(i,n){
        if (i == 0){
            if (a[i] > 0){
                ans = 0;
                break;
            }
            color[0]++;
            ans *= 3;
            continue;
        }
        rep(j,3){
            if (a[i] == color[j]){
                check++;
                c = j;
            }
        }
        if (check == 0){
            ans = 0;
            break;
        }
        ans *= check;
        ans %= 1000000007;
        color[c]++;
        check = 0;
    }
    c = 0;
    rep(i,3){
        if (color[i] != 0) c++;
    }
    PRINT(ans);
}


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

int main(){
    int N,M;
    cin>>N>>M;
    vector<pair<long long,int>> data;
    for(int i=0;i<N;i++){
        long long A;
        cin>>A;
        data.push_back(make_pair(A,1));
    }
    for(int i=0;i<M;i++){
        long long C;
        int B;
        cin>>B>>C;
        data.push_back(make_pair(C,B));
    }
    sort(data.begin(),data.end());
    reverse(data.begin(),data.end());

    int count=0,j=0;
    long long ans=0;
    while(count<N){
        count+=data.at(j).second;
        ans+=data.at(j).second*data.at(j).first;
        if(count>N) ans-=data.at(j).first*(count-N);
        j++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  string w;
  cin>>w;
  vi alphabet(26,0);
  for(char c : w) alphabet.at(c-'a')++;
  bool ok=true;
  rep(i,26) if(alphabet.at(i)%2==1) ok=false;
  if(ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int M = in.nextInt();
            int[] L = new int[M];
            int[] R = new int[M];
            for (int i = 0; i < M; i++) {
                L[i] = in.nextInt();
                R[i] = in.nextInt();
            }

            int maxL = 0;
            int minR = (int) 1e6;
            for (int i = 0; i < M; i++) {
                maxL = Math.max(maxL, L[i]);
                minR = Math.min(minR, R[i]);
            }
            if (maxL > minR) {
                System.out.println(0);
                return;
            }
            System.out.println(minR - maxL + 1);
        }
    }
}


Measured memory_bytes: 84472
H, W = map(int, input().split())
A = [[1 if a == "#" else 0 for a in input()] for _ in range(H)]
X = [[[-2] * (H + 2) for _ in range(W + 2)] for _ in range(H + 2)]
Y = [[[-2] * (W + 2) for _ in range(W + 2)] for _ in range(H + 2)]

for i in range(H):
    Xi = X[i]
    Yi = Y[i]
    for j in range(W):
        Xi[j][i] = j
        Yi[j][j] = i
for i in range(H):
    Xi = X[i]
    Ai = A[i]
    for j in range(W-1)[::-1]:
        if Ai[j] == Ai[j+1]:
            Xi[j][i] = Xi[j+1][i]
for i in range(H-1)[::-1]:
    Yi = Y[i]
    Yi1 = Y[i+1]
    Ai = A[i]
    Ai1 = A[i+1]
    for j in range(W):
        if Ai[j] == Ai1[j]:
            Yi[j][j] = Yi1[j][j]

for i in range(H):
    Xi = X[i]
    Ai = A[i]
    for j in range(W):
        Xij = Xi[j]
        for ii in range(i+1, H):
            if A[ii][j] != Ai[j]:
                break
            Xij[ii] = min(Xij[ii-1], X[ii][j][ii])
for i in range(H):
    Yi = Y[i]
    Ai = A[i]
    for j in range(W):
        Yij = Yi[j]
        for jj in range(j+1, W):
            if Ai[jj] != Ai[j]:
                break
            Yij[jj] = min(Yij[jj-1], Yi[jj][jj])

for k in range(16):
    if X[0][0][H-1] == W-1:
        print(k)
        break
    elif k == 15:
        print(16)
        break
    for i in range(H):
        Xi = X[i]
        Yi = Y[i]
        for j in range(W):
            Xij = Xi[j]
            Yij = Yi[j]
            for ii in range(i, H):
                Xijii = Xij[ii]
                if Xijii >= 0 and X[i][Xijii + 1][ii] >= 0:
                    Xij[ii] = X[i][Xijii + 1][ii]
            for jj in range(j, W):
                Yijjj = Yij[jj]
                if Yijjj >= 0 and Y[Yijjj + 1][j][jj] >= 0:
                    Yij[jj] = Y[Yijjj + 1][j][jj]
            
            jj = W - 1
            for ii in range(i, H):
                while jj >= j and Yij[jj] < ii:
                    jj -= 1
                if jj >= j:
                    Xij[ii] = max(Xij[ii], jj)
            
            ii = H - 1
            for jj in range(j, W):
                while ii >= i and Xij[ii] < jj:
                    ii -= 1
                if ii >= i:
                    Yij[jj] = max(Yij[jj], ii)

Measured memory_bytes: 185756
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
#define INF (1ll << 60)
typedef map<int, vector<int>> Graph;

typedef map<int, map<int, ll>> WGraph;
vector<ll> dijkstra(int v, WGraph &g, int r)
{
    vector<ll> cost(v, INF);
    cost[r] = 0;
    priority_queue<pair<ll, int>> pq;

    pq.push({0, r});

    while (!pq.empty())
    {
        //cerr << "-------------------------------" << endl;
        auto t = pq.top();
        pq.pop();
        //cerr << t.second << "," << t.first << endl;
        if (cost[t.second] < -t.first)
        {
            continue;
        }
        for (auto x : g[t.second])
        {
            if (cost[x.first] > cost[t.second] + g[t.second][x.first])
            {
                cost[x.first] = cost[t.second] + g[t.second][x.first];
                //cerr << "update cost[" << x.first << "] with " << cost[x.first] << endl;
                pq.push({-cost[x.first], x.first});
            }
        }
    }
    return cost;
}

int main(int argc, char const *argv[])
{
    int n, m;
    cin >> n >> m;
    WGraph g;
    rep(i, 1, n)
    {
        g[i][i - 1] = 0;
    }
    map<pair<int, int>, bool> used;
    rep(i, m)
    {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--;
        b--;
        if (used[{a, b}])
        {
            g[a][b] = min(g[a][b], c);
        }
        else
        {
            g[a][b] = c;
        }
        used[{a, b}] = true;
    }
    ll ans = dijkstra(n, g, 0)[n - 1];
    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
const int Inf = 1e9 + 5;

int main()
{
    int n, m;
    cin >> n >> m;
    int left = -1, right = Inf;
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        left = max(a, left);
        right = min(b, right);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++){
        if (i >= left && i <= right){
            ans++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k,dp[100005],h[100005],mn;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&h[i]);
	}
	dp[1]=0;
	for(int i=2;i<=n;i++){
		mn=1e9;
		for(int j=i-k;j<=i-1;j++){
			if(j>=1&&j<=n){
				if(dp[j]+abs(h[i]-h[j])<=mn){
					mn=dp[j]+abs(h[i]-h[j]);
				}
			}
		}
		dp[i]=mn;
	}
	cout << dp[n];                                                                                        
}

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

int main(void) {
    int N, M;
    
    cin >> N >> M;
    
    if (N == M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
int lcm(int a, int b) {
	return a / gcd(a, b)*b;
}
int modpow(int a,int b){
    if(!b)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int fac(int a){
    int Ans=1;
    for(int i=1;i<=a;i++){
        Ans*=i;
        Ans%=MOD;
    }
    return Ans;
}//kaijo
int comb(int a,int b){
    return fac(a)*modpow(fac(a-b),MOD-2)%MOD*modpow(fac(b),MOD-2)%MOD;
}

int main(){
	int n,h,w;
	int a,b;
	cin>>n>>h>>w;
	int ans=0;
	rep(i,n){
		cin>>a>>b;
		if(a>=h&&b>=w)ans++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
def prime_factorize(n):
    a = [1]
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


A, B = map(int, input().split())
cds = set(prime_factorize(A)) & set(prime_factorize(B))
print(len(cds))

Measured memory_bytes: 62776
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;

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

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    int a;
    string s;
    cin>>a>>s;
    if(a>=3200) cout<<s<<endl;
    else cout<<"red"<<endl;
    return 0;
}

Measured memory_bytes: 256
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

ll dp[MAXn];
ll d[MAXn];

int main()
{
    IOS();
    ll n;
    cin>>n;
    REP1(i,n)cin>>d[i];
    dp[1] = 0;
    dp[2] = abs(d[1] - d[2]);
    for(int i = 3;i <= n;i ++)
    {
        dp[i] = min(dp[i-2] + abs(d[i-2] - d[i]), dp[i-1] + abs(d[i-1] - d[i]));
    }
    cout<<dp[n]<<endl;
}


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

using namespace std;

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x,v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int, pii> piii;
typedef pair<ll,ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector <vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

int n, m, dp[N];
vi adj[N];

void dfs(int u){
    if(!adj[u].size()){
        dp[u] = 1;
        return;
    }
    for(auto v : adj[u]){
        if(dp[v] == -1){
            dfs(v);
        }
    }
    for(auto v: adj[u]){
        dp[u] = max(dp[u],dp[v]+1);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
    }
    for(int i=1;i<=n;i++){
        if(dp[i] == -1) dfs(i);
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        ans  = max(ans,dp[i]);
    }
    cout << ans - 1 << "\n";
    return 0;
}

Measured memory_bytes: 8192
import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
    	int a = sc.nextInt();
    	int b = sc.nextInt();
    	int c = sc.nextInt();
    	int x = sc.nextInt();
    	int d = 0;
    	
    	if(a >= b && a >= c) d += b + c + a * (int)Math.pow(2, x);
    	else if(b >= a && b >= c) d += a + c + b * (int)Math.pow(2, x);
    	else if(c >= b && c >= b) d += a + b + c * (int)Math.pow(2, x);
    	System.out.println(d);
	}

}


Measured memory_bytes: 23764
//#pragma GCC optimize(3)
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;

#define MAXN 120
#define INF 999999999
#define lyh 1000000007

int bub[MAXN][MAXN];//第i个灯泡受j个开关控制
int p[MAXN];//看看有多贱
int on[MAXN];

signed main() {
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	int n, m, k, s;
	scanf("%d%d", &n, &m);//n开关m灯泡
	for (int i = 1; i <= m; i++) {
		scanf("%d", &k);
		for (int j = 1; j <= k; j++) {
			scanf("%d", &s);
			bub[i][s] = 1;
		}
	}
	for (int i = 1; i <= m; i++) {
		scanf("%d", &p[i]);
	}
	int ans = 0;
	for (int i = 0; i < (1 << (n)); i++) {
		for (int j = 1; j <= n; j++) {//枚举开关
			for (int k = 1; k <= m; k++) {
				if (i & (1<<(j-1))) {//如果这个开关是开的并且有效
					if(bub[k][j])//如果k灯受j控制
						on[k]++;
				}
			}
		}
		for (int j = 1; j <= m; j++) {
			if ((on[j] % 2)!=p[j]) {
				goto L;
			}
		}
		ans++;
	L:;
		for (int j = 0; j <= 10; j++) {
			on[j] = 0;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    int d,n;
    cin>>d>>n;
    if(d==0){
        if(n!=100)cout<<n<<endl;
        else cout<<101<<endl;
    }
    else if(d==1){
        if(n!=100)cout<<n*100<<endl;
        else cout<<10100<<endl;
    }
    else{
        if(n!=100)cout<<n*10000<<endl;
        else cout<<1010000<<endl;
    }
    return 0;
}

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

signed main(){

    int a, b, c; cin >> a >> b >> c;
    int ans = a * b;
    int aa = a / 2;
    int bb = b / 2;
    int cc = c / 2;
    a -= aa;
    b -= bb;
    c -= cc;
    
    ans = min(ans, (int)abs(a - aa) * (b + bb) * (c + cc));
    ans = min(ans, (int)abs(b - bb) * (a + aa) * (c + cc));
    ans = min(ans, (int)abs(c - cc) * (b + bb) * (a + aa));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def partition(p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1
n = int(input())
A = [int(i) for i in input().split()]
q = partition(0, n - 1)
A[q] = "[%d]"%A[q]
print(*A)

Measured memory_bytes: 18396
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {
	int n;
	int a[11];

	cin>>n;
	rep(i,n){
		cin>>a[i];
	}

	sort(a, a + n, greater<int>());
	int total=0;
	total+=a[0]/2;
	for(int i=1; i<n; i++){
		total+=a[i];
	}
	cout<<total<<endl;
	return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//end

template<unsigned mod=998244353>struct mint {
   unsigned val;
   static unsigned get_mod(){return mod;}
   unsigned inv() const{
      int tmp,a=val,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0)x+=mod; return x;
   }
   mint():val(0){}
   mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
   mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
   mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
   mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
   mint& operator*=(const mint& x){val=ll(val)*x.val%mod; return *this;}
   mint& operator/=(const mint& x){val=ll(val)*x.inv()%mod; return *this;}
   mint operator+(const mint& x)const{return mint(*this)+=x;}
   mint operator-(const mint& x)const{return mint(*this)-=x;}
   mint operator*(const mint& x)const{return mint(*this)*=x;}
   mint operator/(const mint& x)const{return mint(*this)/=x;}
   bool operator==(const mint& x)const{return val==x.val;}
   bool operator!=(const mint& x)const{return val!=x.val;}
};
template<unsigned mod=998244353>struct factorial {
   using Mint=mint<mod>;
   vector<Mint> Fact, Finv;
public:
   factorial(int maxx){
      Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
      Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
   }
   Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
   Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
   Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};
using Mint=mint<>;

Mint dp[510][1020];

int main(){
   int n,x; scanf("%d%d",&n,&x);
   int m=1; while(x>=m)m<<=1;
   dp[0][0]=1;
   rep(k,0,x+1)rep(i,0,n)rep(j,0,m)if(dp[i][j]!=0)dp[i+1][j^k]+=dp[i][j];
   printf("%d\n",dp[n][x].val);
   return 0;
}


Measured memory_bytes: 5264
// AOJ 0398 Beautiful Sequence
// 2019.3.25 bal4u

#include <stdio.h>
#include <stdlib.h>

#define MOD 1000000007
#define MAX 100000
int p2[MAX+5];
int f[MAX + 5];

int main()
{
	int i, t;
	int N, M;

	// p2[n] = 2^n  (2のペキ乗）
	p2[0] = 1; for (i = 1; i <= MAX; i++) p2[i] = (p2[i - 1] << 1) % MOD;

	scanf("%d%d", &N, &M);

	f[M] = 1;    // 自明

	// f[n] = 2*f[n-1] + 2^(n-m-1)  if n <= 2*m
	for (i = M + 1; i < N && i <= 2 * M; i++) {
		f[i] = ((f[i - 1] << 1) % MOD + p2[i - M - 1]) % MOD;
	}

	// f[n] = 2*f[n-1] + 2^(n-m-1) - f[n-m-1]  if n >= 2*m+1
	for (; i <= N; i++) {
		t = p2[i - M - 1] - f[i - M - 1];
		if (t < 0) t += MOD;
		f[i] = ((f[i - 1] << 1) % MOD + t) % MOD;
	}
	printf("%d\n", f[N]);
	return 0;
}


Measured memory_bytes: 2636
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long[] array = new long[n];
        Arrays.setAll(array, i -> scanner.nextLong());
        long sum = 0L;
        long evenSum = 0L;
        for (int i = 0; i < n; i++) {
            sum += array[i];
            if (i % 2 == 1) {
                evenSum += array[i];
            }
        }
        long start = sum - (2 * evenSum);

        System.out.println(start);

        for (int i = 1; i < n; i++) {
            start = 2 * array[i - 1] - start;
            System.out.println(start);
        }
    }
}

Measured memory_bytes: 62288
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n = I()
A = LI()
dp = 1
for a in A:
    dp |= dp << a

b = bin(dp)

s = sum(A)
for i in range((s + 1)//2, s + 1):
    if 1 << i & dp:
        print(i)
        break

Measured memory_bytes: 141960
if __name__ == '__main__':
	n = int(input())
	S = list(set([int(i) for i in input().split()]))
	q = int(input())
	T = [int(i) for i in input().split()]
	
	c = 0
	for i in S:
		if i in T:
			c+=1
	print(c)


Measured memory_bytes: 6560
public class Main{
	
	public static void main(String[] args){
		for(java.util.Scanner sc: java.util.stream.Stream.of(new java.util.Scanner(System.in)).collect(java.util.stream.Collectors.toList())) {
			if(java.util.stream.IntStream.of(0)
				.peek(I -> 
					judgeRange(java.util.stream.IntStream.rangeClosed(1, 3)
						.map(J -> sc.nextInt())
						.mapToObj(Integer::valueOf)
						.collect(java.util.stream.Collectors.toList())
					)
				).count() == 0
			) {}
		}
	}
	
	static void judgeRange(java.util.List<Integer> list) {
		if(list.get(0) < list.get(1)&& list.get(1) < list.get(2)) {
			if(java.util.stream.IntStream.of(0).peek(I -> System.out.println("Yes")).count() == 0) {}
		}else {
			if(java.util.stream.IntStream.of(0).peek(I -> System.out.println("No")).count() == 0) {}
		}
	}
}

Measured memory_bytes: 32576