akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr ll mod = 1e9 + 7;

ll dp[22][1 << 21];

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

  int n;
  cin >> n;

  dp[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    vector<int> a;
    for (int j = 0; j < n; ++j) {
      int tmp;
      cin >> tmp;
      if (tmp) {
        a.emplace_back(j);
      }
    }
    int mask = (1 << n) - 1;
    for (int j: a) {
      int k = mask ^ (1 << j);
      for (int s = k;; s = (s - 1) & k) {
        if (__builtin_popcount(s) == i) {
          dp[i + 1][s | (1 << j)] = (dp[i + 1][s | (1 << j)] + dp[i][s]) % mod;
        }
        if (!s) {
          break;
        }
      }
    }
  }

  cout << dp[n][(1 << n) - 1] << '\n';

  return 0;
}


Measured memory_bytes: 309504
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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



int main(){
    
    int n,d,x;
    cin >> n>> d >> x;

    rep(i,0,n){
        int a;
        cin >> a;
        int day = 1;
        while(day <= d){
            x++;
            day += a;
        }
    }
	P(x);
	return  0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
#define INF (1e9)
#define LINF (1LL << 60)
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,k,n) for(int i=(k);(i)<(n);(i)++)
#define REP(i,n) for(int i = 0;(i)<(n);(i)++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define F first
#define S second
#define MOD (1e9 + 7)

int main() {
	int n, t, a;
	cin >> n >> t >> a;
	vector<int> h(n);
	REP(i, n) cin >> h[i];
	int ans;
	double diff1 = 1e10;
	double diff2;
	REP(i, n) {
		diff2 = abs(a - (t - h[i] * 0.006));
		if (diff2 < diff1) {
			ans = i;
			diff1 = diff2;
		}
	}
	cout << ans + 1 << endl;
}


Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)    cin>>a[i];

    bool x[n+1] = {false};
    int s = 1;
    int cnt=0;
    while(!x[2]){
        x[s] = true;
        if(s==2)    break;
        s = a[s];
        if(x[s])  break;
        cnt++;
    }
    if(!x[2])   cout<<-1<<endl;
    else        cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 768
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N;
string s;

void init()
{
}

void solve()
{
    reverse(ALL(s));
    int n = 0;
    string ss;
    REP(i, s.size()){
        if(s[i] == '('){
            if(n <= 0) ss += ')';
            else n -= 1;
        }
        else n += 1;
    }
    REP(i, n) s += '(';
    s =  ss + s;
    reverse(ALL(s));
    cout << s << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> s;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main(void){
	int n;
	float x[2],y[2];
	pair<float,float> v[2];

	cin >> n;
	for(int i=0;i<n;i++){
		for(int j=0;j<2;j++){
			cin >> x[0] >> y[0] >> x[1] >> y[1];
			v[j]=make_pair(x[0]-x[1],y[0]-y[1]);
		}
		cout << (v[0].first*v[1].second-v[0].second*v[1].first?"NO":"YES") << endl;
	}
		
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
 
using namespace std;
 
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
 
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
 
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
 
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
 
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

  ll A[1000000][100];

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

  rep(i,N){
    ll a;
    cin >> a;
    rep(j,100){
      if(a == 0) break;
      A[i][j] = a % 2;
      a/=2; 
    }
  }
  // rep(i,N){
  //   rep(j,10){
  //     cout << A[i][j];
  //   }
  //   cout << endl;
  // }
  ll ans = 0;
  rep(i,100){
    ll a=0,b=0;
    rep(j,N){
      if(A[j][i] == 0) a++;
      else b++;
    }
    ll mul = pow(2,i);
    mul %= mod;
    ans += (a%mod * b%mod)*mul;
    ans %= mod;
  }
  cout << ans << endl;
  
  
  return 0;
}

  
                           



Measured memory_bytes: 235776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define in freopen("in.txt","r",stdin)
//#define out freopen("out.txt","w",stdout) 
ll n,m,k,t,l,r;
ll b,c,d;
char A,B,C,X,Y,Z;
ll ans,MAX,MIN=40,sum;
ll a[200050],f[200050];
//ll dp1[1000][1000],dp2[1000][1000];
char str[200050],bx[200050];


int main()
{
    ll i,s,x,j;
    t=1;
    //scanf("%lld",&t);
    while(t--)
    {
		cin>>n;
		ll num=0;
		for(i=1;i<=n;i++)
		{
			cin>>a[i];
			if(i%2==1&&a[i]%2==1) num++;
		}
		cout<<num<<endl;
	}
	return 0;
}

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

int main()
{
    unsigned long long int a,b,c,tm;
    cin>>a>>b>>c;
    tm=c;
    for(int i=0;i<10;i++){
        cout<<(a*c)-b<<endl;
        c=(a*tm)-b;
        tm=c;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

import math

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    a, b, x = rli()
    h = x / (a*a)
    if h >= b/2:
        d1 = 2*(b-h)
        d2 = a
        print(math.degrees(math.atan2(d1, d2)))
    else:
        d1 = b
        d2 = 2*a*h/b
        print(math.degrees(math.atan2(d1, d2)))



if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let a = v[0];
	let v:Vec<i32> = procon_read();
	let b = v[0];
	let v:Vec<i32> = procon_read();
	let h = v[0];
	println!("{}", (a+b)*h/2);
}


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

int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	
	long n,a,b,i,j,k,c;
	cin>>n>>a>>b;
	long h[n];
	j=0;
	for(i=0;i<n;i++)
	{
	    cin>>h[i];
	    j=max(j,h[i]);
	    
	}
//	cout<<j<<endl;
	j=(j+b-1)/b;
	
//	cout<<j<<endl;
	long l=0,u=j;
	long m;
	while(l<=u)
	{
	    m=l +(u-l)/2;
	    
	    j=0;
	    for(i=0;i<n;i++)
	    {
	        c=((h[i]-b*m+a-b-1)/(a-b));
	        if(c>0)
	        j=j+c;
	        //cout<<j<<endl;
	    }
//	    cout<<l<<" "<<u<<" "<<j<<endl;
	    if(j<=m)
	    {
	        k=m;
	        u=m-1;
	        //cout<<l<<" "<<u<<" "<<k<<endl;
	    }
	    else
	    {
	        l=m+1;
	    }
	}
	
	cout<<k;
	
	
	
	return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#define N_ 201000
using namespace std;
struct point {
	int num, x;
	bool operator < (const point &p)const {
		return x < p.x;
	}
}w[N_];
int n;
long long BIT[N_], P[N_], R[N_], S[N_], Mod = 1000000007, res, L[N_];
int C[N_];

void Put(int a, int ck) {
	long long t = R[a + 1] * P[a - 1] % Mod;
	int t2 = (ck + 1) / 2;
	t *= ck;
	a = w[a].num;
	while (a <= n) {
		BIT[a] += t;
		C[a] += t2;
		a += (a&-a);
	}
}
long long Sum(int a) {
	long long r = 0;
	while (a) {
		r += BIT[a];
		a -= (a&-a);
	}
	return r % Mod;
}
int Count(int a) {
	int r = 0;
	while (a) {
		r += C[a];
		a -= (a&-a);
	}
	return r;
}
long long Pow(long long a, long long b) {
	long long r = 1;
	while (b) {
		if (b & 1)r = r * a%Mod;
		a = a * a%Mod; b >>= 1;
	}
	return r;
}
int main() {
	int i, j, k;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i].x);
		w[i].num = i;
	}
	sort(w + 1, w + n + 1);
	long long tot = 1;
	L[0] = P[0] = 1;
	for (i = 1; i <= n; i++) {
		S[i] = w[i].x - i + 1;
		if (S[i] <= 0) {
			puts("0");
			return 0;
		}
		tot = 1ll * tot*S[i] % Mod;
		P[i] = P[i - 1];
		L[i] = tot;
		if (S[i] > 1)P[i] = P[i] * (S[i] - 1) % Mod;
	}
	R[n + 1] = 1;
	for (i = n; i >= 1; i--)R[i] = R[i + 1] * S[i] % Mod;
	int pv = n;
	for (i = n; i >= 1; i--) {

		long long t = (1ll * S[i] * (S[i] - 1) / 2) % Mod;
		int c = Count(n) - Count(w[i].num);
		long long s1 = Sum(n);
		long long s2 = Sum(w[i].num);
		s1 = (s1 - s2 + Mod) % Mod;


		long long inv = Pow(P[i], Mod - 2) * L[i - 1] % Mod * t % Mod;
		res = (res + inv * s1 + tot * (n - i - c) - inv * s2%Mod + Mod) % Mod;

		if (S[i] == 1) {
			while (pv > i) {
				Put(pv, -1);
				pv--;
			}
		}
		Put(i, 1);
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 10368
n, m = map(int,input().split())
ab_l = []
for _ in range(n):
    ab_l.append(list(map(int,input().split())))
cd_l = []
for _ in range(m):
    cd_l.append(list(map(int,input().split())))
ans_l = [0]*n

for i in range(n):
    distance_min = float('inf')
    for j in range(m):
        distance = abs(ab_l[i][0]-cd_l[j][0]) + abs(ab_l[i][1]-cd_l[j][1])
        if distance < distance_min:
            distance_min = distance
            ans_l[i] = j+1

for val in ans_l:
    print(val)


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

int main (void){

    int n;
    char answer[4] = "No";
    scanf("%d", &n);

    for(int i = 0; i <= n/7; i++){    
        for(int j = 0; j <= n/4; j++){
  
              if( n == 7*i+4*j){
                strcpy(answer, "Yes");
                break;
               }
          
        }
    }

    printf("%s", answer);
    return 0;   
}


Measured memory_bytes: 128
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
long long n, m;
map<long long, int> mp;

long long P = 1000000007;
class C {
public:
  int n;
  vector<long long> fac, inv, facInv;
  long long power(long long e, long long x) {
    if (x == 0)
      return 1;
    if (x == 1)
      return e;
    if (x % 2 == 0)
      return power((e * e) % P, x / 2);
    return (e * power(e, x - 1)) % P;
  }
  C(int n_) {
    n = n_;
    fac.resize(n + 1);
    inv.resize(n + 1);
    facInv.resize(n + 1);
    fac[0] = fac[1] = 1;
    for (int i = 2; i <= n; i++)
      fac[i] = (i * fac[i - 1]) % P;
    inv[0] = inv[1] = 1;
    for (int i = 2; i <= n; i++)
      inv[i] = power(i, P - 2);
    facInv[0] = facInv[1] = 1;
    for (int i = 2; i <= n; i++)
      facInv[i] = (inv[i] * facInv[i - 1]) % P;
  }
  long long comb(int N, int K) {
    if (N < K || K < 0 || N < 0)
      return 0;
    if (N == 0 || K == 0 || K == N)
      return 1;
    return ((fac[N] * facInv[K]) % P * facInv[N - K]) % P;
  }
  long long hcomb(int N, int K) {
    if (N == 0 && K == 0)
      return 1;
    return comb(N + K - 1, K);
  }
  long long mul(long long a, long long b) { return (a * b) % P; }
  long long add(long long a, long long b) { return (a + b) % P; }
};

void f(long long n) {
  if (n == 1)
    return;
  for (long long j = 2; j * j <= n; j++) {
    if (n % j == 0) {
      mp[j]++;
      n /= j;
      j = 1;
    }
  }
  if (n != 1)
    mp[n]++;
}

int main() {
  cin >> n >> m;
  f(m);
  C c(500000);
  long long ans = 1;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    ans *= c.fac[n + it->second - 1];
    ans %= P;
    ans *= c.facInv[it->second];
    ans %= P;
    ans *= c.facInv[n - 1];
    ans %= P;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N;
int H[21];

int main(){

    cin >> N;
    for(int i = 0;i < N; i++){
        cin >> H[i];
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        bool ok = true;
        for(int j = 0; j < i; j++){
            if(H[i] < H[j]){
                ok = false;
            }
        }
        if(ok)ans++;
    }
    cout<< ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define pint pair<lli,lli>
#define Lower(v,X) lower_bound(v.begin(),v.end(),X)-v.begin();
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
  lli A,B,C,D,E,L,R,X,Y,W,H,N,M,K,sum=0,num=0,flag=0;string S,T;
  cin >> N >> M;
  DV(P,int,M,0,0);
  Vec(Q,int,M,0);
  rep(i,0,M){
    cin >> A;
    rep(j,0,A){
      cin >> B;
      P[i].pb(B-1);
    }
  }
  rep(i,0,M)cin >> Q[i];
  for(int bit=0;bit<(1<<N);bit++){
    flag=true;
    rep(i,0,M){
      for(int q:P[i])if(bit&(1<<q))num++;
      if(num%2!=Q[i])flag=false;
      num=0;
    }
    if(flag)sum++;
  }
  Out(sum);
}


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

int main (void)
{
  int n, count;
  int i,nagare;
  bool start_flag;
  
  cin >> n;
  vector<long long int> a(n);
  for(i=0; i<n; i++)
  {
    cin >> a[i];
  }

  count = 0;
  nagare = 1;
  start_flag = true;

  for(i=0; i<n-2; i++)
  {
    if(start_flag == true && a[i] == a[i+1])continue;
    if(a[i] < a[i+1])nagare = 1;
    if(a[i] > a[i+1])nagare = 0;
    if(nagare == 1)
    {
      if(a[i+1] > a[i+2])
      {
        count++;
        // test_data(i);
        i++;
        start_flag = true;
      }
      else
      {
        start_flag = false;
      }
    }
    
    if(nagare == 0)
    {
      if(a[i+1] < a[i+2])
      {
        count++;
        // test_data(i);
        i++;
        start_flag = true;
      }
      else
      {
        start_flag = false;
      }
    }

  }  
  count++;
  cout << count << endl;
  return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int pars[100000];
class UnionFind{
private:
  vector<int> par, rank;
public:
  UnionFind(int n){
	par.assign(n, 0);
	rank.assign(n, 0);
	for(int i=0;i<n;++i)
	  par[i] = i;
  }

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

  void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(rank[x] < rank[y])
	  par[x] = y;
	else{
	  par[y] = x;
	  if(rank[x] == rank[y])
		++rank[x];
	}
  }

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

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

  int N, Q;
  while(cin >> N >> Q, N){
	pars[0] = 0;
	REP(i,N-1){
	  int p;
	  cin >> p;
	  --p;
	  pars[i+1] = p;
	}
	
	VI marked(N);
	++marked[0];
	vector<PII> qs(Q);
	REP(q,Q){
	  char c;
	  int pyon;
	  cin >> c >> pyon;
	  --pyon;
	  qs[q] = MP(c == 'M'?0: 1, pyon);
	  if(c == 'M') ++marked[pyon];
	}

	UnionFind uf(N);
	VI rt(N);
	iota(ALL(rt), 0);
	REP(i,N){
	  if(!marked[i]){
		int nrt = rt[uf.find(pars[i])];
		uf.unite(i, pars[i]);
		rt[uf.find(i)] = nrt;
	  }
	}

	LL ans = 0;
	for(int q=Q-1;q>=0;--q){
	  int u = qs[q].SS;
	  if(qs[q].FF == 0){
		if(!--marked[u]){
		  int nrt = rt[uf.find(pars[u])];
		  uf.unite(u, pars[u]);
		  rt[uf.find(u)] = nrt;
		}
	  }
	  else{
		ans += rt[uf.find(u)]+1;
	  }
	}
	cout << ans << endl;
  }

  return 0;
}

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

typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;
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; }

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

void printv(vint &v){
    for(auto e:v) cout<<e<<" ";
        cout<<endl;
    }

// 繰り返し二乗法
ll power(ll a, ll b){
    if(a==1)return a;
    // if(a==0)re
    ll res=1;
    while(b>0){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

const int MAX=2100000;

ll fact[MAX], fact_inv[MAX];

void init_fact(ll n){
    fact[0]=1;
    // 階乗の計算
    for(ll i=0; i<n; i++) fact[i+1]=fact[i]*(i+1)%MOD;
    fact_inv[n]=power(fact[n], MOD-2);
    // 逆元の計算
    for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}

ll comb(ll n, ll r){
    return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll perm(ll n, ll r){
    return (fact[n]*fact_inv[n-r])%MOD;
}

int main() {
    cout<<fixed<<setprecision(10);

    ll x,y,a,b,c; cin>>x>>y>>a>>b>>c;
    vint p(a); rep(i,a) cin>>p[i];
    vint q(b); rep(i,b) cin>>q[i];
    vint r(c); rep(i,c) cin>>r[i];

    vint arr;
    sort(ALL(p), greater<ll>());
    sort(ALL(q), greater<ll>());
    sort(ALL(r), greater<ll>());
    rep(i, x) arr.push_back(p[i]);
    rep(i, y) arr.push_back(q[i]);
    rep(i, c) arr.push_back(r[i]);

    sort(ALL(arr), greater<ll>());
    cout << accumulate(arr.begin(), arr.begin()+x+y, 0ll) <<endl;


    return 0;

}

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

struct UnionFind{
    vector<int> parent;
    vector<int> size;
    vector<int> rank;

    /* constructor (initialize) */
    UnionFind(int n){
        parent.resize(n);
        size.resize(n);
        rank.resize(n);
        for(int i=0; i<n; i++){
            parent[i] = i;// completely-disjoint
            size[i] = 1;
            rank[i] = 0;// union by rank
        }
    }

    int root(int x){
        // terminal case
        if(parent[x] == x){
            return x;// by definition
        }

        // recursion
        parent[x] = root(parent[x]);// path compression : keep tree as shallow as possible
        return parent[x];
    }

    void merge(int x, int y){
        int rx = root(x);
        int ry = root(y);

        // if (root(x) == root(y)) do nothing;
        if (rx != ry){
            if(rank[rx] < rank[ry]){
                parent[rx] = ry;// root of merged tree = ry
                size[ry] += size[rx];
            }
            else if(rank[rx] == rank[ry]){
                parent[rx] = ry;
                size[ry] += size[rx];
                rank[ry] += 1;
            }
            else if(rank[rx] > rank[ry]){
                parent[ry] = rx;// root of merged tree = rx
                size[rx] += size[ry];
            }
        }
        return;
    }

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

    int nodes(int x){
        return size[root(x)];
    }
};

int main(){
    long long int n, m;
    cin >> n >> m;

    vector<int> a(m), b(m);
    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i];
        a[i] -= 1;
        b[i] -= 1;
    }

    long long int count = 0;
    vector<long long int> ans(m);
    
    for(int x=0; x<m; x++){
        UnionFind uf(n);
        for(int i=0; i<m; i++){// for each edge
        //for(int i=m-1; i>=0; i--){
            if(i == x) continue;
            if(uf.same(a[i],b[i]) == false){
                // any additional operation
                // (ex.) count = uf.nodes(a[i]) * uf.nodes(b[i]);
                uf.merge(a[i], b[i]);
            }
        }
        for(int j=0; j<n; j++){
            if(uf.same(0,j) == false){
                count += 1;
                break;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/abc107/tasks/arc101_a
# C - Candles
"""
need to consider the case that ticket is not enough to lower everything
"""

s = gw()
K = gi()
ss = set()

for i in range(len(s)):
    for k in range(1, K + 1):
        if i + k > len(s):
            break
        ss.add(s[i:i + k])

sl = []
for st in ss:
    sl.append(st)
sl.sort()
print(sl[K - 1])


Measured memory_bytes: 20460
<?php
fscanf(STDIN, '%d %d', $a, $b);
$gcd = gcd($a, $b);
$divisors = divisors($gcd);
$ans = 1;
foreach ($divisors as $v) {
    if (isPrime($v)) $ans++;
}
echo $ans . PHP_EOL;

/**
 * エラトステネスのふるい
 * $maxまでの整数が素数かどうかboolを格納した配列を返す
 */
function isPrimeArr($max)
{
    $arr = array_fill(0, $max + 1, true);
    $arr[0]  = $arr[1] = false;
    $rmax = (int) floor(sqrt($max));
    for ($i = 2; $i <= $rmax; $i++) {
        for ($j = 2 * $i; $j <= $max; $j += $i) {
            $arr[$j] = false;
        }
    }
    return $arr;
}

function isPrime($n)
{
    if ($n === 1) return false;
    $rmax = (int) floor(sqrt($n));
    for ($i = 2; $i <= $rmax; $i++) {
        if ($n % $i === 0) return false;
    }
    return true;
}

function primes($max)
{
    $arr = [];
    for ($i = 2; $i <= $max; $i++) {
        if (isPrime($i)) $arr[] = $i;
    }
    return $arr;
}

function divisors($max)
{
    $arr = [];
    $rmax = (int) floor(sqrt($max));
    for ($i = 1; $i <= $rmax; $i++) {
        if ($max % $i === 0) {
            $arr[] = $i;
            $arr[] = $max / $i;
        }
    }
    sort($arr);
    return array_unique($arr);
}

// 最大公約数（2つ）
function gcd($m, $n)
{
    if (!$n) return $m;
    return gcd($n, $m % $n);
}

// 最大公約数（3つ以上）
function gcdAll($arr)
{
    $gcd = $arr[0];
    for ($i = 0; $i < count($arr); $i++) {
        $gcd = gcd($gcd, $arr[$i]);
    }
    return $gcd;
}

// 最小公倍数（2つ）
function lcm($m, $n)
{
    return $m * $n / gcd($m, $n);
}

// 最小公倍数（3つ以上）
function lcmAll($arr)
{
    $lcm = $arr[0];
    for ($i = 0; $i < count($arr); $i++) {
        $lcm = lcm($lcm, $arr[$i]);
    }
    return $lcm;
}

Measured memory_bytes: 4604
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    char a,b;
    cin >> a >> b;
    if(a == 'H') cout << b << endl;
    else{
        if(b == 'H') cout << 'D' << endl;
        else cout << 'H' << endl;
     }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x;
    scanf("%d %d",&n,&x);
    int a, i=0, l[n];
    int d[n];
    int ans;
    d[0] = 0;
    for (int i = 0 ;i < n;i++){
        cin >> l[i];
    }
    for (int i = 1; i < n+1;i++){
        d[i] = d[i-1] + l[i-1];
        if (d[i] > x){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = a + b;
		if (c < 10) {
			System.out.println(c);
		} else {
			System.out.println("error");
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 21076
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N; cin >> N;
    vector<vector<long long> > v(50, vector<long long>(50));
    for (int i = 0; i < N; i++) {
        double a; cin >> a;
        long long A = a * 1000000000 + 0.1;
        long long A_tmp = A;
        int two = 0, five = 0;
        while (A_tmp % 2 == 0) {
            A_tmp /= 2;
            two++;
        }
        A_tmp = A;
        while (A_tmp % 5 == 0) {
            A_tmp /= 5;
            five++;
        }
        v[two][five]++;
    }

    long long ans = 0;
    for (int i = 0; i < 50; i++) {
        for (int j = 0; j < 50; j++) {
            for (int k = 0; k < 50; k++) {
                for (int l = 0; l < 50; l++) {
                    if (i + k >= 18 && j + l >= 18) {
                        if (i == k && j == l && v[i][j] != 0) ans += v[i][j] * (v[k][l] - 1);
                        else ans += v[i][j] * v[k][l];
                    }
                }
            }
        }
    }

    ans /= 2;
    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3736
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>


     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define sz size()
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

     
const ll MOD = 1e9 + 7;
const ll ZER = 0;



int main(){
    ll n;
    cin >> n;
    ll res = 0;
    REP(i, 1, n - 1){\
        ll cnt = (n + i - 1) / i - 1;
        res += cnt;
    }
    cout << res << endl;
}





Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int n,q,k,a[2010];
typedef pair<int,int> P;
P b[2010];
//bool vis[2010];
set<int> v;
int main(){
    cin>>n>>k>>q;
    lol(i,n){
	cin>>a[i];
	//vis[i]=0;
	b[i]=make_pair(a[i],i);
    }
    sort(b,b+n);
    v.insert(-1);
    v.insert(n);
    int ans=b[q-1].first-b[0].first;
    //cout<<b[q-1].first<<" "<<b[0].first<<" "<<ans<<endl;
    lol(i,n){
	int x=b[i].second;
	v.insert(x);
	vector<int> e;
	auto it=v.begin(),ir=v.begin();ir++;
	lol(j,v.size()-1){
	    //cout<<*it<<" "<<*ir<<endl;
	    vector<int> p;
	    for(int r=*it+1;r<*ir;r++){
		p.push_back(a[r]);
	    }
	    sort(p.begin(),p.end());
	    lol(r,*ir-*it-k)e.push_back(p[r]);
	    it++,ir++;
	}
	sort(e.begin(),e.end());
	if(e.size()>=q)ans=min(ans,e[q-1]-e[0]);
    }
    //if(n==5&&k==3&&q==2)cout<<"#";
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int GCD(int, int);

int main(){
	int a, b, x, y;
	while(scanf("%d %d", &a, &b) != EOF){
		x = GCD(a, b);
		y = a/x*b;
		printf("%d %d\n", x, y);
	}
	return 0;
}

int GCD(int s, int t){
	if(s%t == 0){
		return t;		
	}else{
		return GCD(t, s%t);
	}
}

Measured memory_bytes: 596
import copy
H,W,K = map(int,input().split())
C = []
for i in range(H):
    C.append(input())
D = copy.deepcopy(C)
count = 0
for j in range(2**(H+W)):
    a = str(bin(j))[2:]
    a = '0'*(H+W-len(a))+a
    for k in range(H):
        if a[k] == '0':
            C[k] = 'r'*W
    for l in range(W):
        if a[H+l] == '0':
            for q in range(H):
                C[q] = C[q][:l] + 'r' + C[q][l+1:]
    b = 0
    for t in range(H):
        b += C[t].count('#')
    if b == K:
        count += 1
    C = copy.deepcopy(D)
print(count)

Measured memory_bytes: 9352
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

ll N , limt;
vector<ll> w;
map<ll, vector<ll> > val;

bool func(ll a, ll b ){
    if(a == 0) return true;
    if(b == 0) return false;
    else return a > b ;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N ;
    cin >> limt;
    
    rep(i,N){
        ll a,b;
        cin >> a >> b ;
        w.pb(a);
        val[a].pb(b);
    }
    
    rmsame(w);
    rep(i, w.size()){
        ll num = w[i];
        val[num].pb(0);
        sort(all(val[num]), func);
    }
    rep(i,w.size())rep(j, val[w[i]].size()){
        if(j == 0) continue;
        val[w[i]][j] += val[w[i]][j-1];
    }
    
    while(w.size() != 4){
        ll num = w[w.size()-1];
        num++;
        w.pb(num);
        val[num].pb(0);
    }
    
    
    ll ans = 0;
    

    rep(i, val[w[0]].size())rep(j, val[w[1]].size())rep(k, val[w[2]].size())rep(l, val[w[3]].size()){
        if((i*w[0] + j*w[1] + k*w[2] + l*w[3])>limt) continue;
        
        ll ret = val[w[0]][i] + val[w[1]][j] + val[w[2]][k] + val[w[3]][l];
        ans = max(ans, ret);
    }
    cout << ans << endl;
    
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
#define ALL(a) a.begin(),a.end()
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

bool IsPrime(ll num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll ans = 0;
    for (int i = 0; i < n-1; i++){
        if (s[i] != s[i+1]) {
            ans++;
        }
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

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

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

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;

ll ans=0;

void solve(vll h){
    if(h.size()==0)return;
    if(h.size()==1){
        ans+=h[0];
        return;
    }
    
    ll min=LLMAX;
    int min_index=-1;
    for(int i=0;i<h.size();i++){
        if(h[i]<min){
            min=h[i];
            min_index=i;
        }
    }
    
    for(ll i=0;i<h.size();i++){
        h[i]-=min;
    }
    
    ans+=min;
    vll a(min_index);
    vll b(h.size()-min_index-1);
    for(int i=0;i<min_index;i++){
        a[i]=h[i];
    }
    for(int i=min_index+1;i<h.size();i++){
        b[i-min_index-1]=h[i];
    }
    solve(a);
    solve(b);
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    cin>>N;
    vll h(N);
    for(ll i=0;i<N;i++)cin>>h[i];
    solve(h);
    cout<<ans<<endl;
    
    return 0;
}


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

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A;
  for (int i = 0; i < N; i++)
    {
      int Ai;
      cin >> Ai;
      A.emplace_back(Ai);
    }

  // cyclic
  A.emplace_back(K + A[0]);
    
  int max_dist = 0;
  for (int i = 0; i < N; i++)
    {
      const int dist = (A[i + 1] - A[i]);
      if (dist > max_dist)
	max_dist = dist;
    }
  cout << K - max_dist << endl;
}


Measured memory_bytes: 1400
chomp($n = <>);

$r = "No";
for $i (0 .. int($n / 4)){
	last if($r eq 'Yes');
	for $p (0 .. int($n / 7)){
		if(($i * 4) + ($p * 7) == $n){
			$r = "Yes";
			last;
		}
	}
}

print "$r\n";


Measured memory_bytes: 384
import scala.io.StdIn

object Main {

  def main(args: Array[String]): Unit = {
    val Array(n, d) = StdIn.readLine().split(' ').map(_.toInt)
    val range = 2 * d + 1
    val remain = if (n % range == 0) 0 else 1
    val ans = n / range + remain
    println(ans)
  }

}

Measured memory_bytes: 25544
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k;
  cin >> n >> k;
  vector<int> snk(n, 0);
  REP(i,k){
    int d;
    cin >> d;
    REP(j,d){
      int a;
      cin >> a;
      snk[a-1]++;
    }
  }
  int ans = 0;
  REP(i,n) if(snk[i]==0) ans++;
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

int main() {
  long long H;
  cin >> H;
  long long cnt = 1;
  long long ans = 0;
  while (H > 0) {
    ans += cnt;
    H /= 2;
    cnt *= 2;
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 256
n,k = map(int,input().split())
mod = 10**9 + 7

b = k
r = n - k

from operator import mul
from functools import reduce
def cmb(n,r):
    if n<r:
        return 0
    else:
        r = min(n-r,r)
        if r == 0: return 1
        over = reduce(mul, range(n, n - r, -1))
        under = reduce(mul, range(1,r + 1))
        return over // under

# a = cmb(n,k)
# print(a)

for i in range(b):
    ans = cmb(r+1,i+1) * cmb(b-1,i)
    print(ans%mod)

Measured memory_bytes: 47452
import sys
n = int(input())
c = 1
a = list(map(int,input().split()))
ok = 0;
for i in range(0,n):
    c *= a[i]
    if c > 1000000000000000000:
        ok = 1
        break
for i in range(0,n):
    if a[i] == 0:
        ok = 0
        c = 0
if (ok):
    print(-1)
else:
    print(c)


Measured memory_bytes: 21656
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
    string s;
	cin >> s;
    const string ss = "CF";
    int j = 0;
    string ans = "No";
    rep(i,int(s.size())) {
        if (s[i] == ss[j]) j++;
        if (j>=2) ans = "Yes";
    }
	cout << ans << endl;
	return 0;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N)
  cin >> a[i];
  ll ans = 0;
  REP(i, N)
  ans += (ll)(a[i] - 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
N2 = N
logN = 0
while N2 // 10 > 0:
    logN += 1
    N2 //= 10

Ans1, Ans2 = 0, 0
for i in range(logN):
    Ans1 += 9*(10**i)
    Ans2 += 9*(10**i)
Ans1 += N2 * (10**logN)
Ans2 += (N2-1) * (10**logN)
if Ans1 <= N:
    print(N2 + 9 * logN)
else:
    print(N2 - 1 + 9 * logN)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int x, res;
    vector<int> val;
    for (int i = 0; i < 5; ++i) {
        cin >> x;
        val.push_back(x);
        if (x == 0) res = i + 1;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3544
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

//struct custom_hash {
//    static uint64_t splitmix64(uint64_t x) {
//        // http://xorshift.di.unimi.it/splitmix64.c
//        x += 0x9e3779b97f4a7c15;
//        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//        return x ^ (x >> 31);
//    }
//    size_t operator()(uint64_t x) const {
//        static const uint64_t FIXED_RANDOM = 
//            chrono::steady_clock::now().time_since_epoch().count();
//        return splitmix64(x + FIXED_RANDOM);
//    }
//};

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	if(n%10==7)
	{
		cout<<"Yes";
		return 0;
	}
	n/=10;
	if(n%10==7)
	{
		cout<<"Yes";
		return 0;
	}
	n/=10;
	if(n%10==7)
	{
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
    return 0;
}


//252908XL

/*
comments:-

*/


Measured memory_bytes: 3572
H,W=map(int,input().split())
if W==1 or H==1:
	print(1)
elif H%2==0 and W%2==0:
	print((H//2)*(W))
elif H%2==1 and W%2==0:
	print(H*W-((H//2)*(W//2))-((H//2)+1)*(W//2))
elif H%2==0 and W%2==1:
	print(H*W-((W//2)*(H//2))-((W//2)+1)*(H//2))
else:
	print(H*W-((H//2)*((W//2)+1))-((H//2)+1)*(W//2))

Measured memory_bytes: 38384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

ll n, m;
bool ok(ll mm){
    if(m < mm * 2)
        return false;
    ll r = m - mm * 2;
    ll nn = n + r/2;
    if(nn >= mm)
        return true;
    else
        return false;
}

int main(){
    fastIO;
    cin >> n >> m;
    ll L = 0, R = (ll)1e14;
    ll M;
    ll nm;
    ll nn;
    while(L + 1 < R){
        M = (L + R) / 2;
        if(ok(M))
            L = M;
        else
            R = M;
    }
    cout << L;
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 1; i < n - 1; i++) if (a[i - 1] != a[i] && a[i] != a[i + 1]) a[i] = -1;
  a[0] = a[1];
  a[n - 1] = a[n - 2];
  sort(a, a + n);
  int m1 = a[n - 1];
  long long res;
  if (m1 != -1 && a + n - lower_bound(a, a + n, m1) >= 4) res = (long long) m1 * m1;
  else {
    int m2 = *(lower_bound(a, a + n, m1) - 1);
    res = (long long) m1 * m2;
  }
  res = max(res, 0LL);
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int i,n;
  int c = 0;
  char s[200];
  scanf("%d%s",&n,s);
  if(n%2 == 1) printf("No");
  else {
    for(i=0;i<n/2;i++){if(s[i] == s[i+n/2]) c++;}
  	if(c == n/2) printf("Yes");
  	else printf("No");
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;
    cout << max(0, A - 2 * B) << endl;
}


Measured memory_bytes: 256
j,p[1<<20],n;
main(i)
{
	for(;++i<999;)
		if(!p[i])
			for(j=i+i;j<1<<20;j+=i)
				p[j]=1;
	for(;scanf("%d",&n),j=0,n;printf("%d\n",j))
		for(i=2;i<=n/2;i++)if(!p[i]&!p[n-i])j++;
	return 0;
}

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

int main() {
	int N, A, B, C, D;
	cin >> N;
	vector<tuple<int, int, int>> a(N);
	for (int i = 0; i < N; ++i) get<0>(a[i]) = 1 + i;
	for (int i = 0; i < (N - 1) * N / 2; ++i) {
		cin >> A >> B >> C >> D;
		if (C < D) get<1>(a[B - 1]) += 3;
		else if (C == D) {
			++get<1>(a[A - 1]);
			++get<1>(a[B - 1]);
		}
		else get<1>(a[A - 1]) += 3;
	}
	sort(a.begin(), a.end(), [](tuple<int, int, int>& a, tuple<int, int, int>& b) { return get<1>(a) > get<1>(b); });	
	for (int i = 0; i < N; ++i) get<2>(a[i]) = 1 + i;
	for (int i = 1; i < N; ++i) {
		if (get<1>(a[i - 1]) == get<1>(a[i])) get<2>(a[i]) = get<2>(a[i - 1]);
	}
	sort(a.begin(), a.end());
	for (tuple<int, int, int>& i : a) cout << get<2>(i) << endl;
}


Measured memory_bytes: 3120