akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll n;
    cin >> n;
    map<ll, ll> odd, even;
    Rep (i, n) {
        ll v;
        cin >> v;
        if(i % 2 == 0) even[v]++;
        else odd[v]++;
    }
    priority_queue<pair<ll, ll>> odd2, even2;
    for (auto e : odd) {
        odd2.push(make_pair(e.second, e.first));
    }
    for (auto e : even) {
        even2.push(make_pair(e.second, e.first));
    }

    auto o1 = odd2.top();
    odd2.pop();
    ll o2 = 0;
    if (!odd2.empty()) o2 = odd2.top().first;
    auto e1 = even2.top();
    even2.pop();
    ll e2 = 0;
    if (!even2.empty()) e2 = even2.top().first;

    if (o1.second != e1.second) {
        n -= o1.first + e1.first;
    } else {
        n -= max(o1.first + e2, e1.first + o2);
    }

    cout << n << endl;
}

Measured memory_bytes: 8824
def main():
    N, A, B = map(lambda i: int(i), input().split())
    numbers = []
    for i in range(N):
        num = sum(list(map(lambda i: int(i), list(str(i + 1)))))
        if num >= A and num <= B:
            numbers.append(i + 1)

    print(sum(numbers))

main()


Measured memory_bytes: 3440
import java.io.*;
import java.util.*;

class Main {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] strArray = new String[n];
        for (int i = 0; i < n; i++) {
            char[] ca = sc.next().toCharArray();
            Arrays.sort(ca);
            strArray[i] = String.valueOf(ca);
        }
        sc.close();
        Arrays.sort(strArray);

        int count = 0;
        long res = 0;
        String before = "";
        String current = "";
        for (String str : strArray) {
            before = current;
            current = str;
            if (before.equals(current)) {
                count++;
                res += count;
            } else {
                count = 0;
            }
        }

        System.out.print(res);
    }
}


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

struct cand {
    int xc, yc; bool xb, yb; int h;
    bool denied;
};


int main(int argc, char const *argv[])
{
    int n; cin >> n;
    vector<int> x(n, 0);
    vector<int> y(n, 0);
    vector<int> h(n, 0);
    for(int i=0;i<n;++i) cin >> x[i] >> y[i] >> h[i];

    for(int i=0;i<=100;++i) {
        for(int j=0;j<=100;++j) {
            vector<int> cand(0);
            for(int k=0;k<n;++k) {
                cand.push_back(h[k] + abs(i-x[k]) + abs(j-y[k]));
            }
            for(auto d:cand) {
                bool flg = true;
                for(int k=0;k<n;++k) {
                    if(max(d - abs(i-x[k]) - abs(j-y[k]), 0) != h[k]) {
                        flg = false;
                        break;
                    }
                }
                if (flg) {
                    cout << i << " " << j << " " << d << endl;
                    break;
                }
            }
            
        }
    }

    return 0;
}


Measured memory_bytes: 256
S = input()
ct_a = 0
ct_b = 0
for i in range(S.__len__()):
    if i % 2 == 0:
        if S[i] == "0":
            ct_a += 1
        else:
            ct_b += 1
    else:
        if S[i] == "0":
            ct_b += 1
        else:
            ct_a += 1

print(min(ct_a,ct_b))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.141592653289793;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define lld long double
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> vp;
typedef vector<tuple<ll, ll, ll>> vt;
//vector<vector<ll>> vv(n, vector<ll>(n));

int main()
{
	ll n, m;
	cin >> n >> m;
	vp v;
	REP(i,m)
	{
		ll a, b;
		cin >> a >> b;
		a--; b--;
		v.emplace_back(a, b);
	}
	vl red(n,0),ball(n,1);
	red[0] = 1;
	REP(i,v.size())
	{
		if(red[v[i].first])
		{
			if(ball[v[i].first]<=1)
			{
				ball[v[i].first] = 0;
				ball[v[i].second]++;
				red[v[i].first] = 0;
				red[v[i].second] = 1;
			}
			else
			{
				ball[v[i].first]--;
				ball[v[i].second]++;
				red[v[i].second] = 1;
			}
		}
		else
		{
			ball[v[i].first]--;
			ball[v[i].second]++;
		}
	}
	cout << accumulate(ALL(red), 0LL) << endl;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			if(i*j==n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

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

int main(){
	int H, W;
	while(1){
	cin >> H >> W;
	if( H == 0 && W == 0 ) return 0;
	for( int i = 0; i < H; i++ ){ if( i % 2 == 1 ){ for( int j = 0; j < W; j++ ){ if( j % 2 == 0 ){ cout << "."; }else{ cout << "#"; } } 
	} else {
	for( int j = 0; j < W; j++ ){ if( j % 2 == 0 ){ cout << "#"; }else{ cout << "."; } }  }
cout << "\n";
}
cout << endl;
}
return 0;
}

Measured memory_bytes: 1156
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n; cin >> n;
    using p = pair<ll, ll>;
    vector<p> v;
    ll x, l;
    REP(i, n) {
        cin >> x >> l;
        v.push_back(make_pair(x+l, x));
    }
    sort(ALL(v));
    // REP(i, n) {
    //     cout << v[i].first << " " << v[i].second << endl;
    // }

    ll cur = -1e10;
    ll res = 0;
    REP(i, n) {
        l = v[i].first - v[i].second;
        x = v[i].second;
        if (x-l >= cur) {
            res++;
            cur = x+l;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5264
#include <iostream>
#include <set> 
#include <iterator>
#include <bitset> 
#include <bits/stdc++.h> 
using namespace std;
typedef  long long int ll;
ll mod=1000000007;


int main() {
    int T=1;
    //cin>>t;
    while(T--)
    {   int n;
        cin>>n;
        ll a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        ll suf[n+1]={0};
        ll sum=0;
        for(int i=n-1;i>=0;i--)
        {   sum=(sum%mod+a[i]%mod)%mod;
            suf[i]=sum;
        }
        ll ans=0;
        for(int i=0;i<=n-2;i++)
        {   ans=((a[i] %mod * suf[i+1] %mod)%mod+ans %mod)%mod;
        }
        cout<<ans;
            
            
    }
	return 0;
}


Measured memory_bytes: 6752
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
typedef pair<int,int> pi;
#define FAST ios_base::sync_with_stdio(0);
const int maxn = 100010;

int dist[maxn][3];
int n,m,s,t;
vector <int> adjlist[maxn];

int32_t main() {
	cin >> n >> m;
	for (int i =0;i<m;i++) {
		int a,b; cin >> a >> b;
		adjlist[a].push_back(b);
	}
	cin >> s >> t;
	queue <pi> q;
	memset(dist,-1,sizeof dist);
	dist[s][0] = 0;
	
	q.push(pi(s,0));
	while (!q.empty()) {
		pi cur = q.front(); q.pop();
		int x = cur.f;
		int nd = (cur.s + 1) % 3;
		//~ cout << cur.f << " " << cur.s << " " << dist[cur.f][cur.s] << "\n";
		for (auto i: adjlist[x]) {
			if (dist[i][nd] != -1) continue;
			dist[i][nd] = dist[x][cur.s] + (cur.s == 0);
			q.push(pi(i,nd));			
		}
	}
	cout << dist[t][0];
}





Measured memory_bytes: 8064
#include<stdio.h>

int main()
{
	int n;
	int data[100]={0};
	scanf("%d",&n);
	int sum=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&data[i]);
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			sum+=data[i]*data[j];
		}
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<map>
using namespace std;
int main()
{
	char s;
  	map<char,char>mp;
  	mp['A']='T';
  	mp['T']='A';
  	mp['G']='C';
  	mp['C']='G';
  	cin>>s;
  	cout<<mp[s];
  
}

Measured memory_bytes: 3564
while True:
    a,b=input().split()
    h = int(a)
    w=int(b)
    if h==0 and w==0:
        break
    odd = "#."*300
    even= ".#"*300
    for i in range(h):
        if (i%2)==0:
            print(odd[:w])
        else:
            print(even[:w])
    print("")

Measured memory_bytes: 7656
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <iostream>
#include <ctype.h>
#include <string>
typedef long long ll;
using namespace std;

int main(){
    
    int n,flag=0;
    cin>>n;
    vector<int> hi(n);
    rep(i,n) cin>>hi[i];
    for(int i=n-1; i>=1; i--){
      if(hi[i]-hi[i-1]<=-2){
        flag++;
        break;
      }
      if(hi[i]-hi[i-1]==-1)
        hi[i-1]--;
    }
    if(flag==0) cout<<"Yes";
    else cout<<"No";
  
    
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }
template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if (e%2 == 0) { p = (p*p)%mod; e /= 2; }
            else { a = (a*p)%mod; e--; }
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

const int MAX_N = 100100;
const int color = 2;
const int MOD = 1e9+7;
vector<vector<int>> G;
ModInt<MOD> dp[MAX_N][color];

void dfs(int v, int p = -1) {
    dp[v][0] = dp[v][1] = 1;
    for (auto u : G[v]) if (u != p) {
        dfs(u, v);
        dp[v][0] *= dp[u][0] + dp[u][1];
        dp[v][1] *= dp[u][0];
    }
}

int main() {
    int N; cin >> N; G.resize(N);
    for (int i = 1; i < N; i++) {
        int a, b; cin >> a >> b; a--; b--;
        G[a].emplace_back(b); G[b].emplace_back(a);
    }
    
    dfs(0);
    ModInt<MOD> ans = dp[0][0] + dp[0][1];
    cout << ans << endl;
    return 0;
}
    

Measured memory_bytes: 75008
S = input()
N = len(S)
rev = S[::-1]
a = int((N-1)/2)
b = int((N+3)/2)

fir = S[0:a]
sec = S[b-1:N]

if (rev == S) and(fir == fir[::-1]) and (sec == sec[::-1]):
  ans = 'Yes'
else :
  ans = 'No'
  
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<queue>
using namespace std;

typedef pair<int,int> pii;

bool cango(int y,int x,map<pii,int> &S){
  return S.find(make_pair(y,x)) == S.end();
}

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

int solve(int sy,int sx,map<pii,int> &M,int t){
  int ini=M.size();
  queue<pii> Q;
  Q.push(make_pair(sy,sx));
  M[make_pair(sy,sx)]=0;
  while(!Q.empty()){
    pii now = Q.front();Q.pop();
    int tc=M[make_pair(now.first,now.second)];
    for(int i=0;i<6;i++){
      int nex=now.second+dx[i],ney=now.first+dy[i];

      if (cango(ney,nex,M) && tc+1 <= t)
	Q.push(make_pair(ney,nex)),
	  M[make_pair(ney,nex)]=tc+1;
    }
  }
  return M.size()-ini;
}

main(){
  int n,t;
  while(cin>>t>>n){
    if (n == 0 && t == 0)break;
    map<pii,int> M;
    for(int i=0;i<n;i++){
      int ty,tx;cin>>tx>>ty;M[make_pair(ty,tx)]=-1;
    }
    int sy,sx;cin>>sx>>sy;
    cout << solve(sy,sx,M,t) << endl;
  }
  return false;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

int n;
vector<int> first, last;
bool seen[100] = {};

void dfs (const Graph& g, int u, int& ptr) {
    first[u] = ptr++;
    seen[u] = 1;
    for (auto next : g[u]) {
        if (seen[next]) continue;
        dfs (g, next, ptr);
    }
    last[u] = ptr++;
}

int main() {
    cin >> n;
    Graph g (n);
    first.resize (n);
    last.resize (n);
    rep (i, n) {
        int a, k;
        cin >> a >> k;
        rep (j, k) {
            int b;
            cin >> b;
            g[a - 1].push_back (b - 1);
            //g[b].push_back (a);
        }
    }
    int ptr = 0;
    rep (i, n) {
        if (first[i] == 0 && last[i] == 0) {
            dfs (g, i, ptr);
        }
    }

    rep (i, n) cout << i + 1 << " " << first[i] + 1 << " " << last[i] + 1 << "\n";
}


Measured memory_bytes: 3152
#include<iostream>
#include<vector>
#include<map>
#define MAX 1001
using namespace std;

int M[MAX];
vector< vector<int> > v;

void compute( int depth, int s )
{
	if( depth == v.size() - 1 ){
		for(unsigned int i = 0; i < v[depth].size(); ++i){
			int t = s + v[depth][i];
			if( t < MAX ){
				M[ t ]++;
			}
		}
	}else{
		for(unsigned int i = 0; i < v[depth].size(); ++i){
			compute( depth + 1, s + v[depth][i] ); 
		}
	}
	return ;
}

int main()
{
	while( true ){
		int g, m;
		//vector< vector<int> > v;
		
		v.clear();
		for(int i = 0; i < MAX; ++i){
			M[i] = 0;
		}

		cin >> m;
		if( m == 0 )
			break;
		
		for(int i = 0; i < m; ++i){
			int a, b;
			cin >> a >> b;
			vector<int> vt;
			vt.push_back(0);
			for(int j = 1; j <= b; ++j){
				vt.push_back( a * j );
			}
			v.push_back( vt );
		}

		compute( 0, 0 );

		cin >> g;
		for(int x = 0; x < g; ++x){
			int n;
			cin >> n;

			cout << M[ n ] << endl;
		}
	}
	return 0;
}

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

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

    string s, t;

    cin >> s >> t;
    for (int i = 0; i < int(s.size()); ++i)
        if (s[i] != t[i]) {
            cout << "No";
            return 0;
        }
    cout << "Yes";
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll MAX = 2010;

ll f[MAX], fi[MAX], in[MAX];

void C() {
    f[0] = f[1] = 1;
    fi[0] = fi[1] = 1;
    in[1] = 1;
    for (int i = 2; i < MAX; i++){
        f[i] = f[i - 1] * i % mod;
        in[i] = mod - in[mod%i] * (mod / i) % mod;//＊１
        fi[i] = fi[i - 1] * in[i] % mod;
    }
}

// 二項係数計算
ll c(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return f[n] * (fi[k] * fi[n - k] % mod) % mod;
}


signed main(){
  ll n,k;
  cin>>n>>k;

  C();

  for(int i=1;i <= k;i++)
  {
    cout<<c(k-1,i-1) * c(n-k+1,i)%mod<<endl;
  }
}


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

int main(){
  bool data[15][15];
  for(int i=0;i<15;i++){
    for(int j=0;j<15;j++){
      data[i][j]=false;
    }
  }

  for(int count=0;count<7;count++){
    data[0][count+8]=true;
  }

  for(int i=1;i<15;i++){
    for(int j=0;j<15;j++){
      if(j==0) data[i][j]=data[i-1][14];
      else data[i][j]=data[i-1][j-1];
    }
  }

  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    getchar();
    string in;
    bool input[15];
    for(int i=0;i<15;i++) input[i]=false;
    for(int i=0;i<n;i++){
      getline(cin, in);
      if(in=="Rock") input[0]=true;
      else if(in=="Gun") input[1]=true;
      else if(in=="Lightning") input[2]=true;
      else if(in=="Devil") input[3]=true;
      else if(in=="Dragon") input[4]=true;
      else if(in=="Water") input[5]=true;
      else if(in=="Air") input[6]=true;
      else if(in=="Paper") input[7]=true;
      else if(in=="Sponge") input[8]=true;
      else if(in=="Wolf") input[9]=true;
      else if(in=="Tree") input[10]=true;
      else if(in=="Human") input[11]=true;
      else if(in=="Snake") input[12]=true;
      else if(in=="Scissors") input[13]=true;
      else if(in=="Fire") input[14]=true;
    }
    int ans=15;
    for(int i=0;i<15;i++){
      if(!input[i]) continue;
      bool flag=true;
      bool fkati=false;
      for(int j=0;j<15;j++){
        if(i==j) continue;
        if(!input[j]) continue;
        if(data[i][j]) fkati=true;
        if(!data[i][j]){
          flag=false;
          break;
        }
      }
      if(flag && fkati){
        ans=i;
        break;
      }
    }

    switch(ans){
    case 0:
      cout << "Rock" << endl;
      break;
    case 1:
      cout << "Gun" << endl;
      break;
    case 2:
      cout << "Lightning" << endl;
      break;
    case 3:
      cout << "Devil" << endl;
      break;
    case 4:
      cout << "Dragon" << endl;
      break;
    case 5:
      cout << "Water" << endl;
      break;
    case 6:
      cout << "Air" << endl;
      break;
    case 7:
      cout << "Paper" << endl;
      break;
    case 8:
      cout << "Sponge" << endl;
      break;
    case 9:
      cout << "Wolf" << endl;
      break;
    case 10:
      cout << "Tree" << endl;
      break;
    case 11:
      cout << "Human" << endl;
      break;
    case 12:
      cout << "Snake" << endl;
      break;
    case 13:
      cout << "Scissors" << endl;
      break;
    case 14:
      cout << "Fire" << endl;
      break;
    default:
      cout << "Draw" << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

int n, m, q;
int a[N], b[N];

int cost(int x, int p, int q)
{
	return abs(x-p) + abs(p-q);
}

int32_t main()
{
	IOS;
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=m;i++)
		cin>>b[i];
	while(q--)
	{
		int ans=1e18;
		int x;
		cin>>x;
		int idx1=lower_bound(a+1, a+n+1, x) - a;
		int idx2=lower_bound(b+1, b+m+1, x) - b;
		for(int i=max(1LL, idx1-2);i<=min(n, idx1+2);i++)
		{
			for(int j=max(1LL, idx2-2);j<=min(m, idx2+2);j++)
			{
				ans=min(ans, cost(x, a[i], b[j]));
				ans=min(ans, cost(x, b[j], a[i]));
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main(){
  int n,m;  cin >> n >> m;
  vector<int>k(m);
  vector<vector<int> >s(n);
  vector<int>p(m);
  for(int i=0;i<m;i++){
    cin >> k.at(i);
    for(int j=0;j<k.at(i);j++){
      int S;
      cin >>  S;
      s.at(S - 1).push_back(i);
    }
  }
  for(int i=0;i<m;i++){
    cin >> p.at(i);
  }

  long long ans = 0;
  for(int bit=0;bit<(1<<n);bit++){
    vector<int>sw(m);
    for(int i=0;i<n;i++){
      if(bit & (1<<i)){
        for(int j : s.at(i))  sw.at(j)++;
      }
    }
    int count = 0;
    for(int i=0;i<m;i++){
      sw.at(i) %= 2;
      if(sw.at(i) == p.at(i)) count++;
    }
    if(count == m)  ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;


const int INF = 1e9;
int V, E, r;
int d[100010];

struct edge{
    int to, cost;
    edge(int to, int cost): to(to), cost(cost){}
};
vector<edge> G[100010];


void dijkstra(int s){
    // memset(d, INF, sizeof(d));
    rep(i, 0, V) d[i] = INF;
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P> > q;
    q.push(P(0, s));
    while(!q.empty()){
        P p = q.top(); q.pop();
        int from = p.second;
        int cost = p.first;
        if(d[from] < cost) continue;
        rep(i, 0, G[from].size()){
            edge e = G[from][i];
            int next = e.to;
            int newCost = e.cost + cost;
            // cout << i << " " << next << " " << newCost << endl;
            
            if(d[next] > newCost){
                d[next] = newCost;
                q.push(P(newCost, next));
            }
        }
    }
}

// void dijkstra(int s){
//     priority_queue<P, vector<P>, greater<P> > q;//P
//     fill(d, d + V, INF);//INF
//     d[s] = 0;
//     q.push(P(0, s));

//     while(!q.empty()){
//         P p = q.top(); q.pop();
//         int v = p.second;
//         if(d[v] < p.first) continue;
//         rep(i, 0, G[v].size()){
//             edge e = G[v][i];
//             if(d[e.to] > d[v] + e.cost){
//                 d[e.to] = d[v] + e.cost;
//                 q.push(make_pair(d[e.to], e.to));
//             }
//         }
//     }
// }

signed main(){
    cin >> V >> E >> r;
    int s, t, a;
    rep(i, 0, E){
        cin >> s >> t >> a;
        G[s].push_back(edge(t, a));
    }
    dijkstra(r);
    rep(i, 0, V){
        if(d[i] == INF) cout << "INF"  << endl;
        else cout << d[i] << endl;
    }
}

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

int main(){
  int n;
  cin >> n;
  int b[100500];
  int a[100500] = {};
  for(int i=0; i<n-1; i++){
    cin >> b[i];
  }
  for(int i=0; i<n-1; i++){
    //iが0のとき
    if(!i){
      a[i] = b[i];
      a[i+1] = b[i];
      continue;
    }
    //それ以外
    if(a[i] > b[i]){
      a[i] = b[i];
      a[i+1] = b[i];
    }else{
      a[i+1] = b[i];
    }
  }
  //和を計算
  int sum = 0;
  for(int i=0; i<n; i++){
    sum += a[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    ll zero = 0;
    for(ll i = k + 1; i <= n; i++){
        ans += (n / i) * (i - k);
        ans += max(zero, n - ((n / i) * i - 1 + k));
    }
    if(k == 0) ans -= n;
    cout << ans << endl;
}

Measured memory_bytes: 256
def solve(n, a):
    ub = max(a) + 1
    a = sorted(a)
    matched = [False] * ub
    for x in a:
        matched[x] = True
    for x in a:
        if matched[x]:
            for y in range(2*x, ub, x):
                matched[y] = False
    for i in range(n-1):
        if a[i] == a[i+1]:
            matched[a[i]] = False
    return sum(matched)

n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))

Measured memory_bytes: 32296
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;

typedef pair<int, int> P;

int bfs[30][30];
int maze[100][100];

int main(){
	int w,h;
	while(scanf("%d%d",&w,&h) && w && h){
		for(int i = 0; i < 2*h-1 ;i++){
			for(int j = 0; j < w+i%2-1 ;j++){
				scanf("%d",&maze[i][j]);
			}
		}
		for(int i = 0; i < 30;i++)
			for(int j = 0; j < 30;j++)
				bfs[i][j] = 0;
		
        bfs[0][0] = 1;

		queue<P> q;
		q.push(P(0,0));

		while(q.size()){
			P p = q.front();
            int row = p.first;
            int col = p.second;
			q.pop();

			if(row){
				if(!maze[row*2-1][col] && !bfs[row-1][col]){
					bfs[row-1][col] = bfs[row][col]+1;
					q.push(P(row-1,col));
				}
			}
			if(row < h-1){
				if(!maze[row*2+1][col] && !bfs[row+1][col]){
					bfs[row+1][col] = bfs[row][col]+1;
					q.push(P(row+1,col));
				}
			}
			if(col){
				if(!maze[row*2][col-1] && !bfs[row][col-1]){
					bfs[row][col-1] = bfs[row][col]+1;
					q.push(P(row,col-1));
				}
			}
			if(col < w-1){
				if(!maze[row*2][col] && !bfs[row][col+1]){
					bfs[row][col+1] = bfs[row][col]+1;
					q.push(P(row,col+1));
				}
			}
		}
		printf("%d\n",bfs[h-1][w-1]);
	}
}


Measured memory_bytes: 2636
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import deque
def main():
    n, *a = map(int, read().split())
    a.sort(reverse=True)
    a = deque(a)
    circle_joined = deque()
    next_score = a.popleft()
    r = 0
    flag = False
    while a:
        circle_joined.append(a.popleft())
        if flag:
            next_score = circle_joined.popleft()
            r += next_score
            flag = False
        else:
            r += next_score
            flag = True
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 31720
/*
 * =template=.cpp
 * Copyright (C) 2017 hzw <hzw@huzhenweideMacBook.local>
 *
 * Distributed under terms of the MIT license.
 */

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#include<sstream>
#define FR first
#define SC second
#define MP make_pair
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200010,p=1000000007,inf=100000000;
int pow(int a,int b,int c)
{
    if (a==0)return 0;int d=a,e=1;
    while (b)
    {
        if (b&1) e=(1LL*e*d)%c;
        d=1LL*d*d%c;b>>=1;
    }
    return e;
}
int random(int n) { return 1LL*rand()*rand()%n+1;}
struct Edge {int y,ne;};
/*int read(int &x)
{
	while (buf[pt]<=32&&pt<len) pt++;
	if (pt>=len) return 0;
	x=0;
	while (buf[pt]>32) x=x*10+buf[pt++]-48;
	return 1;
}*/

int main()
{
	int n,m;
	LL ans=0;
	scanf("%d%d",&n,&m);
	for (int i=m+1;i<=n;i++)
	{
		ans+=1LL*(i-m)*(n/i)+max(n%i-m+1,0);
	}
	if (m==0) ans-=n;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
// 2,3の倍数のみ使うという部分までは考察したが
// そこから詰めることが出来ず、結局解説を読んだ
#include<iostream>
#include<set>
using namespace std;

int main(){
    int n;
    cin >> n;
    if(n < 6){
        int ans[5] = {2, 63, 5, 20, 30};
        for(int i = 0; i < n; i++)  cout << ans[i] << " \n"[i+1==n];
        return 0;
    }
    set<int> ans;
    int cnt[4] = {}, add[4] = {2, 3, 4, 6}, sum = 0;
    for(int i = 0; i < n; i++){
        ans.insert(6*cnt[i%4]+add[i%4]);
        cnt[i%4]++;
        sum = (sum+add[i%4])%6;
    }
    if(sum == 2){
        ans.erase(8);
        ans.insert(6*cnt[3]+6);
    }else if(sum == 3){
        ans.erase(9);
        ans.insert(6*cnt[3]+6);
    }else if(sum == 5){
        ans.erase(9);
        ans.insert(6*cnt[2]+4);
    }
    for(auto it = ans.begin(); it != ans.end();){
        cout << *it;
        it++;
        if(it != ans.end()) cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
int Month[12]={31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
 int MM,DD;
 int i,sum;

 while(1){
      sum=0;
      scanf("%d %d",&MM,&DD);
      if(MM==0 && DD==0)break;

      for(i=0;i<MM-1;i++)
          sum+=Month[i];
      sum=sum+DD-1;

      switch(sum%7){
             case 0:printf("Thursday\n");break;
             case 1:printf("Friday\n");break;
             case 2:printf("Saturday\n");break;
             case 3:printf("Sunday\n");break;
             case 4:printf("Monday\n");break;
             case 5:printf("Tuesday\n");break;
             case 6:printf("Wednesday\n");break;
      }

 }

return 0;
}


Measured memory_bytes: 2032
//zukain5参照

#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
using namespace std;

int main() {

	int n, k; cin >> n >> k;
	vector<vector<int>> nCk(n + 1, vector<int>(n + 1, 0));

	for (int i = 0; i <= n; i++) {
		nCk[i][0] = 1;
		nCk[i][i] = 1;
		for (int j = 1; j <= i - 1; j++) {
			nCk[i][j] = (nCk[i - 1][j - 1] + nCk[i - 1][j]) % 1000000007;
		}
	}

	for (int i = 1; i <= k; i++) cout << (long long)nCk[k - 1][i - 1] * (long long)nCk[n - k + 1][i] % 1000000007 << endl;

	return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
	
ll mod = 1e9 + 7;

int main(){
	ll n; cin >> n;
    ll dp[n + 1] = {0};
    dp[0] = 1;
    for(ll i = 1; i <= n; ++i){
        for(ll j = 3; j <= n; ++j){
            if(i - j >= 0){
                dp[i] += dp[i - j];
                dp[i] %= mod;
            }
        }
    } 
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
  cin>>s;
  vector<int >nos(26,0);
  for(int i=0;i<s.length();i++){
  	nos[s[i]-'a']++;
  }
  int tot=0;
  for(int i=0;i<26;i++)if(nos[i]%2==0)tot++;
  if(tot==26)cout<<"Yes";
  else cout<<"No";
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<bool> issafe(n+1, true);
  for(int i = 0; i < m; i++){
    int temp;
    cin >> temp;
    issafe[temp] = false;
  }
  int dp[n+1];
  for(int i = 0; i < n+1; i++){
    dp[i] = 0;
  }
  dp[0] = 1;
  if(issafe[1])dp[1] = 1;
  
  for(int i = 2; i <= n; i++){
    if(issafe[i]){
      dp[i] = dp[i-1] + dp[i-2];
    }
    dp[i] = dp[i] % 1000000007;
  }
  cout << dp[n] << endl;
  return 0;
}

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


int main()
{
	int N;
	cin >> N;

	for (int i = 1; i <= 9 ; i++)
	{
		for (int j = 1; j <= 9; j++) {
			if (N== i*j)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3628
<?php 
$sc = new Scanner();
$a = $sc->nextInt();
$b = $sc->nextInt();
$c = $sc->nextInt();
$K = $sc->nextInt();

echo ($a+$b+$c+max($a,$b,$c)*pow(2,$K)-max($a,$b,$c)).PHP_EOL;

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}




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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16

const ll B=6000;
ll mod;

ll mod_pow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1)res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}

ll dp[6001][6001*2];
ll inv[6001];

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

  ll N;
  cin>>N>>mod;
  rep(i,6001)inv[i]=mod_pow(i,mod-2);

  dp[0][B]=1;
  rep(i,3*N)repl(j,-3*N,3*N+1){
  	ll jidx=j+B;
  	repl(k,1,3+1){
  		if(k==1){
  			if(i+k<=3*N&&j<=3*N)(dp[i+k][jidx+1]+=dp[i][jidx]*inv[i+k]%mod)%=mod;
  		}else if(k==2){
  			if(i+k<=3*N&&j>=-3*N)(dp[i+k][jidx-1]+=dp[i][jidx]*inv[i+k]%mod)%=mod;
  		}else{
  			if(i+k<=3*N)(dp[i+k][jidx]+=dp[i][jidx]*inv[i+k]%mod)%=mod;
  		}
  	}
  }

  ll res=0;
  repl(j,0,3*N+1)(res+=dp[3*N][j+B])%=mod;
  rep(i,3*N)(res*=(i+1))%=mod;
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 562944
#include <iostream>
    
using namespace std;
    
int main(){
 int x,y;
 while (1) {
  cin >> x;
  cin >> y;
  if (x==0 && y==0) break;
  if (x>y) {
   cout <<y<<" "<<x <<endl;
  } else {
   cout <<x<<" "<<y <<endl;
  }
 }
 return 0;
}


Measured memory_bytes: 3072
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl     '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii      map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
  ll n;
  cin>>n;
  ll cnt[n+1]={0};
  rep(i,2,n+1)
  {
    ll x;
    cin>>x;
    cnt[x]++;
  }
  rep(i,1,n+1) cout<<cnt[i]<<'\n';
}
signed main()
{
  
    /***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/
 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS=1;
//  cin>>TESTS;
  while(TESTS--)
  {
    solve();
    
  }
  TIME
  return 0;
}

Measured memory_bytes: 5360
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,A,B;
    cin>>N>>A>>B;

    if((B-A-1)%2==1)
        cout<<"Alice"<<endl;
    else
        cout<<"Borys"<<endl;
}


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


int check(int start, int end, string S, string T){

	int j=0;
	int count=0;

   for(int i=start;i<=end;i++){

   	if(S[i]!=T[j])
   		count++;

   	j++;

   }

return count;
}


int main(){

	string S;
	string T;

	cin>>S>>T;

	int m= S.length();
	int n=T.length();

    
    int start=0;
    int end= n-1;

    int min_change= INT_MAX;

    while(end<m){

    	int temp= check(start,end,S,T);

    	min_change= min(min_change,temp);
    	
    	end++;
    	start++;


    }

    cout<<min_change<<endl;
	


}

Measured memory_bytes: 3632
let n, s, l = read_int (), ref 0, ref 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let _ = Array.sort (-) a_s; for i = 0 to n - 2 do s := !s + a_s.(i); if a_s.(i + 1) > 2 * !s then l := i + 1 done; Printf.printf "%d\n" @@ n - !l

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

typedef long long ll;

int main()
{
    int n,m,x;

    cin>>n>>m>>x;

    int N[110];
    int pos=0,flag=0;
    for(int i=1; i<=m; i++)
    {
        cin>>N[i];

        if(N[i]>x and N[i-1]<x)
        {
            pos=i;
        }

    }

    if(x<=N[1] || x>=N[m])
    {
        cout<<0<<endl;
        return 0;
    }





    int c1=1,c2=1;
    for(int i=pos+1; i<=m; i++)
    {
        c1++;
    }

    for(int i=pos-2; i>=1; i--) c2++;

    cout<<min(c1,c2)<<endl;

}



Measured memory_bytes: 256
#include<stdio.h>

int fibo(int);

int a[50];

int main()
{
  
  int n,i;

  for(i=0;i<50;i++)
    a[i]=-1;

  scanf("%d",&n);
  printf("%d\n",fibo(n));

  return 0;
}

int fibo(int n)
{
  if(n==0||n==1) return a[n]=1;
  if(a[n]!=-1) return a[n];
  
  return a[n]=fibo(n-1)+fibo(n-2);
}
			     
    



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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> C(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> C[i];
    }
    sort(C.begin(), C.end());
    const ll MOD = 1e9 + 7;
    auto Add = [&](ll& x, ll y) { x = ( x % MOD + y % MOD ) % MOD; };
    auto Mul = [&](ll& x, ll y) { x = ( x % MOD * y % MOD ) % MOD; };
    auto Pow = [&](ll x, ll n) -> ll {
        ll t = x % MOD, r = 1;
        while ( n > 0 ) {
            if ( n & 1 ) Mul(r, t);
            Mul(t, t);
            n >>= 1;
        }
        return r;
    };
    auto Inv = [&](ll a) -> ll {
        return Pow(a, MOD - 2);
    };
    
    vector<ll> num(N);
    for ( int i = 0; i < N; i++ ) {
        ll x1 = Pow(2, i);
        ll x2 = 0;
        if ( N-1-i > 0 ) {
            x2 = Pow(2, N-1-i-1);
            Mul(x2, N-1-i);
        } else {
            x2 = 0;
        }
        Add(x2, Pow(2, N-1-i));
        Mul(x1, x2);
        num[i] = x1;
    }
    ll s = 0;
    for ( int i = 0; i < N; i++ ) {
        ll t = C[i];
        Mul(t, num[i]);
        Add(s, t);
    }
    Mul(s, Pow(2, N));
    return s;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

int main() {
  vector<int> A(9);
  vector<bool> bingo(9);
  for (int i = 0; i < 9; i++){
    cin >> A[i];
    bingo[i] = false;
  }
  int N;
  cin >> N;
  int num;
  for (int i = 0; i < N; i++){
    cin >> num;
    for (int j = 0; j < 9; j++){
      if (num == A[j]){
        bingo[j] = true;
      }
    }
  }
  if ((bingo[0] && bingo[1] && bingo[2]) || (bingo[3] && bingo[4] && bingo[5]) || (bingo[6] && bingo[7] && bingo[8]) || (bingo[0] && bingo[3] && bingo[6]) || (bingo[1] && bingo[4] && bingo[7]) || (bingo[2] && bingo[5] && bingo[8]) || (bingo[0] && bingo[4] && bingo[8]) || (bingo[6] && bingo[4] && bingo[2])){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;



int main(void){

	int H, W, K; cin >> H >> W >> K;

	char c[10][10];
	REP(i,H){
		REP(j,W){
			cin >> c[i][j];
		}
	}

	int Y = (int)pow(2, H);
	int X = (int)pow(2, W);
	int ans = 0;
	REP(i,Y){
		bitset<8> y(i);
		REP(j,X){
			bitset<8> x(j);
			int cnt = 0;
			REP(a, H){
				REP(b, W){
					if(!y[a] and !x[b] and c[a][b] == '#') cnt++;
				}
			}
			if(cnt == K) ans++;
		}
	}

	cout << ans << endl;

	return 0;

}


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

long long n,m,sum;
int a[100];

int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			if(a[j]>a[i])
				swap(a[i],a[j]);
	for(int i=0;i<m;i++)
		sum+=a[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			if (h == 0 && w == 0)
				break;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (i % 2 == 0) {
						if (j % 2 == 0) {
							System.out.print("#");
						} else {
							System.out.print(".");
						}
					} else {
						if (j % 2 == 0) {
							System.out.print(".");
						} else {
							System.out.print("#");
						}
					}
				}
				System.out.printf("\n");
			}
			System.out.printf("\n");
		}
	}

}



Measured memory_bytes: 38156
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a, b;
    cin >>a >>b;
    int num = a + b - 3;
    int den = a - 1;
    cout <<num / den;
    return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll H, W, K;
string S[10];
string T[10];

ll solve(ll h, ll w) {
    REP(i, H) {
        T[i] = S[i];
    }
    REP(i, H) {
        REP(j, W) {
            if (((h >> i) & 1) == 1 || ((w >> j) & 1) == 1)
                T[i][j] = 'R';
        }
    }
    ll ret = 0;
    REP(i, H) {
        REP(j, W) {
            if (T[i][j] == '#')
                ret++;
        }
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W >> K;
    REP(i, H) {
        cin >> S[i];
    }

    ll ans = 0;
    REP(h, pow(2, H)) {
        REP(w, pow(2, W)) {
            if (solve(h, w) == K)
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4116
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=998244353;

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

ll N,M,K;

int main(){
    cin>>N>>M>>K;

    ll ans=0;
    ll comb=1;
    rep(i,K+1){
        ans+=M*mpow(M-1,N-1-i)%MOD*comb%MOD;
        ans%=MOD;
        comb*=(N-1-i)*mpow(i+1,MOD-2)%MOD;
        comb%=MOD;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<math.h>

#define N 100000

typedef struct{
  char mark;
  int num;
} Trump;

void merge(Trump*,int,int,int);
void mergeSort(Trump*,int,int);
int partition(Trump*,int,int);
void quickSort(Trump*,int,int);

Trump A[N];

int main(void){
  int n;
  Trump B[N],C[N];
  int i;

  scanf(" %d",&n);
  for(i = 0; i < n; i++){
    scanf(" %c %d",&A[i].mark,&A[i].num);
    C[i].mark = B[i].mark = A[i].mark;
    C[i].num = B[i].num = A[i].num;
  }

  mergeSort(C,0,n);

  quickSort(B,0,n-1);

  for(i = 0; i < n; i++){
    if(C[i].mark != B[i].mark){
      printf("Not stable\n");
      break;
    }
  }
  if(i == n)printf("Stable\n");

  for(i = 0; i < n; i++){
    printf("%c %d\n",B[i].mark,B[i].num);
  }

  
  return 0;
}

void quickSort(Trump *B, int p, int r){
  int q;
  if(p < r){
    q = partition(B,p,r);
    quickSort(B,p,q-1);
    quickSort(B,q+1,r);
  }
}

int partition(Trump *B, int p, int r){
  int x=B[r].num;
  int i=p-1,j;
  Trump tmp;
  for(j = p; j < r; j++){
    if(B[j].num <= x){
      i++;
      tmp = B[i];
      B[i] = B[j];
      B[j] = tmp;
    }
  }
  tmp = B[i+1];
  B[i+1] = B[r];
  B[r] = tmp;
  return i+1;
}

void merge(Trump *C, int left, int mid, int right){
  int n1,n2;
  int i,j,k;
  Trump L[N],R[N];
  n1 = mid - left;
  n2 = right -mid;
  for(i = 0; i < n1; i++){
    L[i] = C[left + i];
  }
  for(i = 0; i < n2; i++){
    R[i] = C[mid + i];
  }
  L[n1].num = (int)INFINITY;
  R[n2].num = (int)INFINITY;
  i = 0;
  j = 0;
  for(k = left; k < right; k++){
    if(L[i].num <= R[j].num){
      C[k] = L[i];
      i++;
    }
    else{
      C[k] = R[j];
      j++;
    }
  }
}

void mergeSort(Trump *C, int left, int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(C,left,mid);
    mergeSort(C,mid,right);
    merge(C,left,mid,right);
  }
}



Measured memory_bytes: 4832
#!/usr/bin/env python3
import sys


def solve(N: int, S: "List[str]", P: "List[int]"):
    sps = list(zip(S, P))
    inds = sorted(range(N), key=lambda i: (sps[i][0], -sps[i][1]))
    for i in inds:
        print(i+1)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [str()] * (N)  # type: "List[str]" 
    P = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        S[i] = next(tokens)
        P[i] = int(next(tokens))
    solve(N, S, P)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
import math
from functools import reduce
from collections import deque

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

a,b = get_nums_l()

if a >= 13:
    print(b)
elif a >= 6:
    print(b//2)
else:
    print(0)

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

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

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
    int T;
    cin>>T;
    rep(i,T){
        ll N,A,B,C,D;
        cin>>N>>A>>B>>C>>D;
        map<ll,ll> m;
        m[N]=0LL;
        ll ans = INF;
        map<ll,ll> cost;
        cost[2]=A;
        cost[3]=B;
        cost[5]=C;
        while(true&&N!=1){
            map<ll,ll> t;
            for(auto x:m){
                if(x.first == 1) continue;
                ll l = x.first;
                if((l-1)<1000000000000000000/D) {
                    if(t[1]==0) t[1]=(l-1)*D+x.second;
                    else chmin(t[1],(l-1)*D+x.second);
                }
                for(auto y:cost){
                    ll p = y.first;
                    ll q = y.second;
                    if(l%p==0){
                        if(t[l/p]==0) t[l/p]=x.second+q;
                        else chmin(t[l/p],x.second+q);
                    }
                    else{
                        ll r = l%p;
                      if(l/p!=0){
                        if(t[l/p]==0) t[l/p]=x.second+r*D+q;
                        else chmin(t[l/p],x.second+r*D+q);
                      }
                        if(t[l/p+1]==0) t[l/p+1]=x.second+(p-r)*D+q;
                        else chmin(t[l/p+1],x.second+(p-r)*D+q);
                    }
                }
            }

            m=t;
          	if(m[1]!=0) chmin(ans,m[1]);
            if((int)t.size()<=1) break;
        }
        if(N!=1)cout<<ans+D<<endl;
      	else cout<<D<<endl;
    }
}

Measured memory_bytes: 3728