akhauriyash/Code-Regression huggingface dataset:
#for t in xrange(int(raw_input())):
#n,m = map(int, raw_input().split())
#n = int(raw_input())

def solve1():
	maxx = maxy = 0
	minx = miny = 1000111000
	for i in xrange(n):
		maxx = max(maxx, x[i])
		minx = min(minx, x[i])
		maxy = max(maxy, y[i])
		miny = min(miny, y[i])
	return (maxx-minx)*(maxy-miny)

def solve2a(minx):
	miny = min(x)
	maxy = max(y)
	maxx = 0
	
	for i in xrange(n):
		if y[i] < minx:
			return 2**60
		if minx <= x[i]:
			maxx = max(maxx, x[i])
		else:
			maxx = max(maxx, y[i])
	return (maxx-minx)*(maxy-miny)

def solve2_():
	res = 2**60
	for minx in x:
		res = min(res, solve2a(minx))
	for minx in y:
		res = min(res, solve2a(minx))
	return res

def solve2():
	res = 2**60
	xy = x+y
	xy.sort()
	miny = min(x)
	maxy = max(y)
	my = min(y)
	mx = max(x)
	
	pi = 0
	for minx in xy:
		if my < minx:
			break
		while pi < n and p[pi][0] < minx:
			pi += 1
		maxx = max(ly[pi], mx)
		res = min(res, (maxx-minx)*(maxy-miny))
	return res

n = int(raw_input())

x = [0]*n
y = [0]*n
p = [(0,0)]*n
mini = maxi = 0
for i in xrange(n):
	x[i],y[i] = map(int, raw_input().split())
	x[i],y[i] = min(x[i],y[i]),max(x[i],y[i])
	p[i] = x[i],y[i]
	if x[i] < x[mini]:
		mini = i
	if y[maxi] < y[i]:
		maxi = i
p.sort()
ly = [0]*(n+2)
my = 0
for i in xrange(n):
	my = max(my, p[i][1])
	ly[i+1] = my

ans = solve1()
if mini != maxi:
	ans = min(ans, solve2())
print ans


Measured memory_bytes: 38060
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> A(N);
    rep(i, N) cin >> A[i];
    
    sort(A.begin(), A.end());
    long long left = 1e18 * -2;
    long long right = 1e18 * 2;
    while (right - left > 1) {
        long long mid = (right + left) / 2;
        long long cnt = 0;
        rep(i, N) {
            if (A[i] == 0) {
                if (mid >= 0) cnt += N - i - 1;
            } else if (A[i] > 0) {
                int l = i;
                int r = N;
                while (r - l > 1) {
                    int m = (l + r) / 2;
                    if (A[m] * A[i] <= mid) l = m;
                    else r = m;
                }
                cnt += r - i - 1;
            } else {
                int l = i;
                int r = N;
                while (r - l > 1) {
                    int m = (l + r) / 2;
                    if (A[i] * A[m] <= mid) r = m;
                    else l = m;
                }
                cnt += N - r;
            }
        }
        if (cnt < K) left = mid;
        else right = mid;
    }
    cout << right << endl;
    return 0;
}


Measured memory_bytes: 1792
f=[0,1,1,2,3,5,8,13,21,34,55,89];h,w,k=map(int,input().split());a=[0]*(w+2);a[1]=1
for i in range(h):a=[0]+[(f[j-1]*f[w-j+1]*a[j-1]+f[j]*f[w-j+1]*a[j]+f[j]*f[w-j]*a[j+1])%(10**9+7)for j in range(1,w+1)]+[0]
print(a[k])

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

using namespace std;

typedef long long ll;

unordered_set<ll> us;

ll N;
ll a[100000];

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<N;i++){
        if(us.find(a[i]) == us.end()){
            us.insert(a[i]);
        }
    }
    ll k = us.size();
    if(k % 2 == 1){
        cout << k << endl;
    }else{
        cout << k-1 << endl;
    }
    return 0;
}

Measured memory_bytes: 5156
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

typedef vector<int> vi;

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

    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vi b(n);
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    vi p(n);
    for (int i = 0; i < n; i++) {
        p[i] = i + 1;
    }

    int ai, bi;
    int x = 0;
    do {
        if (a == p) {
            ai = x;
        }
        if (b == p) {
            bi = x;
        }

        x++;
    } while (next_permutation(p.begin(), p.end()));

    cout << abs(ai - bi) << endl;

    return 0;
}


Measured memory_bytes: 384
/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
typedef unsigned long long ULL;
using namespace std;

const int maxn = 1002;
int l[maxn];

int _min = 10000000;

int N, A, B, C;

void dfs(int n, int a, int b, int c, int d) {
	if(n == N) {
		if(a == 0 || b == 0 || c == 0)	return;
	
		int cost = abs(A - a) + abs(B - b) + abs(C - c);
		cost += d - 30;
		_min = min(_min, cost);
		return;
	}
	dfs(n+1, a, b, c, d);
	dfs(n+1, a+l[n], b, c, d + 10);
	dfs(n+1, a, b+l[n], c, d + 10);
	dfs(n+1, a, b, c+l[n], d + 10);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	cin >> N >> A >> B >> C;
	for(int i = 0; i < N; i++) cin >> l[i];
	dfs(0,0,0,0,0);
	printf("%d\n", _min);
	return 0;
}
/**/

Measured memory_bytes: 256
#include <cstdio>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define fi first
#define se second
using pii = pair<int,int>;
using ll = long long;

ll pow(ll n, ll p)
{
   ll ret = 1;
   while (p-- > 0) ret *= n;
   return ret;
}

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

   ll maxv = 1;
   ll tmp;
   for (int i=1; i <= N; ++i) {
      for (int j=2; j <= N; ++j) {
         tmp = (ll)pow(i,j);
         if (tmp > N) break;
         else 
            maxv = max(maxv, tmp);
      }
   }
   outl(maxv);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

/* Tutorial:
  Notice that we can always make a valid state with min(n - 1, k)
*/

const int maxN = 2e5; int n; lli k;
const lli mod = 1e9 + 7;

lli fat[maxN + 2], invFat[maxN + 2];
lli modPow(lli x, lli y)
{
  lli ans = 1;
  while (y)
  {
    if (y & 1LL) ans = ans * x % mod;
    x = x * x % mod, y >>= 1LL;
  }
  return ans;
}
lli inv(lli x)
{
  return modPow(x, mod - 2);
}
lli choose(lli nn, lli kk)
{
  if (nn < kk) return 0;
  if (nn < mod) return fat[nn] * invFat[kk] % mod * invFat[nn - kk] % mod;
  lli ans = 1;
  while (nn || kk)
  {
    lli nnn = nn % mod, kkk = kk % mod;
    nn /= mod, kk /= mod;
    ans = ans * choose(nnn, kkk) % mod;
  }
  return ans;
}
lli H(lli nn, lli kk)
{
  return choose(nn + kk - 1, nn - 1);
}

int main()
{
  fat[0] = 1;
  for (lli i = 1; i <= maxN; i++)
    fat[i] = i * fat[i - 1] % mod;
  for (int i = 0; i <= maxN; i++)
    invFat[i] = inv(fat[i]);

  while (scanf("%d %lld", &n, &k) != EOF)
  {
    lli ans = 0;
    for (int m = 0, end = min((lli)n - 1, k); m <= end; m++)
      ans = (ans + choose(n, m) * H(n - m, m) % mod) % mod;
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3328
from collections import deque
h,w=map(int,input().split())
s=[input()for _ in range(h)]
a=[[400]*w for _ in range(h)]
ans=0
def bfs(b,i,j):
    b[i][j]=0
    seen=[[0]*w for _ in range(h)]
    todo=deque([(i,j)])
    while len(todo)>0:
        x,y=todo.popleft()
        if seen[x][y]==1:
            continue
        seen[x][y]=1
        if x>0 and seen[x-1][y]==0 and s[x-1][y]=='.':
            b[x-1][y]=b[x][y]+1
            todo.append((x-1,y))
        if x>0 and s[x-1][y]=='#':
            seen[x-1][y]=1
        if x<h-1 and seen[x+1][y]==0 and s[x+1][y]=='.':
            b[x+1][y]=b[x][y]+1
            todo.append((x+1,y))
        if x<h-1 and s[x+1][y]=='#':
            seen[x+1][y]=1
        if y>0 and seen[x][y-1]==0 and s[x][y-1]=='.':
            b[x][y-1]=b[x][y]+1
            todo.append((x,y-1))
        if y>0 and s[x][y-1]=='#':
            seen[x][y-1]=1
        if y<w-1 and seen[x][y+1]==0 and s[x][y+1]=='.':
            b[x][y+1]=b[x][y]+1
            todo.append((x,y+1))
        if y<w-1 and s[x][y+1]=='#':
            seen[x][y+1]=1
    ret=0 
    for bi in b:
        for bij in bi:
            if bij<400:
                ret=max(ret,bij)
    #print(b)
    return ret

for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            b=a
            ans=max(ans,bfs(b,i,j))
print(ans)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using v = vector<ll>;
void dpA(){
    int n;
    cin >> n;
    auto h = vector<ll>(n,0);
    for(ll i =0;i<n;i++) cin >> h[i];

    auto dp = vector<ll>(n+2,1e9);
    
    dp[0] = 0;
    dp[1] = 0;
    for(ll i=1;i<n;i++){
        if(i>=2) dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2])); 
        else if(i>=1) dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
    }
    cout << dp[n-1];
}

void dpB(){
    ll n,k;
    cin >> n >> k;
    auto h = vector<ll>(n+1,0);
    for(ll i=0;i<n;i++) cin >> h[i];

    auto dp = vector<ll>(100000,1e9);
    dp[0] = 0;
    for(ll i=0;i<n;i++){
        for(ll j=1;j<=k;j++){
           if(i+j<=n) dp[i+j] = min(dp[i+j],dp[i] + abs(h[i+j]-h[i]));
        }
    }
    cout << dp[n-1];
}

void dpC(){
    ll n; cin >> n;
    vector<v> a(n,v(3,0));
    for(ll i=0;i<n;i++) cin >> a[i][0] >> a[i][1] >> a[i][2];

    auto dp = vector<v>(n+1,v(3,0));

    for(ll i=0;i<n;i++)
        for(ll today=0;today<3;today++)
            for(ll oday=0;oday<3;oday++)
                if(today!=oday) 
                    dp[i+1][today] = max(dp[i+1][today],dp[i][oday] + a[i][today]);
    
    cout << max(dp[n][0],max(dp[n][1],dp[n][2]));
   
    
}

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

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

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

	vector<vector<int>> vec(M);

	for (int i = 0; i < M; ++i) {
		int k; cin >> k;
		vec[i].resize(k);
		for (int j = 0; j < k; ++j) {
			cin >> vec[i][j];
			--vec[i][j];
		}
	}

	vector<int> p(M);
	for (int i = 0; i < M; ++i) cin >> p[i];

	int ans = 0;
	for (int i = 0; i < (1 << N); ++i) {
		bool ok = true;
		for (int j = 0; j < M; ++j) {
			int c = 0;
			for (int id : vec[j]) {
				if ((i >> id) & 1) {
					++c;
				}
			}
			c %= 2;
			if (c != p[j]) {
				ok = false;
			}
		}
		if (ok) {
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 2048;
const int INF = 1e7;
int n;
int a[nax * 3];
int f[nax][nax];
int local_max[nax];
tuple <int, int, int> to_update[nax * 16]; /// never go more than this
/// it's O(n) but cannot tell exactly how large, should be no more than this
int top_update = 0;

void add_update (int x, int y, int z) {
    to_update[++ top_update] = make_tuple(x, y, z);
}


void shift_array (int *b) {
    static int tmp[3];
    for (int i = 0 ; i < 3; ++ i)
        tmp[i] = b[i];
    b[0] = tmp[1], b[1] = tmp[2], b[2] = tmp[0];
}

int main() {

    scanf("%d", &n);
    for (int i = 1; i <= 3 * n; ++ i)
        scanf("%d", a + i);
    for (int i = 0 ; i <= n + 10 ; ++ i)
    for (int j = 0 ; j <= n + 10; ++ j)
        f[i][j] = -INF;
    for (int i = 0 ; i <= n + 10 ; ++ i)
        local_max[i] = -INF;
    f[a[1]][a[2]] = f[a[2]][a[1]] = 0;
    local_max[a[1]] = local_max[a[2]] = 0;

    int to_add = 0;
    int ans = 0;


    for (int cur = 3 ; cur < 3 * n ; cur += 3) {
        if (a[cur + 1] == a[cur] && a[cur] == a[cur + 2]) {
            to_add += 1;
            continue;
        }

        static int b[3];
        b[0] = a[cur], b[1] = a[cur + 1], b[2] = a[cur + 2];

        for (int i = 0 ; i < 3 ; ++ i)
        for (int j = i + 1 ; j < 3 ; ++ j) {
            int k = 3 - i - j;
            add_update(b[i], b[j], ans);
            add_update(b[i], b[j], f[b[k]][b[k]] + 1);
        }

        for (int shift = 0; shift < 3 ; ++ shift) {
            shift_array(b);
            int x = b[0], y = b[1], z = b[2];
            for (int t = 1 ; t <= n ; ++ t) {
                if (y == z) {

                    add_update(x, t, f[t][y] + 1);
                }
                /// add new state
                add_update(y, z, f[x][x] + 1);
                add_update(x, t, local_max[t]);
            }
        }

        for (int i = 1 ; i <= top_update ; ++ i) {
            const auto &[x, y, z] = to_update[i];
            ans = max(ans, z);
            local_max[x] = max(local_max[x], z);
            local_max[y] = max(local_max[y], z);
            f[x][y] = max(f[x][y], z);
            f[y][x] = max(f[y][x], z);

        }
        top_update = 0;
    }


    ans = max(ans, f[a[3 * n]][a[3 * n]] + 1);
    printf("%d\n", ans + to_add);
}



Measured memory_bytes: 20072
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	string s,t[4],temp="";
	cin>>s;
	t[0]="dream",t[1]="dreamer",t[2]="erase",t[3]="eraser";
	REP(i,4){
		reverse(t[i].begin(),t[i].end());
	}
	reverse(s.begin(),s.end());
	REP(i,s.size()){
		temp+=s[i];
		REP(j,4){
			if(temp==t[j]){
				temp="";
				break;
			}
		}
	}
	if(temp.empty()){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	return 0;
}

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

int main(){
int N, C;
cin >> N >> C;
int sum = 0;
for(int i=0; i<C; i++){
int p;
cin >> p;
sum += p;
}
int P = sum/(N+1);
if(sum%(N+1)>0){
P++;
}
cout << P << endl;
return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<queue>

using namespace std;
static const int N=100;
static const int INF=(1<<21);

int n,M[N][N];
int d[N];
void breadth(int s){
  int i,u,v;
  queue<int> q;
  q.push(s);
  for(i=0;i<n;i++)d[i]=INF;
  d[s]=0;
  while(!q.empty()){
    u=q.front();
    q.pop();
    for(v=0;v<n;v++){
      if(M[u][v]==0)continue;
      if(d[v]!=INF)continue;
      d[v]=d[u]+1;
      q.push(v);
    }
  }
  for(i=0;i<n;i++){
    cout << i+1 << " " << ((d[i]==INF) ? (-1) : d[i])<<endl;
  }
}
int main(){
  int u,k,v;
  int i,j;
  cin >> n;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j]=0;
  }
  for(i=0;i<n;i++){
    cin >> u >> k;
    u--;
    for(j=0;j<k;j++){
      cin >> v;
      v--;
      M[u][v]=1;
    }
  }
  breadth(0);

  return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }

int n;
int a[20];
int x[20][20], y[20][20];

int main () {
  cin >> n;

  rep(i,n) {
    cin >> a[i];
    rep(j,a[i]) {
      cin >> x[i][j] >> y[i][j];
      x[i][j]--, y[i][j];
    }
  }

  int ans = 0;
  rep(b,1<<n) {
    bool ok = true;
    rep(i,n) {
      if (!bit(b,i)) continue;
      rep(j,a[i]) {
        if (bit(b,x[i][j])^y[i][j]) {
          ok = false;
          break;
        }
      }
      if (!ok) break;
    }
    if (ok) ans = max(ans, pcnt(b));
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
//ITP1_6_D

#include <stdio.h>

int main(){

	int n,m,i,j;
	scanf("%d %d",&n,&m);
	
	int A[n][m],b[m][1];
	int Ans[m];
	
	//?????????
	for(i=0;i<n;i++){
		Ans[i]=0;
	}
	
	
	//??\???
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&A[i][j]);
		}
	}
	for(i=0;i<m;i++){
		scanf("%d",&b[i][0]);
	}
	
	//?¨????
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			Ans[i] = Ans[i] + A[i][j]*b[j][0];
		}
	}
	
	//??¨???
	for(i=0;i<n;i++){
		printf("%d\n",Ans[i]);
	}
	
	return 0;
}

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

const int N = 3e5 + 9;

vector<int> v;
long long dp[20][10][2][2];
long long yo(int i, int last, int f, int st)
{
    if(i == -1) return 1;
    long long &ret = dp[i][last][f][st];
    if(ret != -1) return ret;
    int m = f ? v[i] : 9;
    long long ans = 0;
    for(int k = 0; k <= m; k++){
        if(!st|| abs(k - last) <= 1)
            ans += yo(i - 1, k, k == m? f : 0, st |  (k > 0));
    }
    ret = ans;
    return ans;
}
long long solve(long long n)
{
    if(n == 0) return 0;
    memset(dp, -1, sizeof dp);
    v.clear();
    while(n){
        v.push_back(n % 10); n /= 10;
    }
    return yo((int)v.size() - 1, 0, 1, 0) - 1;
}

int32_t main()
{
    int k; cin >> k;
    long long l = 1, r = 4e9, ans;
    while(l <= r){
        long long mid = (l + r) / 2;
        if(solve(mid) < k)  l = mid + 1;
        else ans = mid, r = mid - 1;
    }
    cout << ans << '\n';
    return 0;
}


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

using namespace std;

int main() {
  int N, M;
  int like[31] = {};
  int c = 0;
  int tmp;
  int K[31];
  int A[31][31];

  cin >> N >> M;

  for (int i=0; i<N; i++) {
    cin >> K[i];
    for (int j=0; j<K[i]; j++) {
      cin >> A[i][j];
      like[ A[i][j] ]++;
      if (like[A[i][j]] == N) {
        c++;
      }
    }
  }

  cout << c << endl;
}

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

using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(0); 
  cin.tie(0); 
  
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) cout << "Yes" << "\n";
  else cout << "No" << "\n";
}


Measured memory_bytes: 3664
#include <iostream>
using namespace std;
int cnt;
int n,sum;
void dfs(int n, int i , int s){

  if(s == sum && n == 0){
    cnt++;
    return; 
  }

  if(i == 10 || n == 0 ){
    return; 
  }

  dfs(n-1,i + 1,s + i);  
  dfs(n,i + 1,s);

}

int main(){

  while( cin >> n >> sum, n + sum){
    cnt = 0;
    dfs(n,0,0);
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import * as fs from "fs";

let input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const n = +input[0];
const a = input[1].split(" ").map((x: string): number => +x).sort((a, b) => a - b);

let current = 0;
let count = 0;
const r = [];
for (const v of a) {
	if (v === current) {
		count += 1;
	}
	else {
		r.push({value: current, count});
		current = v;
		count = 1;
	}
}
r.push({value: current, count});

let result = 0;
for (const p of r) {
	result += p.value <= p.count ? p.count - p.value : p.count;
}

console.log(result);



Measured memory_bytes: 28796
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define inf 100000000
#define eps (1e-11)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

class Circle{
public:
  Point c;
  double r;
  Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}

double getDistanceLP(Line l,Point p){
  return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}

double getDistanceSP(Segment s,Point p){
  if(dot(s.p2-s.p1,p-s.p1)<0.0)return abs(p-s.p1);
  if(dot(s.p1-s.p2,p-s.p2)<0.0)return abs(p-s.p2);
  return getDistanceLP(s,p);
}

bool iscross(Segment s,Circle c){
  if(abs(s.p1-c.c)<c.r && abs(s.p2-c.c)<c.r)return false;
  if(abs(s.p1-c.c)<c.r && abs(s.p2-c.c)>=c.r)return true;
  if(abs(s.p1-c.c)>=c.r && abs(s.p2-c.c)<c.r)return true;
  if(getDistanceSP(s,c.c)<=c.r)return true;
  return false;
}

int main()
{
  int n,m;

  while(1){
    cin>>n;
    if(n==0)break;
    vector<Circle> vc;
    vc.resize(n);
    for(int i=0;i<n;i++)cin>>vc[i].c.x>>vc[i].c.y>>vc[i].r;
    cin>>m;
    vector<Segment> vs;
    int x,y,a,b;
    for(int i=0;i<m;i++){
      cin>>x>>y>>a>>b;
      vs.push_back(Segment(Point(x,y),Point(a,b)));
    }

    for(int i=0;i<m;i++){
      bool flag=true;
      for(int j=0;j<n;j++){
	if(iscross(vs[i],vc[j]))flag=false;
      }
      if(flag)cout<<"Danger"<<endl;
      else cout<<"Safe"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define inf 100000000000000000
#define ll long long 
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define test ll t ; cin>>t; while(t--)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	
	string str ; 
	cin>> str ;
	if(str[2]==str[3] && str[4]==str[5])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 100050;
int n, a[N], b[N], o[N];
int main(){
	cin>>n;
	for(int i = 1;i <= n + 1; i++){
		scanf("%d", &a[i]);
		o[i] = a[i];
	}
	for(int i = 1;i <= n; i++){
		scanf("%d", &b[i]);
	}
	int x;
	for(int i = n; i >= 1; i--){
		if(a[i+1] >= b[i]){
			a[i+1] -= b[i];
			b[i] = 0;
		}
		else{
			b[i] -= a[i+1];
			a[i+1] = 0;
			if(a[i] >= b[i]){
				a[i] -= b[i];
				b[i] = 0;
			}
			else {
				a[i] = 0;
			}
		}
	} 
	long long ans = 0;
	for(int i = 1;i <= n + 1; i++){
		ans += 1LL * (o[i] - a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	static String N;

	public static void main(String args[]) {
		try (Scanner sc = new Scanner(System.in)) {
			N = sc.next();
		}
		long summary=0;
		for(int i=0;i<N.length();i++) {
			summary += Long.parseLong(N.substring(i,i+1));
		}
			
		if (summary%9==0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 49688
#include<iostream>
using namespace std;
int main() {
    int tbl[]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
    int K;cin>>K;
    cout << tbl[K-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
    int n; cin >> n;
    ll prv_t, prv_a; cin >> prv_t >> prv_a;
    for (int i = 0; i < n - 1; i++) {
        ll cur_t, cur_a; cin >> cur_t >> cur_a;
        ll k = 1;
        if (cur_t < prv_t) {
            ll tmp = (prv_t + cur_t - 1) / cur_t;
            k = max(k, tmp);
        }
        if (cur_a < prv_a) {
            ll tmp = (prv_a + cur_a - 1) / cur_a;
            k = max(k, tmp);
        }
        prv_t = cur_t * k;
        prv_a = cur_a * k;
    }
    cout << prv_t + prv_a << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repo' is at "https://github.com/Loptall/prcn_lib"

/*
    6月で水色になるぞ〜!!!
*/

// from std...
use std::cmp::{
    max, min,
    Ordering::{Equal, Greater, Less},
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, Integer};
use num_rational::Rational;
use num_traits::{one, zero, One, Zero};
use permutohedron::Heap;
use petgraph::unionfind::UnionFind;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

pub const MOD: usize = 1000000007;
pub const MAX: usize = 1usize << 63usize;
pub const MIN: i64 = i64::MIN;
pub const PI: f64 = f64::consts::PI;
pub const A: u8 = 'A' as u8;

/// # Usage
///
/// `T`は基本的にusizeが入る想定
///
/// `pred`について`l`側が`true`、
/// `r`側が`false`を返すような単調性を持っているとき、
///
/// `pred`を満たす`T`の中で最も大きいものを求める。
///
/// 最初に`l`と`r`について`pred`がそれぞれ`true`、`false`を返すかどうかを調べるので、
/// 範囲は閉空間で指定して良い。
///
/// 返り値`res`は必ず、
///
/// Some(inner) (l <= inner <= r) | None
///
/// になる
///
/// ```rust
/// use prcn_lib::binary_search::binary_search;
///
/// let v = vec![1, 3, 3, 3, 4, 6, 7, 7, 8, 10];
/// assert_eq!(3, binary_search(|i| v[i] < 4, 0, v.len() - 1).unwrap());
/// assert_eq!(9, binary_search(|i| v[i] <= 10, 0, v.len() - 1).unwrap());
/// ```
pub fn binary_search<T, F>(pred: F, l: T, r: T) -> Option<T>
where
    T: Add<Output = T> + Div<Output = T> + PartialEq + Copy + From<u8>,
    F: Fn(T) -> bool,
{
    if !pred(l) {
        return None;
    }
    if pred(r) {
        return Some(r);
    }
    let mut l = l;
    let mut r = r;
    let two = T::from(2);
    loop {
        let m = (l + r) / two;
        if l == m {
            break Some(l);
        }
        if pred(m) {
            l = m;
        } else {
            r = m;
        }
    }
}

// code...
// #[fastout]
fn main() {
    input! {
        n: usize,
        mut l: [i64; n]
    }

    l.sort();
    let mut ans = 0usize;

    for i in 0..n {
        for j in 0..n {
            if i < j {
                // j < k < n && l[k] < l[i] + l[j]
                ans += binary_search(|x| l[x] < l[i] + l[j], j, n-1).unwrap() - j;
            }
        }
    }

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


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

int main(){
  ll n,m;
  cin>>n>>m;
  vector<int> a(n+1,true);
  for(ll i=0; i<n; i++){
    int x;
    cin>>x;
    a[x]=false;
  }
  vector<ll> dp(n+1);
  dp[0]=1;
  for(ll i=0; i<n; i++){
    for(ll j=i+1; j<=min(n,i+2); j++){
      if(a[j]){
        dp[j]+=dp[i];
        dp[j] %= mod;
      }
    }
  }
  cout<<dp[n];
}

Measured memory_bytes: 1408
N, *ABC = gets.split.map(&:to_i)
LS = N.times.map{ gets.to_i }
INF = 10**9

def dfs(cur, *abc)
  if cur == N
    return abc.min > 0 ? 3.times.inject(0){|s, i| s + (abc[i]-ABC[i]).abs } - 30 : INF
  end
  r1 = dfs(cur+1, abc[0], abc[1], abc[2])
  r2 = dfs(cur+1, abc[0] + LS[cur], abc[1], abc[2]) + 10
  r3 = dfs(cur+1, abc[0], abc[1] + LS[cur], abc[2]) + 10
  r4 = dfs(cur+1, abc[0], abc[1], abc[2] + LS[cur]) + 10
  return [r1, r2, r3, r4].min
end


puts dfs(0, 0, 0, 0)



Measured memory_bytes: 3836
import java.util.Scanner
import scala.collection.immutable.Queue

// '.': true
case class Input(maze: List[List[Boolean]]) {
  val w = maze(0).length
  val h = maze.length
  def bfs(from: (Int, Int)): Int = {
    val mary = maze.map(_.toArray).toArray
    def neighbors(from: (Int, Int)): List[(Int, Int)] = {
      val (x, y) = from
      List((0,1),(0,-1),(1,0),(-1,0)).flatMap(
        { case (dx, dy) =>
          val (nx, ny) = (x+dx, y+dy)
          if (nx >= 0 && nx < h && ny >= 0 && ny < w) Some((nx,ny))
          else None
        }).filter({ case (x, y) => mary(x)(y) })
    }
    def aux(q: Queue[((Int, Int), Int)], max: Int): Int = q match {
      case (from, cnt) +: rst => {
        val nb = neighbors(from)
        nb foreach({ case (x, y) => mary(x)(y) = false })
        aux(rst.enqueue(nb.map((_, cnt+1))), math.max(max, cnt))
      }
      case _ => max
    }
    { val (x, y) = from; mary(x)(y) = false }
    aux(Queue((from, 0)), 0)
  }
  def solved: Output = {
    val withIndex =
      maze.map(_.zipWithIndex).zipWithIndex
        .flatMap({ case (l, i) => l.map({ case (b, j) => (((i, j), b)) }) })
    val dots = withIndex.filter({ case (coord, b) => b }).map(_._1)
    val ans = dots.map(bfs(_)).max
    Output(ans)
  }
}

object Input {
  def fromString(s: String): Input = {
    Input(s.split('\n').map(_.toCharArray().map(_ == '.').toList).toList)
  }
  def fromStdin(): Input = {
    val sc = new Scanner(System.in)
    val h = sc.nextInt()
    val w = sc.nextInt()
    sc.nextLine()
    fromString(List.fill(h)(sc.nextLine()).foldLeft("")({ case (acc, s) => s"${acc}${s}\n" }))
  }
}

case class Output(ans: Int) {
  override def toString(): String = {
    ans.toString()
  }

  def print() = println(this.toString())
}

object Main extends App {
  Input.fromStdin().solved.print()
}


Measured memory_bytes: 70352
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(N);
    vector<int> A(N+1),B(N);
    rep(i,N+1) cin >> A[i];
    rep(i,N) cin >> B[i];
    ll ans = 0;
    rep(i,N){
        ll beatsLeft = min(A[i],B[i]);
        A[i] -= beatsLeft;
        B[i] -= beatsLeft;
        ans += (ll)beatsLeft;
        if(B[i]>0){ 
            ll beatsRight = min(A[i+1],B[i]);
            A[i+1] -= beatsRight;
            B[i] -= beatsRight;
            ans += beatsRight;
        }
    }
    cout << ans << nn;
    return 0;
}

Measured memory_bytes: 1024
p, g, ig = 998244353, 3, 332748118
W = [pow(g, (p - 1) >> i, p) for i in range(24)]
iW = [pow(ig, (p - 1) >> i, p) for i in range(24)]

def fft(k, f):
    for l in range(k, 0, -1):
        d = 1 << l - 1
        U = [1]
        for i in range(d):
            U.append(U[-1] * W[l] % p)
        
        for i in range(1 << k - l):
            for j in range(d):
                s = i * 2 * d + j
                f[s], f[s+d] = (f[s] + f[s+d]) % p, U[j] * (f[s] - f[s+d]) % p

def ifft(k, f):
    for l in range(1, k + 1):
        d = 1 << l - 1
        for i in range(1 << k - l):
            u = 1
            for j in range(i * 2 * d, (i * 2 + 1) * d):
                f[j+d] *= u
                f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
                u = u * iW[l] % p

def convolve(a, b):
    n0 = len(a) + len(b) - 1
    k = (n0).bit_length()
    n = 1 << k
    a = a + [0] * (n - len(a))
    b = b + [0] * (n - len(b))
    fft(k, a), fft(k, b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(k, a)
    invn = pow(n, p - 2, p)
    for i in range(n0):
        a[i] = a[i] * invn % p
    del a[n0:]
    return a

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
print(*convolve(A, B))


Measured memory_bytes: 204336
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  u == s ? --a : --b;
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (){
	int i, m[3] = {}, a;
	for(i = 0; i < 10; i++){
		scanf("%d", &a);
		if(a > m[0]){
			m[2] = m[1];
			m[1] = m[0];
			m[0] = a;
		} else if(a > m[1]){
			m[2] = m[1];
			m[1] = a;
		} else if(a > m[2]){
			m[2] = a;
		}
	}
	for(i = 0; i < 3; i++){
		printf("%d\n", m[i]);
	}
	return 0;
}

Measured memory_bytes: 600
def main():
    a,b,c,x,y = map(int, input().split())
    ans = 10**10
    for i in range(max(x, y)+1):
        total = i*2*c + max(0, x-i)*a + max(0, y-i)*b
        ans = min(ans, total)
    print(ans)


    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
import sys
from math import *

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a,b,h,m=MI()
    r1=2*pi*m/60
    r2=2*pi*(h*60+m)/720
    rad=abs(r1-r2)
    if rad>pi:rad=2*pi-rad
    ans=sqrt(a**2+b**2-2*a*b*cos(rad))
    print(ans)

main()

Measured memory_bytes: 9436
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

ll a[100001], b[100001];
ll diff[100001];

int
main(void){  
  ios_base::sync_with_stdio(false);

  ll n=0LL, mns=0LL, pls=0LL;
  ll sum_minus = 0LL;
  cin >> n;
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];

  ll sum_a=0LL, sum_b=0LL;
  REP(i, n) {
    sum_a += a[i];
    sum_b += b[i];
    diff[i] = a[i] - b[i];
    
    if(diff[i] < 0) {
      sum_minus += diff[i];
    }
  }
  if(sum_a < sum_b) {cout << "-1" << endl; return 0;}
  sum_a = sum_a - sum_b; 

  sort(diff, diff+n, greater<ll>());

  //cout << sum_minus << endl;
  
  int itr = 0;
  //sum_a = 0;
  while(sum_minus < 0){
    sum_minus += diff[itr];
    mns++;
    itr++;
  }

  //cout << diff[0] <<endl;

  sum_a = 0;
  REP(i, itr){
    sum_a += diff[i];
  }
  
  REP(i, n){
    if(diff[i] < 0){
      sum_a += diff[i];
      //cout << "sum_a: " << sum_a << " diff[" << i << "]: " << diff[i] << endl;      
      if(sum_a < 0) break;
      pls++;
    }
  }

  
  cout << pls+mns << endl;
  
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;
int n;
map<string, int>arr;

int main(){
	IOS
	cin >> n;
	while(n--){
		string a;
		cin >> a;
		arr[a]++;
	}
	int maks=-1;
	for(auto x:arr){
		maks=max(maks, x.second);
	}
	//cout << maks.second;
	for(auto i:arr){
		if(i.second==maks){
			cout << i.first << endl;
		}
	}
}

Measured memory_bytes: 19272
from itertools import combinations
N=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(N):
    S=input()
    if(S[0]=='M'):
        m+=1
    elif(S[0]=='A'):
        a+=1
    elif(S[0]=='R'):
        r+=1
    elif(S[0]=='C'):
        c+=1
    elif(S[0]=='H'):
        h+=1
res=0
for x in combinations([m,a,r,c,h],3):
    res+=x[0]*x[1]*x[2]
print(res)

Measured memory_bytes: 49768
#include<stdio.h>
int main(void){
int a,b;

scanf("%d %d\n",&a,&b);
if(a<b){
printf("a < b\n");
}
else if(a>b){
printf("a > b\n");
}
else if(a==b){
printf("a == b\n");
}
return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n, m; cin >> n >> m;
	cout << n*(n-1)/2 + m*(m-1)/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define ll long long 
#define MAX 150 
using namespace std; 
void printString(ll n) 
{ 
	char str[MAX];
	ll i = 0;
	while (n > 0) { 
		int rem = n % 26; 
		if (rem == 0){ 
			str[i++] = 'z'; 
			n = (n / 26) - 1; 
		} 
		else{ 
			str[i++] = (rem - 1) + 'a'; 
			n = n / 26; 
		} 
	} 
	str[i] = '\0'; 
	reverse(str, str + strlen(str)); 
	cout << str << endl; 
	return; 
} 
int main() 
{ 
    ll n;
    cin >> n;
	printString(n);
	return 0; 
} 


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


int main(){


    char S[200001];
    char T[200001];

    scanf("%s",S);
    scanf("%s",T);

    int i;
    int n=0;

    for (i=0;i<strlen(S);i++){
        if(S[i]!=T[i]){
            T[i]=S[i];
            n++;

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

}

Measured memory_bytes: 2128
N = int(input())
ans = 0
for i in range(N):
    x,u = map(str,input().split())
    if(u == "JPY"):
        ans += int(x)
    else:
        x = x.replace(".","")
        ans += (int(x) * 380000 / 10**8)
print(str(ans))

Measured memory_bytes: 9116
///////////////////////////////////////////// Template /////////////////////////////////////////////
#![allow(non_snake_case, unused)]
use std::collections::*;

//////////////////// missing functions in 1.15.1 ////////////////////
macro_rules! eprint {
	($($t:tt)*) => { {
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	} };
}
macro_rules! eprintln {
	($($t:tt)*) => { {
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	} };
}

//////////////////// useful functions ////////////////////
pub trait SetMin {
	fn setmin(&mut self, v: Self) -> bool;
}
impl<T> SetMin for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
}
pub trait SetMax {
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMax for T where T: PartialOrd {
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

macro_rules! debug {
	($($v: expr),*) => {
		$(eprint!("{} = {:?} ", stringify!($v), $v);)*
		eprintln!("@ {}:{}", file!(), line!());
	}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:ty),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}
////////////////////////////////////////////////////////////////////////////////////////////////////

fn run() {
	let s = read!([char]);
	let w = read!(usize);
	let mut i = 0;
	while i < s.len() {
		print!("{}", s[i]);
		i += w;
	}
	println!();
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

template < typename T > std::string toString( const T& n )
    {
        std::ostringstream stm ;
        stm << n ;
        return stm.str() ;
    }

int N, M;
V(bool) hate(10, false);

int dfs(string s) {
    if(s.size()==M) {
        int temp = 0;
        int mul = 1;
        rep(i, s.size()) {
            temp += int(s[i]-'0')*mul;
            mul *= 10;
        }
        if(temp >= N) return temp;
    } else if(s.size() > M) {
        int temp = 0;
        int mul = 1;
        rep(i, s.size()) {
            temp += int(s[i]-'0')*mul;
            mul *= 10;
        }
        return temp>=N ? temp : INF;
    }
    int res = INF;
    rep(i, 10) {
        if(!hate[i]) res = min(res, dfs(s+char('0'+i)));
    }
    return res;
    
}

signed main() {
    int K;
    cin >> N >> K;
    rep(i, K) {
        int d;
        cin >> d;
        hate[d] = true;
    }

    string s = toString(N);
    M = s.size();

    cout << dfs("") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    for(int i=1; i<=9; i++){
        if(A % i == 0){
            if((A/i) >= 1 && (A/i) <= 9){
                cout << "Yes";
                return 0;
            }
        }
    }

    cout << "No";
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  vector<ll> a(n+1),limit(n);
  rep(i, n+1)cin>>a[i];

  if(n==0){
    if(a[0]==1)cout<<1<<endl;
    else cout<<-1<<endl;
    return 0;
  }

  limit[n-1]=a[n]+a[n-1];
  rrep(i, n-1){
    limit[i] = limit[i+1]+a[i];
  }
  limit.push_back(a.back());

  ll result = 1;
  ll l=1;

  if(a[0]==1 && n>0) { cout<<-1<<endl; return 0; }

  rep(i, n+1){
    ll c=a[i];

    ll nl = min<ll>((l-c)*2, limit[i+1]);
    if(l-c<0) { cout<<-1<<endl; return 0;}
//    if(l-c<0 || nl-a[i+1]<0) { cout<<-1<<endl; return 0;}
//    if(l==0 && a[i]>0) { cout<<-1<<endl; return 0;}

    if(i<n-1)result += nl;
    swap(l, nl);
  }

//  if(l!=a.back()) { cout<<-1<<endl; return 0;}

  cout<<result+a.back()<<endl;

  return 0;
}


Measured memory_bytes: 5572