akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string s; cin >> s;
    lint min_max_dist = 1LL << 58;
    range(i, 0, 26) {
        char c = 'a' + i;
        lint max_dist = 0, dist = 0;
        range(j, 0, s.size()) {
            if (s.at(j) == c) {
                max_dist = max(max_dist, dist);
                dist = 0;
            }
            else dist += 1;
        }
        max_dist = max(max_dist, dist);
        min_max_dist = min(min_max_dist, max_dist);
    }
    cout << min_max_dist << "\n";
}

Measured memory_bytes: 256
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass
    
N = int(input())
p = list(filter(lambda x:x%10 == 1, primes(55555)))
for i in range(N):
    print(p[i], end=" ")


Measured memory_bytes: 39664
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
def walk(a,b,c):
    a.extend(b)
    a.extend(c)
    #print(a)
    count1=a.count(1)
    count2=a.count(2)
    count3=a.count(3)
    count4=a.count(4)
    list=[count1,count2,count3,count4]
    #print(list)
    if list.count(1)==2 and list.count(2)==2:
        return print("YES")
    else:
        return print("NO")
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
walk(a,b,c)


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<int> a(N + 1, 0);
  rep(i, N) cin >> a[i + 1];
  vector<int> cnt(N + 1, 0), b(N + 1, 0);

  for (int i = N; i > 0; i--) {
    if (a[i] != (cnt[i] % 2)) {
      b[i] = 1;
      for (int j = 1; j * j <= i; j++) {
        if (i % j == 0) {
          cnt[j]++;
          if (i / j != j) cnt[i / j]++;
        }
      }
    }
  }

  vector<int> ans;
  rep(i, N) if (b[i + 1]) ans.eb(i + 1);

  cout << ans.size() << endl;
  rep(i, ans.size()) {
    if (i != 0) cout << ' ';
    cout << ans[i];
  }
  if (ans.size() > 0) cout << endl;
}


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

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

const ll MOD = 998244353;

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n & 1)ans = ans * x % MOD;
        x = x * x % MOD;
        n = n >> 1;
    }
    return ans;
}

int main(){
    int m, d;
    cin >> m >> d;
    int res = 0;
    REP(i, 1, m){
        REP(j, 22, d){
            int a = j / 10, b = j % 10;
          if(a < 2 || b < 2)continue;
            if(i == a * b)res++;
        }
    }
    cout << res;
}

Measured memory_bytes: 888
#include <iostream>

#define ll long long

using namespace std;

int main() {
    int n, m;
    ll h[100001], maxh[100001];
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
        maxh[i] = 0;
    }
    int a, b;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        if (maxh[a] < h[b]) {
            maxh[a] = h[b];
        }
        if (maxh[b] < h[a]) {
            maxh[b] = h[a];
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (maxh[i] < h[i]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long LL;
inline int toint(char c){
    if(isdigit(c)) return c - '0';
    else if(isupper(c)) return c - 'A' + 10;
    else if(islower(c)) return c - 'a' + 36;
}
LL parse(){
    int p;
    char m[100];
    scanf("%d %s", &p, m);
    LL res = 0;
    for(int idx = 0; m[idx]; idx++){
        res = res * p + toint(m[idx]);
    }
    return res;
}

int main(){
    int n;
    while(cin >> n){
        LL sum = 0;
        for(int i = 0; i < n; i++){
            LL x = parse();
            sum = sum ^ x;
        }
        if(sum == 0){
            cout << "lose" << endl;
        }else{
            cout << "win" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1240
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353 
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,t,a[3005],b[3005];
int dp[3005][3005];
vector<P>vec;
int main(){
	cin>>n>>t;
	repn(i,n) cin>>a[i]>>b[i];
	repn(i,n) vec.pb(P(a[i],b[i]));
	sort(vec.begin(),vec.end());
	repn(i,n) { a[i] = vec[i-1].fi; b[i] = vec[i-1].sc; }
	
	rep(i,3005)rep(j,3005)dp[i][j]=-INF;
	dp[0][0] = 0;
	int ans = 0;
	repn(i,n){
		rep(j,t){
			if(dp[i-1][j] < 0) continue;
			ans = max(ans,dp[i-1][j]+b[i]);
			if(j+a[i] < t) dp[i][j+a[i]] = max(dp[i][j+a[i]],dp[i-1][j]+b[i]);
			dp[i][j] = max(dp[i][j],dp[i-1][j]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n;
	cin>>n;
	ll arr[n+1],cnt[200002]={0};
	for(int i=2;i<=n;i++){
		cin>>arr[i];
		cnt[arr[i]]++;
	}
	for(int i=1;i<=n;i++) cout<<cnt[i]<<endl;
	return 0;
}

Measured memory_bytes: 6720
#include<bits/stdc++.h>
using namespace std;
#define R freopen("A.in","r",stdin);
#define W freopen("A.out","w",stdout);
const int maxn = 205;
const double eps=1e-10;
const double pi=acos(-1);
struct Point
{
    double x, y,id;
    Point(double x=0, double y=0,int id=0):x(x),y(y),id(id) { }
};
typedef Point Vector;
int dcmp(double x)
{
    if(fabs(x) < eps) return 0;
    else return x < 0 ? -1 : 1;
}
Vector operator + (Vector A, Vector B)
{
    return Vector(A.x+B.x, A.y+B.y);
}
Vector operator - (Point A, Point B)
{
    return Vector(A.x-B.x, A.y-B.y);
}
Vector operator * (Vector A, double p)
{
    return Vector(A.x*p, A.y*p);
}
Vector operator / (Vector A, double p)
{
    return Vector(A.x/p, A.y/p);
}
bool operator < (const Point& a, const Point& b)
{
    return a.x < b.x || (a.x == b.x && a.y < b.y);
}
bool operator == (const Point& a, const Point &b)
{
    return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;
}
double Dot(Vector A, Vector B)
{
    return A.x*B.x + A.y*B.y;
}
double Length(Vector A)
{
    return sqrt(Dot(A, A));
}
double Angle(Vector A, Vector B)
{
    return acos(Dot(A, B) / Length(A) / Length(B));
}
double Cross(Vector A, Vector B)
{
    return A.x*B.y - A.y*B.x;
}
double angle(Vector v)
{
    return atan2(v.y, v.x);
}

Vector Rotate(Vector A, double rad)
{
    return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
}
Vector Normal(Vector A)
{
    double L = Length(A);
    return Vector(-A.y/L, A.x/L);
}
Point read_point(int k)
{
    double x, y;
    scanf("%lf%lf", &x, &y);
    return Point(x, y,k);
};

// 点集凸包
// 如果不希望在凸包的边上有输入点，把两个 <= 改成 <
// 注意：输入点集会被修改
vector<Point> ConvexHull(vector<Point>& p)
{
    // 预处理，删除重复点
    sort(p.begin(),p.end());
    p.erase(unique(p.begin(), p.end()), p.end());

    int n = p.size();
    int m = 0;
    vector<Point> ch(n+1);
    for(int i = 0; i < n; i++)
    {
        while(m > 1 && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--;
        ch[m++] = p[i];
    }
    int k = m;
    for(int i = n-2; i >= 0; i--)
    {
        while(m > k && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--;
        ch[m++] = p[i];
    }
    if(n > 1) m--;
    ch.resize(m);
    return ch;
}
bool OnSegment(const Point& p, const Point& a1, const Point& a2)
{
    return dcmp(Cross(a1-p, a2-p)) == 0 && dcmp(Dot(a1-p, a2-p)) < 0;
}
vector<Point>p;
double ans[maxn];
int n,f;
int main()
{
    
    cin>>n;
    for(int i=0; i<n; i++)
        p.push_back(read_point(i));
    sort(p.begin(),p.end());
    for(int i=1;i<n-1;i++)
    {
        if(OnSegment(p[i],p[0],p[n-1]))continue;
        f=1;break;
    }
    if(!f)
    {
        int id1=p[0].id,id2=p[n-1].id;
        ans[id1]=ans[id2]=0.5;
    }
    else{
    p=ConvexHull(p);
    int m=p.size();
    for(int i=0; i<m; i++)
    {
        Point la=p[(i+m-1)%m],ne=p[(i+1)%m],no=p[i];
        int id=no.id;
        ans[id]=(pi-Angle(la-no,ne-no))/(2.0*pi);
    }
    }
    for(int i=0; i<n; i++)
    {
        printf("%.20f\n",ans[i]);
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  vector<int> seen(n, -1);
  vector<int> a(n), b(n);
  for(int i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }
  queue<pair<int, int>> que;
  que.push({0, 0});
  seen[0] = 0;

  int maxi = 0;
  map<pair<int, int>, int> mp;
  while(!que.empty()) {
    auto tmp = que.front();
    que.pop();
    int t = 1, skip = tmp.second;
    for(auto p : g[tmp.first]) {
      if(seen[p] == -1) {
        if(t == skip) {
          t++;
        }
        seen[p] = t;
        que.push({p, t});
        mp[{tmp.first, p}] = t;
        mp[{p, tmp.first}] = t;
        maxi = max(maxi, t);
        t++;
      }
    }
  }
  cout << maxi << '\n';
  for(int i = 0; i < n - 1; i++) {
    cout << mp[{a[i], b[i]}] << '\n';
  }
  return 0;
}

Measured memory_bytes: 19712
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 100007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

void solve()
{
    TIN(string, s, t);
    ll m  = INF;
    rep(i, s.size()-t.size()+1) {
        ll a = 0;
        rep(j, t.size()) {
            if (s[i+j] != t[j]) ++a;
        }
        chmin(m, a);
    }
    cout << m << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

int main() {
	int n;
	int a = 0, b = 0;

	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			int x, y;
			cin >> x >> y;
			if (x > y) { a += (x + y); }
			else if (x < y) { b += (x + y); }
			else { 
			a += x;
			b += y;
			}
		}
		cout << a <<' '<< b << endl;
		a = 0;
		b = 0;
	}
	return 0;
}

Measured memory_bytes: 2948
while True:
    h,w = map(int, input().split())
      
    if h == 0 and w == 0:
        break
    for i in range(h):
        if i == 0 or i == h - 1:
            print('#' * w)
        else:
            print('#' + '.' * (w - 2) + '#')
    print()


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

int n, t, s, a[3001], b[3001], dp[3001][3001];

int main()
{
	cin >> n >> t >> s;
	for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];

	for (int i = 1; i <= t; i++){
		for (int j = 1; j <= n; j++){
			if (i - b[j] >= ((i <= s) ? 0 : s) && max(dp[i][j - 1], dp[i - 1][j]) < dp[i - b[j]][j - 1] + a[j]) dp[i][j] = dp[i - b[j]][j - 1] + a[j];
			else dp[i][j] = max(dp[i][j - 1],dp[i - 1][j]);
		}
	}
	cout << dp[t][n] << endl;
	return 0;
}

Measured memory_bytes: 36364
#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

const int maxn = 51;
int h, w;
char maps[maxn][maxn];
int vis[maxn][maxn];

struct Node{
    int x, y, dis;
    Node(int x=0, int y=0, int dis=0):x(x), y(y), dis(dis) {}
};

int bfs(){
    queue<Node> q;
    Node st;
    st.x=0;
    st.y=0;
    st.dis=1;
    q.push(st);
    while(!q.empty()){
        Node u = q.front();
        q.pop();
        if(u.x==h-1 && u.y==w-1) return u.dis;
        for(int dx=-1; dx<=1; dx++){
            if(dx!=0 && u.x+dx >= 0 && u.x+dx < h){
                if(!vis[u.x+dx][u.y] && maps[u.x+dx][u.y] == '.') {
                    q.push(Node(u.x+dx, u.y, u.dis+1));
                    vis[u.x+dx][u.y] = 1;
                }
            }
        }
        for(int dy=-1; dy<=1; dy++){
            if(dy!=0 && u.y+dy >= 0 && u.y+dy < w){
                if(!vis[u.x][u.y+dy] && maps[u.x][u.y+dy] == '.') {
                    q.push(Node(u.x, u.y+dy, u.dis+1));
                    vis[u.x][u.y+dy] = 1;
                }
            }
        }
    }
    return -1;
}

int main(){
    while(cin >> h >> w){
        memset(vis, 0, sizeof(vis));
        vis[0][0] = 1;
        int cnt = 0;
        for(int i=0; i<h; i++)
            for(int j=0; j<w; j++)
                {
                    cin >> maps[i][j];
                    if(maps[i][j] == '.') cnt++;
                }
        int ans = bfs();
        /*for(int i=0; i<h; i++){
            cout << endl;
            for(int j=0; j<w; j++)
                cout << vis[i][j];
        }*/
        if(ans == -1) cout << ans << endl;
        else cout << cnt - ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define ll long long int
#define mod 1000000007
#define vec vector<long long int>
#define fi first
#define se second
#define pb push_back

int main()
{
    vector<int> x;
    for (int i = 0; i < 5; i++)
    {
        ll t;
        cin >> t;
        x.pb(t);
    }
    for (int i = 0; i < 5; i++)
    {
        if (x[i] == 0)
        {
            cout << i + 1;
        }
    }
}

Measured memory_bytes: 3600
import java.util.Scanner;

class Main{
    public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int ans,n;
    while(sc.hasNext()){
    	n=sc.nextInt();
    	ans=0;
    	if(n==1)ans=-1;
    	for(int i=1;i<=n;i+=2){
    		int flag=0;
    		for(int j=3;j<=Math.sqrt(i);j+=2){
    			if(i%j==0){
    				flag=1;break;
    			}
    		}
    		if(flag==0)ans++;
    	}
    	System.out.println(ans);
    }
    }
}

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

using namespace std;

int main()
{
//    freopen("in.txt","r",stdin);
    double a[1010];
    int n;
    while(cin>>n&&n)
    {
        double sum=0;
        for(int i=0;i<n;i++)
        {
            scanf("%lf",&a[i]);
            sum+=a[i];
        }

        double avg=sum/n;
        double var=0;
        for(int i=0;i<n;i++)
        {
            var+=(a[i]-avg)*(a[i]-avg);

        }
        var/=n;
        printf("%.8lf\n",sqrt(var));
    }
}



Measured memory_bytes: 3236
from sys import stdin
import sys

S = stdin.readline().rstrip()
T = ''

data = ['dream', 'erase', 'dreamer', 'eraser']

if len(S) < len('dream'):
    print('NO')
    sys.exit()

pos = 0

OTHER=0
DREAM=1
ERASE=2
last_word = OTHER

while pos < len(S):
    if S[pos:pos+len(data[0])] == data[0]:
        pos = pos + len(data[0])
        last_word = DREAM
    elif S[pos:pos+len(data[1])] == data[1]:
        pos = pos + len(data[1])
        last_word = ERASE
    elif S[pos:pos+len(data[2])] == data[2]:
        pos = pos + len(data[2])
        last_word = OTHER
    elif S[pos:pos+len(data[3])] == data[3]:
        pos = pos + len(data[3])
        last_word = OTHER
    elif last_word == DREAM and S[pos:pos+len('er')] == 'er':
        pos = pos + len('er')
        last_word = OTHER
    elif last_word == ERASE and S[pos:pos+len('r')] == 'r':
        pos = pos + len('r')
        last_word = OTHER
    else:
        print('NO')
        sys.exit()


print('YES')


Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;

int r,d,x,arr[11];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>r>>d>>x;
	arr[0]=x;
	for(int i=0;i<10;i++){
		arr[i+1]=r*arr[i]-d;
		cout<<arr[i+1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
	  result=(result*base)%modulus;
	  exponent=exponent>>1;
	  base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/
ll n,m;
vl a[MAX];
int main(){FAST;
cin>>n>>m;
for(ll i=1;i<=n;i++){
	ll x,y;cin>>x>>y;
	a[x].pb(y);
}
priority_queue<ll>pq;
ll ans = 0;
for(ll i=1;i<=m;i++){
	for(auto it:a[i]){
		pq.push(it);
	}
	if(!pq.empty())ans+=pq.top(),pq.pop();
}
cout<<ans;
return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "")
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    cout << min(B / A, C) << endl;
    return 0;
}


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

struct edge {
	int to, cost;
	edge(int to_, int cost_):to(to_), cost(cost_) {}
};

struct state {
	int v;
	int dist;
	bool used;
	state(int v_, int dist_, bool used_):v(v_), dist(dist_), used(used_) {}
	bool operator>(const state &s) const {
		return dist > s.dist;
	}
};

vector<int> calc(int s, const vector<vector<edge>> &G) {
	typedef pair<int, int> P;
	const int n = G.size();

	queue<P> que;
	que.push({0, s});

	vector<int> res;
	vector<bool> in_res(n, false);
	in_res[s] = true;

	while(!que.empty()) {
		const int d = que.front().first;
		const int v = que.front().second;
		que.pop();

		if(d > 2) break;

		if(d == 2 && !in_res[v]) {
			res.emplace_back(v);
			in_res[v] = true;
		}

		for(const auto &e : G[v]) {
			que.push({d + 1, e.to});
		}
	}

	return res;
}

int dijkstra(const vector<vector<edge>> &G, const vector<vector<int>> &G_dist2) {
	const int n = G.size();
	vector<vector<int>> dist(n, vector<int>(2, INT_MAX));
	dist[0][0] = 0;
	priority_queue<state, vector<state>, greater<state>> que;
	que.push(state(0, 0, false));

	while(!que.empty()) {
		const state s = que.top();
		que.pop();

		if(dist[s.v][s.used] < s.dist) continue;
		if(s.v == n - 1) return s.dist;

		for(const auto &e : G[s.v]) {
			const int next_dist = s.dist + e.cost;
			if(dist[e.to][s.used] > next_dist) {
				dist[e.to][s.used] = next_dist;
				que.push(state(e.to, next_dist, s.used));
			}
		}

		if(s.used) continue;
		for(const auto &to : G_dist2[s.v]) {
			if(dist[to][true] > s.dist) {
				dist[to][true] = s.dist;
				que.push(state(to, s.dist, true));
			}
		}
	}
	assert(false);
}

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

	for(int n, m; cin >> n >> m && (n | m);) {
		vector<vector<edge>> G(n);

		for(int i = 0; i < m; ++i) {
			int a, b, c;
			cin >> a >> b >> c;
			--a; --b;
			G[a].emplace_back(b, c);
			G[b].emplace_back(a, c);
		}

		vector<vector<int>> G_dist2;
		G_dist2.reserve(n);
		for(int i = 0; i < n; ++i) {
			G_dist2.emplace_back(calc(i, G));
		}

		cout << dijkstra(G, G_dist2) << endl;
	}

	return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    string s;
    cin >> s;
    int maxi = 0;
    int seq = 0;
    for (char c : s)
    {
        if (c == 'A' || c == 'C' || c == 'G' || c == 'T')
        {
            ++seq;
        }
        else
        {
            maxi = max(seq, maxi);
            seq = 0;
        }
    }
    maxi = max(seq, maxi);
    cout << maxi << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
     
    int main(){
      int A[3];
      cin >> A[0] >> A[1] >> A[2];
      sort(A,A+3);
      cout << 10*A[2]+A[1]+A[0];
      return 0;}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (G[i].empty()) {
      ans++;
      continue;
    }
    bool good = true;
    for (auto to : G[i]) {
      if (H[i] <= H[to]) {
        good = false;
        break;
      }
    }
    if (good) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8804
N = int(input())
upper = list(input())
lower = list(input())
ans = 0

def count(upper, lower, state):
    global ans
    if upper[0] == lower[0]:
        if state == 1:
            ans *= 2
            try:
                count(upper[1:],lower[1:],state=1)
            except:
                return ans
        if state == 2:
            try:
                count(upper[1:], lower[1:], state=1)
            except:
                return ans
    else:
        if state == 1:
            ans *= 2
            try:
                count(upper[2:], lower[2:], state=2)
            except:
                return ans
        if state == 2:
            ans *= 3
            try:
                count(upper[2:], lower[2:], state=2)
            except:
                return ans

if upper[0] == lower[0]:
    ans = 3
    try:
        count(upper[1:], lower[1:], state=1)
    except:
        pass
else:
    ans = 6
    try:
        count(upper[2:], lower[2:], state=2)
    except:
        pass

print(ans%1000000007)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
    
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        String t = sc.next();
        int N = s.length();
        int M = t.length();
        char[] S = new char[N];
        char[] T = new char[M];
        
        for(int i = 0; i < N; i++) S[i] = s.charAt(i);
        for(int i = 0; i < M; i++) T[i] = t.charAt(i);
        
        //辞書順に文字列を並び替え
        Arrays.sort(S);
        Arrays.sort(T);
        
        //文字数の少ない数だけfor文をループ
        int loop = 0;
        if(N <= M){
            loop = N; 
        }else{
            loop = M;
        }
        
        //S[]の先頭とT[]の後方から文字列を比較
        for(int i = 0; i < loop; i++){
            if(S[i] < T[(M - 1) - i]){
                System.out.println("Yes");
                return;
            }else if(S[i] > T[i]){
                System.out.println("No");
                return;
            }else{
                continue;   
            }
        }
        //文字列が一緒のとき、文字数で比較
        System.out.println(N < M ? "Yes" : "No");
    }
}


Measured memory_bytes: 23892
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [None for _ in range(k+1)]
#dp[i]: i個のときにどっちが勝つか
for i in range(a[0]):
	dp[i] = "Second"
dp[a[0]] = "First"
for i in range(a[0]+1, k+1):
	f = False
	for j in range(n):
		if i < a[j]:
			break
		else:
			if dp[i - a[j]] == "Second":
				f = True
				break
	if f:
		dp[i] = "First"
	else:
		dp[i] = "Second"

#print(dp)
print(dp[-1])

Measured memory_bytes: 3864
N = int(input())
H = list(map(int,input().split()))

dp = [0]*N
dp[1] = abs(H[0] - H[1])
for i in range(2,N):
    dp[i] = min(dp[i-2] + abs(H[i-2]-H[i]), dp[i-1] + abs(H[i-1]-H[i]))
print(dp[-1])

Measured memory_bytes: 13980
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    sp = list(input().strip())
    s = ''
    for i, c in enumerate(sp):
        if i == 0 or sp[i-1] == ' ':
            s += c.upper()
    print(s)

main()


Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node {
    int key;
    Node *prev, *next;
};

Node *nil;

Node* listSearch(int key) {
    Node *cur = nil->next;
    while (cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while (1) {
        if (cur == nil) break;
        if (isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t) {
    if (t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    deleteNode(listSearch(key));
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main()
{

    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; ++i) {
        scanf("%s%d", com, &key);
        if (com[0] == 'i') {
            insert(key); ++np; ++size;
        }
        else if (com[0] == 'd') {
            if (strlen(com) > 6) {
                if (com[6] == 'F') deleteFirst();
                else if (com[6] == 'L') deleteLast();
            }
            else {
                deleteKey(key); ++nd;
            }
            --size;
        }
    }

    printList();

}


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

#define ll long long

using namespace std;

//memset(dp, 0, sizeof(dp));

void work(int T) {
	ll n, m = 26;
	cin >> n;
	n--;
	int l = 1;
	while(n >= m) {
		n -= m;
		m *= 26;
		l++;
	}
	string s;
	m /= 26;
	for(int i = 0; i < l; i++) {
		s += n / m + 'a';
		n %= m;
		m /= 26;
	}
	cout << s << endl;
	return;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
	// int t;
	// for(cin >> t; t > 0; t--) {
		// work(t);
	// }
	work(0);
	return 0;
};

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

int main(){
    char b;
    cin >> b;

    if(b == 'A'){
        cout << 'T' << endl;
    }
    else if(b == 'T'){
        cout << 'A' << endl;
    }
    else if(b == 'G'){
        cout << 'C' << endl;
    }
    else {
        cout << 'G' << endl;
    }
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n, m;
  cin >> n >> m;
  int tt = 0;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    tt += a[i];
  }
  int cnt = 0;
  rep(i, n) if (tt <= 4 * m * a[i]) cnt++;

  cout << (cnt >= m ? "Yes" : "No") << endl;
}


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

#include <vector>

int main(){
    int n,i,num=1;
    cin >> n; i=n;
    vector<int> p;
    while(i--){
        int tmp;cin >> tmp;
        if(tmp == num) {
            p.push_back(tmp);
            num++;
        }
    }
    if(p.size()==0){
        cout << -1 << endl;
    } else {
        cout << n-p.size() << endl;
    }
}

Measured memory_bytes: 4264
#include <bits/stdc++.h>
#define int long long
#define N 11
#define H (1e18)
#define W 76
using namespace std;
typedef pair<int,int> P;
const int INF = 1LL<<55;
const int mod = (1e9)+9;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
typedef vector<int> vec;
typedef vector<vec> mat;
int w,h,n;

mat mul(const mat &a,const mat &b){
  mat res(w,vec(w,0));
  for(int i=0;i<w;i++)
    for(int j=0;j<w;j++)
      for(int k=0;k<w;k++) res[i][j] = (res[i][j] + a[i][k]*b[k][j]%mod)%mod;
  
  return res;
}

vec calc(const mat &a,const vec &b){
  vec res(w,0);
  for(int i=0;i<w;i++)
    for(int j=0;j<w;j++) res[i] = (res[i] + b[j]*a[j][i]%mod)%mod;
  return res;
}

mat doubling(mat x,int y){
  mat res(w,vec(w,0));
  for(int i=0;i<w;i++) res[i][i] = 1;
  
  while(y){
    if(y%2) res = mul(res,x);
    y/=2;
    x = mul(x,x);
  }
  return res;
}


signed main(){
  int t = 0;
  while(1){
    cin>>w>>h>>n;
    if(w == 0 && h == 0 && n == 0) break;
    priority_queue <P,vector<P>,greater<P> > ng;
    int flg = 0 ;
    for(int i=0;i<n;i++){
      int x,y;
      cin>>x>>y;   x--,y--;
      flg |= (x == w-1) && (y == h-1);
      flg |= (x == 0) && (y == 0);
      if(y >= h) i--,n--;
      else if(y == 0) i--,n--;
      else ng.push(P(y,x));
    }
    ng.push(P(h-1,-1));
    
    vector<int> ans(w,0);   ans[0] = flg == 0;
    
    int height = 0;
    mat num(w,vec(w,0));
    for(int i=0;i<w;i++)
      for(int j=i-1;j<=i+1;j++)if(j>=0 && j<w) num[i][j] = 1;

    while(!ng.empty()){
      int nheight = ng.top().first;
      int d = nheight - height;
      mat res = doubling(num,d);
      ans = calc(res,ans);
      height = nheight;
      
      while(!ng.empty() && nheight == ng.top().first) {
        if(ng.top().second>=0) ans[ng.top().second] = 0; 
        ng.pop();
      }
    }
    
    assert(height == h-1);
    cout<<"Case "<<++t<<": "<<ans[w-1]<<endl;
  }
  return 0;
}

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

int main(){
    int n;
    cin>>n;
    string s;
    set<string>q;
    for(int i=0;i<n;i++)
        cin>>s,q.insert(s);
    cout<<q.size();
    return 0;
}


Measured memory_bytes: 19220
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2; // x^kがxの逆元
    ll y = x; // 検証してないけどこれ要らなくないですか
    while (k) {	// 二分累乗法
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}

int main(){
  ll N; cin >> N;
  vector<ll> X(N); rep(i,N) cin >> X[i];
  vector<ll> kaijo(100100, 1);
  rep(i,100005){
    kaijo[i+2] = kaijo[i+1] * (i+2);
    kaijo[i+2] %= mod;
  }
  ll ans = 0;
  ll now = kaijo[N-1];
  for(ll i=0; i<N-1; i++){
    ans += now*(X[i+1]-X[i]);
    ans %= mod;
    now += kaijo[N-1]*inv(i+2);
    now %= mod;
  }
  cout << ans%mod << endl;
  return 0;
}


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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair	
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld;	
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
	 
const ll MAX = 100400;
const ll inf = 1e18+5;

int main() {
	fastio;
	ll n, m, x;
  cin >> n >> m >> x;
  ll arr[n];
  vector<vi> v(n, vi(m));
  f(i,0, n) {
    cin >> arr[i];
    f(j,0, m) cin >> v[i][j];
  }
  ll ans = inf;
  f(s,0,1<<n) {
    ll now = 0;
    vi arr2(m);
    f(i,0, n) {
      if (s >> i & 1) {
        f(j,0, m) arr2[j] += v[i][j];
        now += arr[i];
      }
    }
 
    bool go = true;
    f(i,0, m) if (arr2[i] < x) go = false;
    if (go) ans = min(ans, now);
  }
 
  if (ans == inf) ans = -1;
  cout <<ans<< endl;
	return 0;
}

Measured memory_bytes: 3580
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll x[55],y[55];
ll xx[55],yy[55];
int n,K;
ll ans=9223372036854775807;
inline int check(int x1,int x2,int y1,int y2)
{
	int tot=0;
	for(int i=1;i<=n;i++)
	  if(x1<=x[i]&&x[i]<=x2&&y1<=y[i]&&y[i]<=y2) tot++;
	return tot;
}
int main()
{
	scanf("%d%d",&n,&K);
	for(int i=1;i<=n;i++)
	  scanf("%lld%lld",&x[i],&y[i]),xx[i]=x[i],yy[i]=y[i];
	sort(xx+1,xx+n+1);
	sort(yy+1,yy+n+1);
	for(int i=1;i<=n;i++)
	  for(int j=i;j<=n;j++)
	    for(int k=1;k<=n;k++)
	      for(int l=k;l<=n;l++)
		if(check(xx[i],xx[j],yy[k],yy[l])>=K) ans=min(ans,(xx[j]-xx[i])*(yy[l]-yy[k]));
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int h, w;
	cin >> h >> w;
	vector<vector<int>> v(h, vector<int>(w, 0));
	rep(i, h){
		rep(j, w){
			int in;
			cin >> in;
			in %= 2;
			v.at(i).at(j) = in;
		}
	}
	int n = 0;
	vector<vector<int>> ans;
	rep(i, h){
		rep(j, w){
			if((v.at(i).at(j) == 0) || (i == h-1 && j == w-1)) continue;
			n++;
			vector<int> add(4);
			add.at(0) = i+1; add.at(1) = j + 1;
			if(j != w-1){
				v.at(i).at(j+1) = (v.at(i).at(j+1) + 1) % 2;
				add.at(2) = i+1; add.at(3) = j + 2;
			}else{
				v.at(i+1).at(j) = (v.at(i+1).at(j) + 1) % 2;
				add.at(2) = i+2; add.at(3) = j + 1;
			}
			ans.push_back(add);
		}
	}
	cout << n << endl;
	rep(i, ans.size()){
		rep(j, 4){
			if(j != 0) cout << " ";
			cout << ans.at(i).at(j);
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 10032
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, (int)vec.size() - 1)std::cout << vec[i] << " ";
	if(!vec.empty())std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int n,a[100010],b[100010],c[100010];
int main(){
	std::cin>>n;
	rep(i,n)std::cin>>a[i];
	rep(i,n)std::cin>>b[i];
	rep(i,n)std::cin>>c[i];
	std::sort(a,a+n);
	std::sort(b,b+n);
	std::sort(c,c+n);
	lint ans=0;
	rep(i,n){
		ans+=(std::lower_bound(a,a+n,b[i])-a)*(c+n-std::upper_bound(c,c+n,b[i]));
	}
	std::cout<<ans<<std::endl;
	return 0;
}

Measured memory_bytes: 4808
import sys
import heapq
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    a = list(map(int, input().split()))

    q = []
    for i in range(N):
        heapq.heappush(q, -a[i])
    
    for i in range(M):
        t = -heapq.heappop(q)
        t /= 2
        heapq.heappush(q, -t)
    
    ans = 0
    for i in range(N):
        ans += int(- q[i])
    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;

long long x, k, d;

int main() {
	scanf("%lld%lld%lld", &x, &k, &d);
	x = abs(x);
	long long tmp = min(k, x / d);
	x -= tmp * d;
	k -= tmp;
	tmp = abs(x - d);
	printf("%lld\n", k % 2 == 0 ? x : tmp);
}

Measured memory_bytes: 3804
#include <stdio.h>
#define MAX 500000

int H[MAX+1];

void maxHeepify( int , int );
void buildMaxHeep( int );
void swap(int , int );


int main(){
  int i;
  int n;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&H[i]);
    // printf(" %d",H[i]);
  }

  
  buildMaxHeep(n);

  for(i=1;i<=n;i++){
    printf(" %d",H[i]);
  }

  printf("\n");
  
  return 0;
}


void maxHeepify(int i, int n ){
  int l,r;
  int largest;
 
  l = i*2;
  r = i*2+1;
  //左の子、自分、右の子で値が最大のノードを選ぶ

  if( l <= n && H[l] > H[i] )
    largest = l;
  else
    largest = i;

  if( r <= n && H[r] > H[largest] )
    largest = r;

  if(largest != i){
    swap(i , largest );
    maxHeepify(largest,n);
  }


  

}

void buildMaxHeep(int n){
  int i;

  for(i=n/2 ; i >= 1 ; i--){
    maxHeepify(i,n);
  }
  
}

void swap(int a, int b){

  int tmp;
  tmp = H[a];
  H[a]= H[b];
  H[b]= tmp;

}



Measured memory_bytes: 3684
a, b = map(int, input().split())
c = 0
for i in range(1, 1001):
    tax_8 = (i * 2 / 25) // 1
    tax_10 = (i / 10) // 1
    if tax_8 == a and tax_10 == b:
        print(i)
        c += 1
        break
if c == 0:
    print('-1')


Measured memory_bytes: 2940