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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  string s;
  cin>>s;
  REP(i,4)cout<<s[i];
  cout<<" ";
  REP(i,8)cout<<s[i+4];
  cout<<endl;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            long fact = n;

            for (int i = n - 1; i > 0; i--) fact *= i;

            Console.WriteLine(fact);
        }
    }
}

Measured memory_bytes: 9168
#!/usr/bin/env python3
import sys
import numpy as np

# https://atcoder.jp/contests/abc152/submissions/9602537
def solve(N: int, P: "List[int]"):
    P = np.array(P)
    Q = np.minimum.accumulate(P)
    # print(np.count_nonzero(P<=Q))
    print(np.sum(P<=Q))



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P)

if __name__ == '__main__':
    main()


Measured memory_bytes: 37268
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  if (m != 100) {
  if (n != 0) {
    cout << pow(100, n)*m << endl;
  }
  if (n == 0) {
    cout << 1*m << endl;
  }
  }
  else {
    if (n != 0) {
      if (n == 2) {
        cout << 1010000 << endl;
      }
      else {
    cout << pow(100, n)*101 << endl;
  }
    }
  if (n == 0) {
    cout << 1*101 << endl;
  }
  }
}

Measured memory_bytes: 3916
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


const int SIZE = 101;
int N; 
int M; 
int L; 
int K; 
int A; 
int H; 

bool CD[SIZE];
int CNT[SIZE]; 
int DEST[SIZE][SIZE]; 
int COST[SIZE][SIZE]; 

void init() {
    fill( CD, CD+SIZE, false );
    fill( CNT, CNT+SIZE, 0 );
}

void input() {
    CD[A] = CD[H] = true;
    for ( int i = 0; i < L; ++ i ) {
        int townID;
        cin >> townID;
        CD[townID] = true;
    }
    for ( int i = 0; i < K; ++ i ) {
        int x, y, t;
        cin >> x >> y >> t;
        DEST[x][CNT[x]] = y;
        DEST[y][CNT[y]] = x;
        COST[x][CNT[x]] = t;
        COST[y][CNT[y]] = t;
        CNT[x] ++;
        CNT[y] ++;
    }
}

typedef pair <int, II> NODE;
typedef priority_queue <NODE, vector<NODE>, greater<NODE> > QUEUE;
QUEUE Q;
int MC[SIZE][SIZE];
int solve() {
    Q = QUEUE();
    fill( (int*)MC, (int*)MC+SIZE*SIZE, INT_MAX );

    Q.push( NODE( 0, II( A, M ) ) );
    MC[A][M] = 0;

    while ( ! Q.empty() ) {
        NODE node = Q.top();
        Q.pop();

        int steps = node.first;
        int townID = node.second.first;
        int remain = node.second.second;

        if ( townID == H ) {
            return steps;
        }

        for ( int i = 0; i < 1 && CD[townID]; ++ i ) {
            int nSteps = steps + 1;
            int nRemain = min( M, remain + 1 );
            int nTownID = townID;
            if ( nSteps >= MC[nTownID][nRemain] ) continue;
            MC[nTownID][nRemain] = nSteps;
            NODE next( nSteps, II( nTownID, nRemain ) );
            Q.push( next );
        }
        for ( int i = 0; i < CNT[townID]; ++ i ) {
            int nTownID = DEST[townID][i];
            int nSteps = steps + COST[townID][i];
            int nRemain = remain - COST[townID][i];
            if ( nRemain < 0 ) continue;
            if ( nSteps >= MC[nTownID][nRemain] ) continue;
            MC[nTownID][nRemain] = nSteps;
            NODE next( nSteps, II( nTownID, nRemain ) );
            Q.push( next );
        }
    }
    
    return -1;
}

int main() {
    while ( cin >> N >> M >> L >> K >> A >> H && N ) {
        init();
        input();
        int ret = solve();
        if ( ret == -1 ) cout << "Help!" << endl;
        else cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 1192
import sys
readline = sys.stdin.readline

def check():
    R = [0]*(N+1)
    R[0] = 1
    for i in range(N):
        if R[i] < A[i]:
            return -1
        R[i+1] = 2*(R[i]-A[i])
    if R[N] < A[N]:
        return -1
    
    
    CA = A[:]
    
    for i in range(N-1, -1, -1):
        CA[i] += CA[i+1]
    
    
    return sum(min(r, c) for r, c in zip(R, CA))


N = int(readline())
A = list(map(int, readline().split()))

if N == 0:
    if A[0] == 1:
        print(1)
    else:
        print(-1)
elif A[0] or A[N] == 0:
    print(-1)
else:
    print(check())

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


int main() 
{

    vector<vector<int>> A(3, vector<int>(3));

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> A.at(i).at(j);
        }
    }

  
    int N;
    int B;
  	cin >> N;
    for(int i=0;i<N;i++){
       cin >> B;
       for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if(A.at(i).at(j)==B){
                   A.at(i).at(j)=0;
                }
           }
        }
    }
  
    bool flag = false;
    if(A.at(0).at(0)==0&&A.at(0).at(1)==0&&A.at(0).at(2)==0)
        flag=true;
    if(A.at(1).at(0)==0&&A.at(1).at(1)==0&&A.at(1).at(2)==0)
        flag=true;
    if(A.at(2).at(0)==0&&A.at(2).at(1)==0&&A.at(2).at(2)==0)
        flag=true;
    if(A.at(0).at(0)==0&&A.at(1).at(0)==0&&A.at(2).at(0)==0)
        flag=true;
    if(A.at(0).at(1)==0&&A.at(1).at(1)==0&&A.at(2).at(1)==0)
        flag=true;
    if(A.at(0).at(2)==0&&A.at(1).at(2)==0&&A.at(2).at(2)==0)
        flag=true;
    if(A.at(0).at(0)==0&&A.at(1).at(1)==0&&A.at(2).at(2)==0)
        flag=true;
    if(A.at(0).at(2)==0&&A.at(1).at(1)==0&&A.at(2).at(0)==0)
        flag=true;   


    if(flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    

    return 0;
}




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

int main() {
    std::string alphabet = "abcdefghijklmnopqrstuvwxyz";
    std::map<char, int> counter;
    for (char c : alphabet) {
        counter[c] = 0;
    }

    char c;
    while (std::cin >> c) {
        if (std::isalpha(c)) {
            counter[std::tolower(c)] += 1;
        }
    }

    for (char c : alphabet) {
        std::cout << c << " : " << counter[c] << std::endl;
    }
}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define ins insert
#define sb substr
#define con continue
#define ub upper_bound
#define lb lower_bound
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define pll pair<ll,ll>
#define pld pair<ld,ld>
using namespace std;

ll power(ll x, ll y);
ll mpower(ll x, ll y, ll p);
ll modInv(ll a, ll m);
ll gcdExtended(ll a, ll b, ll *x, ll *y);
bool isPrime(ll n);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,i,j,k,l,h,p,q,r,x,y,z,a,b,c,d,f,n,m,M=1000000007;
    char ch,ch2,ch3;
    string s,s1,s2,s3;
    // freopen ("input.txt", "r", stdin);
    // freopen ("output.txt", "w", stdout);
    t=1;
    // cin>>t;
    while(t--){
        vector<ll> v,w;
        unordered_map<ll,ll> N;
        set<ll> S,SS;
        cin>>n;
        ll A[n+1];
        x=1000;
        y=0;
        for(i=0;i<n;i++){
            cin>>A[i];
        }
        A[n]=0;
        for(i=0;i<n;i++){
            x+=y*A[i];
            y=0;
            if(A[i]<A[i+1]){
                p=x/A[i];
                x=x%A[i];
                y=p;
            }
        }
        cout<<x<<"\n";
    }
    return 0;
}

ll modInv(ll a, ll m){
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);
    ll res = (x%m + m) % m;
    return res;
}

ll gcdExtended(ll a, ll b, ll *x, ll *y){
    if (a == 0){
        *x = 0, *y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;
    return gcd;
}

ll mpower(ll x, ll y, ll p){
    ll res = 1;
    x = x % p;
    while(y > 0){
        if(y & 1) res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll power(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}

bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    ll p=sqrt(n);
    for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << ((a <= c && c <= b) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
MA = max(A)
N = MA/2
X = max(A)-1
for i in range(n):
    if abs(A[i] - N) < X and A[i] != MA:
        X = abs(A[i] - N)
        k = i       
print('{} {}'.format(MA, A[k]))

Measured memory_bytes: 14428
# -*- coding: utf-8 -*-        

s = input()
l = []
r = []
len_s = len(s)
if(len_s==1):
    print(1)
else:
    for i in range(len_s-1):
        if(s[i]!=s[i+1]):
            l.append(i+1)
            r.append(len_s-i-1)
    if(len(l)==0):
        print(len_s)
    else:
        half = len(l)
        l.extend(r)
        l.sort()
        print(len_s-l[half-1])

Measured memory_bytes: 7920
#include<bits/stdc++.h>
int n,vs[107],xs[207],xp=0;
struct edge{
	int to,nx,v;
}e[100007];
int ep=2,e0[207],h[207],q[207],S,T;
bool bfs(){
	for(int i=1;i<=T;++i)h[i]=0;
	int ql=0,qr=0;
	h[q[++qr]=S]=1;
	while(ql!=qr){
		int w=q[++ql];
		if(w==T)return 1;
		for(int i=e0[w];i;i=e[i].nx)if(e[i].v){
			int u=e[i].to;
			if(!h[u])h[q[++qr]=u]=h[w]+1;
		}
	}
	return 0;
}
int dfs(int w,int f){
	if(w==T)return f;
	int c,used=0;
	for(int i=e0[w];i;i=e[i].nx)if(e[i].v){
		int u=e[i].to;
		if(h[u]!=h[w]+1)continue;
		c=dfs(u,std::min(e[i].v,f-used));
		e[i].v-=c;
		e[i^1].v+=c;
		used+=c;
		if(f==used)return f;
	}
	h[w]=0;
	return used;
}
bool isp(int x){
	if(x<0)x=-x;
	if((~x&1)||x<3)return 0;
	for(int i=3;i*i<=x;i+=2)if(x%i==0)return 0;
	return 1;
}
void ae(int a,int b){
	e[ep]=(edge){b,e0[a],1};e0[a]=ep++;
	e[ep]=(edge){a,e0[b],0};e0[b]=ep++;
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;++i)scanf("%d",vs+i);
	for(int i=0,j=0;i<n;i=j){
		for(++j;j<n&&vs[j]-vs[j-1]==1;++j);
		xs[++xp]=vs[i];
		xs[++xp]=vs[j-1]+1;
	}
	S=xp+1,T=xp+2;
	int co=0,ce;
	for(int i=1;i<=xp;++i){
		if(xs[i]&1){
			ae(S,i);
			++co;
			for(int j=1;j<=xp;++j)if((~xs[j]&1)&&isp(xs[j]-xs[i]))ae(i,j);
		}else ae(i,T);
	}
	int ans=0,c2;
	while(bfs())ans+=dfs(S,0x3f3f);
	ce=xp-co;
	co-=ans,ce-=ans;
	printf("%d\n",ans+ce+co+(co&1));
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
vector<int> E[55], vec;
bool vis[55];
int cnt;
map<pair<int, int>, bool> mp;
void dfs(int u, int p) {
    vis[u] = true;
    vec.push_back(u);
    //cout << u << '\n';
    for (int v : E[u]) {
        if (v != p and vis[v] == false) {
            dfs(v, u);
        } else if (v != p and vis[v] == true) {
            for (int i = vec.size() - 2; i >= 0; --i) {
              //  ++cnt;
                //cout << vec[i] << " ";
                int x = vec[i], y = vec[i + 1];
                if (x > y) {
                    swap(x, y);
                }
                mp[{x, y}] = true;
                if (vec[i] == v) {
                    break;
                }
            }
      //      cout << '\n';
        }
    }
    vis[u] = false;
    vec.pop_back();
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int u, v;
        cin >> u >> v;
        E[u].push_back(v);
        E[v].push_back(u);
    }
    dfs(1, 1);
    cout << m - mp.size();
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,count=0,i,owari;
  
  cin >> n;
  vector<int>leng(n);
  for (i = 0; i < n;i++)
    cin>>leng.at(i);
  for(i=0;i<n;i++){
    owari=0;
    for(int i2=0;i2<i;i2++)
      if(leng.at(i2)==leng.at(i)){owari=1;break;}
    
    if(owari==0){
      if(i==n-1){break;}
      for(int i2=i+1;i2<n;i2++)  
        if(leng.at(i2)==leng.at(i)) count++;
    }
  }
  cout << n-count <<endl;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	string s;
	cin>>s;

	int res = INF;

	FOR (c, 'a', 'z' + 1)
	{
		FOR (r, 0, SZ(s) + 1)
		{
			bool ok = true;
			s += c;
			FOR (j, 0, SZ(s))
			{
				bool okk = false;
				FOR (k, 0, r+1)
				{
					if (s[j+k] == c)
					{
						okk = true;
						break;
					}
				}

				if (!okk)
				{
					ok = false;
					break;
				}
			}

			s.erase(s.end() - 1);

			if (ok)
			{
				res = min(res, r);
				break;
			}
		}
	}

	cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>;
using namespace std;
 
const int N = 1e5 + 100;
const int NN = 1e8 + 100;
 
int n, h[N], d[N], k;
int main ()
{
    cin >>n >>k;
    for (int i = 1; i<=n; i++)
    {
        d[i] = NN;
        cin >>h[i];
    }
    d[1] = 0;
    for (int i = 2; i<=n; i++)
    {
        int mi = 1e9;
        for (int u = 1; u <=k; u++)
        {
            if (i - u >= 1)
            {
                mi = min(mi, d[i - u] + abs(h[i] - h[i - u]));
            }
            //cout <<d[i - u] <<" " <<h[i] <<" " <<h[i - u] <<" - " <<i <<" " <<u <<endl;
        }
        d[i] = mi;
    }
    cout <<d[n];
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int x;
    cin>>x;
    if(x>=30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3624
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        v: [u32; n],
    }
    let m = v.iter().map(|&n| n.trailing_zeros()).min().unwrap();
    println!("{}", m);
}


Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
##############################

N = int(input())

def dfs(next_value, value, count_flag, count):
    value += next_value
    int_value = int(value)

#    print(int_value)

    if int_value > N:
        return count

    if int_value >= 357:
        if count_flag == False:
            if len(set(list(value))) == 3:
                count_flag = True

        if count_flag:
            count += 1

    count = dfs('3', value, count_flag, count)
    count = dfs('5', value, count_flag, count)
    count = dfs('7', value, count_flag, count)

    return count


count = 0
value = ''

count = dfs('3', '', False, count)
count = dfs('5', '', False, count)
count = dfs('7', '', False, count)

print(count)

Measured memory_bytes: 3064
x,y=map(int,input().split())
n=x
f=0
for i in range(1,x+1):
  c=0
  c+=i*2+(n-i)*4
  if c==y:
    f=1
    break
  if f==1:
    break
if x*2==y or x*4==y:
  print('Yes')
else:
  if f:
    print('Yes')
  else:print('No')

Measured memory_bytes: 61624
class PriorityQueue
  def initialize; @buf = []; end
  def parent_of(n); (n - 1) / 2; end
  def left_child_of(n); n * 2 + 1; end
  def to_s; @buf.to_s; end

  def push(x)
    n = @buf.size
    @buf.push(x)
    loop {
      break if n == 0
      m = parent_of(n)
      @buf[n], @buf[m] = [@buf[m], @buf[n]].minmax
      n = m
    }
  end

  def pop
    return @buf.pop if @buf.size <= 1
    ret, @buf[0] = @buf[0], @buf.pop
    n = 0
    loop {
      m = left_child_of(n)
      break unless m < @buf.size
      m += 1 if m + 1 < @buf.size && (@buf[m] <=> @buf[m + 1]) < 0
      break if (@buf[n] <=> @buf[m]) > 0
      @buf[n], @buf[m] = @buf[m], @buf[n]
      n = m
    }
    ret
  end
end

require 'set'

def main
  x, y, z, k = gets.chomp.split(' ').map(&:to_i)
  a = gets.chomp.split(' ').map(&:to_i)
  b = gets.chomp.split(' ').map(&:to_i)
  c = gets.chomp.split(' ').map(&:to_i)
  a.sort!; b.sort!; c.sort!
  pq = PriorityQueue.new
  flag = Set.new
  ai = a.size - 1; bi = b.size - 1; ci = c.size - 1
  pq.push([a[ai] + b[bi] + c[ci], ai, bi, ci])
  flag.add([ai, bi, ci])
  k.times {|i|
    v, ai, bi, ci = pq.pop
    puts v
    pq.push([a[ai - 1] + b[bi] + c[ci], ai - 1, bi, ci]) if ai >= 1 && !flag.include?([ai - 1, bi, ci])
    flag.add([ai - 1, bi, ci])
    pq.push([a[ai] + b[bi - 1] + c[ci], ai, bi - 1, ci]) if bi >= 1 && !flag.include?([ai, bi - 1, ci])
    flag.add([ai, bi - 1, ci])
    pq.push([a[ai] + b[bi] + c[ci - 1], ai, bi, ci - 1]) if ci >= 1 && !flag.include?([ai, bi, ci - 1])
    flag.add([ai, bi, ci - 1])
  }
end

main

Measured memory_bytes: 3576
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,ans=0, x = 0, y = 0, z = 0,n=0,m=0, maxy = 0, mini = 9999, counter = 0, endp = 0, checker = 0;

std::vector <char> vec{}, vecsec{}, vecth{};
long long int iremono[100001], sec[100001];
long long int iremono2[100001],check[100001];
std::vector<long long int>kinds{}, kaku{};
char maze[1000][1000];
int sx, sy;
int gx, gy;

int d[1000][1000];
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
std::string output, output2, input,input2;
char rev[100001];


int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

int N, M;//はんい
int bfs() {
	queue<pair<int, int>> que;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= M; j++) {
			d[i][j] = INF;
		}
	}
	que.push(pair<int, int>(sx, sy));
	d[sx][sy] = 1;
	while (que.size()) {
		pair<int, int> p = que.front();
		que.pop();
		if (p.first == gy && p.second == gx) {
			break;
		}
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (1 <= nx && nx <= N && 1 <= ny && ny <= M && maze[nx][ny] != '#'&&d[nx][ny] == INF) {
				que.push(pair<int, int>(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[gy][gx];
}
int main()
{
	cin >> N >> M;
	string s;
	sx = 1, sy = 1, gx = M,gy = N;
	for (int i = 1; i <= N; i++) {
		cin >> s;
		for (int j = 1; j <= M; j++) {
			maze[i][j] = s[j - 1];
			if (maze[i][j] == '.') {
				counter++;
			}
		}
	}

	int res = bfs();
	if (res == INF) {
		cout << -1 << endl;
		return 0;
	}
	cout << counter-res << endl;

}

Measured memory_bytes: 4608
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

const int N = 1e4 + 5;

struct flag {
    int pos, idx;
    inline bool operator < (const flag& a) const { return pos < a.pos; }
    inline flag(int p = 0, int id = 0) : pos(p), idx(id) { }
} f[N << 1];
int n;

const int V = N << 3;
int vc, refer[V];
vector<int> G[V];
int dfn[V], low[V], timer;
int stk[V], top; bool inS[V];
int cmp[V], scc;

inline void addEdge(int fr, int to) {
    G[fr].push_back(to);
}

#define mid ((l + r) >> 1)
#define op(x) ((x) <= n ? (x) + n : (x) - n)
void build(int l, int r, int x) {
    refer[x] = ++vc;
    if (l == r)
        return addEdge(refer[x], op(f[l].idx));
    build(l, mid, x << 1);
    addEdge(refer[x], refer[x << 1]);
    build(mid + 1, r, x << 1 | 1);
    addEdge(refer[x], refer[x << 1 | 1]);
}
#undef op

void link(int l, int r, int x, int ql, int qr, int p) {
    if (ql <= l && r <= qr) return addEdge(p, refer[x]);
    if (ql <= mid) link(l, mid, x << 1, ql, qr, p);
    if (qr > mid) link(mid + 1, r, x << 1 | 1, ql, qr, p);
}
#undef mid

void tarjan(int x) {
    dfn[x] = low[x] = ++timer;
    inS[stk[++top] = x] = 1;
    for (auto y : G[x]) {
        if (!dfn[y]) tarjan(y), low[x] = min(low[x], low[y]);
        else if (inS[y]) low[x] = min(low[x], dfn[y]);
    }
    if (low[x] == dfn[x]) {
        ++scc;
        for (; ; ) {
            int k = stk[top--];
            cmp[k] = scc, inS[k] = 0;
            if (k == x) break;
        }
    }
}

#define CLR(x, v) memset(x, v, sizeof(x))
bool judge(int d) {
    for (int i = 1; i < n * 7; i++) G[i].clear();
    CLR(dfn, 0), CLR(low, 0), CLR(cmp, 0);
    CLR(stk, 0), CLR(inS, 0);
    timer = top = scc = 0, CLR(refer, 0);

    vc = n * 2, build(1, n * 2, 1);
    for (int i = 1; i <= n * 2; i++) {
        int l = upper_bound(f + 1, f + 1 + n * 2, flag(f[i].pos - d)) - f;
        int r = upper_bound(f + 1, f + 1 + n * 2, flag(f[i].pos + d - 1)) - f - 1;
        if (l < i) link(1, n * 2, 1, l, i - 1, f[i].idx);
        if (i < r) link(1, n * 2, 1, i + 1, r, f[i].idx);
    }

    for (int i = 1; i <= n * 2; i++)
        if (!dfn[i]) tarjan(i);
    for (int i = 1; i <= n; i++)
        if (cmp[i] == cmp[i + n]) return 0;
    return 1;
}
#undef CLR

signed main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &f[i].pos, &f[i + n].pos);
        f[i].idx = i, f[i + n].idx = i + n;
    }
    sort(f + 1, f + 1 + n * 2);

    int lb = 0, ub = f[n * 2].pos - f[1].pos + 1, ans = 0;
    while (lb <= ub) {
        int mid = (lb + ub) >> 1;
        if (judge(mid)) ans = mid, lb = mid + 1;
        else ub = mid - 1;
    }

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 17160
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    int n, m;
    cin >> n >> m;
    vll h(n,0);
    vint edge[n];
    ll ans=0;
    rep(i,n) cin >> h[i];
    rep(i,m){
        int a, b;
        cin >> a >> b;
        edge[a-1].pb(b-1);
        edge[b-1].pb(a-1);
    }
    rep(i,n){
        int flag=1;
        rep(j, edge[i].size()){
            if(h[i] <= h[edge[i][j]] ){
                flag = 0;
                break;
            }
        }
        if(flag) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 9072
#include <cstdio>
using namespace std;

int dfs(int n, int s, int p){
	if(s == 0 && n == 0) return 1;
	if(n == 0 || s < 0) return 0;
	
	int c = 0;
	while(p < 10){
		c += dfs(n - 1, s - p, p + 1);
		p++;
	}
	
	return c;
}

int main(){
	int n, s;
	
	while(true){
		scanf("%d%d", &n, &s);
		if(n + s == 0) break;
		
		printf("%d\n", dfs(n, s, 0));
	}
	
	return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}

template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

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

  int n;
  cin >> n;

  vector<int64> xs;
  vector<char> ops;
  ops.push_back('+');
  for (int i = 0; i < 2 * n - 1; i++) {
    if (i % 2 == 0) {
      int64 x;
      cin >> x;
      xs.push_back(x);
    } else {
      char op;
      cin >> op;
      ops.push_back(op);
    }
  }

  vector<int64> c_sums(n + 1);
  for (int i = 0; i < n; i++) {
    c_sums[i + 1] = c_sums[i] + xs[i];
  }

  int64 ans = INT64_MIN;
  int64 current = 0;
  for (int i = 0; i < n; i++) {
    if (ops[i] == '-') {
      int p = n;
      for (int j = i + 1; j < n; j++) {
        if (ops[j] == '-') {
          p = j;
          break;
        }
      }
      int64 s = current - (c_sums[p] - c_sums[i]) + (c_sums[n] - c_sums[p]);
      UpdateMax(ans, s);
    }

    if (ops[i] == '+') current += xs[i];
    else if (ops[i] == '-') current -= xs[i];
  }
  UpdateMax(ans, current);

  cout << ans << endl;
}

Measured memory_bytes: 2036
N,P = map(int, input().split())

def factorize(a:int)->dict:
    """prime factorization O(sqrt(N))
    return dict of prime factor
    """
    ps = {}
    i = 2
    nokori = a
    while i*i <= nokori:
        if nokori%i==0:
            cnt = 0
            while nokori%i==0:
                cnt += 1
                nokori //= i
            ps[i] = cnt
        i += 1
    if nokori != 1:
        ps[nokori] = 1
    return ps

ps = factorize(P)
ans = 1
for k,v in ps.items():
    ans *= pow(k, v//N)
print(ans)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll=long long;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a%2==0 || b%2==0 || c%2==0){
    cout << 0 << endl;
    return 0;
  }
  int z=max(a,b);
  ll x=min(a,b);
  ll y=min(z,c);

  cout << x*y << endl;
}

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

using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int N;
  cin >> N;
  vector< int64 > A(N);
  cin >> A;

  int64 intai = 0, sum = 0;

  for(int i = 0; i < N; i++) {
    sum += A[i];
  }
  for(int i = 0; i + 1 < N; i += 2) {
    intai += A[i];
  }

  vector< int64 > ref(N);
  ref.back() = (sum / 2 - intai);
  
  for(int i = N - 2; i >= 0; i--) {
    ref[i] = A[i] - ref[i + 1];
  }

  for(auto &t: ref) t *= 2;

  cout << ref << endl;

}





Measured memory_bytes: 2944
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  ll x;
  cin >>x;
  int a=0;
  rep2(i,-1000,1000) {
    if(a==1) break;
    rep2(j,-1000,1000) {
      if(a==1) break;
      if(pow(i,5)-pow(j,5)==x) {
        cout <<i<<" "<<j<<endl;
        a=1;
      }
    }
  }
}

Measured memory_bytes: 4104
#include <stdio.h>
int main() {
	int a, b, c, x;
	int i, j, k;
	int cnt = 0;
	
	scanf("%d%d%d%d", &a, &b, &c, &x);
	
	for (i = 0; i <= a; ++i) {
		for (j = 0; j <= b; ++j) {
			for (k = 0; k <= c; ++k) {
				if (500 * i + 100 * j + 50 * k == x) {
					++cnt;
				}
			}
		}
	}
	
	printf("%d\n", cnt);
}

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

int main(){
  int p1,p2,p3,p4,d1,d2,ans,p;
  cin >> p1 >> p2 >> p3 >> d1 >> d2;
  p4 = min(p1,p2);
  p = min(p4,p3);
  ans = min(d1,d2) + p -50;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3084
fn readone() -> i64 {
    let reader = std::io::stdin();
    let mut line = String::new();
    let _l = reader.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    let n: i64 = vec[0].parse().unwrap();
    return n;
}
fn readvec() -> Vec<i64> {
    let reader = std::io::stdin();
    let mut line = String::new();
    let _l = reader.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    let mut num = Vec::<i64>::new();
    for i in 0 .. vec.len() {
        let n: i64 = vec[i].parse().unwrap();
        num.push(n);
    }
    return num;
}

fn main() {
    let mut tmp = readvec();
    while 0 < tmp[0] + tmp[1]{
        let n = tmp[0] as usize;
        let m = tmp[1] as usize;
        let mut vn = Vec::<i64>::new();
        for _i in 0 .. n {
            vn.push(readone());
        }
        vn.sort();
        let mut vm = Vec::<i64>::new();
        for _i in 0 .. m {
            vm.push(readone());
        }
        vm.sort();
        let mut nsum = 0;
        let mut msum = 0;
        for i in 0 .. n {
            nsum = nsum + vn[i];
        }
        for i in 0 .. m {
            msum = msum + vm[i];
        }
        let mut found = false;
        for i in 0 .. n {
            for j in 0 .. m {
                if nsum - vn[i] + vm[j] == msum - vm[j] + vn[i] {
                    found = true;
                    println!("{} {}", vn[i], vm[j]);
                    break;
                }
            }
            if found { break; }
        }
        if !found {
            println!("-1");
        }

        tmp = readvec();
    }
}



Measured memory_bytes: 1068
import sys
w = input()

# すべての文字が偶数回出現する

# 入力が１文字の時、wは美しくない
if len(w) == 1:
    print("No")
    sys.exit()
    
# 文字数分ループする
for i in range(len(w)-1):
    # 1文字目の文字が偶数回出現するなら継続。奇数回なら終了
    if w.count(w[i])%2==0:
        continue
    else:
        print("No")
        sys.exit()

# 途中で終了しなかったら、wは美しい
print("Yes")

Measured memory_bytes: 38256
#include <string>
#include <numeric>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;

int main(){
	int a,b;
	int answer = 0;
	cin >> a >> b;
	if(a > b){
		answer += a;
		a--;
	}else{
		answer += b;
		b--;
	}
	if(a > b){
		answer += a;
	}else{
		answer += b;
	}
	cout << answer << endl;
}


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

using ll = long long;

int main() {

	int n, k; 
	cin >> n >> k;

	vector<ll> health(n);
	for (auto& h : health)
		cin >> h;

	sort(health.begin(), health.end());

	ll sum = 0;
	for (int i = 0; i < n - k; i++) {
		sum += health[i];
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
long long n,m;
int x,y;
cin>>n>>m;
vector< pair <long long,long long> > list;  
list.resize(n);
for(int i=0;i<n;i++)
{
	cin>>x>>y;
	list[i]=make_pair(x,y); 
}
sort(list.begin(),list.end());
long long sum=0,count = list[0].second;int i=0;
while(count<=m)
{
	sum=sum+(list[i].first)*(list[i].second);
	i++;
	if(i>n-1)
		break;
	count+=(list[i].second);
}
if(count>m)
{
	count=count-(list[i].second);
	int rem=m-count;
	sum=sum+(list[i].first)*rem;
}
cout<<sum;
	// your code goes here
	return 0;
}

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

#define rep(i,c) for(int i = 0; i < (int)c; ++i)
using llint = long long int ;
using namespace std;



int main(){
    llint A,B,M;
    cin>>A>>B>>M;
    llint a[100009],b[100009];
    llint amin=100009;
    llint bmin=100009;
    rep(i,A){
        cin>>a[i];
        amin=min(amin,a[i]);
    }
    rep(i,B){
        cin>>b[i];
        bmin=min(bmin,b[i]);
    }
    llint abmin=amin+bmin;

    int x,y,c;
    rep(i,M){
        cin>>x>>y>>c;
        abmin=min(abmin,a[x-1]+b[y-1]-c);
    }

    cout<<abmin<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

bool cmp(pair< int, int > a, pair< int, int > b)
{
  if(a.first != b.first) return(a.first > b.first);
  return(a.second < b.second);
}
int main()
{
  int N, p[100];
  
  while(scanf("%d", &N), N) {
    for(int i = 0; i < N; i++) {
      scanf("%d", &p[i]);
    }
    
    pair< int, int > dp[2][50001];
    fill_n(*dp, 2 * 50001, make_pair(-INF, INF));
    pair< int, int > *now = dp[0], *nxt = dp[1];
    
    now[0] = {0, 0};
    int reach = 0;
    for(int i = 0; i < N; i++) {
      int mod = p[i] % 1000;
      if(1 <= mod && mod <= 500) {
        int rev = 1000 - mod - 500;
        reach += rev;
        for(int j = reach; j >= rev; j--) {
          nxt[j] = min(nxt[j], {now[j - rev].first + 1, now[j - rev].second + p[i]}, cmp);
        }
      } else {
        int rev = (1000 - mod) % 1000;
        int need = (mod + 500) % 1000;
        reach += max(rev, need);
        for(int j = reach; j >= 0; j--) {
          nxt[j] = min(nxt[j], now[j], cmp);
        }
        for(int j = reach; j >= rev; j--) {
          nxt[j] = min(nxt[j], {now[j - rev].first, now[j - rev].second + p[i]}, cmp);
        }
        for(int j = need; j <= reach; j++) {
          nxt[j - need] = min(nxt[j - need], {now[j].first + 1, now[j].second + p[i]}, cmp);
        }
      }
      swap(now, nxt);
      for(int j = 0; j <= reach; j++) nxt[j] = {-INF, INF};
    }
    auto p = *min_element(now, now + 50000, cmp);
    printf("%d %d\n", p.first, p.second);
  }
}

Measured memory_bytes: 3972
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
long long int mod=1000000007;
set<long long int> hoge;
long long int c(long long int n,long long int r){
  long long int re=1;
  for(int i=0; i<r; i++){
    re*=n-i;
    re%=mod;
  }
  for(int i=0; i<r; i++){
    re/=r-i;
    re%=mod;
  }
  return re;
}
int main(void){
  long long int n;
  cin>>n;
  long long int k;
  cin>>k;
  long long int low;
  long long int high;
  long long int ruiseki_low[n+1];
  ruiseki_low[0]=0;
  long long int ruiseki_high[n+1];
  ruiseki_high[0]=n;
  for(int i=1; i<=n; i++){
    ruiseki_low[i]=ruiseki_low[i-1]+i;
    ruiseki_high[i]=ruiseki_high[i-1]+n-i;
  }
  long long int ans=0;
  for(int i=k; i<=n+1; i++){
    low=ruiseki_low[i-1];
    high=ruiseki_high[i-1];
    ans+=high-low+1;
    ans%=mod;
  }
  cout<<ans<<endl;
}

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

using i64 = long long;
using u64 = unsigned long long;

const int mod = (int)1e9+7;

void __print() {cerr << "]\n";}

template<typename T, typename... V>
void __print(T t, V... v)
{ cerr << t; if(sizeof...(v)) cerr << ", "; __print(v...);}

#define dbg(x...) cerr << "[" << #x << "] = ["; __print(x);

i64 modInverse(i64 k)
{
    i64 res = 1;
    i64 n = mod - 2;
    while(n) {
        if(n & 1) {
            res *= k;
            res %= mod;
        }
        k *= k;
        k %= mod;
        n /= 2;
    }
    return res;
}

int main()
{
    int x, y;
    scanf("%d%d", &x, &y);
    if((x+y)%3) {
        puts("0\n");
    } else {
        int n = (x+y);
        int m = 0;
        int k = (x+y)/3;
        int r = 0;
        for(int i = 0; i < k; i++) n--, m++;
        while(n != x && m != y && r < k) n--, m++, r++;
        if(n == x && m == y) {
            i64 kf = 1;
            for(int i = 1; i <= k; i++) {
                kf *= i;
                kf %= mod;
            }
            i64 rf = 1;
            for(int i = 1; i <= r; i++) {
                rf *= i;
                rf %= mod;
            }
            i64 krf = 1;
            for(int i = 1; i <= k-r; i++) {
                krf *= i;
                krf %= mod;
            }
            krf *= rf;
            krf %= mod;
            krf = modInverse(krf);
            printf("%lld\n", (kf*krf)%mod);
        } else {
            puts("0");
        }
    }
}


Measured memory_bytes: 3796
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
eat_p = p[:X]
eat_q = q[:Y]

all_apple = eat_p + eat_q + r
all_apple.sort(reverse=True)

print(sum(all_apple[:X+Y]))

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;cin >> s;
    if(s == "ABC")cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,k,res1,res2;
int main() {
	cin>>a>>b>>k;
	if(a-k>=0) res1=a-k,res2=b;
	else if(a-k<0) {
		res1=0,res2=b+(a-k);
		if(res2<0) res2=0;
	}
	cout<<res1<<" "<<res2;
	return 0;
}

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

void selectionSort(int *A, int N);

int main()
{
	int N;
	cin >> N;
	int A[N];
	for (int i = 0; i < N; i++)
		cin >> A[i];

	selectionSort(A,N);
	return 0;
}

void selectionSort(int *A, int N)
{
	int count = 0;
	int min;

	for (int i = 0; i <= N-1; i++) {
		min = i;

		for (int j = i; j <= N-1; j++) {
			if (A[j] < A[min]) {
				min = j;
			}
		}
		if (min != i) {
			swap(A[i],A[min]);
			count++;
		}
	}

	for (int i = 0; i < N; i++) {
		cout << A[i];
		if (i != N-1)
			cout << ' ';
		else
			cout << '\n';
	}

	cout << count << '\n';

	return;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

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

	int N, M; cin >> N >> M;
	priority_queue<int> Q;
	for (int i = 0; i < N; i++) {
		int tmp; cin >> tmp;
		Q.push(tmp);
	}
	for (int i = 0; i < M; i++) {
		int tmp = Q.top();
		Q.pop();
		Q.push(tmp / 2);
	}
	ll ans = 0;
	while (!Q.empty()) {
		ans += ll(Q.top());
		Q.pop();
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int masu, a1 , a2, a3;
  cin >> masu;
  a1 = masu/100;
  a3 = masu%10;
  a2 = masu - a1*100 - a2;
  a2 = a2 / 10;
  cout << a1 + a2 + a3 << endl;
}


Measured memory_bytes: 256
import sys
n,x=map(int,input().split())
xlist=[abs(x-int(y)) for y in input().split()]

def gcd(x,y):
    if x<y:
        x,y=y,x
    #x>y
    if y==0:
        return x
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)

if n==1:
    print(xlist[0])
    sys.exit()

ans=0
for i in range(n-1):
    if i==0:
        ans=gcd(xlist[i],xlist[i+1])
    else:        
        ans=min(ans,gcd(xlist[i],xlist[i+1]))
print(ans) 

Measured memory_bytes: 20040
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
#define P pair<int, int>
typedef long long ll;
using namespace std;

int main()
{
	int a; cin >> a;
	co(a * a);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

int main(){
    int K, T;
    cin>>K>>T;
    int a, m=0;
    rep(i, T){
        cin>>a;
        m=max(a, m);
    }
    cout<<max(0, m-(K-m+1))<<endl;
}

Measured memory_bytes: 256