akhauriyash/Code-Regression huggingface dataset:
N,W = list(map(int,input().split()))
WV = []
Vsum = 0
for i in range(N):
    [Wtmp,Vtmp] = list(map(int,input().split()))
    WV.append([Wtmp,Vtmp])
    Vsum += Vtmp

inf = float('inf')
dp = [[inf]*(Vsum+1) for i in range(N)]

W0 = WV[0][0]
V0 = WV[0][1]

for j in range(Vsum+1):
    if V0>=j:
        dp[0][j] = W0

for i in range(1,N):
    newW = WV[i][0]
    dp[i][0] = min(newW,dp[i-1][0])

for i in range(1,N):
    newW = WV[i][0]
    newV = WV[i][1]
    for j in range(1,Vsum+1):
        if j<=newV:
            dp[i][j] = newW
        if j-newV>=0:
            dp[i][j] = min(dp[i-1][j-newV]+newW,dp[i][j])
        dp[i][j] = min(dp[i-1][j],dp[i][j])

out = 0
for i in range(N):
    for j in range(Vsum+1):
        if dp[i][j]<=W:
            if j >= out:
                out = j

print(out)
#print(*dp,sep='\n')

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

using namespace std;

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

int main() {
    int n, i, t, ans = -1, cnt = 0;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> t;
        if (ans <= t) {
            ans = t;
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    string s; cin >> s;
    string t; cin >> t;
    int n = s.size();
    int m = t.size();

    vector<int> ans;
    rep(i,n - m + 1){
        int ans_ = s.find(t, i);
        if(ans_ == std::string::npos){
            i = n;
        }else{
            ans.push_back(ans_);
            i = ans_;
        }
    }

    rep(i, ans.size()){
        printf("%d\n", ans[i]);
    }
    
    return 0;
}
 
 



Measured memory_bytes: 3296
#include<stdio.h>

int main(){

    long a[100001]={};
    long b[100000]={};
    long N=0;
    long sum=0;
    long temp=0;
    scanf("%ld",&N);
    for(int i=0;i<N+1;i++){
        scanf("%ld",&a[i]);
    }
    for(int i=0;i<N;i++){
        scanf("%ld",&b[i]);
    }


    for(int i=0;i<N;i++){
        if(a[i]>b[i]){
            sum+=b[i];
        }else{
            temp=b[i]-a[i];
            if(a[i+1]>temp){
                sum+=b[i];
                a[i+1]-=temp;
           }else{
               sum+=a[i]+a[i+1];
               a[i+1]=0;
           }
        }
    }

    printf("%ld",sum);



    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint N, K;
  cin >> N >> K;
  vector<lint> A(N);
  REP(i, N) cin >> A[i];
  sort(ALL(A));
  lint l = -1e18;
  lint r = 1e18+1;
  while(r-l > 1) {
    lint x = l + (r - l) / 2;
    lint sum = 0;
    REP(i, N) {
      lint ll = -1;
      lint rr = N;
      if(A[i] > 0) {
        while(rr-ll > 1) {
          lint m = (ll+rr) / 2;
          if(A[i]*A[m] <= x) {
            ll = m;
          } else {
            rr = m;
          }
        }
        sum += ll+1;
        if(ll != -1 && A[i] <= A[ll]) sum--;
      } else if(A[i] < 0){
        while(rr-ll > 1) {
          lint m = (ll+rr) / 2;
          if(A[i]*A[m] <= x) {
            rr = m;
          } else {
            ll = m;
          }
        }
        sum += N-rr;
        if(rr != N && A[i] >= A[rr]) sum--;
      } else {
        if(x >= 0) sum += N-1;
      }
    }
    if((sum/2) >= K) {
      r = x;
    } else {
      l = x;
    }
    
  }
  cout << r << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
 
int main(){
   int a, b;
   scanf("%d",&a);
   scanf("%d",&b);
   if (a > b) {
      printf("a > b\n");
   }
   if (a < b) {
      printf("a < b\n");
   }
   if (a == b) {
      printf("a == b\n");
   }
   return 0;
}
 

Measured memory_bytes: 2684
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[300],s=0;
	cin>>n;
	for(int i=1;i<=2*n;i++)  cin>>a[i];
	sort(a+1,a+2*n+1);
	for(int i=1;i<=2*n;i++) if(i%2==1) s+=a[i];
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

//s0 t1
struct tv{int st,kind,c;};
bool cmp(tv l, tv r){
	if(l.st==r.st){
		return l.kind > r.kind;
	}
	return l.st < r.st;
}

int main(void){
	ll n,C;
	cin>>n>>C;
	int s,t,c;
	vector<tv> TV;
	rep(i,n){
		cin>>s>>t>>c;
		TV.push_back(tv{s,0,c});
		TV.push_back(tv{t,1,c});
	}
	sort(TV.begin(),TV.end(),cmp);
	vector<int> countC;
	rep(i,C+1){
		countC.push_back(0);
	}
	int count = 0;
	int ans = 0;
	int now = 0;
	int ti = 0;
	
	while(ti < 2*n && now < 100005){
		while(TV[ti].st > now) now++;
		while(ti<2*n && TV[ti].st == now && TV[ti].kind == 1){
			countC[TV[ti].c]++;
			//cout<<ti<<" "<<countC[TV[ti].c]<<endl;
			ti++;
		}
		while(ti<2*n && TV[ti].st == now && TV[ti].kind == 0){
			if(countC[TV[ti].c] > 0){
				countC[TV[ti].c]--;
			}else{
				count++;
			}
			ti++;
		}
		chmax(ans,count);
		rep(i,C+1){
			if(countC[i] != 0){
				count -= countC[i];
				countC[i] = 0;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
int main(){
    int n,k;
    cin >> n >> k;
    vector <int> A(n);
    rep(i,n) cin >> A[i];

    if(n == 1){
        cout << min(n,k) << endl;
    }

    else{
        for(int l=1; l<=min(k,50); l++){
            vector <int> B(n,0);
            for(int i=0; i<n; i++){
                int l = max(0,i-A[i]);
                int r = min(i+A[i],n-1);
                B[l] ++;
                if(r+1<n){
                    B[r+1]--;
                }
            }
    
            for(int i=1; i<n; i++) B[i] += B[i-1];//B complete

            rep(i,n){
                A[i] = B[i];//new A
            }        
        }
    }

    rep(i,n){
        if(i == n-1){
            if(A[i]>n){
                cout << n << endl;
            }
            else{
                cout << A[i] << endl;
            }
        }
        else{
            if(A[i]>n){
                cout << n << endl;
            }
            else{
                cout << A[i] << " ";
            }
        }
    }
}


Measured memory_bytes: 4840
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
using namespace std;
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define N 100005
vector<pair<lld,lld>> v,sum;
int main()
{
	lld n,k,curr=0,x,y;
	cin>>n>>k;
	rep(i,0,n) cin>>x>>y,v.pb({x,y});
	sort(all(v));
	rep(i,0,n) curr+=v[i].s,sum.pb({curr,v[i].f});
	
	auto it=lower_bound(all(sum),mp(k,0LL))-sum.begin();
	cout<<sum[it].s;
	return 0;
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define INF 1e9
#define MOD 1000000007
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main(void){
    int N,K;cin>>N>>K;
    vector<ll> H(N);
    ll ans=0;
    REP(i,N)cin>>H[i];
    sort(All(H));
    if(K>=N){cout<<0<<endl;return 0;}
    for(int i=N-1-K;i>=0;i--)ans+=H[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
bool isPrime(int x){
    if(x < 2) return false;
    if(x == 2) return true;
    if(x % 2 == 0) return false;
    for(int i=3; i*i<=x; i+=2){
        if(x % i == 0) return false; 
    }
    return true;
}
int main(){
    int n,p;
    while(cin >> n >> p){
        if(n == -1 && p == -1) break;
        vector<int> vec;
        for(int i=n+1; i<=n+1000; i++){
            if(isPrime(i)){
                for(int j=i; j<=n+1000; j++) if(isPrime(j)) vec.push_back(i+j);
            }
        }
        sort(vec.begin(),vec.end());
        cout << vec[p-1] << endl;
    }
    return 0;
}



Measured memory_bytes: 3236
from itertools import permutations
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
ln = []
for i in range(1, n + 1):
    ln.append(i)
pn = list(permutations(ln))
sorted_pn = sorted(pn)

# print(sorted_pn)

a = sorted_pn.index(p) + 1
b = sorted_pn.index(q) + 1

print(abs(a-b))

Measured memory_bytes: 8308
n = int(input())
a = list(map(int,input().split()))
q = int(input())
for i in range(q):
    b,m,e = map(int,input().split())
    s = a[b:e]
    a = a[:b] + s[m-b:] + s[:m-b] + a[e:]
    
print(*a)


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

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

int main() {
  int64_t A, B;
  cin >> A >> B;
  cout << A * B / gcd(A,B) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,A;
  cin >> N >> A ;
  
  bool wareru=false;
  for(int i=0; i<=A; i++){
    if(N%500==i){
      wareru=true;
      break;
    }
  }
  
  if(wareru) cout <<"Yes"<<endl;
  else cout<<"No"<<endl; 
}

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

using namespace std;

const int maxn=500005;
typedef long long ll;

int read()
{
	int f=0; char c=getchar();
	while(c>'9' || c<'0') c=getchar();
	while(c<='9' && c>='0') {f=f*10+c-'0'; c=getchar();}
	return f;
}

ll n,m;
ll a[maxn];
ll s;

int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++) cin>>a[i];
	for(int i=1;i<=m;i++)
	{
		s+=a[i];
	}
	if(s>n) cout<<-1<<endl;
	else cout<<n-s<<endl;
	return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    string s;
    cin >> s;
    bool ans = true;
    rep(i,3){
        if(s[i]==s[i+1]){
            ans = false;
        }
    }
    cout << (ans ? "Good" : "Bad") << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;

using namespace std;
int main(){

    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    cout<<s<<endl;




return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int A,B;
    cin >> A >> B;
    pr(max(max(A+B, A-B), A*B));
}

Measured memory_bytes: 256
from collections import deque
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

routes = [[] for _ in range(n)]

for i in range(m):
    routes[ab[i][0]-1].append(ab[i][1]-1)
    routes[ab[i][1]-1].append(ab[i][0]-1)

#%%
signs = [-1 for _ in range(n)]
seen = [False for _ in range(n)]
seen[0] = True

todo = deque()
todo.append(0)

while len(todo) > 0:
    looking = todo.popleft()
    for i in range(len(routes[looking])):
        if seen[routes[looking][i]] == False:
            seen[routes[looking][i]] = True
            todo.append(routes[looking][i])
            signs[routes[looking][i]] = looking

print("Yes")
for i in range(n-1):
    print(signs[i+1] + 1)

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

signed main(){
  string S;
  cin>>S;
  string ans="No";
  if(S[2]==S[3]&&S[4]==S[5])ans="Yes";
  cout<<ans<<endl;
}

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

maxx = 0
answ, anss = 100*a, 0

for i in range(0, 31):
    for j in range(0, 31):
        water = 100 * a * i + 100 * b * j
        if water == 0:
            continue

        rest = f - water
        if rest < 0:
            break

        ub = water * e // 100
        if ub > rest:
            ub = rest

        for k in range(0, 3001):
            rest2 = ub - c * k
            if rest2 < 0:
                break
            dnum = rest2 // d

            sugar = k * c + dnum * d
            conc = sugar / (water + sugar)
            if maxx < conc:
                maxx = conc
                answ, anss = water+sugar, sugar

print(answ, anss)
        



Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  string s;
  cin >> s;
  int n = s.length();
  for(int i = 0; i < n; i++){
    if(s[i] == '?'){
      s[i] = 'D';
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

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


Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');

            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);

            if (a < b)
            {
                Console.WriteLine("a < b");

            }

            else if (a >b)
            {
                Console.WriteLine("a > b");

            }
            else if (a == b)
            {
                Console.WriteLine("a == b");
            }




            //int n = int.Parse(s);

            //int h = n / 3600;
            //int m = (n - h * 3600) / 60;
            //int s2 = n % 60;


            //Console.WriteLine(h+":"+m+":"+s2);



            //int tate = int.Parse(s[0]);
            //int yoko = int.Parse(s[1]);

            //int area = tate * yoko;
            //int rect = (tate + yoko )* 2;

            //Console.WriteLine(area + " "+rect);
        }
    }
}

Measured memory_bytes: 9376
let abc = readLine()!.split(separator: " ").compactMap { Int($0) }
let a = abc[0]
var b = abc[1]
var c = abc[2]

let k = Int(readLine()!)!
var count = 0
while count < k {
    if a >= b {
        b *= 2
    } else if b >= c {
        c *= 2
    } else {
        break
    }
    count += 1
}
print((a < b && b < c) ? "Yes" : "No")


Measured memory_bytes: 8260
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main (){
  int N;
  cin >> N;
  int a[100000];
  for (int i=0;i<N;i++){
    cin >> a[i];
  }
  for (int i=0;i<N;i++){
    mpa[a[i]]++;
  }
  ll ans=0;
  int f=0;
  int s=0;
  for (auto itr=mpa.begin();itr!=mpa.end();itr++){
      f=itr->first;
      s=itr->second;
      if(s<f){
        ans+=s;
      }
      else{
        ans+=s-f;
      }
  }

  cout << ans;
  return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    int ans=120;
    string str;
    cin>>str;
    for(int i=0;i<26;i++){
        string s=str;
        s+=('a'+i);
        int c=0;
        int mx=0;
        for(char x:s){
            if(x!=('a'+i)) c++;
            else{
                mx=max(c,mx);
                c=0;
            }
        }
        ans=min(mx,ans);
    }
    cout<<ans;
}


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

/*
  REMEMBER:
  1.Think TWICE, code ONCE!
  Are there any counterexamples to your algo?
	
  2.Be careful about the BOUNDARIES in your algo!
  N=1? P=1? Is P a prime? Something about 0?
	
  3.Never make STUPID MISTAKES!
  Integer overflow? Array size? Time complexity? Memory usage? Precition error?
*/

long long sum; int arr[100003] , N;

int main(){
	cin >> N; for(int i = 1 ; i <= N ; ++i) cin >> arr[i];
	for(int i = 1 ; i <= N ; ++i){
		sum += arr[i] / 2; arr[i] %= 2;
		if(arr[i] && arr[i + 1]){--arr[i + 1]; --arr[i]; ++sum;}
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 640
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] xs) {
    int ans = 0;
    foreach (x; xs) {
        while (x > 0 && x % 2 == 0) {
            ans++;
            x /= 2;
        }
    }
    return ans;
}

void main() {
    readint;
    auto xs = readints;

    auto ans = calc(xs);
    writeln(ans);
}

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

#define int long long

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

  string S[N];
  for ( int i = 0; i < N; i++ ) cin >> S[i];

  int ans = 0;
  for ( int i = 0; i < N; i++ ) {
    bool flag = true;
    for ( int j = 0; j < N; j++ ) {
      for ( int k = 0; k < N; k++ ) {
	if ( S[(j+i)%N][k] != S[(k+i)%N][j] ) {
	  flag = false;
	  j = N;
	  break;
	}
      }
    }

    if ( flag ) ans++;
  }

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


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    map<int, int> A;
    CIN(int, N);

    int ans = 0;
    for (int i = 0; i < N; i++) {
        int temp;
        cin >> temp;
        if ( A[temp] == 0 ) {
            A[temp] = 1;
            ans++;
        } else {
            A[temp] = 0;
            ans--;
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4864
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

immutable long inf = 10L^^15;

void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);

    auto m = 1<<n;
    auto dp = new int[][](m, 2);
    foreach (i ; 0 .. m) {
        dp[i][0] = i;
        dp[i][1] = -1;
    }

    debug {
        writeln(dp);
    }

    foreach (s ; 0 .. m) {
        int[] ids = [s];

        foreach (j ; 0 .. 20) {
            if ((s >> j) & 1) {
                int sb = s ^ (1 << j);
                foreach (r ; 0 .. 2) {
                    if (dp[sb][r] == -1) continue;
                    ids ~= dp[sb][r];
                }
            }
        }

        ids = ids.sort().uniq.array;
        ids.sort!((i, j) => a[i] > a[j]);
        dp[s][0] = ids[0];
        if (ids.length > 1) dp[s][1] = ids[1];
    }

    debug {
        writeln(dp);
    }

    auto ans = new long[](m + 1);

    foreach (i ; 1 .. m) {
        ans[i] = max(ans[i-1], a[dp[i][0]]+ a[dp[i][1]]);
        writeln(ans[i]);
    }

}




































void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 35608
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;

int main() {
    int n , k;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> num(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        num[a[i] - 1]++;
    }
    sort(num.begin(),num.end());
    int ans = 0;
    for(int i = 0; i < n-k; i++) {
        ans += num[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import fractions

A, B = list(map(int, input().split()))

def make_divisors(n):
    lower_divisors = []
    upper_divisors = []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

l = sorted(list(set(make_divisors(A)) & set(make_divisors(B))))
#print(l)
i = 0
while i < len(l):
    v = l[i]
    if v == 1:
        i += 1
        continue
    l = l[0:i+1] + list(filter(lambda x: x % v != 0, l[i+1:]))
#    print(l)
    i += 1
print(len(l))

Measured memory_bytes: 7260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

void primeFactor(ll val, map<ll,ll> &primeList){
  cerr<<__FUNCTION__<<":start"<<endl;
  if(val<1){
    return;
  }
  for(int i=2;i*i<val;i++){
    while(val%i==0){
      primeList[i]++;
      val/=i;
    }
  }
  if(val!=1){
    primeList[val]=1;
  }
  cerr<<__FUNCTION__<<":end"<<endl;

  return;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  ll n;cin>>n;
  int ans=0;
  map<ll,int> pl;
  for(ll i=2;i*i<n;i++){
    while(n%i==0){
      pl[i]++;
      n/=i;
    }
  }
  if(n!=1){
    pl[n]=1;
  }
  for(auto it:pl){
    int d=it.second;
    for(int s=1;s<=d;s++){
      d-=s;
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

//Author: Jiangsu Nanjing Li Zongtai
//强壮标记*10000,手牌*10000,血量10000 lyl+hzj也打不死我哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈~~~~

const long long inf=20000000000000000LL;

struct edge
{
	long long to;
	long long cost;
};

long long v;
vector<edge> G[333333];
long long n;
long long d[333333];

void dij(long long s)
{
	priority_queue<pair<long long,long long>,vector<pair<long long,long long> >,greater<pair<long long,long long> > > q;
	
	for(int i=0;i<300000;i++) d[i]=inf;
	
	d[s]=0;
	
	q.push(make_pair(0,s));
	
	while(!q.empty())
	{
		pair<long long,long long> p=q.top();
		q.pop();
		
		long long vv=p.second;
		
		if(d[vv]<p.first) continue;
		
		for(long long i=0;i<G[vv].size();i++)
		{
			edge e=G[vv][i];
			
			if(d[e.to]>d[vv]+e.cost)
			{
				d[e.to]=d[vv]+e.cost;
				q.push(make_pair(d[e.to],e.to));
			}
		}
	}
	
	
}

int main()
{
	cin>>n;
	
	for(long long i=1;i<n;i++)
	{
		long long a,b,c;
		cin>>a>>b>>c;
		
		G[a].push_back(edge{b,c});
		G[b].push_back(edge{a,c});
	}
	
	long long qq;
	long long ss;
	
	cin>>qq>>ss;
	
	dij(ss);
	
	while(qq--)
	{
		long long fr,tt;
		cin>>fr>>tt;
		
		cout<<d[fr]+d[tt]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 19072
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function f(N, K)
    s = 0
    for n in 1:N
        if n < K
            s += 1 / (2^(ceil(log(2, K / n)))) 
        else
            s += 1
        end
    end
    return s / N 
end


function main()
    N, K = parseMap(split(readline()))
    println(f(N, K))
end

main()

Measured memory_bytes: 200472
#include <stdio.h>

#define MAXN 2999

double S[MAXN+1][MAXN+1];
double A[MAXN+1];

double Coins(int n)
{
	int i,j;
	double sum = 0;


	S[0][0] = 1;
	for ( i = 1; i <= n; i++ ) S[i][0] = S[i-1][0]*(1-A[i]);
	for ( i = 1; i <= n; i++ ) S[i][i] = S[i-1][i-1]*A[i];

	for ( i = 1; i <= n; i++ ) {
		for ( j = 1; j < i; j++ ) {
			S[i][j] = S[i-1][j-1]*A[i]+S[i-1][j]*(1-A[i]);
		}
	}

	for ( i = n/2+1; i <= n; i++ ) sum += S[n][i];

	return sum;
}

int main(void)
{
	int i, n;

	scanf("%d", &n);
	for ( i = 1; i <= n; i++ ) scanf("%lf", &A[i]);


	printf("%.10f\n", Coins(n));

	return 0;
}


Measured memory_bytes: 68864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    ll sum=0,os=0;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
        sum+=a[i];
        if(i&1){
            os+=a[i];
        }
    }
    vector<ll> ans(n);
    REP(i,n){
        if(!i){
            cout << sum-os*2 << " ";
            ans[i]=sum-os*2;
        }
        else{
            cout << a[i-1]*2-ans[i-1] << " ";
            ans[i]=a[i-1]*2-ans[i-1];
        }
    }
    cout << endl;
}

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

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

const int MX = 100005;

#define F0R(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define sz(x) (int)x.size()
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define f first
#define s second

void setIO(string name) {
	ios_base::sync_with_stdio(0); cin.tie(0);
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}

int N, a[MX];
int dp[MX];

int main() {
	memset(dp, 1000000, sizeof dp);
	cin >> N;
	F0R(i, N) cin >> a[i];

	/*
	Define dp[i] to be the minimum cost of reaching step i.
	dp[i] = dp[i - 1] + d(i, i - 1), dp[i - 1] + d(i - 1).
	*/


	dp[0] = 0;
	for (int i = 1; i < N; i++) {
		dp[i] = min(dp[i], dp[i - 1] + abs(a[i] - a[i - 1]));
		if (i - 2 >= 0) {
			dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));
		}
	}

	cout << dp[N - 1] << "\n";
}

// watch out for int overflow

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

/* global variables */

int n, q;
int prnts[MAX_N + 1];
bool marked[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n >> q;
    if (n == 0) break;

    marked[1] = true;
    prnts[1] = 0;
    for (int i = 2; i <= n; i++) {
      cin >> prnts[i];
      marked[i] = false;
    }

    ll sum = 0;
    
    for (int qi = 0; qi < q; qi++) {
      char op;
      int i;
      cin >> op >> i;

      if (op == 'M') {
	marked[i] = true;
      }
      else {
	while (! marked[i]) i = prnts[i];
	sum += i;
      }
    }

    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 1644
import collections
a=int(input())
b=list(map(int,input().split()))

c=collections.Counter(b)

n,m=zip(*c.most_common())
n,m=list(n),list(m)
result=0
for i in range(len(m)):
    result+=(m[i]*(m[i]-1))//2

for i in b:
    print(result-c[i]+1)


Measured memory_bytes: 40460
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

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

    int N, M;
    cin >> N >> M;

    vector<long> c(N + 1, 1);

    int a_m;
    for (int m = 0; m < M; m++) {
        cin >> a_m;
        c[a_m] = 0;
    }

    for (int n = 2; n < N + 1; n++) {
        if (c[n] != 0) {
            c[n] = (c[n - 1] + c[n - 2]) % MOD;
        }
        //cout << c[n] << '\n';
    }

    cout << c[N] << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
    ll n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    for (ll m=0; m<n; m++){
        if (m*c-(n-m-1)*d<=b-a && b-a<=m*d-(n-m-1)*c){
            cout << "YES" << endl;
            exit(0);
        }
    }
    cout <<"NO"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int a= stdIn.nextInt();
		int b=stdIn.nextInt();
		int x=stdIn.nextInt();
		
		if(a+b<x||a>x){
			System.out.println("NO");
		}
		else
			System.out.println("YES");
		
	}

}


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


int main(){
    int A,B;
    cin >>A>>B;
    int N = 1;
    int a = N*0.08; 
  	int b = N*0.10;
    while(N<10000){
        int a = N*0.08; 
      	int b = N*0.10;
        if((a==A)&(b==B)){
            cout << N <<endl;
            return 0;
        }
        N++;
      
    }
    cout <<"-1"<<endl;

}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, ans = 0; cin >> n;
    char a, b; cin >> a >> b;
    for(int i = 0; i < n - 2; ++i){
        char c; cin >> c;
        if(a == 'A' && b == 'B' && c == 'C') ans++;
        a = b; b = c;
    }cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n=7, k,count=1;
  cin>>k;
  while(n%k){
  n=(n%k)*10+7;
  count++;
  if(count>=1000000){count=-1;break;}
  }
  cout<<count;
return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 300000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
		ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	setcomb();
	ll n, k, i;
	cin >> n >> k;
	for (i = 1; i <= k; i++)
		cout << comb(n - k + 1, i)*comb(k - 1, i - 1) % M << endl;
}

Measured memory_bytes: 4992
s = input()
k = int(input())

num = [26 - i for i in range(26)]
num[0] = 10 ** 9 + 10

a_ = ord('a')

ans = ''
for c in s:
    x = ord(c) - a_
    if num[x] <= k:
        ans += 'a'
        k -= num[x]
    else:
        ans += c
k %= 26
if k > 0:
    c = ans[-1]
    ans = ans[:-1] + chr(a_ + ((ord(c) - a_ + k) % 26))
print(ans)


Measured memory_bytes: 3444
x = int(input())

for a in range(-120, 120):
  f_a = a**5
  r_b = (x-f_a)**(1/5).real
  b = round(r_b.real)
  if f_a - b**5 == x:
    print(a, b)
    break

  b *= -1
  if f_a - b**5 == x:
    print(a, b)
    break

Measured memory_bytes: 9448
import Control.Applicative
import Control.Monad
import Data.List

main = do
    [n, m, k] <- fmap read . words <$> getLine :: IO [Int]

    let xs = do
            a <- [0 .. n]
            b <- [0 .. m]
            return $ a * (m - b) + (n - a) * b

    if k `elem` xs
        then putStrLn "Yes"
        else putStrLn "No"

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

const ll mod = 1000000007;

int power(ll a, ll b){
  ll res=1;
  while(b>0){
   if(b & 1) res=res*a%mod;
    a=a*a%mod;
    b>>=1;
  }
  
  return res;
  
}

int main(){
  ll n,k; 
  cin >> n >> k;
  
  for(int i=1; i<=k; i++){
    if(n-k+1<i){
     cout << 0 << endl;
     continue;
    }
    
    ll ans=1;
    
    for(int j=1; j<=n-k+1; j++){
     ans*=j;
     ans%=mod;
   }
  
    for(int j=1; j<=i; j++){
     ans*=power(j,mod-2);
     ans%=mod;
   }
   
    for(int j=1; j<=n-k+1-i; j++){
      ans*=power(j,mod-2);
      ans%=mod;
    }
    
    for(int j=1; j<=k-1; j++){
      ans*=j;
      ans%=mod;
    }
    
    for(int j=1; j<=i-1; j++){
      ans*=power(j,mod-2);
      ans%=mod;
    }
    
    for(int j=1; j<=k-i; j++){
      ans*=power(j,mod-2);
      ans%=mod;
    }
    
    cout << ans << endl;
    
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string as = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string ab = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

//--------------------------

typedef tuple<string, int, int> mytuple;

int main() {

  int n;
  string s;
  int sc;
  cin >> n;
  vector<mytuple> vt(n);
  rep(i, n) {
    cin >> s >> sc;
    vt[i] = make_tuple(s, sc, i+1);
  }

  sort(vt.begin(), vt.end(), [](mytuple const &lhs, mytuple const &rhs) {
    if(get<0>(lhs) != get<0>(rhs)) return get<0>(lhs) < get<0>(rhs);
    if(get<1>(lhs) != get<1>(rhs)) return get<1>(lhs) > get<1>(rhs);
  });

  for( auto x: vt) {
    cout << get<2>(x) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, x, y;
    cin>>a>>b;
    int arr[a];
    if (a==1 && b==0){
        cout<<"0\n";
        return 0;
    }
    for (int i=0; i<a; i++) arr[i]=-1;
    for (int i=0; i<b; i++){
        cin>>x>>y;
        if (arr[x-1]==-1 || arr[x-1]==y) arr[x-1]=y;
        else {
            cout<<"-1\n";
            return 0;
        }
    }
    if (arr[0]==0 && a!=1){
        cout<<"-1\n";
        return 0;
    }
    if (arr[0]==-1) arr[0]=1;
    cout<<arr[0];
    for (int i=1; i<a; i++){
        if (arr[i]==-1) cout<<0;
        else cout<<arr[i];
    }
    cout<<endl;
}

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

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

int main() {
	int n;
	string s;
	cin >> n >> s;
    
	string t = s;
	string target = "ABC";     
	string replacement = ""; 
	if (!target.empty()) {
		string::size_type pos = 0;
		while ((pos = s.find(target, pos)) != string::npos) {
			s.replace(pos, target.length(), replacement);
			pos += replacement.length();
		}
	}

	int ans = (t.size()-s.size())/3;

	cout << ans << endl;
}


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

long long func(long long l,long long r, long long num){
  long long ok = (l%num==0) ? 1:0;
  //cout<< l <<" "<< r <<" "<< ok <<endl;
  //cout << r/num - l/num + ok << endl;
  return r/num - l/num + ok;
  
}

int main(){
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  //cout<<c / __gcd(c, d)*d<<endl;
  cout<< b-a + 1 - func(a,b,c) - func(a,b,d) + func(a,b,c / __gcd(c, d)*d) <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//#define int long long  ←保留
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/*-------------ここまで---------------------------------------------*/

//C++(GCC9.2.1)

/*signed*/int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int k = (a + n - 1) / n;
    if (k * n >= a and k * n <= b) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3612
N, X = map(int,input().split())
L = list(map(int,input().split()))
pre = 0
counter = 1
if N == 1:
    if L[0] <= X:
        print(2)
    else:
        print(1)
else:
    for i in range(N):
        if pre + L[i] <= X:
            counter += 1
            pre += L[i]
        else:
            print(counter)
            exit()
        if i == (N-1):
            print(counter)
        


Measured memory_bytes: 3060
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let (a, b) = {
    let v: Vec<u64> = read_vec();
    (v[0], v[1])
  };

  if a > 8 || b > 8 {
    println!(":(")
  }
  else {
    println!("Yay!")
  }
}


Measured memory_bytes: 4352
s=input()
t=input()
#print(s,t)

if len(s) < len(t):
    print('UNRESTORABLE') 
elif len(s) == len(t):
  cnt=0
  for i in range(len(s)):
    if s[i] == t[i]:
      cnt+=1
    elif s[i] == '?':
      cnt+=1
  if len(t)==cnt:
    print(t)
  else:
    print('UNRESTORABLE') 
else:
  flag1=0
  for j in range(len(s)-len(t),-1,-1):
    cnt=0
    for i in range(len(t)):
      if s[i+j]==t[i]:
        cnt+=1
      elif s[i+j]=='?':
        cnt+=1
    if cnt==len(t):
      flag1=1
      s=s[0:j]+t+s[j+len(t):]
      s=s.replace('?','a')
      print(s)
    
  if flag1==0:
    print('UNRESTORABLE') 




Measured memory_bytes: 3064