akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
using namespace std;
 
#define INF (int) 1000000000
 
typedef long long ll;
 
int n, k, arr[105], grundy[101005];
 
int mex(set<int> s){
    int ans = 0;
    while(s.find(ans) != s.end()){
        ans++;
    }
    return ans;
}
 
int find_grundy(int a){
//    cout << "finding the grundy of: " << a << endl;
    if(a == 0){
        return 0;
    }
    if(grundy[a] != -1){
        return grundy[a];
    }
    set<int> grundies;
    for(int i = 0; i < n; i++){
        if(a >= arr[i]){
            grundies.insert(find_grundy(a-arr[i]));
        }
    }
    grundy[a] = mex(grundies);
    return grundy[a];
}
 
int main(){
    for(int i = 0; i < 100005; i++){
        grundy[i] = -1;
    }
 
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    if( find_grundy(k) != 0 ){
        cout << "First";
    }
    else{
        cout << "Second";
    }
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) {
		cout << "a > b" << endl;
	}
	else if (a < b) {
		cout << "a < b" << endl;
	}
	else {
		cout << "a == b" << endl;
	}
	

}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
int gcd (int x, int y) {
    if (x < y) swap(x, y);
    if (y == 0) return x;
    return gcd(x % y, y);
}
int main() {
    int n;
    cin>>n;
    vector<int>a(n+2,0);
    rep(i,n) cin>>a.at(i+1);
    
    vector<int> left(n+2), right(n+2);
    rep(i,n) left.at(i+1)=gcd(left.at(i),a.at(i));
    rrep(i,n) right.at(i+1)=gcd(right.at(i+2),a.at(i+2));
    
    int ans=-1;
    rep(i,n) ans=(max)(ans,gcd(left.at(i+1),right.at(i+1)));
    cout<<ans<<endl;
}


Measured memory_bytes: 1408
/**
*    created: 12.05.2020 09:27:58
**/
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int w, h, x, y;
    cin >> w >> h >> x >> y;
    double s = abs(w * h);
    cout << fixed << setprecision(15);
    if (2 * x == w && 2 * y == h) cout << s / 2 << " " << 1 << endl;
    else cout << s / 2 << " " << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	string s;
	cin >> s;

	int ans = 0;
	int t = 0;
	rep(i, n){
		if(s[i] == 'I'){
			t++;
			ans = max(ans, t);
		}else{
			t--;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

class UnionFind {
public:
  vector<int> par, rank;
  // if par is negative, it is a root, of which tree size is the abs-value.
  // rank represents depth
  UnionFind(int sz) : par(sz, -1), rank(sz, 0){}
  int find(int x){
    if(par[x]<0) return x;
    else 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]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    if(rank[x]==rank[y]) rank[x]++;
  }
  inline bool same(int x, int y){ return find(x) == find(y); }
  inline int size(int x){ return -par[find(x)]; }
};


bool solve(){
  string s;
  int n;
  cin>>s>>n;
  vector<int> l(n),r(n);
  rep(i,n) cin>>l[i]>>r[i];

  if(s.size()==1) return true;

  int m = s.size() + 1;
  vector<int> diff(m);
  rep(i,m-2) diff[i+1] = s[i+1] - s[i];
  diff[0] = s[0] - 'a';
  diff[m-1] = 'a' - s.back();

// dbg(diff);
  UnionFind uf(m);
  rep(i,m/2) uf.unite(i, m-i-1);

  rep(i,n) uf.unite(l[i]-1, r[i]);

  vector<int> acc(m,0);
  rep(i,m) acc[uf.find(i)] += diff[i];

  rep(i,m) if(acc[i]%26 != 0) return false;

  return true;
}

int main(){
  if(solve()) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 2816
class Card():
    def __init__(self, suit, value):
        self.suit = suit
        self.value = value
    
    def __eq__(self, ins):
        if not isinstance(ins, Card):
            return NotImplemented
        return self.suit == ins.suit and self.value == ins.value

def bubbleSort(C, N):
    for i in range(N):
        for j in range(n-1, i, -1):
            if C[j].value < C[j-1].value:
                C[j], C[j-1] = C[j-1], C[j]

def selectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[minj].value > C[j].value:
                minj = j
        C[i], C[minj] = C[minj], C[i]

def printCard(C, N):
    c = [C[i].suit + C[i].value for i in range(N)]
    print(' '.join(c))

def isStable(inc, outc, N):
    for i in range(N):
        for j in range(i+1, N):
            for a in range(N):
                for b in range(a+1, N):
                    if inc[i].value == inc[j].value and inc[i] == outc[b] and inc[j] == outc[a]:
                        return False
    return True


n = int(input())
input_cards = [Card(*c) for c in input().split()]
output_cards = input_cards.copy()
bubbleSort(output_cards, n)
printCard(output_cards, n)
if isStable(input_cards, output_cards, n):
    print('Stable')
else:
    print('Not stable')
output_cards = input_cards.copy()
selectionSort(output_cards, n)
printCard(output_cards, n)
if isStable(input_cards, output_cards, n):
    print('Stable')
else:
    print('Not stable')


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)
#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl

inline ll cube(ll n){return n*n*n;}

int main(){
    ll n,k;
    cin>>n>>k;
    if(!(k%2)){
        //cerr << n / (k / 2) - n / k;
        cout<< cube(n / k) + cube(n / (k / 2) - n / k) << endl;
    }else{
        cout<<cube(n/k)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N, M = list(map(int, input().split()))

ACflg = [0] * N
WAflg = [0] * N

WAcnt = 0
for _ in range(M):
    p, S = list(input().split())
    p = int(p)
    if(S == "AC"):
        if(ACflg[p-1] == 0):
            ACflg[p - 1] = 1
            WAcnt += WAflg[p-1]
    
    else:
        if(ACflg[p - 1] == 0):
            WAflg[p - 1] += 1

#    print(ACflg)
#    print(WAflg)

print(sum(ACflg), WAcnt)

Measured memory_bytes: 4596
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

struct UF {
    vector<int> data;

    UF(int n) {
        data.resize(n, -1);
    }

    int root(int i) {
        return data[i] < 0 ? i : data[i] = root(data[i]);
    }

    int size(int i) {
        return -data[root(i)];
    }

    void unite(int x, int y) {
        x = root(x), y = root(y);

        if (x == y) return ;

        if (size(x) < size(y)) swap(x, y);

        data[x] += data[y];
        data[y] = x;
    }

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

int N, M;

int main()
{
    while (cin >> N >> M, N) {
        UF uf(N);

        vector<pair<int, pii>> edges;

        for (int i = 0; i < M; ++i) {
            int s, t, c; cin >> s >> t >> c;

            --s, --t;

            edges.push_back(make_pair(c, pii(s, t)));
        }

        sort(begin(edges), end(edges));

        vector<int> a;

        for (pair<int, pii> e : edges) {
            int cost = e.first;
            pii info = e.second;
            if (!uf.same(info.first, info.second)) {
                uf.unite(info.first, info.second);
                a.push_back(cost);
            }
        }

        sort(begin(a), end(a));

        cout << a[a.size() / 2] << endl;
    }
}

Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int ans=0,f=0;s='0'+s;
	for(int i=s.size()-1;i>=0;i--)
		if(s[i]+f-'0'<10-s[i]-f+'0'||s[i]+f-'0'==10-s[i]-f+'0'&&s[i-1]<'5')
		{ans+=f+s[i]-'0';f=0;}
		else
		{ans+=10-s[i]-f+'0';f=1;}
	cout<<ans+f<<endl;
	return 0;
}

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

int main()
{
    int a[105];
    int i,j,k,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    int mx=999999999,sum,t;
    for(k=1;k<100;k++){
            sum=0;
        for(i=0;i<n;i++){
            sum+=(a[i]-k)*(a[i]-k);
        }
        if(sum<mx)
        {
            t=i;
            mx=sum;
        }
        else break;
    }
    printf("%d",mx);
    return 0;
}


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

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

const int MAXN = 100;

int N;
char S[MAXN+10];
ll K, ans;

int main()
{
    int i, j;

    scanf("%s%d", S+1, &K);
    N=strlen(S+1);

    vector<int> V;
    int cnt=0;
    for(i=1; i<=N; i++)
    {
        cnt++;
        if(S[i]!=S[i+1])
        {
            V.push_back(cnt);
            cnt=0;
        }
    }

    if(V.size()==1)
    {
        ans=K*N/2;
    }
    else
    {
        for(i=1; i+1<V.size(); i++) ans+=K*(V[i]/2);
        if(S[1]==S[N]) ans+=V[0]/2+V[V.size()-1]/2+(V[0]+V[V.size()-1])/2*(K-1);
        else ans+=V[0]/2*K+V[V.size()-1]/2*K;
    }
    printf("%lld", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset>
#include <string>
#include <cmath>
#include <set>
#include <map>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
#define ev g[i].y
using namespace std;
typedef long long ll;
typedef double db;
const int N = 200005;
int n, sz, pos[N], m1[N], m2[N], low[N], b[N];
ll ans;
char s[N];
struct edge { int y, nex; } g[N * 2];
void init(int x, int y) { g[++ sz] = (edge) { y, pos[x] }, pos[x] = sz; }
void dfs1(int x, int fa) {
	low[x] = n;
	if (s[x] == '1') b[x] ++, low[x] = 0;
	RepE(i, x) if (ev != fa) {
		dfs1(ev, x);
		b[x] += b[ev];
		int z = m1[ev] + 1;
		if (m1[x] < z) m2[x] = m1[x], m1[x] = z;
		else m2[x] = max(m2[x], z);
		if (b[ev]) low[x] = min(low[x], z);
	}
}
void dfs2(int x, int fa) {
	RepE(i, x) if (ev != fa) {
		int z;
		if (m1[x] == m1[ev] + 1) z = m2[x] + 1;
		else z = m1[x] + 1;
		if (m1[ev] < z) m2[ev] = m1[ev], m1[ev] = z;
		else m2[ev] = max(m2[ev], z);
		if (b[ev] < b[1]) low[ev] = min(low[ev], z);
		dfs2(ev, x);
	}
//	cout <<x<<" "<< m1[x]<<" "<<m2[x]<<" "<<low[x]<<endl;
	int z = min(m2[x] + 1, m1[x] - 1);
	if (z >= low[x]) ans += z - low[x] + 1;
//	if (m1[x] == m2[x]) ans --;
}
int main()
{
	scanf ("%d", &n);
	Rep(i, 1, n - 1) {
		int x, y;
		scanf ("%d%d", &x, &y);
		init(x, y), init(y, x);
	}
	scanf ("%s", s + 1);
	dfs1(1, 0);
	dfs2(1, 0);
	printf("%lld\n", ans + 1);

	return 0;
}

Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int t;
  int s;
  int A;
  cin >> A;
  for ( int l = 0 ; A == ( ( A / 2 ) * 2 ) ; A = A / 2 ) {
    t++;
  }
  s = t;
  if ( N == 1 ) {
    cout << t << endl;
  }
  else {  
    for ( int i = 0 ; i < ( N - 1 ) ; i++ ) {
      int A;
      cin >> A;
      t = 0;
      for ( int l = 0 ; A == ( ( A / 2 ) * 2 ) ; A = A / 2 ) {
        t++;
      }
      if ( s > t ) { 
        s = t;
      }
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>

using namespace std;

int MAX = 1010;

void solve(int n, int W, vector<int> v, vector<int> w) {
	int **dp = new int*[n];
	for (int i=0; i<n; i++) {
		dp[i] = new int[MAX+1];
		for (int j=0; j<MAX+1; j++)
			dp[i][j] = 0;
	}

	dp[0][w[0]] = v[0];
	for (int i=1; i<n; i++) {
		for (int j = 0; j<MAX+1; j++) {
			dp[i][j] = max(dp[i][j], dp[i-1][j]);
			if (j+w[i] <= W) dp[i][j+w[i]] = max(dp[i][j+w[i]], dp[i-1][j]+v[i]);
		}
	}

	int val = -1, weight = 0;
	for (int j=0; j<=W; j++) {
		if (val < dp[n-1][j]) {
			val = dp[n-1][j];
			weight = j;
		}
	}

	cout << val << endl << weight << endl;

	for (int i=0; i<n; i++)
		delete [] dp[i];
	delete [] dp;
}

int main() {
	

	int n, W;
	int ver = 1;

	cin >> W;
	while (W!=0) {
		cin >> n;

		vector<int> v(n), w(n);
		for (int i=0; i<n; i++)
			scanf("%d,%d", &v[i], &w[i]);

		cout << "Case " << ver << ":" << endl;
		solve(n, W, v, w);

		cin >> W;
		ver++;
	}

	return 0;
}

Measured memory_bytes: 5076
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define F first
#define S second
#define SHN 1e9
#define lSHN 1e18
using namespace std;
ll n,res=0;
int main()
{
	cin >>n;
	for (ll i=1;(n-i)/i>i;i++) if ((n-i)%i==0) res+=(n-i)/i;
	cout <<res;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
int n,m,k,x,y,c;
int a[maxn],b[maxn];
int ans = inf;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m >> k;
	int ma = inf,mb = inf;
	for(int i = 1;i <= n;i++) {
		cin >> a[i];
		ma = min(ma,a[i]);
	}
	for(int i = 1;i <= m;i++) {
		cin >> b[i];
		mb = min(mb,b[i]);
	}
	ans = ma + mb;
	for(int i = 1;i <= k;i++){
		cin >> x >> y >> c;
		ans = min(ans,a[x] + b[y] - c);
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	LL sum = 0;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	LL cur = 0;
	LL ans = INF * INF;
	for (int i = 1; i < n; i++)
	{
		cur += a[i];
		sum -= a[i];
		ans = min(ans, abs(cur - sum));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
int main()
{
	int t;
	bool f1=0;
	scanf("%d",&t);
	while(t--)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		if((b+c)>a||(b+c)%2!=a%2)
			f1=1;
	}
	if(f1)
		puts("No");
	else
		puts("Yes");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
vector<long long > v;
bool judge(int num){
	bool is[3] = {0};
	while(num>0){
		if( num % 10 == 3)
			is[0] = 1;
		if( num % 10 == 5)
			is[1] = 1;
		if( num % 10 == 7)
			is[2] = 1;
		num/=10;
	}
	if(is[0]&&is[1]&&is[2])
		return 1;
	return 0;
}
void dfs(long long now){
	if(now > 1000000000){
		return ;
	}
	v.push_back(now *10 + 3);
	v.push_back(now *10 + 5);
	v.push_back(now *10 + 7);
	dfs(now *10 + 3);
	dfs(now *10 + 5);
	dfs(now *10 + 7);
}
int main() {
	int n;
	cin >> n;
	dfs(0);
	sort(v.begin(),v.end());
	int ans = 0;
	for(int i = 0; v[i] <= n; i++){
		if(judge(v[i]))
			ans++;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

#define fi first
#define se second
#define pb push_back
#define MP std::make_pair
#define PII std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define CL(a, b) memset(a, b, sizeof a)
#define rep(i, l, r) for (int i = (l); i <= (r); ++ i)
#define per(i, r, l) for (int i = (r); i >= (l); -- i)
#define PE(x, a) for (int x = head[a]; x;x = edge[x].next)

typedef long long ll;

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	ll c = 1ll * a / std::__gcd(a, b) * b;
	printf("%lld", c);
	return 0;
}

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


int main() {
    int N;
    cin >> N;
    vector<int> x(N);
    for(int i=0;i<N;i++) cin >> x[i];
    sort(x.begin(), x.end());
    int first=x[0];
    int end = x[x.size()-1];
    ll ans = 100000000000;
    for(int i=first;i<=end;i++){
    ll n = 0;
    for(int j=0;j<N;j++) {
        n += pow(x[j]-i,2);
    }
        ans = min(ans,n);
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [u64; n], }
//
// # matrix
// input! { n: usize, m: usize, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }
 
// https://practice.contest.atcoder.jp/tasks/practice_1

fn main() {
    input! {
         n: usize, q: usize,
         s: chars,
         t: [(usize, usize); q]
    }
    let mut sum = vec![0;100000];
    for (i, c) in s.iter().enumerate() {
        if i >= 1 { sum[i] += sum[i-1]; }
        if i >= 1 && s[i-1] == 'A' && s[i] == 'C' {
            sum[i] += 1;
        } 
    }
    for (l,r) in t { 
        //println!("l-1: {} sum[l-1]: {}", l-1, sum[l-1]);
        //println!("r-1: {} sum[r-1]: {}", r-1, sum[r-1]);
        println!("{}",sum[r-1]-sum[l-1]);
    }
    //println!("{:?}", sum);
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
  	vector<int>so;
	for(int i=0;i<n;++i)
    {
      int n;
      cin>>n;
      so.push_back(n);
    }
	sort(so.begin(), so.end());
	int r=so[n/2]-so[n/2 -1];
	cout<<r;
	return 0;
}


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

int main() {
    string s ;
    cin >> s ;
    
    int x=0 ;
    
    for(int i=0;i< s.size();i++){
        if( s.at(i) == '1'){
            x+= 1 ;
        }
    }
    cout<< x << endl;
}



Measured memory_bytes: 3488
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
vvi E(222222);
ll dp[222222];
ll dfs(ll now,ll par){
  map<ll,ll>MP;
  for(auto a:E[now]){
    if(a==par)continue;
    MP[dfs(a,now)]++;
  }
  if(MP.size()==0)return dp[now]=0;
  else{
    ll num=-1;
    for(auto a:MP)
      num=(a.F>num)?a.F+a.S-1:num+a.S;
    return dp[now]=num+1;
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  for(int i=0;i<n-1;i++){
    ll a;cin>>a;
    E[--a].pb(i+1);
    E[i+1].pb(a);
  }
  fill(dp,dp+222222,llINF);
  cout<<dfs(0,-1)<<endl;
  return 0;
}


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

int main() {
	ios_base::sync_with_stdio( false );
	
	double W, H, x, y;
	cin >> W >> H >> x >> y;
	cout << fixed << setprecision( 10 );
	cout << W*H/2.0 << ' ' << (2*x == W && 2*y == H ? 1 : 0) << endl;

	return 0;
}


Measured memory_bytes: 256
def main():
    stack = list(input().split(' '))
    stack_x = list()
    for s in stack:
        try:
            int(s)
            stack_x.append(s)
        except ValueError:
            y = stack_x.pop()
            x = stack_x.pop()
            stack_x.append(eval(str(f'{x}{s}{y}')))
    print(*stack_x)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5616
N,M,K = gets.split.map &:to_i
A = gets.split.map &:to_i
B = gets.split.map &:to_i

total = 0
ai = 0
while (ai<A.size) && (total + A[ai] <= K) 
    total += A[ai]
    ai += 1
end

bi = 0
while (bi<B.size) && (total + B[bi] <= K)
    total += B[bi]
    bi += 1
end

count = ai + bi
ans = count

(ai-1).downto(0) do |i|
    break if bi >= B.size

    total -= A[i]
    count -= 1
    while (bi<B.size) && (total + B[bi] <= K)
        total += B[bi]
        bi += 1
        count += 1
    end
    ans = [ans,count].max
end

p ans

Measured memory_bytes: 41640
def is_ok(x):
    cnt = 0
    for a in A:
        cnt += -(-a//x)-1
    if cnt <= k:
        return True
    return False


def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok
    
n, k = map(int,input().split())
A = list(map(int,input().split()))

print(meguru_bisect(0,10**9+1))


Measured memory_bytes: 31040
#include<iostream>
#include<algorithm>
using namespace std;
long ans,n,a[2<<17],b;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)a[i]-=i+1;
	sort(a,a+n);
	if(n==1)cout<<0<<endl;
	else
	{
		ans=1e15;
		for(int i=n/2;i<=n/2;i++)
		{
			long now=0;
			for(int j=0;j<n;j++)now+=abs(a[j]-a[i]);
			ans=min(ans,now);
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 1792
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    string s; cin >> s;

    int sum = 0;
    rep(i,0,s.size()) sum += (s[i] - '0');

    int N = atoi(s.c_str());
    if(N % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int A,B,C,D,E,F;
cin >> A >> B >> C >> D;
if(A<=B){
	E=A;
		}else{
			E=B;
}
	if(C<=D){
		F=C;
			}else{
				F=D;
}

cout << E + F << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>

using namespace std;

const int N=20;
const int L=(1<<N)+10;
const int INF=0x3f3f3f3f;

int n,S,a[L],t[L],t2[L];

bool vis[L];

int main()
{
	scanf("%d",&n);
	S=(1<<n)-1;
	for(int i=0;i<=S;++i)
		scanf("%d",a+i);
	for(int i=0;i<=S;++i)
	{
		t[i]=a[i];
		t2[i]=-INF;
	}
	for(int i=0;i<n;++i)
		for(int j=S,k;j;--j)if((j>>i)&1)
		{
			k=j^(1<<i);
			if(t[k]>t[j])
			{
				t2[j]=t[j];
				t[j]=t[k];
			}
			else
				t2[j]=max(t2[j],t[k]);
		}
	int ans=-INF;
	for(int i=1;i<=S;++i)
	{
		ans=max(ans,t[i]+t2[i]);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int n,k; cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; ++i){
    int d; cin >> d;
    for(int j = 0; j < d; ++j){
      int c; cin >> c; --c;
      ++a[c];
    }
  }
  int ans = 0;
  for(int i = 0; i < n; ++i){
    if(a[i]==0)++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3588
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
    const numList1 = input[0].split(' ').map(x => parseInt(x, 10));
    const N = numList1[0];

    const numList2 = input[1].split(' ').map(x => parseInt(x, 10));

    var cnt = 1;
    var max = 0;
    for (var i = 1; i < N; i++) {
        max = Math.max(numList2[i - 1], max);
        var H = numList2[i];
        if (max <= H) {
            cnt++;
        }
    }

    console.log(cnt);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <chrono>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<LL>& a, vector<LL>& b) {
	return a[0] < b[0];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

LL N, A, B;
vector<LL> v(0);

LL ultrasuperfunction(LL v,LL A) {
	if (v <= 0) {
		return 0;
	}
	else {
		if (v%A == 0) {
			return v / A;
		}
		else {
			return v / A+1;
		}
	}
}

bool hypergreatfunction(LL i) {
	LL sum = 0;
	REP(j, v.size()) {
		sum += ultrasuperfunction(v[j] - B*i, A);
	}
	if (sum <= i) {
		return true;
	}
	else {
		return false;
	}
}

int main() {
	cin >> N >> A >> B;
	A = A - B;
	REP(i, N) {
		LL a;
		cin >>a;
		v.push_back(a);
	}
	SORT(v);
	LL ans = 0;
	for (LL j = 1000000000; j >= 10; j /= 10) {
		for (LL i = 0; i <= j; i += j/10) {
			if (hypergreatfunction(ans + i)) {
				ans += i - j / 10;
				break;
			}
		}
	}
	cout << ans+1 << endl;
}

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

int main() {
  string s;
  cin >> s;
  if(s.at(0) == 'A'){
    int ccount = 0;
    for(int i = 2;i < s.size()-1;i++){
      if(s.at(i) == 'C'){
        ccount++;
      }
    }
    if(ccount ==  1){
      int ocount = 0;
      for(int j = 0;j < s.size();j++){
        if(isupper(s.at(j)) != 0){
          ocount++;
        }
      }
      if(ocount == 2){
        cout << "AC" << endl;
        goto end;
      }
    }
  }
  cout << "WA" << endl;
  end:;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    L=list(input())
    N=len(L)
    
    #桁dp
    dpl=[0]*(N+1)
    dpt=[0]*(N+1)
    dpt[0]=1
    
    
    for i in range(N):
        if L[i]=="1":
            dpl[i+1]=(dpl[i]*3+dpt[i])%mod#00,01,10,  00
            dpt[i+1]=(dpt[i]*2)%mod
        else:
            dpl[i+1]=(dpl[i]*3)%mod#00,01,10
            dpt[i+1]=dpt[i]
            
    ans=(dpl[-2]+dpt[-2])%mod
    print(ans)
            
            
            

main()


Measured memory_bytes: 72024
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    string s;
    cin >> s;
    string y,m,d;
    y.push_back(s[0]); y.push_back(s[1]); y.push_back(s[2]); y.push_back(s[3]);
    m.push_back(s[5]); m.push_back(s[6]);
    d.push_back(s[8]); d.push_back(s[9]);
    int year = stoi(y);
    int month = stoi(m);
    int day = stoi(d);
    if (year >= 2020) {
        cout << "TBD" << endl;
        return 0;
    }
    else {
        if (month >= 5) {
            cout << "TBD" << endl;
            return 0;
        }
    }
    cout << "Heisei" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>

using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
 

    
    int a,b,c;
    int x;
    
    cin >> a >> b >> c;
    cin >> x;
    
    
    int i,j,k;
    
    int ans=0;
    for(i=0;i<a+1;i++){ //500円A枚
        for(j=0;j<b+1;j++){ //100円B枚
            for(k=0;k<c+1;k++){ //50円C枚
                if(x==(500*i+100*j+50*k)){
                    ans++;
                    //cout << "500 :"<<i <<"100 :" <<j <<"50 :" << k << endl;
                }
            }
        }
    }
    cout << ans << endl;
                
    
    return 0;
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n;
vector<int> res;

int main(void){
	scanf("%lld",&n);
	ll now=n;
	ll v=0;
	for(v=40;v>=0;v--){
		if(n>=(1LL<<v)-1)break;
	}
	for(int i=0;i<v;i++){
		res.push_back(i+1);
	}
	now-=(1LL<<v)-1;
	for(int i=v-1;i>=0;i--){
		if(now<(1LL<<i))continue;
		v++;
		res.insert(res.begin()+i,v);
		now-=1LL<<i;
	}
	for(int i=0;i<v;i++){
		res.push_back(i+1);
	}
	printf("%d\n",res.size());
	for(int i=0;i<res.size();i++){
		printf("%d%c",res[i],i+1==res.size()?'\n':' ');
	}
	return 0;
}


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

class UnionFind {
 public:
    int g_num;
    vector<int> rank, par;

    UnionFind() {}
    UnionFind(int size) {
        rank.resize(size, 0);
        par.resize(size, 0);
        for (int i = 0; i < size; i++) {
            par[i] = i;
            rank[i] = 0;
        }
        g_num = size;
    }

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

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

        g_num--;
        if (rank[x] > rank[y]) {
            par[y] = x;
        } else {
            par[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
    }

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

    int group_num() {
        return g_num;
    }
};

int main(void) {
    int n, m, a, b, q;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i= 0; i < m; i++) {
        cin >> a >> b;
        uf.unite(a, b);
    }

    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> a >> b;
        cout << (uf.same(a, b) ? "yes":"no") << endl;
    }
    return 0;
}

Measured memory_bytes: 1788
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    a,b,x = map(int,ipt().split())
    print(b//x-(a-1)//x)

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 75000
n = int(raw_input())
temp = ''
S = ['S']
D = ['D']
H = ['H']
C = ['C']

for i in range(n):
    temp = str(raw_input())
    if temp[0] == 'S':
        S.append(temp)
    elif temp[0] == 'H':
        H.append(temp)
    elif temp[0] == 'C':
        C.append(temp)
    elif temp[0] == 'D':
        D.append(temp)

def find(X):
    frag = 0
    for i in range(1, 14):
        for j in range(1, len(X)):
            if X[j] == X[0][0] + ' ' + str(i):
                frag = 1
                break
        if frag == 0:
            print X[0][0] + ' ' + str(i)
        frag = 0

find(S)
find(H)
find(C)
find(D)

Measured memory_bytes: 6408
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int MOD = 1000000007;
ull fac[200001][2];
int H, W, A, B;
ull inv(ull a){
  int n = MOD - 2;
  ull r = 1;
  while(n){
    if(n & 1)r = r * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return r;
}
ull comb(int i, int j){
  return (fac[i+j][0] * fac[i][1] % MOD) * fac[j][1] % MOD;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W >> A >> B;

  ull p = 1;
  FOR(i, 1, H+W+1){
    fac[i-1][0] = p;
    fac[i-1][1] = inv(p);
    p = p * i % MOD;
  }
  ull s = 0;
  FOR(i, B, W) s =(s + comb(i, H-A-1) * comb(W-i-1, A-1)) % MOD;
  cout << s % MOD << "\n";
}


Measured memory_bytes: 3328
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			long i = 1;
			long[][] gcdlcm = new long[2][2];
			gcdlcm[0][0] = scan.nextLong();
			gcdlcm[0][1] = scan.nextLong();
			gcdlcm[1][0] = gcdlcm[0][0];
			gcdlcm[1][1] = gcdlcm[0][1];
			
			while(i != 0){
				i = gcdlcm[0][0] % gcdlcm[0][1];
				gcdlcm[0][0] = gcdlcm[0][1];
				gcdlcm[0][1] = i;
			}
			System.out.println(gcdlcm[0][0]+ " " + (gcdlcm[1][0] * gcdlcm[1][1] / gcdlcm[0][0]));
		}
	}
}

Measured memory_bytes: 26012
#include <iostream>

using namespace std;
int main(){
	int n;
	cin >> n;
	if(n==1||n==2||n==3||n==5||n==6||n==9||n==10||n==13||n==17){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mk make_pair
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pf(a) printf("%d\n",a);
#define pfl(a) printf("%lld\n",a);
#define TEST int test; cin >> test;while(test--)
#define ii pair<int,int>
#define iil pair<ll,ll>
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define INF 2147483647


int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const double pi = acos(-1.0);


ll n, m, x;

void solve()
{

    ll cost = 1e18;
    cin >> n >> m >> x;
    vector<vector<ll> > book(n, vector<ll>(m + 1));
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j <= m ; j++)
            cin >> book[i][j];

    for(int i = 1 ; i < (1 << n); i++)
    {
        ll total = 0;
        vector<ll> val(m,0);
        for(int j = 0 ; j < n ; j++)
        {
            if(i & (1 << j))
            {
                total += book[j][0];
                for(int k = 0 ; k < m ; k++)
                {
                    val[k] += book[j][k+1];
                }
            }
        }
        bool f = true;
        for(int k = 0 ; k < m ; k++)
        {
            if(val[k] < x)
            {
                f = false;
                break;
            }
        }
        if(f)
        {
            cost = min(cost, total);
        }

    }
    if( cost == 1e18) cout << "-1" << endl;
    else cout << cost << endl;

}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    solve();
    return 0;
}


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

int main() {
    int N,result;
    int* a;
    int* b;
    cin >> N;
    a = new int[N];
    b = new int[N];

    for(int i=0;i<N-1;i++){
        cin >> b[i];
    }
    result = 0;
    result+=b[0];
    for(int i=1;i<N-1;i++){
        if(b[i-1]<b[i]){
            a[i]=b[i-1];
        } 
        else{
            a[i]=b[i];
        }
        result += a[i];
    }
    result += b[N-2];
    cout << result << endl;
    return 0;
}

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

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

  scanf("%d",&n);
  
  for(t = 1;t <= n;t++) 
  {
    x = t;
    
    if(x %3 == 0) 
    {
      printf(" %d",t);
    } 
    else if(x % 10 == 3) 
    {
      printf(" %d", t);
    } 
    else 
    { 
      while(x != 0) 
      {
          x /=10;
	      if(x % 10 == 3) 
	      {
	          printf(" %d", t);
	          break;
	      }
      }
    }
    
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2036
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

x=r()
if 400 <= x < 600:
    print(8)
elif 600 <= x < 800:
    print(7)
elif 800 <= x < 1000:
    print(6)
elif 1000 <= x < 1200:
    print(5)
elif 1200 <= x < 1400:
    print(4)
elif 1400 <= x < 1600:
    print(3)
elif 1600 <= x < 1800:
    print(2)
elif 1800 <= x < 2000:
    print(1)


Measured memory_bytes: 71084
#include <bits/stdc++.h>
using namespace std;
#define int long long int
 main() {
	int n;
	cin>>n;
	int arr[n];
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	map<int, int>m;
	m[(arr[0])]++;
	int ans=0;
	for(int i=1; i<n; i++){
		int val=arr[i]-i;
		ans+=m[(-val)];
		m[arr[i]+i]++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 27876
import math

a,b,h,m = map(int,input().split())
s = (h*60+m)/2
r = 6*m%360
if s>=r:
  d = math.cos(math.radians(s-r))
else:
  d = math.cos(math.radians(r-s))
kotae = math.sqrt(a**2+b**2-2*a*b*d)
print(kotae)

Measured memory_bytes: 9512
// skyrim belongs to the nords
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back 
#define sz(a) ((int)(a).size())
#define rep(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define dec(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end() 
#define LOGN 18
#define EPS 1e-8
#define fcin ios_base::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

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

	int N;
	cin >> N;
	while (N) {
		if (N % 10 == 9) {
			cout << "Yes";
			return 0;
		}
		N /= 10;
	}
	cout << "No";
	return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define lld long long int
using namespace std;
int main() 
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vector <int> dp(n);
    fill(dp.begin(),dp.end(),0);
    for(int i=1;i<n;i++)
    {
        if(i-k < 0)
        {
            int m=INT_MAX;
            for(int j=0;j<i;j++)
            {
                 m=min((dp[j]+abs(a[i]-a[j])),m);   
            }
            dp[i]=m;
        }
        else
        {
            int m=INT_MAX;
            for(int j=i-k;j<i;j++)
            {
             m=min((dp[j]+abs(a[i]-a[j])),m);   
            }
            dp[i]=m;
        }
        
    }
    cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
N,M = map(int,input().split())
p = 1000000007
L = []
for i in range(M):
  L.append(int(input()))
dp = [float('inf')]*(N+1)
dp[0] = 1
if 1 in L:
  dp[1] = 0
else:
  dp[1] = 1
for j in range(len(L)):
  dp[L[j]] = 0
for i in range(N-1):
  if dp[i+2] == float('inf'):
    dp[i+2] = (dp[i+1]+dp[i])%p
print(dp[N])

Measured memory_bytes: 7848
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

H, W = rl()
S = []
for i in range(H):
  s = rs()
  S.append(s + '#')
S.append('#'*(W+1))

tab = [[0 for _ in range(W+1)] for _ in range(H+1)]

for i in range(H):
  k = 0
  prev = -1
  for j in range(W+1):
    if S[i][j] == '#':
      n = j-prev-1
      while k < j:
        tab[i][k] += n
        k += 1
      tab[i][k] = 0
      k += 1
      prev = j

for j in range(W):
  k = 0
  prev = -1
  for i in range(H+1):
    if S[i][j] == '#':
      n = i-prev-1
      while k < i:
        tab[k][j] += n - int(tab[k][j]>0)
        k += 1
      tab[k][j] = 0
      k += 1
      prev = i

ans = 0
for i in range(H):
  for j in range(W):
    ans = max(ans, tab[i][j])
print(ans)


Measured memory_bytes: 111444
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define all(x) (x).begin(),(x).end()
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)


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

int gcd(int a,int b)  {
	if (a%b==0)  return(b);
	else return(gcd(b,a%b));
}

int vector_finder(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
    string S; cin >> S;
    int K, N;  cin >> K;
    N = S.length();

    vector<string> s;
    rep(i, N){
      reps(j, 5){
        s.push_back(S.substr(i, j));
      }
    }
    sort(all(s));
    s.erase(unique(all(s)), s.end());
    cout << s[K-1] << endl;
    return 0;
}


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

int main() 
{
    int a , b , flag = 0 ;
    scanf("%d", &a);

    for (int i = 0 ; i <= 9 ; i++)
    {
        for (int j = 0 ; j <= 9 ; j++)
        {
            if (i * j == a)
            {
                flag = 1 ;
            }
        }
    }

    (flag == 1) ? printf("Yes\n") : printf("No\n");


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h)cin >> s[i];
    vector<vector<ll>> dp(h, vector<ll>(w, 0));
    if(s[0][0] == '#')dp[0][0] = 1;
    REP(i, w-1){
        dp[0][i] = dp[0][i-1];
        if(s[0][i] != s[0][i-1] && s[0][i] == '#' )dp[0][i]++;
    }
    REP(i, h-1){
        dp[i][0] = dp[i-1][0];
        if(s[i][0] != s[i-1][0] && s[i][0] == '#')dp[i][0]++;
    }
    REP(i, h-1){
        REP(j, w-1){
            ll now1=0, now2=0;
            if(s[i][j] != s[i-1][j] && s[i][j] == '#')now1=1;
            if(s[i][j] != s[i][j-1] && s[i][j] == '#')now2=1;
            dp[i][j] = min(dp[i-1][j] + now1, dp[i][j-1] + now2);
        }
    }
    cout << dp[h-1][w-1] << endl;
}      

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll n,m;
cin >> n >> m;
ll k[m];
ll p[m];
ll ans = 0;
vector<vector<ll>> s(m);
for (ll i = 0; i < m;i++){
    cin >> k[i];
    for (ll j = 0; j < k[i];j++){
    ll t;
    cin >> t;
    s[i].push_back(t);
    }
}
for (ll i = 0; i < m; i++) cin >> p[i];
for (ll bit = 0; bit < (1 << n); bit++) {
    ll cnt = 0;
    bool sw[n];
    for (ll i = 0; i < n;i++){
            sw[i] = 0;
            if (bit & (1 << i)) sw[i] = 1;
        }
        for (ll i = 0;i<m;i++){
            ll tmp = 0;
            for (ll j = 0; j < k[i];j++){
                if (sw[s[i][j]-1]) tmp++;
            }
            if (tmp % 2 == p[i]) cnt++;
        }
        if (cnt == m) ans++;
}
    cout << ans << endl;
}


Measured memory_bytes: 256