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

int main(){
  int n;
  string s;
  cin >> n >> s;
  
  string res = "Yes";
  if(n == 1 || n % 2 != 0){
    res = "No";
  }
  else{
    for(int i=0; i<(n/2); ++i){
      if(s[i] != s[i+(n/2)]){
        res = "No";
        break;
      }
    }
  }
  
  cout << res << endl;
  return 0;
}

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

using namespace std;

char a[1200][1200];

const int di[] = {1, 0, -1, 0};
const int dj[] = {0, 1, 0, -1};

int n, m, k;
int sx, sy;

int main() {
	scanf("%d%d%d", &n, &m, &k);
	for(int i = 1; i <= n; ++i) {
		scanf("%s", a[i] + 1);
		for(int j = 1; j <= m; ++j)
			if(a[i][j] == 'S') sx = i, sy = j;
	}
	queue< pair<int,int> > q;
	q.push({sx, sy});

	for(int d = 1; d <= k; ++d) {
		int sz = q.size();
		while(sz--) {
			int i, j; tie(i, j) = q.front(), q.pop();
			for(int r = 0; r < 4; ++r) {
				int si = i + di[r], sj = j + dj[r];
				if(a[si][sj] == '.') {
					a[si][sj] = 'S';
					q.push({si, sj});
				}
			}
		}
	}

	while(!q.empty()) q.pop();

	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			if(a[i][j] == 'S') q.push({i, j});
		}
	}

//	for(int i = 1; i <= n; ++i) puts(a[i] + 1);

	int cnt = 0;
	bool flag = true;
	while(flag) {
		int sz = q.size();
		while(sz--) {
			int i, j; tie(i, j) = q.front(), q.pop();
			if(i==1||j==1||i==n||j==m) flag = false;
			for(int r = 0; r < 4; ++r) {
				int si = i + di[r], sj = j + dj[r];
				if(a[si][sj] == '.' || a[si][sj] == '#') {
					a[si][sj] = 'S';
					q.push({si, sj});
				}
			}
		}
		++cnt;
	}
	
	--cnt;

	int ans = (cnt + (k - 1)) / k + 1;
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 6272
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;


int main()
{
	int R;
	cin >> R;
	double p = 3.1415926535;
	cout << 2.0 * R * p << endl;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

int main() {
  string S;
  cin>>S;
  int N=S.size();
  int count0=0;
  int count1=0;
  for(int i=0; i<N; i++){
    if(S.at(i)=='0') count0++;
    if(S.at(i)=='1') count1++;
  }
  cout<<2*min(count0, count1)<<endl;
}

Measured memory_bytes: 512
a, b, c, d, e, f = map(int, input().split())

maximum = 0
max_water = 0
max_sugar = 0

queue = [[a, 0], [b, 0]]

visited = set()

while queue:
    now = queue.pop(0)
    now = tuple(now)

    if now in visited:
        continue

    visited.add(now)

    water, sugar = now

    if water * 100 + sugar > f:
        continue

    if (sugar / water) <= e:
        if maximum < sugar / (water*100):
            maximum = sugar / (water * 100)
            max_water = water
            max_sugar = sugar
    queue.append([water+a, sugar])
    queue.append([water+b, sugar])
    queue.append([water, sugar+c])
    queue.append([water, sugar+d])

if max_water == 0:
    print(min(a, b)*100, 0)
else:
    print(max_water*100 + max_sugar, max_sugar)


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

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

using namespace std;

typedef long long ll;

const int MAX_A=55555;

bool flg[MAX_A+1];
vector<int> pri;

void era(){
	memset(flg,true,sizeof(flg));
	FOR(i,2,MAX_A+1){
		if (flg[i]){
			if (i%5==1) pri.push_back(i);
			for(int j=i*2;j<=MAX_A;j+=i){
				flg[j]=false;
			}
		}
	}
}

int main(){
	int A,B,C,K;
	cin>>A>>B>>C>>K;
	int m=max({A,B,C});
	int mp=m;
	REP(i,K){
		mp*=2;
	}
	cout<<A+B+C+mp-m<<endl;
	return 0;
}

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

int main(){

    while(1){
        double r0, W, c, r; cin >> r0 >> W >> c >> r;
        if(r0 == 0) break;
        int ans = 0;
        int R = r0;
        while(R / W <= c - 0.000000000001){
            R += r;
            ans++;
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3132
/*input
5 4 2



*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define mp make_pair
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(long long* a,long long n,long long val){
	for(long long i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	ll n,k,s;
	cin>>n>>k>>s;

	rep(i,0,k){
		cout<<s<<" ";
	}
	if(s==1000000000)
			s=10000;
	rep(i,0,n-k){

		cout<<s+1<<" ";
	}
	return 0;
}




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

int q, dp[1001][1001], xnum, ynum;
char x[1001], y[1001];

int main() {
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%s%s", x, y);
    xnum = ynum = 0;
    while (x[xnum] != 0) xnum++;
    while (y[ynum] != 0) ynum++;
    for (int j = 0; j <= xnum; j++) for (int k = 0; k <= ynum; k++) dp[i][j] = 0;
    for (int j = 0; j < xnum; j++) for (int k = 0; k < ynum; k++) {
      if (x[j] == y[k]) dp[j+1][k+1] = dp[j][k] + 1;
      else dp[j+1][k+1] = max(dp[j+1][k], dp[j][k+1]);
    }
    printf("%d\n", dp[xnum][ynum]);
  }
}



Measured memory_bytes: 6504
n = gets.chomp.to_i
tree = Array.new(n)
n.times { |i| tree[i] = [] }
(n - 1).times do
  a, b = gets.chomp.split(' ').map { |i| i.to_i - 1 }
  tree[a] << b
  tree[b] << a
end

distances = Array.new(n, 100001)
queue = [0]
visited = Hash.new(false)
distance = 0
until queue.empty?
  length = queue.length
  length.times do
    q = queue.shift
    next if visited[q]
    visited[q] = true
    distances[q] = distance
    tree[q].each do |t|
      next if visited[t]
      queue << t
    end
  end
  distance += 1
end

route = [n - 1]
current = n - 1
while route.first != 0 do
  tree[current].each do |i|
    if distances[current] - distances[i] == 1
      current = i
      route.unshift(i)
      break
    end
  end
end

start_index = route.length % 2 == 0 ? (route.length / 2) - 1 : route.length / 2
start = route[start_index]
close = route[start_index + 1]
tree[start].delete(close)
queue = [start]
visited = Hash.new(false)
fennec_count = 0
until queue.empty?
  q = queue.pop
  next if visited[q]
  visited[q] = true
  fennec_count += 1
  tree[q].each do |t|
    next if visited[t]
    queue << t
  end
end

puts fennec_count > n - fennec_count ? 'Fennec' : 'Snuke'

Measured memory_bytes: 24040
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  sort(a.begin(),a.end());
  vector<vector<int>> bc(m,vector<int>(2));
  int sb=0;
  for(int i=0;i<m;i++)
    cin>>bc.at(i).at(0)>>bc.at(i).at(1);
  sort(bc.begin(),bc.end(),[](vector<int> x,vector<int> y){
    return x.at(1)>y.at(1);
  });
  int p=0;
  for(int i=0;i<n;i++){
    if(a.at(i)<bc.at(p).at(1)){
      a.at(i)=bc.at(p).at(1);
      bc.at(p).at(0)--;
      if(bc.at(p).at(0)==0)
        p++;
      if(p==m)
        break;
    }
  }
  int64_t s=0;
  for(int i=0;i<n;i++)
    s+=a.at(i);
  cout<<s<<endl;
}

Measured memory_bytes: 6144
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <limits>
#include <type_traits>

using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main() {
    int N;
    int cnt = 0;
    cin >> N;
    FOR(i, 1 ,N+1){
        if(to_string(i).length() % 2 == 1) cnt++;
    }
    cout << cnt << endl;
 }


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

int main(){
	int p[5]={0};
	int no=0;
	double n;
	cin >> n;
	while(cin >> n){
		if(n<165){
			no++;
		}else{
			if(n>185.0)n=185.0;
			p[(int)((n-165.0)/5)]++;
		}
	}
	cout << "1:";
	for(int j=0;j<no;j++)
		cout << "*";
	cout << endl;

	for(int i=0;i<5;i++){
		cout << i+2 << ":";
		for(int j=0;j<p[i];j++)
			cout << "*";
		cout << endl;
	}
}

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

int N,M,visited[5010] = {},cnt[5010] = {};
vector<vector<int>> v(5010);
vector<int> p,ans;


void dfs(int n){
    visited[n] = 1;
    for(auto x:v[n]){
        if(visited[x]==0) dfs(x);
    }
    ans.push_back(n);
}

void dfs2(int n){
    visited[n] = 1;
    for(auto x:v[n]){
        if(visited[x]==0) dfs2(x);
    }
}

int main(){
    cin >> N >> M;
    int a,b;
    for(int i=0;i<M;i++){
        cin >> a >> b;
        v[a].push_back(b);
        cnt[b]++;
    }
    for(int i=1;i<=N;i++){
        if(cnt[i]==0) p.push_back(i);
    }
    for(auto x:p) dfs(x);
    reverse(ans.begin(),ans.end());
    bool judge = false;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++) visited[ans[j]] = 0;
        dfs2(ans[i]);
        for(int j=i+1;j<N;j++) if(visited[ans[j]]==0) judge = true;
    }
    for(auto x:ans) cout << x << endl;
    cout << judge << endl;
}


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

/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

using namespace std;

typedef long long ll;

int n;

string s;

map <string, int> mp;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << "\n";
    cout << "WA x " << mp["WA"] << "\n";
    cout << "TLE x " << mp["TLE"] << "\n";
    cout << "RE x " << mp["RE"] << "\n";
    return 0;
}


Measured memory_bytes: 3664
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            int[] pqr = sc.intarr;

            Array.Sort(pqr);

            wr.wri(pqr[0] + pqr[1]);
        }


    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }

    class Method
    {
        static public int max(params int[] nums)
        {

            int maxx = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                maxx = Math.Max(maxx, nums[i]);
            }
            return maxx;
        }
    }
}


Measured memory_bytes: 13396
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')


n,m,c = map(int,input().split())

a = list(map(int,input().split()))

b = [list(map(int,input().split())) for i in range(n)]


#print(n,m,c)
#print(a)
#print(b)

test = 0
ans = 0

for i in range(n):
	for j in range(m):
		#print(a[j])
		#print(b[i][j])
		test = test + a[j]*b[i][j]
	#print(test+c)
	if test+c > 0:
		ans = ans + 1
	test = 0

print(ans)
		



Measured memory_bytes: 3064
S=list(input())

maxlen=0
for i in range(len(S)):
    for j in range(i,len(S)):
        for k in range(i,j+1):
            #cnt=0
            if S[k]!='A' and S[k]!='C' and S[k]!='G' and S[k]!='T':
                break
            if k==j and j-i+1>maxlen:
                maxlen=j-i+1
print(maxlen)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const ll mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K;cin>>N>>K;
    
    if(N<=10){
        cout<<K+100*(10-N)<<endl;
    }else{
        cout<<K<<endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  ll c[111];
  mem(c);
  REP(i,2,n+1) {
    ll x=i;
    for(ll j=2; j*j<=x; j++) {
      while(x%j==0) {
        c[j]++;
        x/=j;
      }
    }
    if(x>1) c[x]++;
  }
  ll ans=0;
  for(int i=2; i<=100; i++) {
    if(c[i]>=74) ans++;
    for(int j=2; j<=100; j++) {
      if(i!=j&&c[i]>=2&&c[j]>=24) ans++;
      if(i!=j&&c[i]>=4&&c[j]>=14) ans++;
      for(int k=j+1; k<=100; k++) {
        if(i!=j&&i!=k&&c[i]>=2&&c[j]>=4&&c[k]>=4) ans++;
      }
    }
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const long long INF = 1LL << 60;

int a,b,c;

int main()
{
  cin >> a >> b >> c;
  int res = 0;
  if(a != b) res++;
  if(b != c) res++;
  if(c != a) res++;
  if(res == 2) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define all(x) (x).begin(),(x).end()

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int MOD = 1e9+7;

int main()
{
	int w,h;
	cin >> w >> h;
	int f[52][52] = {0};

	loop(i,1,h+1){
		loop(j,1,w+1){
			char c;
			cin >> c;
			if(c == '.')
				f[i][j] = 0;
			else
				f[i][j] = 1;
		}
	}

	loop(i,1,h+1){
		loop(j,1,w+1){
			if(f[i][j] == 1){
				int sum = 0;
				rep(k,4){
					sum += f[i+dx[k]][j+dy[k]];
				}
				if(sum == 0){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,s1,s2,s3,s4;
int main()
{
	cin>>a;
	s4=a%10;
	s3=((a-a%10)%100)/10;
	s2=((a-a%100)%1000)/100;
	s1=(a-a%1000)/1000;
	if(s2==s3&&(s1==s2||s3==s4))cout<<"Yes";
	else cout<<"No";
	cout<<endl;
}

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

int factors[10000007];

int main()
{
	int n;
	cin >> n;
	
	for(int i = 1; i <= n; i++) {
		for(int j = i; j <= n; j += i) {
			factors[j]++;
		}
	}
	
	long long answer = 0;
	
	for(int i = 1; i <= n; i++) {
		answer += (long long) factors[i] * (long long) i;
	}
	
	cout << answer;
}


Measured memory_bytes: 42664
n = gets.to_i
p = gets.chop.split.map(&:to_i)
q = gets.chop.split.map(&:to_i)

ary = []

for i in 1..n do
  ary.push(i)
end

array = ary.permutation(n).to_a

num1 = 1+array.index(p)
num2 = 1+array.index(q)

ans = num1 - num2
puts ans.abs

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

void Main()
{
    int x, y;
    cin >> x >> y;
    for (int i = 0; i <= x; i++)
    {
        if(2*i + 4*(x-i) == y){
            cout << "Yes" << endl;
            return;
        }
    }
    
    cout << "No" << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


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

using namespace std;

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

    else
        return gcd(b,a%b);
}

int main()
{
    long int a,b;

    cin>>a>>b;

    cout<<gcd(max(a,b),min(a,b))<<endl;

    return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  cin>>N;
  int i,j;
  for(i=0;i<23;i++){
    for(j=0;j<15;j++){
      if(N==4*i+7*j){
        cout<<"Yes";
        exit(0);
      }
    }
  }
  cout<<"No";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int i;
  int j;
  int W;
  int H;


  
  while (1)
    {
      scanf("%d %d",&H,&W);

      if(H == 0 && W == 0){
	break;}
	
      for( i = 0; i < H;  i++){

    for ( j = 0; j < W; j++)
      printf("#");
     

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



Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T &a, T b) {if (a < b) {a = b;return 1;}return 0;}
template<class T> inline bool chmin(T &a, T b) {if (a > b) {a = b;return 1;}return 0;}

int main() {
  char s;
  cin >> s;
  if (isupper(s)) cout << "A" << endl;
  else cout << "a" << endl;
}


Measured memory_bytes: 3564
#include <cstdio>
#include <algorithm>
#include <vector>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef pair<int, int> pii;
const int N = 310;
const int mod = 1e9 + 7;

int f[N][N][N], g[N][4];

void inc(int &a, int b) { a = (a + b) % mod;}

vector<pii> tt[N];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	Rep(i, m) {
		int l, r, c;
		scanf("%d%d%d", &l, &r, &c);
		l += 3, r += 3;
		tt[r].push_back(mp(l, c));
	}
	
	f[3][2][1] = 1;
	
	int ans = 0;
	
	for (int i = 3; i <= n + 3; i ++)
		Rep(j, i - 1) Rep(k, j - 1) {
			bool flag = false;
			for (int h = 0; h < tt[i].size(); h ++){
				pii tmp = tt[i][h];
				if (tmp.second == 1 && tmp.first <= j) flag = true; 
				else if (tmp.second == 2 && (tmp.first > j || tmp.first <= k)) flag = true;
				else if (tmp.second == 3 && tmp.first > k) flag = true;
			}
			if (flag) continue;
			if (i < n + 3){
				inc(f[i + 1][j][k], f[i][j][k]);
				inc(f[i + 1][i][j], f[i][j][k]);
				inc(f[i + 1][i][k], f[i][j][k]);
			}
			else inc(ans, f[i][j][k]);
		}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 112896
#include <iostream>
using namespace std;
#define MOD 1000000007

long powMod(long x, long n, long mod){
	if (n == 0) return 1;
	else if (n == 1) return (x % mod);
	else if (n % 2 == 0){
		long t = powMod(x, n/2, mod);
		return (t*t) % mod;
	}
	else{
		return (x*powMod(x, n-1, mod)) % mod;
	}
}

long divMod(long a, long b, long mod){
	long t = powMod(b, mod-2, mod);
	return (a*t) % mod;
}

long combMod(long m, long n, long mod){
	long k = min(n, m-n);
	long numer = 1;
	long denom = 1;
	for (int i = 0; i < k; ++i){
		numer = (numer * (m-i)) % mod;
		denom = (denom * (i+1)) % mod;
	}
	return divMod(numer, denom, mod);
}

int n, a, b;
long ans;

int main(){
    cin >> n >> a >> b;
    ans = powMod(2, n, MOD) - 1;
    ans = (ans - combMod(n, a, MOD) + MOD) % MOD;
    ans = (ans - combMod(n, b, MOD) + MOD) % MOD;
    cout << ans;
}

Measured memory_bytes: 384
import math
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(math.sqrt(n))+1):
    if temp%i == 0:
      cnt = 0
      while temp%i == 0:
        cnt += 1
        temp //= i
      arr.append([i, cnt])
  if temp != 1:
    arr.append([temp, 1])
  if arr == []:
    arr.append([n, 1])
  return arr

n = int(input())
factors = factorization(n)
res = 0
for j,cnt in factors:
  if j == 1: continue
  i = 1
  while cnt >= i:
    cnt -= i
    i += 1
    res += 1

print(res)

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

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n,m,p,c2(0),c1(0);
  string s;
  unordered_set<int> us;
  unordered_map<int,int> um;
  cin >> n >> m;
  for(int i=0;i<m;++i){
    cin >> p >> s;
    if(s == "AC"){
      if(us.insert(p).second){
        c1++;
        c2 += um[p];
        }
    }
    else if(us.find(p) == us.end()){
      um[p]++;
    }
  }
  cout << c1 << ' ' << c2;
  return 0;
}



Measured memory_bytes: 8520
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	vector<int> X(N + 1, 0);
	vector<int> res;
	for (int i = N; i > 0; i--) {
		int cnt = 0;
		for (int j = i; j <= N; j += i) {
			cnt ^= X[j];
		}
		if (cnt != A[i]) {
			X[i] = 1;
			res.push_back(i);
		}
	}
	cout << res.size() << endl;
	for (int i = 0; i < res.size(); i++) {
		if (i > 0)cout << " ";
		cout << res[i];
	}
	cout << endl;
}

Measured memory_bytes: 5108
#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  ll N;
  cin >> N;
  ll B = N;
  for (ll i = 1; i <= sqrt(N); i++) {
    if (N % i == 0) B = N / i;
  }
  ll ans = 1;
  while (B / 10 != 0) {
    B /= 10;
    ans++;
  }

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

Measured memory_bytes: 256
n=int(input())
L=list(map(int,input().split()))
L.sort()
if L[0]==0:
    print(0)
else:
    ans=1
    for i in range(n-1,-1,-1):
        ans=ans*L[i]
        if ans >1e18:
            print(-1)
            break
    else:
        print(ans)



Measured memory_bytes: 21652
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<queue>

using namespace std;


int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> arms;
    int X, L;
    for(int i=0;i<N;i++){
        cin >> X >> L;
        arms.emplace_back(X+L, X-L);
    }
    sort(arms.begin(), arms.end());
    vector<int> st;
    st.push_back(arms[0].first);
    for(int i=1;i<N;i++){
        if(arms[i].second >= st.back()){
            st.push_back(arms[i].first);
        }
    }
    cout << st.size() << endl;


    return 0;
}


Measured memory_bytes: 1908
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
//#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i,n) for(int i=n-1;i>=0;i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef pair<int,int> P;
//typedef long long int ll;

int n,m,ans,co;
int x[111111],y[111111],z[111111];
vector<vector<int>> v(111111);
int f[111111];
void dfs(int i){
    f[i]=1;
    for(int j:v[i]){
        if(!f[j])dfs(j);
    }
}


signed main(){

    
    cin>>n>>m;
    
    rep(i,m){
        cin>>x[i]>>y[i]>>z[i];
        v[x[i]].push_back(y[i]);
        v[y[i]].push_back(x[i]);
    }

    rep(i,m){
        if(!f[x[i]]){
            dfs(x[i]);
            ans++;
        }
    }

    for(int i=1;i<=n;i++){
        if(!f[i])co++;
    }

    cout<<ans+co<<endl;



}


Measured memory_bytes: 10624
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int N;
ll W, weight[110], value[110];
ll dp[110][100100] = {0};
 
int main() {
    cin >> N >> W;
    rep(i, N) {
        cin >> weight[i] >> value[i];
    }

    rep(i, N) {
        for(int sum_w = 0; sum_w <= W; sum_w++) {
            if(sum_w - weight[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    cout << dp[N][W];
    
    cout << endl;
    return 0;
}

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

#define endl "\n"
#define int long long
#define vec(x) vector<x>
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define matrix(x) vector<vector<x>>
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a, b, sizeof a)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed<<setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it:x) cout<<it<<" ";
#define dbg(x) cerr<<#x<<" :: "<<x<<endl;
#define dbg2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
const int INF = 1e9;
const int MOD = 1e9 + 7; 
const double pi = acos(-1);
int power(int a,int b,int m=MOD)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}
int dir[]={-1, 0, 1, 0, -1};
int dx[]={1,1,0,-1,-1,-1, 0, 1};
int dy[]={0,1,1, 1, 0,-1,-1,-1};

const int N = 1e5+1;
matrix(int) adj(N);
int dp[N],vis[N];

void dfs(int u)
{
	vis[u]=1;
	for(auto v:adj[u])
	{
		if(!vis[v])
		dfs(v);
		dp[u]=max(dp[u],1+dp[v]);
	}
}

void solve()
{
	int n,e,i;
    cin>>n>>e;
    for(i=0;i<e;i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
    }
	mem(dp,0);
	mem(vis,0);
	for(i=1;i<=n;i++)
	{
		if(!vis[i])
		dfs(i);
	}
	cout<<*max_element(dp,dp+n+1)<<endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t;
	t=1;
	//cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 9344
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
void debug(vector<int> &A, vector<int> &B, long long ans) {
	printf("\n");
	for (int i = 0; i < (int) A.size(); i++) {
		printf("%d", A[i]);
		if (i != (int) A.size() - 1) printf(" ");
	}
	printf("\n");
	for (int i = 0; i < (int) B.size(); i++) {
		printf("%d", B[i]);
		if (i != (int) B.size() - 1) printf(" ");
	}
	printf("\n%lld\n", ans);
}

int main(void) {
	int N;
	scanf("%d", &N);
	vector<int> A(N + 1);
	for (int i = 0; i < N + 1; i++) {
		scanf("%d", &A[i]);
	}
	vector<int> B(N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &B[i]);
	}
	long long ans = 0;
	for (int i = 0; i < N + 1; i++) {
		if (i != 0) {
			ans += min(A[i], B[i - 1]);
			int tmp = A[i];
			A[i] -= min(tmp, B[i - 1]);
			B[i - 1] -= min(tmp, B[i - 1]);
		}
		// debug(A, B, ans);
		// getchar();
		if (i != N) {
			ans += min(A[i], B[i]);
			int tmp = A[i];
			A[i] -= min(tmp, B[i]);
			B[i] -= min(tmp, B[i]);
		}
		// debug(A, B, ans);
		// getchar();
	}
	printf("%lld\n", ans);
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;

    bool ok = false;
    int ans = 0;
    rep(i, 50001){
        int x = i * 1.08;
        if(x == n){
            ok = true;
            ans = i;
        }
    }

    if(ok) {
        cout << ans << endl;
    }else{
        cout << ":(" << endl;
    }

    return 0;
}



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

int main() {
	cin.tie(0)->sync_with_stdio(false);

	int n; cin >> n;
	string s; cin >> s;

	int cnt = 0;
	string res = s;
	REP(i, n) {
		if (s[i] == '(') cnt++;
		else {
			cnt--;
			if (cnt < 0) {
				res = '(' + res;
				cnt++;
			}
		}
	}

	while (cnt) {
		res += ')';
		cnt--;
	}

	cout << res << '\n';
	return 0;
}


Measured memory_bytes: 3616
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

temp = [T - h * 0.006 for h in H]

diff = 10 ** 9
res = -1
for i, t in enumerate(temp):
    if abs(A - t) < diff:
        res = i
        diff = abs(A - t)

print(res + 1)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();

        int cnt = 0;
        for(int i =0; i < a.length(); i++){
            if(a.charAt(i)=='1'){
                cnt += 1;
            }
        }

        System.out.println(cnt);

    }
}


Measured memory_bytes: 20948
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

string f(ll n) {
    string res;
    while (0 < n) {
        res += 'a' + ((n - 1) % 26);
        n = (n - 1) / 26;
    }
    reverse(res.begin(), res.end());
    return res;
}

int main() {
    ll n;
    cin >> n;
    cout << f(n) << endl;
}

Measured memory_bytes: 3584
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, K: int):
    a = 0 if A < K else A - K
    b = max(A + B - K, 0) if A < K else B
    print(str(a) + ' ' + str(b))
    return


# Generated by 1.1.7.1 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()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
def search(width, books, m):
  acc = 0
  cnt = 1
  for book in books:
    if book > width:
      return False
    if acc + book > width:
      cnt += 1
      acc = book
    else:
      acc += book
  return cnt <= m
while True:
  m, n = map(int, input().split())
  if m == 0:
    break
  books = [int(input()) for _ in range(n)]
  left = 0
  right = 1500000
  while right - left > 1:
    mid = (left + right) // 2
    #print(mid)
    if search(mid, books, m):
      right = mid
    else:
      left = mid
  print(right)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin >> n;
  long long sum = 0;
  for(int i = 1;i<=n;i++){
    if(i%3&&i%5){
      sum += i;
    }
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 998244353;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<ll> D(N), cnt(N, 0);
    ll num = 0;
    rep(i, N) {
        cin >> D[i];
        cnt[D[i]]++;
        num = max(num, D[i]);
    }

    ll ans = 0;
    if (cnt[0] != 1) ans = 0;
    else if (D[0] == 0) {
        ans = 1;
        repd(i, 2, num + 1) {
            rep(j, cnt[i]) {
                ans *= cnt[i - 1];
                ans %= MOD;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        // input
        final int NUM = scan.nextInt();
        int[] nums = new int[NUM];
        int k = scan.nextInt();
        for(int i = 0; i < NUM; i++){
            nums[i] = scan.nextInt();
        }

        // calc
        int count = 0;
        for(int i = 0; i < NUM;){
            if(i == 0){
                count++;
                i += k;
            } else {
                count++;
                i += k - 1;
            }
        }

        // answer
        System.out.println(count);

    }
}

Measured memory_bytes: 50464
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int a, b;
    cin >> a >> b;
    if (a > 8 || b > 8) cout << ":(" << endl;
    else cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int square(int x){
    return x * x;
}
int compress(int x){
    if(x >= 256) return 255;
    if(x < 0) return 0;
    return x;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    while(cin >> N >> M && N){
        vector<int> c(M), x(N);
        rep(i, M) cin >> c[i];
        rep(i, N) cin >> x[i];
        vector<vector<int> > dp(2, vector<int>(256, INF));
        //dp[i][j] := i???????????§???????????????j?????¨??????????????????????°????
        int crr = 0, nxt = 1;
        dp[crr][128] = 0;
        rep(k, N){
            rep(i, 256) dp[nxt][i] = INF;
            rep(i, 256) rep(j, M){
                int it = compress(i + c[j]);
                dp[nxt][it] = min(dp[nxt][it], dp[crr][i] + square(it - x[k]));
            }
            swap(crr, nxt);
        }
        int ans = INF;
        rep(i, 256) ans = min(ans, dp[crr][i]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1304
using System;
class Program{
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		double a=s[0]*100,b=0;
		for(int i=0;i<=s[5]/(s[0]*100);i++){
			for(int j=0;j<=s[5]/(s[1]*100);j++){
				if(i+j!=0){
					int o=i*s[0]+j*s[1],m=Math.Min(o*s[4],s[5]-o*100);
					for(int k=m/s[2],l=0;k>=0;k--){
						l=(m-k*s[2])/s[3];
						if((k*s[2]+l*s[3])*100.0/(o*100+k*s[2]+l*s[3])>b*100/(a+b)){
							a=o*100;
							b=k*s[2]+l*s[3];
						}
					}
				}
			}
		}
		Console.WriteLine("{0} {1}",a+b,b);
	}
}

Measured memory_bytes: 13140
import java.math.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuffer ans = new StringBuffer(sc.next());
        int q = sc.nextInt();
        int t = 0;
        int f = 0;
        int tmp = 0;
        StringBuffer forw = new StringBuffer();
        StringBuffer back = new StringBuffer();
        String c = "";
        for (int i = 0; i < q; i++) {
            tmp = sc.nextInt();
            if (tmp == 1) {
                t++;
            } else {
                f = sc.nextInt();
                c = sc.next();
                if ((t % 2 == 1 && f == 2) || (t % 2 == 0 && f == 1)) {
                    forw.append(c);
                } else {
                    back.append(c);
                }
            }
        }
        ans = forw.reverse().append(ans).append(back);
        if (t % 2 == 1)
            ans.reverse();
        System.out.println(ans.toString());
        sc.close();
    }
}

Measured memory_bytes: 128316
#include<stdio.h>
int main()
{
  int N, M;
  int i;
  int A[10000];
  
  scanf("%d %d", &N, &M);
  
  for(i=0; i<M; i++){
    scanf("%d", &A[i]);
    N = N - A[i];
  }
  
  if(N >= 0)
    printf("%d", N);
  else
    printf("-1");
  
  return 0;
  
}

Measured memory_bytes: 1744
#include<stdio.h>

int main(){
  int x[3],p;
  int i,j;

  scanf("%d %d %d",&x[0],&x[1],&x[2]);
  for(i=0;i<2;i++){
    for(j=i+1;j<3;j++){
      if(x[i]>x[j]){
        p = x[i];
        x[i] = x[j];
        x[j] = p;
      }
    }
  }
  printf("%d %d %d\n",x[0],x[1],x[2]);
  return 0;
}

Measured memory_bytes: 2656
import sys
input = sys.stdin.readline
import numpy as np

N,M,K= map(int,input().split())

A = np.array([0] + list(map(int,input().split())))
B = np.array([0] + list(map(int,input().split())))

cA = np.cumsum(A)
cB = np.cumsum(B)
rcA = (K - cA)[::-1]
ind = N - np.searchsorted(rcA,cB,side='left')
cand = np.arange(M+1) + ind
cand *= (ind >= 0)
print(np.max(cand))



Measured memory_bytes: 52648
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define ll long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n,m; cin>>n>>m;
    vector<double>a(n);
    int sum=0;
    rep(i,0,n-1)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sort(a.begin(),a.end());
    double k=((double)sum/(4*m));
    int c=0; int i=a.size()-1;
    while(i>=0)
    {
        if(a[i]>=k)
        {
            i--;
            c++;
        }
        else
        {
            break;
        }
    }
    if(c>=m)
        cout<<"Yes\n";
    else 
        cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
N, x = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

ans = 0

b = A.map do |i|
  if x >= i
    i
  else 
    x
  end
end

(N-1).times do |i|
  
  if b[i] + b[i+1] > x
    b[i+1] = ( x - b[i] )
  end
end

A.each_with_index{ |a,i| ans += (a-b[i]) }

puts ans

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

int main(void){
    int a,b;
    char c;
    vector<pair<int,int> >st;
    while(true){
        cin>>a>>c>>b;
        if(a==0&&b==0)break;
        st.push_back(make_pair(b,a));
    }
    sort(st.begin(),st.end(),greater<pair<int,int> >());
    int n;
    int t;
    int ans;
    while(true){
        cin>>n;
        if(cin.fail())break;
        t=st[0].first;
        ans=1;
        for (int i = 0; i < st.size(); ++i) {
            if(st[i].first!=t){t=st[i].first,ans++;}
            if(st[i].second==n){cout<<ans<<endl;break;}
        }
    }
    return 0;
}


Measured memory_bytes: 2984
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  map<ll, int> A;
  for (int i = 0; i < N; i++) {
    ll a;
    scanf("%lld", &a);
    A[a]++;
  }
  vector<int> B(M);
  vector<ll> C(M);
  for (int i = 0; i < M; i++) {
    scanf("%d%lld", &B[i], &C[i]);
  }
  // for (auto k = A.begin(); k != A.end(); ++k)
  //   for (int l = 0; l < k->second; l++)
  //     printf("%lld ", k->first);
  // printf("\n");
  for (int i = 0; i < M; i++) {
    int b = B[i];
    while (b > 0) {
      auto j = A.begin();
      if (j == A.end() || j->first >= C[i]) break;
      int p = min(b, j->second);
      ll key = j->first;
      int q = j->second - p;
      A[C[i]] += p;
      if (q == 0) {
        A.erase(key);
      } else {
        A[key] = q;
      }
      b -= p;
    }
    // for (auto k = A.begin(); k != A.end(); ++k)
    //   for (int l = 0; l < k->second; l++)
    //     printf("%lld ", k->first);
    // printf("\n");
  }
  ll ans = 0;
  for (auto k = A.begin(); k != A.end(); ++k) {
    ans += k->first * k->second;
  }
  printf("%lld\n", ans);
}


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

using namespace std;

const int sz = 20;
bool pl[sz];

bool ok (int x) {
    for(int bit = 0; bit < sz; ++ bit) {
        if(((x>>bit)&1) && pl[bit]) return false;
    }

    return true;
}

int main () {
    int n;
    cin  >> n;
    vector< int > v(n + 1);
    for(int i = 1; i <= n; ++i) {
        cin >> v[i];
    }

    int ptr = 0;
    long long ans = 0;
    for(int i = 1; i <= n; ++i) {
        while(ptr < n && ok(v[ptr+1])) {
            ptr ++;
            for(int bit = 0; bit < sz; ++bit) {
                if((v[ptr]>>bit)&1) pl[bit] = true;
            }
        }

        ans += 1ll*((ptr-i)+1);

        for(int bit = 0; bit < sz; ++bit) {
            if((v[i]>>bit)&1){
                assert(pl[bit]);
                pl[bit] = false;
            }
        }
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
/*      Welcome to my Code      */

#include <bits/stdc++.h>
#define ll                      long long int
#define i(a,n)                  int a=n;
#define l(a,n)                  ll a=n;
#define d(a,n)                  double a=n;
#define s(a)                    string a;
#define c(a)                    ll a; cin>>a;a
#define cd(a)                   double a; cin>>a;
#define cs(a)                   string a; cin>>a;
#define ci(a)                   cin>>a
#define co(a)                   cout<<a
#define cos(a)                  cout<<a<<" "
#define con(a)                  cout<<a<<endl
#define yes                     cout<<"YES"<<endl
#define no                      cout<<"NO"<<endl
#define nl                      cout<<endl
#define ca(arr,n)               for(ll i=0;i<n;i++) cin>>arr[i]
#define caa(arr,n)              c(n); ll arr[n]; for(ll i=0;i<n;i++) cin>>arr[i];
#define f0(i,a,n)               for(ll i=a;i>=n;i--)
#define f(i,n)                  for(ll i=0;i<n;i++)
#define f1(i,a,n)               for(ll i=a;i<n;i++)
#define lcm(a,b)                (a*b)/__gcd(a,b)
#define T                       ll t=1; cin>>t; while(t--)
#define sr(a,n)                 sort(a,a+n)
#define rv(a,n)                 reverse(a,a+n)
#define fast                    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ret(x)                  return cout<<x,0;

using namespace std;

int main()
{
    fast;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*c,max(a*d,max(b*c,b*d)));
    return 0;
}

/*It's not who I am underneath, but what I do that defines me

MMMMMMMMMMMMMMMMMMMMM.                             MMMMMMMMMMMMMMMMMMMMM
 `MMMMMMMMMMMMMMMMMMMM           M\  /M           MMMMMMMMMMMMMMMMMMMM'
   `MMMMMMMMMMMMMMMMMMM          MMMMMM          MMMMMMMMMMMMMMMMMMM'
     MMMMMMMMMMMMMMMMMMM-_______MMMMMMMM_______-MMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
     .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM.
    MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
                   `MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'
                          `MMMMMMMMMMMMMMMMMM'
                              `MMMMMMMMMM'
                                 MMMMMM
                                  MMMM
                                   MM
*/


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int A = sc.nextInt();
        int B = sc.nextInt();
        if(2*B > A){
            System.out.println("0");
        }else{
            System.out.println(A-2*B);
        }
        return;
    }
}



Measured memory_bytes: 21716
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

ll const mod = 1000000007;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, m;
  cin >> n >> m;
  vll dp(n + 1, 0);
  set<ll> dec;
  rep(i, m) {
    ll a;
    cin >> a;
    dec.insert(a);
  }

  dp[0] = 1;
  rep(i, n) {
    if (dec.find(i+1) != dec.end()) continue;
    dp[i + 1] = dp[i];
    if (i >= 1) dp[i + 1] += dp[i - 1];
    dp[i + 1] %= mod;
  }

  cout << dp.back() << endl;

  return 0;
}


Measured memory_bytes: 5760