akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

const int N = 25;
const int NIL = -1;

struct Node {
  int parent, left, right;
};

void set_depth(int id, int dep, int depth[], Node T[]) {
  depth[id] = dep;
  if (T[id].left != NIL) set_depth(T[id].left, dep+1, depth, T);
  if (T[id].right != NIL) set_depth(T[id].right, dep+1, depth, T);
}

void set_type(int n, string type[], Node T[]) {
  for (int i = 0; i < n; i++) {
    if (T[i].parent == NIL) type[i] = "root";
    else if (T[i].left == NIL && T[i].right == NIL) type[i] = "leaf";
    else type[i] = "internal node";
  }
}

int find_root(int n, string type[]) {
  int root = 0;
  for (int i = 0; i < n; i++) {
    if (type[i] == "root") {
      root = i;
      break;
    }
  }
  return root;
}

int set_height(int id, int height[], string type[], Node T[]) {
  if (type[id] == "leaf") {
    height[id] = 0;
    return 0;
  }
  int h, h1 = 0, h2 = 0;
  if (T[id].left != NIL) h1 = 1 + set_height(T[id].left, height, type, T);
  if (T[id].right != NIL) h2 = 1 + set_height(T[id].right, height, type, T);
  h = max(h1, h2);
  height[id] = h;
  return h;  
}

int main() {
  int i, n, id, left, right;
  Node T[N];
  int sibling[N], degree[N], depth[N], height[N];
  string type[N];
  
  cin >> n;

  // init
  for (i = 0; i < n; i++) {
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
    sibling[i] = NIL;
  }

  // input
  for (i = 0; i < n; i++) {
    cin >> id >> left >> right;
    T[id].left = left;
    T[id].right = right;
    if (left != NIL && right != NIL) {
      T[left].parent = id;
      T[right].parent = id;
      sibling[left] = right;
      sibling[right] = left;
      degree[id] = 2;
    } else if (left == NIL && right != NIL) {
      T[right].parent = id;
      sibling[right] = left;
      degree[id] = 1;
    } else if (left != NIL && right == NIL) {
      T[left].parent = id;
      sibling[left] = right;
      degree[id] = 1;
    } else {
      degree[id] = 0;
    }
  }

  set_type(n, type, T);
  int root = find_root(n, type);
  set_depth(root, 0, depth, T);
  set_height(root, height, type, T);

  // output
  for (i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << T[i].parent << ", sibling = "
         << sibling[i] << ", degree = " << degree[i] << ", depth = "
         << depth[i] << ", height = " << height[i] << ", " << type[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 3204
#include<stdio.h>
#include<string.h>
int main(){
    int n, i, jud, Taro=0, Hanako=0;
    char t[100], h[100];
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%s %s", t, h);
        jud=strcmp(t, h);
        if(jud>0)Taro+=3;
        else if(jud<0)Hanako+=3;
        else{
            Taro++;
            Hanako++;
        }
    }
    printf("%d %d\n", Taro, Hanako);
    return 0;
}

Measured memory_bytes: 604
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

/*-----<Defines>-----*/
#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)size(x))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)-1)/(x)+1)
#define     flush           fflush(stdout)

using ull=unsigned long long;
using ll=long long;
using ld=long double;
/*-----</Defines>-----*/

/*-----<Debugging Stuff>-----*/
string to_string(char s)
{   string res="'''";res[1]=s;return res; }

string to_string(string s)
{   return '"'+s+'"'; }

string to_string(const char* s)
{   return to_string((string)s); }

string to_string(bool b)
{   return (b?"true":"false"); }

template<typename A, typename B>
string to_string(pair<A, B> p)
{   return "("+to_string(p.F)+", "+to_string(p.S)+")"; }

template<typename A>
string to_string(A v)
{
    bool first=1; string res="{";
    for(const auto &x:v)
    {
        if(!first)  res+=", ";
        first=0;
        res+=to_string(x);
    }
    res+="}";
    return res;
}

void debug() { cout<<"\n"; }
template<typename Head, typename... Tail>
void debug(Head H, Tail... T)
{
    cout<<" "<<to_string(H);
    debug(T...);
}

#define show(...) cout << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
/*-----</Debugging Stuff>-----*/

/*-----<Mod Operations>-----*/
const int M=1e9+7;
inline int add(int a,int b,int p=M){ a=a+b; if(a>=p) a-=p; return a; }
inline int sub(int a,int b,int p=M){ a=a-b; if(a<0) a+=p; return a; }
inline int mul(int a,int b,int p=M){ a=(a*1ll*b)%p; return a; }
/*-----</Mod Operations>-----*/

/*-----<Constants>-----*/
const ld pi=acos(-1),eps=1e-9;
const ll inf=1e18;
const int N=1;
/*-----</Constants>-----*/

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

    int mx=0;
    int ans=0;
    for(int i=0;i<n;++i)
    {
        int x;
        cin>>x;

        if(x<mx)
            ans+=(mx-x);
        else
            mx=x;
    }

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int P[222222];

int x[222222];

signed main(){
    cin>>N;
    rep(i,N)cin>>P[i],P[i]--;
    rep(i,N)x[P[i]]=i;

    int ans=0;
    int uku=0;
    rep(i,N){
        if(i&&x[i-1]>x[i])uku=0;
        uku++;
        chmax(ans,uku);
    }
    cout<<N-ans<<endl;
}

Measured memory_bytes: 3328
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (n, k) = get!(usize, usize);
    let xy = get!(i64, i64; n);
    let mut x_order = xy.clone();
    let mut y_order = xy.clone();

    x_order.sort_by_key(|xy| xy.0);
    y_order.sort_by_key(|xy| xy.1);

    let mut ans = i64::max_value();

    let mut deq = VecDeque::with_capacity(256);
    for i1 in 0..n {
        for i2 in i1 + 1..n {
            deq.clear();
            let l = x_order[i1].0;
            let r = x_order[i2].0;
            for &(x, y) in &y_order {
                if l <= x && x <= r {
                    deq.push_back(y);

                    while deq.len() > k {
                        deq.pop_front();
                    }

                    if deq.len() == k {
                        ans = min(ans, (r - l) * (deq.back().unwrap() - deq.front().unwrap()));
                    }
                }
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll i,j,k;

int main(){
    ll n,m;cin>>n>>m;
    priority_queue<ll> P_que;
    
    for(i=0;i<n;i++){
        ll a;cin>>a;
        P_que.push(a);
    }
    for(i=0;i<m;i++){
        ll num=P_que.top();
        P_que.push(num/2);
        P_que.pop();
    }

    ll ans=0;
    for(i=0;i<n;i++){
        ans+=P_que.top();
        P_que.pop();
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int i;
    vector<int> A;
    int n;
    cin >> n;
    for (i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        A.push_back(a);
    }
    int q;
    cin >> q;
    for (i = 0; i < q; i++)
    {
        int b, m, e;
        cin >> b >> m >> e;
        rotate(next(A.begin(), b), next(A.begin(), m), next(A.begin(), e));
    }
    for (i = 0; i < (A.size() - 1); i++)
    {
        cout << A.at(i) << ' ';
    }
    cout << A.back() << endl;
}


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

#define printl(s) cout << s << endl;
#define print(s) cout << s << endl; return 0;
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n)+1; ++i)
using ll = long long;

const ll modseed = pow(10,9) + 7;

template <typename T>
vector<T> getValues(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
int N, cnt;

int main(){
  cin >> N >> S;
  rep(i,N-2){
    if(S.at(i)=='A' && S.at(i+1) == 'B' && S.at(i+2) == 'C'){
      cnt++;
    }
  }
  print(cnt);
}


Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int cnt;
vector<int> G;

void insertionSort(int* T,int num,int g)
{
	for(int i=g;i<num;i++)
	{
		int v = T[i];
		int j = i - g;
		while(j>=0&&T[j]>v)
		{
			T[j + g] = T[j];
			j = j - g;
			cnt++;
		}
		T[j + g] = v;
	}
}

void shellSort(int* T,int num)
{
	for(int h=1;;)
	{
		if (h > num) break;
		G.push_back(h);
		h = 3 * h + 1;
	}
	for(int i=G.size()-1;i>=0;i--)
	{
		insertionSort(T, num, G[i]);
	}
}

int main()
{
	int num;
	cin >> num;
	int* T = new int[num];
	for(int i=0;i<num;i++)
	{
		cin >> T[i];
	}
	shellSort(T, num);
	cout << G.size() << endl;
	for(int i=G.size()-1;i>=0;i--)
	{
		cout << G[i] << (i == 0 ? '\n' : ' ');
	}
	cout << cnt << endl;
	for(int i=0;i<num;i++)
	{
		cout << T[i] << endl;
	}
	delete[] T;

}


Measured memory_bytes: 6700
#include <stdio.h>
#include <stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
//Node treeMinimum(Node x){
 
 
  //}
 
Node treeSearch(Node u, int k){
  while(u != NULL){
    if(k == u->key) return u;
    else if(k <= u->key){
      u = u->left;
    } else {
      u = u->right;
    }
  }
  return NULL;
 
}
 
//Node treeSuccessor(Node x){
 
 
//}
 
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
 
 
 
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x!=NIL){
    y = x;
    if( z->key < x->key )
      x = x->left;
    else
      x = x->right;
  }
 
  z->parent = y;
  if(y==NIL)
    root = z;
  else if(z->key<y->key)
    y->left = z;
  else
    y->right = z;
   
}
 
void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);  
    inorder(u->right);
  }
}
 
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key); 
    preorder(u->left);
    preorder(u->right);
  }
}
 
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
 
  return 0;
}

Measured memory_bytes: 19364
#include<iostream>
using namespace std;
int main() {
    int n, t; cin >> n >> t;
    long long ans = 0;
    int tt; cin >> tt;
    int bef = tt;
    for (int i = 1; i < n; ++i) {
        cin >> tt;
        if (bef + t > tt) { //次のtiまでみればいい
            ans += tt - bef;
        } else {
            ans += t;
        }
        bef = tt;
    }
    ans += t;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldbl;
typedef pair<int,int> P;

#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define pb push_back

// from codeforces
#define what_is(x) cerr << #x << " is " << x << endl;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))

ll mod = 1e9+7;

int n;

int main(){
  // fast I/O
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;

  cout << (n>999?"ABD":"ABC") << endl;

  return 0;
}
// notes
//


Measured memory_bytes: 256
while true
  n, m = gets.split(' ').map(&:to_i)
  break if n == 0 && m == 0
  results = []
  prices = gets.split(' ').map(&:to_i)
  (0..n-1).each do |i|
    (0..i-1).each do |j|
      sum = prices[i] + prices[j]
      results.push(sum) if sum <= m
    end
  end
  puts results.empty? ? 'NONE' : results.max
end



Measured memory_bytes: 24468
def main():
    N = int(input())
    S = ""

    if N == 0:
        print(0)

    else:
        while N:
            if N % 2 != 0:
                S = '1' + S
                N -= 1

            else:
                S = '0' + S

            N //= -2

        print(S)

    return


main()


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

int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
        for(int j = 1; j <= A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for(int bits = 1; bits < (1 << N); bits++) {
        bool ok = true;
        for(int i = 1; i <= N; i++) {
            if(!(bits & (1 << (i-1)))) continue;
            for(int j = 1; j <= A[i]; j++) {
                if(((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
            }
        }
        if(ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
    return 0;
}

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

using namespace std;

const int maxi = 1e6+10;
const long long inf = 1e9+10;
int n;
long long t;
pair<long long, long long> a[maxi];
long long dp[41][maxi];

bool cmp(pair<long long, long long> x, pair<long long, long long> y)
{
    if (!x.first && !y.first) return x.second < y.second;
    return  y.first * (x.second + 1) < x.first *(y.second + 1);
}
int main()
{
    cin>>n>>t;

    for (int i =1;i<=n;i++)
        scanf("%lld%lld",&a[i].first, &a[i].second);

    sort(a + 1, a+n+1, cmp);

    for (int i = 0 ; i<=40;i++)
        for (int j = 0; j<=n;j++)
         dp[i][j] = inf;

    dp[0][0] = 0;

   int poz = n + 1;

    for (int i = 1;i<=n;i++)
    {
        if (!a[i].first)
        {
            poz = i;
            break;
        }

        for (int j = 0 ; j <= 40; j++)
            if (!j) dp[0][i] = 0; else
        {
            dp[j][i] = min(dp[j][i-1], (dp[j-1][i-1]+1)*(a[i].first + 1) + a[i].second);
            dp[j][i] = min(dp[j][i], inf);
        }
    }

    int ans = 0;


    for (int k = 0; k<=40;k++)
    {
         if (dp[k][poz-1]>t) continue;

         long long val = dp[k][poz-1];

         int cnt = k ;

         for (int i = poz; i<=n;i++)
          if (val + a[i].second + 1<=t)
         {
             val+=a[i].second + 1;
             cnt++;
         }

        ans = max(cnt, ans);
    }


    printf("%d\n",ans);
}
//1 3
//0 3




Measured memory_bytes: 151296
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

ll gcd(ll a,ll b){
	if(a<b){
		swap(a,b);
	}

	while(ll r=(a%b)){
		a = b;
		b = r;
	}
	return b;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	vector<ll> A=vecin<ll>(N);
	ll ans = A[0];

	for(int i=1;i<N;i++){
		ans = lcm(ans,A[i]);
	}
	out(ans);
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int calc_keta(ll a) {
    int ret = 0;
    if (a == 0) return 1;
    while(1) {
        if (a == 0) break;
        ++ret;
        a /= 10;
    }
    return ret;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> a;
    a.push_back(1);
    for (ll i = 2; i * i <= n; ++i) {
        if (n % i == 0) a.push_back(n/i);
    }
    int ans = 1e8;
    for (auto aa: a) {
        ll b = n / aa;
        int keta_a = calc_keta(aa);
        int keta_b = calc_keta(b);
        ans = min(ans, max(keta_a, keta_b));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};

ll gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
vector<int> lat[100010];
vector<int> pet[100010];
bool rel[100010];
bool lal[100010];
void rec(int pe) {

	rel[pe] = true;
	for (int c : pet[pe])
	{
		if (lal[c]) continue;
		lal[c] = true;
		for (int ne : lat[c])
		{
			if (rel[ne]) continue;
			rec(ne);
		}
	}
}
void Solve() {
	
	int n,m;
	cin >> n >> m;
	for (size_t i = 1; i <= n; i++)
	{
		int k;
		cin >> k;
		for (size_t j = 0; j < k; j++)
		{
			int la;
			cin >> la;
			pet[i].push_back(la);
			lat[la].push_back(i);
		}
	}
	rec(1);
	for (size_t i = 1; i <= n; i++)
	{
		if (!rel[i]) {
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}


int main() {
	Solve();
	return 0;
}



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

#define rep3(i, s, n ,a) for (int i = (s); i < (int)(n); i+=a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

#define MOD 1000000007

unsigned long repeat_square(unsigned long x, unsigned long n);

int main(){
    unsigned long n, k;
    unsigned long ans=0;
    cin >> n >> k;
    vector<unsigned long> box;
    rep(i, k){
        box.push_back(0);
    }
    for(unsigned long x=k;x>0;x--){
        unsigned long ans_num;
        ans_num = repeat_square(k/x, n) % MOD;
        rep3(tmp, x<<1, k+1, x){
            //cout << tmp << " : " << box[tmp-1] << endl;
            if(ans_num - box[tmp-1] > 9223372036854775807)  ans_num += MOD;
            //cout << ans_num << " : " << tmp << " : " << box[tmp-1] << endl;
            ans_num = (ans_num - box[tmp-1]) % MOD;
            //ans_num -= box[tmp-1];
        }
        box[x-1] = ans_num;
        ans = (ans + ans_num * x) % MOD; 
    }
    // rep(i, k){
    //     cout << i << " : " << box[i] << endl;
    // }
    cout << ans << endl;
    return 0;
}

unsigned long repeat_square(unsigned long x, unsigned long n){
    unsigned long ret = 1;
    while(n>0){
        if(n & 1){
            ret = ret * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

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

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

ll N;
vector<ll> W(101);
ll T;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> N;
  for (int i = 1; i <= N; i++)  cin >> W.at(i);
  ll ans = 100000;
  for (T = 1; T < N; T++) {
    ll S1 = 0;
    ll S2 = 0;
    for (int i = 1; i <= T; i++) {
      S1 += W.at(i);
    }
    for (int i = T+1; i <= N; i++) {
      S2 += W.at(i);
    }
    ll v = abs(S1 - S2);
    ans = min(ans, v);
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
int main() {
        int N, K;
        cin >> N >> K;

        vector<int> h(N);
        for(auto &x: h) {
                cin >> x;
        }
        sort(h.begin(), h.end());

        long long min = 2000000000;
        for(int i = 0; i <= N - K; i++) {
                long long nm = h[i + K - 1] - h [i];
               if(min > nm) min = nm;
        }

        cout << min << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()

int main() {
    string s,t;
    cin >> s >> t;
    rep(i,s.size()) {
        if (s[i] != t[i]) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>

void main()
{
    int N, X, T;

    scanf("%d %d %d", &N, &X, &T);

    if(!((N >= 1) && (N <=1000))){
        return;
    }
    if(!((X >= 1) && (X <=1000))){
        return;
    }
    if(!((T >= 1) && (T <=1000))){
        return;
    }

    int Z;

    Z = ((N / X) + (((N % X)!=0)?1:0)) * T;

    printf("%d\n", Z);
}


Measured memory_bytes: 1728
using System;
using System.Collections.Generic;
class _1180
{
    public static void Main()
    {
        string str = Console.ReadLine(), argument, san;
        string[] data;
        int an = 0, max, min, count, L;
        bool flag;
        char[] maxChar, minChar;
        Dictionary<int, int> nums = new Dictionary<int, int>();
        while (str != "0 0")
        {
            data = str.Split();
            nums.Clear();
            an = int.Parse(data[0]);
            L = int.Parse(data[1]);
            argument = "D" + L;
            san = an.ToString(argument);
            flag = false;
            count = 0;
            maxChar = new char[L];
            minChar = new char[L];
            nums.Add(an, count);
            while (!flag)
            {
                count++;
                san.ToCharArray().CopyTo(maxChar, 0);
                maxChar.CopyTo(minChar, 0);
                Array.Sort(maxChar);
                Array.Sort(minChar);
                Array.Reverse(maxChar);
                max = int.Parse(new string(maxChar));
                min = int.Parse(new string(minChar));
                an = max - min;
                san = an.ToString(argument);
                if (nums.ContainsKey(an))
                {
                    Console.WriteLine(nums[an] + " " + an + " " + (count - nums[an]));
                    flag = true;
                }
                else
                {
                    nums.Add(an, count);
                }
            }
            str = Console.ReadLine();
        }
    }
}

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

using namespace std;

int main()
{
    int n,v,l,i,j,m,p,f,k;
    cin>>n;
  	k = 2;
    int a[n],dp[n];
    cin>>a[0]>>a[1];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++)
    {
        cin>>a[i];
        p=dp[i-1]+abs(a[i]-a[i-1]);
        j=i-1;
          //cout<<dp[j]<<" "<<abs(a[i]-a[j])<<" "<<p<<"*";
        j=i-2;
        while((j>=0)&&((i-k)<=j))
        {
            if((dp[j]+abs(a[i]-a[j]))<p)
               {
                   p=(dp[j]+abs(a[i]-a[j]));
                 //   cout<<dp[j]<<" "<<abs(a[i]-a[j])<<" "<<p<<"*";
               }
            j--;
        }
        dp[i]=p;
        //cout<<p<<"\n";
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 1024
s = input()
at = ['A', 'C', 'G', 'T']

tmp = 0
cnt = 0
for i in s:
    if i in (at):
        tmp+=1
    else:
        if cnt < tmp:
            cnt = tmp
        tmp = 0
if cnt < tmp:
    cnt = tmp
            
print(cnt)

Measured memory_bytes: 3060
#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;

struct Vertex
{
    vector<ll> pre;
    vector<ll> node;
};

Vertex V[1005];
bool U[1005];
ll R[1005];

int main()
{
    ll N, M;
    cin >> N >> M;
    REP(i, M)
    {
        ll a, b;
        cin >> a >> b;
        V[--a].node.push_back(--b);
        V[b].pre.push_back(a);
    }

    memset(U, 0, sizeof(U));
    ll s = -1;
    ll minCost = INF;
    REP(i, N)
    {
        memset(U, 0, sizeof(U));
        queue<pll> q;
        q.push(pll(i, 0));
        U[i] = true;
        while (!q.empty())
        {
            pll t = q.front();
            q.pop();
            ll cost = t.second + 1;
            REP(j, V[t.first].node.size())
            {
                ll n = V[t.first].node[j];
                if (n == i)
                {
                    if (cost >= minCost)
                    {
                        break;
                    }
                    //! iから始まるループがある
                    s = i;
                    minCost = cost;
                    break;
                }
                if (U[n])
                    continue;
                U[n] = true;
                q.push(pll(n, cost));
            }
        }
    }

    if (s == -1)
    {
        cout << -1 << endl;
        return 0;
    }

    memset(U, 0, sizeof(U));
    REP(i, N)
    {
        R[i] = INF;
    }
    vector<ll> v;
    v.push_back(s);
    {
        queue<pll> q;
        q.push(pll(s, 0));
        U[s] = true;
        R[s] = 0;
        ll min = -1;
        ll nxt = s;
        while (!q.empty())
        {
            pll t = q.front();
            q.pop();
            ll cost = t.second + 1;
            REP(i, V[t.first].node.size())
            {
                ll n = V[t.first].node[i];
                if (n == s)
                {
                    min = cost - 1;
                    nxt = t.first;
                    break;
                }
                if (U[n])
                    continue;
                q.push(pll(n, cost));
                R[n] = cost;
                U[n] = true;
            }
            if (min >= 0)
                break;
        }

        while (nxt != s)
        {
            v.push_back(nxt);
            REP(i, V[nxt].pre.size())
            {
                ll n = V[nxt].pre[i];
                if (min - 1 == R[n])
                {
                    min--;
                    nxt = n;
                    break;
                }
            }
        }
    }

    cout << v.size() << endl;
    REP(i, v.size())
    {
        cout << v[i] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 384
h, n = map(int, input().split())
a, b = [0]*n, [0]*n

for i in range(n):
    a[i], b[i] = list(map(int, input().split()))

dp = [float("inf")] * (h+1)
dp[0] = 0

for i in range(h):
    for t in range(n):
        if i + a[t] < h:
            dp[i+a[t]] = min(dp[i+a[t]], dp[i]+b[t])
        else:
            dp[-1] = min(dp[-1], dp[i]+b[t])

print(dp[-1])

Measured memory_bytes: 43484
n = gets.to_i
ary1 = []
n.times do
  string = gets
  ary1 << string.chomp
end
m = gets.to_i
ary2 = []
m.times do 
  string = gets
  ary2 << string.chomp
end
cnt = [0]
for i in 0..n-1
  cnt << ary1.count(ary1[i])-ary2.count(ary1[i])
end
puts cnt.max

Measured memory_bytes: 14320
program main
    use iso_fortran_env
    implicit none
    integer(int64) :: n, q
    integer(int64) :: an(100000)
    integer(int64),allocatable :: a(:), b(:), c(:)
    integer(int64) :: i
    integer(int64) :: s

    read *, n
    allocate(a(n))
    read *, (a(i), i = 1, n)
    read *, q
    allocate(b(q), c(q))
    read *, (b(i), c(i), i = 1, q)

    an = 0
    an(a) = an(a) + 1

    s = sum(a)

    do i = 1, q
        s = s + (c(i) - b(i)) * an(b(i))
        an(c(i)) = an(c(i)) + an(b(i))
        an(b(i)) = 0
        print *, s
    enddo

end program main

Measured memory_bytes: 6360
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;
typedef long long ll;


long long answer[10] = {};

set< pair<int,int>> memo;

int main(){
	int H, W, N;
	cin >> H >> W >> N;
	
	answer[0] = 1ll * (H - 2) * (W - 2);
	
	set< pair<int,int> > S;
	for(int i = 0 ; i < N ; i++){
		int a, b;
		cin >> a >> b;
		--a, --b;
		memo.insert({a, b});
		for(int j = 0 ; j < 3 ; j++){
			for(int k = 0 ; k < 3 ; k++){
				int y = a - j;
				int x = b - k;
				if( x < 0 || y < 0 ) continue;
				if( x + 3 > W || y + 3 > H ) continue;
				S.insert({y, x});
			}
		}
	}
	
	for( auto p : S ) {
		int y = p.first;
		int x = p.second;
		int cnt = 0;
		for(int j = 0 ; j < 3 ; j++){
			for(int k = 0 ; k < 3 ; k++){
				int ty = p.first + j;
				int tx = p.second + k;
				if( memo.count({ty, tx}) ) cnt++; 
			}
		}
		answer[0]--;
		answer[cnt]++;
	}
	
	for(int i = 0 ; i < 10 ; i++){
		cout << answer[i] << endl;
	}
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A.at(i);
    bool flag = 1;
    rep(i, N) {
        if((A[i] % 2 == 0) && (A[i] % 3 != 0) && (A[i] % 5 != 0)) flag = 0;
    }
    cout << (flag ? "APPROVED" : "DENIED") << endl;
}

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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pinin=pair<int ,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

int main() {
    
    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
    int ans=10000;
    rep(i,n-m+1){
        int k=0;
        rep(j,m){
            if(t[j]!=s[i+j]){
                k++;
            }
        }
        ans=min(ans,k);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3600
#include <iostream>

bool is_palindrome(const std::string& s) {
    for (int i = 0; i < s.size() / 2; i ++) {
        if (s[i] != s[s.size() - i - 1]) {
            return false;
        }
    }
    return true;
}

int main() {
    std::string s;
    std::cin >> s;

    std::cout << (is_palindrome(s) &&
    is_palindrome(s.substr(0, (s.size() - 1) / 2)) &&
    is_palindrome(s.substr((s.size() + 3) / 2 - 1, 1 + s.size() - (s.size() + 3) / 2)) ? "Yes" : "No" )<< '\n';

    return 0;
}

Measured memory_bytes: 256
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
typedef mp::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


int main()
{
    char a,b;
    cin>>a>>b;
    cout<<((a==b)?"H":"D")<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 int N, A[3][3], b[10];
 bool appear[3][3];
 int main() {
 for(int i = 0; i < 3; i++) {
 for(int j = 0; j < 3; j++) cin >> A[i][j];
 }
 cin >> N;
 for(int i = 0; i < N; i++) cin >> b[i];
 for(int i = 0; i < N; i++) {
 for(int j = 0; j < N; j++) {
 appear[i][j] = false;
 for(int k = 0; k < N; k++) {
 if(A[i][j] == b[k]) appear[i][j] = true;
 }
 }
 }
 string ANS = "No";
 for(int i = 0; i < 3; i++) {
 if(appear[i][0] and appear[i][1] and appear[i][2]) ANS = "Yes";
 }
 for(int i = 0; i < 3; i++) {
 if(appear[0][i] and appear[1][i] and appear[2][i]) ANS = "Yes";
 }
 if(appear[0][0] and appear[1][1] and appear[2][2]) ANS = "Yes";
 if(appear[0][2] and appear[1][1] and appear[2][0]) ANS = "Yes";
 cout << ANS << endl;
 return 0;
 }

Measured memory_bytes: 256
import itertools
a_to_e = [int(input()) for i in range(5)]

res = 10 ** 5
for i in itertools.permutations(range(5)):
    sum_min = 0
    for j in range(len(i)):
        if j == 4:
            sum_min += a_to_e[i[j]]
        else:
            sum_min += (a_to_e[i[j]] + 9) // 10 * 10
    res = min(res, sum_min)

print(res)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

signed main(void){
    
    string S;
    cin >> S;
    int a[26]={};
    REP(i,S.size()){
        a[S[i]-'a']++;
    }
    int kisu=0;
    int Ans=0;
    REP(i,26){
        if(a[i]%2==1)kisu++;
    }
    
    Ans = kisu/2;
    
    cout << Ans << endl;
    
    return 0;
}





Measured memory_bytes: 3208
#include <cstdio>

using namespace std;

int main(void){
  int n,x,t,m;
  
  scanf("%d%d", &n, &x);
  t = 0; m = 10000;
  for (int i=0; i<n; i++){
    int tmp;
    scanf("%d", &tmp);
    t += tmp;
    m = tmp<m?tmp:m;
  }
  printf("%d\n", n+(x-t)/m);
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0297
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = RInt();
            for (int i = 0; i < n; i++)
            {
                int[] vs = RArInt();
                Console.WriteLine((vs[0] - 1) % vs[1] + 1);
            }
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 17920
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;

int mark[100005];
vector<int> adj[100005];

void solve(int u){
    mark[u] = 1;
    for(int v : adj[u])
        if(!mark[v])
            solve(v);
}

int main(){
    int n, m; cin >> n >> m;
    int res = 0;
    for(int i = 0; i < m; i++){
        int a, b, c; cin >> a >> b >> c;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i = 1; i <= n; i++)
        if(!mark[i])
            solve(i),
            res++;
    cout << res << endl;
	return 0;
}

Measured memory_bytes: 9216
from collections import deque
n,m = map(int,input().split())

b = [[] for i in range(n)]
for i in range(m):
    a=list(map(int,input().split()))
    b[a[1]-1].append(a[0])
    b[a[0]-1].append(a[1])
    
c = [-1 for i in range(n)]
c[0] = 0
q = deque([1])
now = 0
count = 0
while q:
    #print(c,q, now)
    count = count + 1
    if count > n:
        print("No")
        exit()
    now = q.popleft() - 1
    for i in range(len(b[now])):
        #count = count + 1
        #print(now+1, "=>", b[now][i])
        if c[b[now][i] - 1] == -1:
            q.append(b[now][i])
            c[q[-1] - 1] = now + 1
            #print(c)
            
#print(count)
print("Yes")
for i in range(1,len(c)):
    print(c[i])


Measured memory_bytes: 97288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int a=0;
	string s;
	cin>>s;
	for(int i=0;i<4;i++)
	{
		if(s[i]=='+')a++;
		else a--;
	}
	cout<<a<<endl;
	return 0;
}

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

typedef unsigned long long ull;

#define REP(i, N) for (int i = 0; i < N; i++)
#define ANS(a) cout << a << endl;
#define SORT(V) sort(V.begin(), V.end())
#define RSORT(V) sort(V.rbegin(), V.rend())

int A, B, C; 
int N;
vector<int> TAKE;

int
dfs(int depth, int a, int b, int c)
{
  int r0, r1, r2, r3;

  if (depth == N) {
    if (a > 0 && b > 0 && c > 0) 
      return abs(A-a) + abs(B-b) + abs(C-c);
    else
      return 1e9;
  }
  
  r0 = dfs(depth + 1, a, b, c);
  r1 = dfs(depth + 1, a + TAKE[depth], b, c) + (a > 0 ? 10 : 0);
  r2 = dfs(depth + 1, a, b + TAKE[depth], c) + (b > 0 ? 10 : 0);
  r3 = dfs(depth + 1, a, b, c + TAKE[depth]) + (c > 0 ? 10 : 0);

  return min({r0, r1, r2, r3});
}

int
main()
{
  cin >> N >> A >> B >> C;
  REP(i, N) { int t; cin >> t; TAKE.emplace_back(t); };
  
  ANS(dfs(0, 0, 0, 0));

  return 0;
}
/*
8 1000 800 100
300 333 400 444 500 555 600 666
*/


Measured memory_bytes: 256
from itertools import product
def check(C,p,q,H,W):
    ret = 0
    for i in range(H):
        if p[i] == 1:
            continue
        for j in range(W):
            if q[j] == 1:
                continue
            if C[i][j] == "#":
                ret += 1
    return ret

def main():
    H, W, K = map( int, input().split())
    C = [ list( input()) for _ in range(H)]
    ans = 0
    for p in product(range(2), repeat=H):
        for q in product(range(2), repeat=W):
            if check(C,p,q,H,W) == K:
                ans += 1
    print(ans)
if __name__ == '__main__':
    main()


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

int main() {
  int64_t n, x;
  cin >> n >> x;
  int64_t p[n + 1], size[n + 1], result = 0;
  p[0] = 1;
  size[0] = 1;
  for (int64_t i = 1; i <= n; ++i) {
    p[i] = 2 * p[i - 1] + 1;
    size[i] = 2 * size[i - 1] + 3;
  }
  for (int64_t i = n; i >= 0; --i) {
    if (x == 0) {
      break;
    }
    if (x == size[i]) {
      result += p[i];
      break;
    }
    if (x == 1) {
      break;
    }
    if (x <= 1 + size[i - 1]) {
      --x;
    } else {
      result += 1 + p[i - 1];
      x -= 2 + size[i - 1];
    }
  }
  cout << result;
  return 0;
}

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

using namespace std;

int main()
{
	int n,k;
	cin >> n >> k;

	int array[n];
	int indexOne;
	for (int i = 0; i < n; ++i)
	{
		cin >> array[i];
		if (array[i]==1) indexOne = i;

	}

	// int Ones=1,left,right;
	// left = indexOne;
	// right = 
	int answer=0;
	// if (n==k) answer = 1;
	// else {
	// 	answer = (n)/k;
	// 	answer += n%k;
	// }
	// cout << n/2;
	bool flag = true;
	while (n>0)
	{
		answer++;
		if (flag )
		{
			n -= k;
			flag = false;
		}
		else
			n = n - k + 1;
	}
	cout << answer;


	return 0;
}

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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, k;
	cin >> n >> k;
	int sum = 0;
	int arr[n];
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
		sum += arr[i];
	}
	vector<int> div;
	for(int i = 1; i * i <= sum; i++) {
		if(sum % i == 0) {
			div.push_back(i);
			if(sum / i != i)
				div.push_back(sum / i);
		}
	}
	int ans = 1;
	for(int d : div) {
		int rem = 0;
		int q[n];
		for(int i = 0; i < n; i++)
			q[i] = arr[i] % d;
		sort(q, q + n);
		int l = 0, r = n - 1;
		while(l < r) {
			if(q[l] == 0) {
				l++;
				continue;
			}
			if(q[r] == d) {
				r--;
				continue;
			}
			int toRemove = min(d - q[r], q[l]);
			q[r] += toRemove;
			q[l] -= toRemove;
			rem += toRemove;
		}
		if(q[l] != 0 && q[l] != d)
			rem += q[l];
		if(rem <= k)
			ans = max(ans, d);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath> 
#include <string>
#include <iostream>
using namespace std;
const int N = 10010;
const int ai_max = 10000010;

int BIT(int a){
	int sum = 0;
	while(a >= 2){
		if(a & 1) return sum;
		a = a / 2;
		sum += 1;
	}
	return sum;
}

int main(){	
	int sum = 0;
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int t;
		cin >> t;
		//cout << BIT(t) << endl;
		sum += BIT(t);
	}
	cout << sum;
	return 0;
} 

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

typedef int flow_type;

const flow_type flow_inf=10000;

typedef struct flow_edge{
  int vertex;
  int next;
  flow_type capacity;
} flow_edge;

typedef struct maxFlowGraph{
  flow_edge *edge;
  int *start;
  int vertex_num;
  int pointer;
  int edge_length;
} graph;

graph* newGraph(const int vertex_num){
  graph *g=(graph *)calloc(1,sizeof(graph));
  g->vertex_num=vertex_num;
  const int initial_length=4;
  g->edge=(flow_edge *)calloc(initial_length,sizeof(flow_edge));
  g->start=(int *)calloc(vertex_num,sizeof(int));
  g->pointer=0;
  g->edge_length=initial_length;
  for(int i=0;i<vertex_num;i++) g->start[i]=-1;
  return g;
}

void freeGraph(graph *g){
  free(g->edge);
  free(g->start);
  free(g);
}

void addEdge(graph *g,int from,int to,flow_type capa){
  if(g->pointer==g->edge_length){
    g->edge_length*=2;
    g->edge=(flow_edge *)realloc(g->edge,sizeof(flow_edge)*g->edge_length);
  }
  int p=g->pointer;
  g->edge[p]=(flow_edge){to,g->start[from],capa};
  g->start[from]=p;
  g->edge[p+1]=(flow_edge){from,g->start[to],0};
  g->start[to]=p+1;
  g->pointer+=2;
}

flow_type dinic_dfs(int v,graph *g,int dst,int *level,int *iter,flow_type e){
  if(v==dst) return e;
  for(int p=iter[v];p!=-1;p=g->edge[p].next,iter[v]=p){
    int u=g->edge[p].vertex;
    flow_type capa=g->edge[p].capacity;
    if(level[u]<=level[v] || capa<=0) continue;
    flow_type f=dinic_dfs(u,g,dst,level,iter,capa<e?capa:e);
    if(f>0){
      g->edge[p].capacity-=f;
      g->edge[p^1].capacity+=f;
      return f;
    }
  }
  return 0;
}

flow_type dinic(const graph *input_graph,const int src,const int dst){
  const int vertex_num=input_graph->vertex_num;
  const int edge_num=input_graph->pointer;
  graph *g=(graph *)calloc(1,sizeof(graph));
  g->edge=(flow_edge *)malloc(sizeof(flow_edge)*edge_num);
  g->start=(int *)malloc(sizeof(int)*vertex_num);
  memcpy(g->edge,input_graph->edge,sizeof(flow_edge)*edge_num);
  memcpy(g->start,input_graph->start,sizeof(int)*vertex_num);
  int *level=(int *)calloc(vertex_num,sizeof(int));
  int *queue=(int *)calloc(vertex_num,sizeof(int));
  int *iter=(int *)calloc(vertex_num,sizeof(int));
  flow_type flow=0;
  while(1){
    memset(level,0,sizeof(int)*vertex_num);
    int front=0,last=0;
    level[src]=1;
    queue[last++]=src;
    while(front<last && level[dst]==0){
      const int v=queue[front++];
      for(int p=g->start[v];p!=-1;p=g->edge[p].next){
	int u=g->edge[p].vertex;
	if(g->edge[p].capacity>0 && level[u]==0){
	  level[u]=level[v]+1;
	  queue[last++]=u;
	}
      }
    }
    if(level[dst]==0) break;
    memcpy(iter,g->start,sizeof(int)*vertex_num);
    while(1){
      flow_type f=dinic_dfs(src,g,dst,level,iter,flow_inf);
      if(f<=0) break;
      flow+=f;
    }
  }
  freeGraph(g);
  free(level);
  free(queue);
  free(iter);
  return flow;
}

void run(void){
  int v,e;
  scanf("%d%d",&v,&e);
  graph *g=newGraph(v);
  while(e--){
    int u,v,c;
    scanf("%d%d%d",&u,&v,&c);
    addEdge(g,u,v,c);
  }
  printf("%d\n",dinic(g,0,v-1));
}

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



Measured memory_bytes: 2112