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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int WWW = 0;WWW < (n);WWW++)cerr << v[WWW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int x[80][111111];
double diff[111111];

int main(){
	
	ll n;cin >> n;
	vector<ll> v(n);
	REP(i,n)cin >> v[i];
	ll m,k;cin >> m >> k;
	vector<ll> a(m);
	REP(i,m){
		cin >> a[i];
	}
	
	REP(i,n)x[0][i] = i;
	REP(i,m)swap(x[0][a[i]],x[0][a[i]-1]);
	
	for(int i = 0;i < 79;i++){
		REP(j,n){
			x[i+1][j] = x[i][x[i][j]];
		}
	}
	
	for(int i = 1;i < n;i++){
		int tmp = i;
		for(ll j = 0;j < 60;j++){
			if(k & (1LL << j)){
				tmp = x[j][tmp];
			}
		}
		DBG(cout << "tmp " << i << ' ' << tmp << endl;)
		diff[i] = v[tmp] - v[tmp-1];
	}

	DBG(cout << "x" << endl;REP(i,10)SHOW1d(x[i],n);)
	DBG(cout << "diff" << endl;SHOW1d(diff,n););
	
	diff[0] = v[0];
	cout << v[0] << endl;
		
	for(int i = 1;i < n;i++){
		diff[i] += diff[i-1];
		cout << Decimal << diff[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 40192
#include <iostream>
#include <string>
using namespace std;
 
int main() {
	string S;
	cin>>S;
	if(S=="Sunny"){
		cout<<"Cloudy";
	}else if(S=="Cloudy"){
		cout<<"Rainy";
	}else if(S=="Rainy"){
		cout<<"Sunny";
	}
}

Measured memory_bytes: 3508
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

double round(double src,int n);

int main(){ 
    double a,b,c,d,e,f;

    while(cin>>a>>b>>c>>d>>e>>f){
        double x = (b*f-c*e)/(b*d-a*e);
        double y = (a*f-c*d)/(a*e-b*d);
        x = round(x,4);
        y = round(y,4);

        printf("%.3f %.3f\n", x,y);
    }
    return 0;
}

double round(double src,int n){
    double p = src * pow(10,n-1);
    p = floor(p+0.5);
    p = p * pow(10,-(n-1));
    return p;
    
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextLong();
        }
        Arrays.sort(A);
        long[] sum = new long[N+1];
        sum[0] = 0;
        for(int i = 1; i <= N; i++) {
            sum[i] = sum[i-1] + A[i-1];
        }
        int answer = 1;
        for (int i = 2; i <= N; i++) {
            if (sum[i-1]*2 < A[i-1]) {
                answer = 1;
                continue;
            }
            answer += 1;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 52912
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  string S;
  cin >> S;
  string ans = "AC";
  if(S[0] != 'A'){
    ans = "WA";
  } else{
    S[0] = 'a';
    int count = 0;
    for(int i=2; i<S.size()-1;i++){
      if(S[i] == 'C'){
        count++;
        S[i] = 'c';
      }
    }
    if(count != 1){
      ans = "WA";
    } else {
      for(int i=0; i<S.size();i++){
        if(!islower(S[i])){
          ans = "WA";
          break;
        }
      }
    }
  }
  cout << ans << endl;

}

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

int m = 1000000;
int A,B,C,N;
int l[8];

void magic(int a, int b, int c, int n, int total){
  if(a != 0 && b != 0 && c != 0){
    m = min(abs(A-a) + abs(B-b) + abs(C-c) + total, m);
  }

  if(n >= N){
    return;
  }

  int aa = 0, bb = 0, cc = 0;
  if(a != 0){
    aa += 10;
  }
  if(b != 0){
    bb += 10;
  }
  if(c != 0){
    cc += 10;
  }

  magic(a + l[n], b, c, n + 1, total + aa);
  magic(a, b + l[n], c, n + 1, total + bb);
  magic(a, b, c + l[n], n + 1, total + cc);
  magic(a, b, c, n + 1, total);
}

int main() {
  cin >> N >> A >> B >> C;

  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    l[i] = tmp;
  }

  magic(l[0],0,0,1,0);
  magic(0,l[0],0,1,0);
  magic(0,0,l[0],1,0);
  magic(0,0,0,1,0);
  //magic(0,0,0,0,0);
  cout << m << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch VotingJudges | diff VotingJudges.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address VotingJudges.cpp && ./a.out

/*

 6/28/2020

 9:50-

 */

const int MAX_N=1e6+1;
LL A[MAX_N],M;
int N,V,P;

bool ok(int m) {
  vector<LL> as(A,A+N);
  int v=0;
  as[m]+=M,++v;
  REP(i,P-1) if(v<V) as[i]+=M,++v;
  int i=N-1;
  for(; i>=0&&v<V&&as[i]<=as[m]-M; --i) {
    LL x=min(as[m]-as[i],(LL)M);
    if(x>0) as[i]+=x,++v;
  }
  LL rem=M*(V-v);
  //dump(p,rem,i,as[P-1],as[p]);
  //dumpc(as);
  while(rem>0&&i>P-2) {
    LL x=min(as[m]-as[i],rem);
    rem-=x,as[i]+=x;
    --i;
  }
  if(rem>0) return false;
  else return as[m]>=as[P-1];
}
void solve() {
  sort(A,A+N),reverse(A,A+N);
  //dumpC(A,A+N);
  int good=P-1,bad=N;
  while(abs(good-bad)>1) {
    int mid=(good+bad)/2;
    bool res=ok(mid);
    //dump(mid,res);
    (res?good:bad)=mid;
  }
  cout<<good+1<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N>>M>>V>>P;
  REP(i,N) cin>>A[i];
  solve();

  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<string> S(N);
    rep(i, N) cin >> S[i];

    vector<int> cnt(27, INF);
    rep(i, N) {
        rep(j, 27) {
            cnt[j] = min(cnt[j], (int)count(S[i].begin(), S[i].end(), char('a' + j)));
        }
    }

    rep(i, 27) {
        rep(j, cnt[i]) cout << char('a' + i);
    }
    cout << endl;
}

Measured memory_bytes: 256
N = int(input())

t=[1,4,16]
a=[0,1,4]
g=[0,1,4]
c=[0,0,1]
 
for i in range(3, N + 1):
    #print(i)
    t.append(t[i-1]*4 - a[i-2] - c[i-1] - g[i-2] - a[i-3]*3)
    a.append(t[i-1])
    g.append(t[i-1] - c[i-1])
    c.append(t[i-2] - g[i-2])
#print(t,a,g,c)
print(t[N] % (10**9 + 7))

Measured memory_bytes: 38256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

struct block {
    int w, s;
    ll v;
};

bool operator<(const block& x, const block& y)
{
    return x.w + x.s < y.w + y.s;
}

int main() {
    int N;
    cin >> N;
    // vector<int> w(N), s(N);
    // vector<ll> v(N);
    vector<block> blocks(N);
    for(int i=0; i<N; i++){
        int x, y;
        ll z;
        cin >> x >> y >> z;
        blocks[i] = block{x, y, z};
    }

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

    vector<vector<ll>> dp(N, vector<ll>(2e4+10, -1));

    dp[0][0] = 0;
    dp[0][blocks[0].w] = blocks[0].v;
    for(int i=1; i<N; i++) {
        block b = blocks[i];
        // cerr << "b.w = " << b.w << " b.s = " << b.s << " b.v = " << b.v << endl;
        for(int w=0; w<=2e4+10; w++) {
            if(b.s >= w - b.w && w - b.w >=0 && dp[i-1][w-b.w] >= 0) {
                // cerr << "    " << "w = " << w << " s = " << b.s  << " w-b.w = " << w-b.w << " dp[i-1][w-b.w] = " << dp[i-1][w-b.w];
                dp[i][w] = max(dp[i-1][w], dp[i-1][w-b.w] + b.v);
                // cerr << " dp[i][w] = " << dp[i][w] << endl;
            }
            else {
                dp[i][w] = dp[i-1][w];
            }
        }
    }

    ll ans = 0;
    for(int w=0; w<=2e4+10; w++)
        if(ans < dp[N-1][w]) ans = dp[N-1][w];

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

Measured memory_bytes: 160384
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    ll x, k, d;
    cin >> x >> k >> d;

    ll a = ceil((double)abs(x) / d);

    a = min(a, k);
    if(x >= 0) {
        x -= a * d;
        k -= a;
        if(k % 2 == 1) x += d;
    } else if(x < 0) {
        x += a * d;
        k -= a;
        if(k % 2 == 1) x -= d;
    }
    cout << abs(x) << endl;
    return 0;
}

Measured memory_bytes: 3688
n,d=gets.split.map(&:to_i)
x=$<.map{|s|s.split.map &:to_i}
a=(0...n).to_a
r = a.combination(2).map {|x1,x2| x[x1].map.with_index{|m,i| (m - x[x2][i])**2 }.inject(&:+) }
p r.map {|m| m**(1/2.0)}.select {|s| s.to_i == s}.size


Measured memory_bytes: 1916
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String args[] ) throws Exception {
    	new Main().exec(args);
    }

    public Main() {
    }

    public void exec(String args[]) throws Exception {
    	Scanner sc = new Scanner(System.in);
    	int N=sc.nextInt();
    	int x=sc.nextInt();
    	boolean flg=true;
    	if(x==1 || x==2*N-1) flg=false;
    	Map<Integer,Integer> output = new HashMap<Integer,Integer>();
    	Map<Integer,Integer> outputVal = new HashMap<Integer,Integer>();
    	System.out.println(flg?"Yes":"No");
    	if(flg) {
    		if(N==2) {
    			output.put(1,1);
    			output.put(2,2);
    			output.put(3,3);
    		}
    		else {
    			if(x==2) {
            		put(output,outputVal, N-1,2*N-1);
            		put(output,outputVal, N,x);
            		put(output,outputVal, N+1,1);
            	}else{
            		put(output,outputVal, N-2,2);
            		put(output,outputVal, N-1,2*N-1);
        			put(output,outputVal, N,x);
            		put(output,outputVal, N+1,1);
            	}
    		}
    		output(output, 2*N-1);
    	}

    }
    private void output(Map<Integer,Integer> map, int max) {
    	StringBuilder sb = new StringBuilder();
		for(int i=1; i<=max; i++) {
			if(map.containsKey(i)){
				sb.append(map.get(i)).append("\n");
			}else{
				sb.append(i).append("\n");
			}
		}
		System.out.println(sb);
    }
    private void put(Map<Integer,Integer>  map,Map<Integer,Integer>  valmap, int index, int val) {
    	int tmp_idxs_val = index;
    	int tmp_vals_idx = val;
    	if(map.containsKey(index)){
    		tmp_idxs_val = map.get(index);
    	}
    	if(valmap.containsKey(val)){
    		tmp_vals_idx = valmap.get(val);
    	}
    	map.put(index, val);
    	valmap.put(val, index);
    	map.put(tmp_vals_idx, tmp_idxs_val);
    	valmap.put(tmp_idxs_val, tmp_vals_idx);
    }
}

Measured memory_bytes: 30876
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <functional>
using namespace std;

int main(){
    vector<pair<double, int>> p1(8);
    vector<pair<double, int>> p2(8);
    vector<pair<double, int>> p3(8);
    for(int i = 0;i<8;i++){
        cin >> p1[i].second >> p1[i].first;
    }
    for(int i = 0;i<8;i++){
        cin >> p2[i].second >> p2[i].first;
    }
    for(int i = 0;i<8;i++){
        cin >> p3[i].second >> p3[i].first;
    }
    sort(p1.begin(), p1.end());
    sort(p2.begin(), p2.end());
    sort(p3.begin(), p3.end());
    cout << p1[0].second << " " << p1[0].first << endl;
    cout << p1[1].second << " " << p1[1].first << endl;
    cout << p2[0].second << " " << p2[0].first << endl;
    cout << p2[1].second << " " << p2[1].first << endl;
    cout << p3[0].second << " " << p3[0].first << endl;
    cout << p3[1].second << " " << p3[1].first << endl;
    p1.erase(p1.begin(), p1.begin()+2);
    p2.erase(p2.begin(), p2.begin()+2);
    p3.erase(p3.begin(), p3.begin()+2);
    // copy(p2.begin(), p2.end(), back_inserter(p1));
    // copy(p2.begin(), p2.end(), back_inserter(p1));
    p1.insert(p1.end(), p2.begin(), p2.end());
    p1.insert(p1.end(), p3.begin(), p3.end());
    sort(p1.begin(), p1.end());
    cout << p1[0].second << " " << p1[0].first << endl;
    cout << p1[1].second << " " << p1[1].first << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int>v;
    for (int i = 0;i < n;++i) {
        v.push_back(i + 1);
    }
    while(1){
        for(int i = 0;i < n;++i){
            if(i){
                cout << " ";
            }
            cout << v[i];
        }
        cout << endl;
        if(!next_permutation(v.begin(),v.end())){
            break;
        }
    }
}


Measured memory_bytes: 3120
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()
    A.sort()

    sm = 0
    j = -1
    for i, a in enumerate(A[:-1]):
        sm += a
        # print(sm, 2 * sm, A[i+1])
        if 2 * sm >= A[i+1]:
            pass
        else:
            j = i
    # print(j)
    print(N - (j + 1))

if __name__ == '__main__':
    solve()


Measured memory_bytes: 20672
'use strict';
const p = s => console.log(s);
// let a,b,c,d;
// [a,b,c,d] = input[0].trim().split(" ").map(i => parseInt(i));

function main(input) {
  let K = parseInt(input[0].trim().split(" ")[0]);
  let S = input[1].trim().split("");
  let result;

  if(K >= S.length) {
    result = S.join("");
  } else {
    result = S.slice(0,K).join("") + '...';
  }
  p(result);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));


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

void nabeatsu(int n) {
  for (int i=1; i<=n; i++) {
    if (i%3 == 0) {
      cout << " " << i;
      continue;
    }
    int x = i;
    for (int j=0; j<5; j++) {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    }
  }
  cout << endl;
  return;
}

int main() {
  int n;
  cin >> n;
  nabeatsu(n);
  
  return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

int main()
{
    ll i,j,n;
    cin>>n;
    vector<int> a(n),b(n);
    for(i=0;i<n;i++) cin>>a[i]>>b[i];
    for(i=2;i<n;i++)
    {
        if(a[i]==b[i] && a[i-1]==b[i-1] && a[i-2]==b[i-2])
        {
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string[] cin = Console.ReadLine().Split();
        int n = int.Parse(cin[0]);
        int k = int.Parse(cin[1]);
        int[] a = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();

        var dic = new Dictionary<int, int>();
        for (int i = 0; i < n; i++)
        {
            if (dic.ContainsKey(a[i])) dic[a[i]]++;
            else dic.Add(a[i], 1);
        }

        int[] b = dic.Values.ToArray();
        Array.Sort(b);

        int ans = 0;
        for (int i = 0; i < b.Length - k; i++)
        {
            ans += b[i];
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 42820
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
s = str(n)
K = int(input())
l = len(str(n))

# dp[loose/tight][count][length]
dp = [[[0] * l for _ in range(K + 1)] for _ in range(2)]
for i, item in enumerate(s):
    val = int(item)
    # Initialize
    if i == 0:
        dp[0][0][i] = 1
        for j in range(1, 10):
            if j < val:
                dp[0][1][i] += 1
            if j == val:
                dp[1][1][i] += 1
        continue
    # Use 0
    if val == 0:
        for k in range(K+1):
            dp[0][k][i] += dp[0][k][i-1]
            dp[1][k][i] += dp[1][k][i-1]
    else:
        for k in range(K+1):
            dp[0][k][i] += dp[0][k][i-1] + dp[1][k][i-1]
    for j in range(1, 10):
        if val == j:
            for k in range(K):
                dp[0][k+1][i] += dp[0][k][i-1]
                dp[1][k+1][i] += dp[1][k][i-1]
        elif j < val:
            for k in range(K):
                dp[0][k+1][i] += dp[0][k][i-1] + dp[1][k][i-1]
        else:
            for k in range(K):
                dp[0][k+1][i] += dp[0][k][i-1]

print(dp[0][-1][-1] + dp[1][-1][-1])

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

long long a[5010];

bool comp(int a, int b) {
	return a > b;
}

int main() {
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1, comp);
	long long sum = 0, _count = 0;
	for (int i = 1; i <= n; i++) {
		sum += a[i];
		if (sum < k) {
			_count++;
		} else {
			sum -= a[i];
			_count = 0;
		}
	}
	cout << _count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,d,x,a[100];
    int ans=0;
    cin>>n>>d>>x;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]<=d){
          ans=ans+(d-1)/a[i]+1;  
        }
        else if(a[i]>=d){
            ans++;
        }
        
        
    }// Your code here!
    
    cout<<ans+x<<endl;
}


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

int main() {
  int N;
  cin >> N;
  int A,B;
  cin >> A >> B;
  int C=A+B;
  for(int i=0;i<N;i++){
    char x;
    cin >> x;
    if(x=='a'&&C>0){
      cout << "Yes" << endl;
      C--;
    }else if(x=='b'&&B>0&&C>0){
      cout << "Yes" << endl;
      B--;
      C--;
    }else{
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 640
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
D = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(i+1, N):
        D[i][j] = D[j][i] = ( (L[i][0]-L[j][0])**2 + (L[i][1]-L[j][1])**2 )**0.5

M = [-1]*N
pathlist = []
def makepath(k, prev):
    if k==N: pathlist.append(M[:])
    for i in range(N):
        if M[i]>=0: continue
        M[i] = k
        makepath(k+1, i)
        M[i] = -1

makepath(0, -1)

s = 0
for p in pathlist:
    for i in range(N-1):
        s += D[p[i]][p[i+1]]
        
print(s/len(pathlist))

Measured memory_bytes: 8948
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, x = 0;
  int sum_kyori = 0;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++){
    cin >> x;
    if (x > K / 2){
      sum_kyori += (K - x) * 2;
    }else{
      sum_kyori += x * 2;
    }
  }
   
  cout << sum_kyori << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main
{
  public static void main(String[] args)
  {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt(), a = in.nextInt(), b = in.nextInt();
    int mod = 1_000_000_007;
    long total = pow(2L, n) - 1;
    long cab = (choose(n, a) + choose(n, b)) % mod;
    long ans = (total - cab + mod) % mod;
    System.out.println(ans);
  }
  
  static long choose(int n, int a)
  {
    if(n - a < a) return choose(n, n - a);
    long nf = 1, af = 1;
    int mod = 1_000_000_007;
    for(int i = 1; i <= a; i++)
    {
      nf *= n - i + 1;
      nf %= mod;
      nf *= pow(i, mod - 2);
      nf %= mod;
    }
    return nf;
  }
  
  static long pow(long a, int b)
  {
    long re = 1;
    int mod = 1_000_000_007;
    while(b > 0)
    {
      if(b % 2 != 0)
      {
        re *= a;
        re %= mod;
      }
      a *= a;
      a %= mod;
      b /= 2;
    }
    return re;
  }
}
  

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

#define MAX 8

int N, M;
bool A[MAX][MAX];

int memo[MAX][MAX + 1][(1 << MAX) + 1];

int dfs( int n, int cnt, int visit )
{
	if( cnt >= N ) {
		return 1;
	}
	if( memo[n][cnt][visit] ) {
		return memo[n][cnt][visit];
	}
	int res = 0;
	visit |= 1 << n;
	for( int i = 0; i < N; i++ ) {
		if( A[n][i] && ((1 << i) & visit) == 0 ) {
			res += dfs( i, cnt + 1, visit );
		}
	}
	memo[n][cnt][visit] = res;
	return res;
}

int main() {
	cin >> N >> M;
	for( int i = 0; i < M; i++ ) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		A[a][b] = true;
		A[b][a] = true;
	}

	int ans = dfs( 0, 1, 0 );

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,w;
	cin >> n >> w;
	int weight[n];
	int cost[n];
	for (int i = 0; i < n; ++i){
		cin >> weight[i] >> cost[i];
	}
	long dp[n+1][w+1];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=w;j++){
			if(i==0 || j==0){
				dp[i][j]=0;
			}
			else{
				long val;
				val = j >= weight[i-1] ? dp[i-1][j-weight[i-1]] + cost[i-1] : 0;
				dp[i][j] = max(dp[i-1][j],val);
			}
		}
	}
	/*for(int i=0;i<=n;i++){
		for(int j=0;j<=w;j++){
			cout << dp[i][j] << " ";
		}
		cout << "\n";
	}*/
	cout << dp[n][w];
	return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e4;
const long inf=1e9;
int main(){
	int N;cin>>N;
	int X[N];
	rep(i,0,N) cin>>X[i];
	sort(X,X+N);
	int ans=inf;int res;
	rep(i,0,100){
		res = 0;
		rep(j,0,N) res += (X[j] - i)*(X[j] - i);
		ans = min(ans , res);
	}cout<<ans<<endl;
}

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

int main() {
  int n,max_h=0,ans;
  cin >> n;
  vector<int> h(n);
  for(int i=0;i<n;i++) cin >> h[i];
  for(int i=0;i<n;i++) {
    if(max_h<=h[i]) {
      ans++;
      max_h=h[i];
    };
  };
  cout << ans << endl;
}

Measured memory_bytes: 256
//((a + b) / 2 + c) / 2 == (a + b + 2c) / 4
//上記より、後に回したほうが価値の毀損が少ない
//昇順にソートして前から生成していく

#include <stdio.h>

void qsort(int len, int seq[len], int f, int l);
float generate(int len, int seq[len]);

int main()
{
  int N;
  scanf("%d",&N);
  int v[N];
  int i;
  i = 0;
  while (i < N)
  {
    scanf("%d",&v[i]);
    i++;
  }
  qsort(N, v, 0, N - 1);
  printf("%f",generate(N, v));
}

//quicksort
void qsort(int len, int seq[len], int f, int l)
{
  int i;
  int j;
  i = f;
  j = l;
  int threshold;
  threshold = seq[(f + l) / 2];
  int tmp;
  while (1)
  {
    while (threshold > seq[i])
      i++;
    while (threshold < seq[j])
      j--;
 	if (i >= j)
      break;
    tmp = seq[i];
    seq[i] = seq[j];
    seq[j] = tmp;
    i++;
    j--;
  }
  if (f < i - 1)
    qsort(len, seq, f, i - 1);
  if (l > j + 1)
    qsort(len, seq, j + 1, l);
}

//生成
float generate(int len, int seq[len])
{
  int i;
  float material;
  i = 1;
  material = seq[0];
  while (i < len)
  {
    material = (material + seq[i]) / 2;
    i++;
  }
  return (material);
}

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

int main() {
    string s;
    long long k, n;
    cin >> s >> k;
    n = s.length();
    for (int i = 0; i < min(k, n); i++)
    {
        if (s[i] != '1')
        {
            cout << s[i];
            return 0;
        }
    }
    cout << '1';
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#include<vector>
#define maxx 1000000
#define ll long long
#define boostUP ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fsr(i,n) for(ll i=0;i<n;i++)
#define fcr(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define sz(arr) sizeof(arr)/sizeof(arr[0])

using namespace std;

int main(){
	int t; cin >> t;
	vector<string> holdStrings;
	vector<string> x{"AC", "WA", "TLE", "RE"};
	while(t--){
		string str; cin >> str;
		holdStrings.pb(str);
	}
	map<string, int> mp{{"AC",0}, {"RE",0}, {"TLE", 0}, {"WA", 0}};
	for(auto str : holdStrings)
		mp[str]++;

	for(auto str : x)
		cout << str <<  " x " << mp[str] << endl;

}



Measured memory_bytes: 7408
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x,y;
    cin>>n>>x>>y;
    int c[n];
    int i,j;
    for(i = 0;i<n;i++) c[i] = 0;
    for(i = 1;i<=n;i++){
        for(j = i+1;j<=n;j++){
            c[min(abs(j-i), abs(y-j)+1+abs(x-i))]++;
        }
    }
    for(i = 1;i<n;i++) cout<<c[i]<<"\n";
}

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

namespace ABC
{
    class ProgramC
    {
        static void Main(string[] args)
        {
            // F(n)を繰り返し呼ぶのをやめた版
            var n = int.Parse(Console.ReadLine());
            var list = new int[n];
            var end = Math.Sqrt(n);
            for (var i = 1; i < end; i++)
            {
                var ii = i * i;
                for (var j = 1; j < end; j++)
                {
                    var jj = j * j;
                    var ij = i * j;
                    for (var k = 1; k < end; k++)
                    {
                        var kk = k * k;
                        var r = ii + jj + kk + ij + i * k + j * k;

                        if (r <= n)
                        {
                            list[r - 1]++;
                        }
                        if (r >= n)
                        {
                            break;
                        }
                    }
                }
            }

            for (var i = 0; i < n; i++)
            {
                Console.WriteLine(list[i]);
            }
        }
    }
}


Measured memory_bytes: 27240
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, k, a, c = 0, d = 0, e = 0, f = 0, sum = 0, num = 0; cin >> n >> k;
	int b[123456] = { 0 };
	for (int h = 0; h < n; h++) {
		cin >> a >> b[h];
		sum = max(sum, a);
		num += b[h];
		e += a;
	}
	sort(b, b + n);
	if (k%sum == 0) { f = k / sum; }
	else { f = k / sum + 1; }
	if (num >= k) {
		for (int h = n - 1; h >= 0; h--) {
			d += b[h];
			if (d >= k && n - h <= f) {
				cout << n - h << endl;
				cin >> n; return 0;
			}
		}
	}
	for (int h = 0; h < n; h++) {
		if (b[h] < sum) {
			num = num - b[h]; c++;
		}
	}
	if ((k - num) % sum == 0) {
		cout << (k - num) / sum + n - c << endl;
	}
	else {
		cout << (k - num) / sum + n - c + 1 << endl;
	}
	cin >> n;
}

Measured memory_bytes: 768
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j,v;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  
  for(i=1;i<=n;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      
      A[j+1]=A[j];
      j--;
      A[j+1]=v;
      
    }

    trace(A, n);
  }


  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <string>

using namespace std;

int main(){

    int N;
    cin >> N;
    string S;
    cin >> S;

    bool ans = false;
    if(S.length() % 2 == 0) {
        int length = S.length() / 2;
        string first = S.substr(0, length);
        string second = S.substr(length);
        if(first == second) ans = true;
    }

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

    return 0;
}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]


res = 0
for h in range(2**H):
    for w in range(2**W):
        cnt = 0
        for i in range(H):
            if (h>>i)&1:
                continue
            for j in range(W):
                if (w>>j)&1:
                    continue
                if c[i][j] == "#":
                    cnt += 1
                    
        if cnt == K:
            res += 1

print(res)

Measured memory_bytes: 8976
a,b,c = map(int,input().split())
if a <= b <= c:
    print (str(a)+" "+str(b)+" "+str(c))
elif a <= c <= b:
    print (str(a)+" "+str(c)+" "+str(b))
elif b <= a <= c:
    print (str(b)+" "+str(a)+" "+str(c))
elif b <= c <= a:
    print (str(b)+" "+str(c)+" "+str(a))
elif c <= a <= b:
    print (str(c)+" "+str(a)+" "+str(b))
else:
    print (str(c)+" "+str(b)+" "+str(a))


Measured memory_bytes: 5592
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    int a,b,c,x,count = 0;
    cin >> a >> b >> c >> x;
    for(int i = 0;i <= a;i++)
    {
        for(int j = 0;j <= b;j++)
        {
            for(int q = 0;q <= c;q++)
            {
                if(i * 500 + j * 100 + q * 50 == x){count++;}
            }
        }
    }
    cout << count << endl;
    return 0;
}

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

#define sheep 1
#define wolf -1

	long long N;
bool ans[100005];

bool cal(vector<int> ani){
	for(int i = 1; i < N - 1; i++){
		if(ani[i] == sheep){
			if(ans[i] == true){
				ani.push_back(ani[i-1]);
			}else{
				ani.push_back(-1 * ani[i-1]);
			}
		}else{
			if(ans[i] == true){
				ani.push_back(-1 * ani[i-1]);
			}else{
				ani.push_back(ani[i-1]);
			}
		}
	}

	//first
	if(ani[0] == sheep){
		if(ans[0] == true){
			if(ani[1] != ani[N-1]){
				return false;
			}
		}else{
			if(ani[1] == ani[N-1]){
				return false;
			}
		}
	}else{
		if(ans[0] == true){
			if(ani[1] == ani[N-1]){
				return false;
			}
		}else{
			if(ani[1] != ani[N-1]){
				return false;
			}
		}
	}


	//last
	if(ani[N-1] == sheep){
		if(ans[N-1] == true){
			if(ani[0] != ani[N-2]){
				return false;
			}
		}else{
			if(ani[0] == ani[N-2]){
				return false;
			}
		}
	}else{
		if(ans[N-1] == true){
			if(ani[0] == ani[N-2]){
				return false;
			}
		}else{
			if(ani[0] != ani[N-2]){
				return false;
			}
		}
	}

	for(int i = 0; i < N; i++){
		if(ani[i] == sheep){
			cout << 'S';
		}else{
			cout << 'W';
		}
	}
	cout << endl;
	return true;


}

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++){
		char ch;
		cin >> ch;
		if(ch == 'o'){
			ans[i] = true;
		}else if(ch == 'x'){
			ans[i] = false;
		}else{
			return 1;
		}
	}
	vector<int> ani;
	ani.push_back(sheep);
	ani.push_back(sheep);
	if(cal(ani)){
		return 0;
	}
	ani[1] = wolf;
	if(cal(ani)){
		return 0;
	}
	ani[0] = wolf;
	if(cal(ani)){
		return 0;
	}
	ani[1] = sheep;
	if(cal(ani)){
		return 0;
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 1380
// 2019/06/20
// AtCoder Beginner Contest 073 - B

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, psum, ans;
    int l, r;
    cin >> n;
    psum = 0;
    for(int i = 0; i < n; i++){
        cin >> l >> r;
        psum += r - l + 1;
    }
    cout << psum;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define e cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)
 
ll i,j,k,l,ii,jj;
ll n,m;
ll a,b,c;
ll h,w;

ll ans=0;
ll sum=0;
ll memo,num;
bool dame=false;
bool x[500005];//素数ならtrue

int main(){
	cin>>n;
	
	for(i=1;i<=500000;i++){
		x[i]=true;
	}
	x[1]=false;
	x[2]=true;
	for(i=1;i<=500000;i++){
		if(!x[i])continue;
		for(j=2;j*i<=500000;j++){
			x[i*j]=false;
		}
	}
	k=0;
	for(i=1;i<=500000;i++){
		if(x[i] && i%5==1 && k<n){
			pe(i);
			k++;
		}
	}
	e;

	
	return 0;
				
}


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

int main()
{
	int64_t n;
	cin >> n;
	vector<string> ss(n);
	for (auto &&s : ss)
	{
		cin >> s;
	}

	map<vector<int64_t>, int64_t> mp;

	int64_t ans = 0;

	for (auto &&s : ss)
	{
		vector<int64_t> v(26, 0);

		for (auto &&c : s)
		{
			v[c - 'a']++;
		}

		ans += mp[v]++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 36992
n = int(input())
a = list(map(float, input().split()))
b = list(map(float, input().split()))

c = [abs(a[i] - b[i]) for i in range(n)]

for p in range(1, 4):
    ans = 0
    for d in c:
        ans += d ** p
    print("{:.6f}".format(ans ** (1 / p)))

print("{:.6f}".format(max(c)))


Measured memory_bytes: 5676
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main() {
	string tmp; cin >> tmp;
	vector<string>vol = { "maerd", "remaerd" ,"esare", "resare" };
	
	string s;
	for (int i = tmp.size()-1; i >= 0; i--) {
		s += tmp[i];
	}
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'm') {
			if (s.substr(i, vol[0].size()) == vol[0]) {
				i += vol[0].size() - 1;
			}
			else {
				cout << "NO" << endl;
				return 0;
			}
		}
		else if (s[i] == 'r') {
			if (s.substr(i, vol[1].size()) == vol[1]) {
				i += vol[1].size() - 1;
			}
			else if (s.substr(i, vol[3].size()) == vol[3]) {
				i += vol[3].size() - 1;
			}
			else {
				cout << "NO" << endl;
				return 0;

			}
		}
		else if (s[i] == 'e') {
			if (s.substr(i, vol[2].size()) == vol[2]) {
				i += vol[2].size() - 1;
			}
			else {
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>

std::vector<std::vector<int>> memo;

bool is_cat(const std::string &s, size_t il, size_t ir) {
  if (memo[il][ir] > -1) return memo[il][ir];

  // fprintf(stderr, "\"%s\"[%zu:%zu] (\"%s\")\n", s.c_str(), il, ir, s.substr(il, ir-il).c_str());
  int &res=memo[il][ir];
  if (il == ir) return (res = 1);
  if ((ir-il) % 3 > 0) return (res = 0);
  if (!(s[il] == 'm' && s[ir-1] == 'w')) return (res = 0);

  for (size_t i=il+1; i+1<ir; i+=3) {
    if (s[i] != 'e') continue;
    if (is_cat(s, il+1, i) && is_cat(s, i+1, ir-1)) return (res = 1);
  }
  return (res = 0);
}

int main() {
  char buf[512];
  scanf("%s", buf);
  std::string s=buf;

  if (s.length() % 3 > 0)
    return !printf("Rabbit\n");

  memo.assign(s.length()+1, std::vector<int>(s.length()+1, -1));
  printf("%s\n", is_cat(s, 0, s.length())? "Cat":"Rabbit");
}



Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
	ll W, H; cin >> W >> H;
	priority_queue<pll, vector<pll>, greater<pll>> que;
	for (int i = 0; i < W; ++i) {
		ll val; cin >> val;
		que.push({val, 0});
	}
	for (int i = 0; i < H; ++i) {
		ll val; cin >> val;
		que.push({val, 1});
	}

	ll ans = 0, usedH = 0, usedW = 0;
	while (!que.empty()) {
		pll p = que.top(); que.pop();
		ll val = p.first;
		ll type = p.second;
		if (type == 0) {
			ans += val * (H + 1 - usedH);
			++usedW;
		}
		else {
			ans += val * (W + 1 - usedW);
			++usedH;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6384
x=int(input())
if x<100:
	print(0)
elif x>=100:
	a=int(str(x)[-2:])
	b=int(str(x)[:-2])
	counter=0
	while a>=5:
		a-=5
		counter+=1
	while a>=4:
		a-=4
		counter+=1
	while a>=3:
		a-=3
		counter+=1
	while a>=2:
		a-=2
		counter+=1
	while a>=1:
		a-=1
		counter+=1
	print(1 if counter<=b else 0)


Measured memory_bytes: 3064
line=input()
items=line.split(' ')
# print(items)
N=int(items[0])
X=int(items[1])
line2=input()
items2=line2.split(' ')
# print(items2)
l=[]
for i in range(N):
    l.append(int(items2[i]))
# print(l)
res=[0]
for i in range(2,N+2):
    d=res[i-2]+l[i-2]
    res.append(d)
# print(res)
c=0
for i in res:
    if i<=X:
        c+=1
print(c)

Measured memory_bytes: 3064
#include <cstdio>

int i,n,t,x,y;

inline int SG(int n,int k)
{
	if (! (n%k))
		return n/k;
	else
	{
		int l,r,mid,t=(n-1)/k+1;
		l=1,r=n/t,mid;
		while (l<r)
		{
			mid=(l+r)/2+1;
			if ((n-mid*t)/k==n/k)
				l=mid;
			else
				r=mid-1;
		}
		return SG(n-l*t,k);
	}
}

int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		scanf("%d%d",&x,&y),t=t^SG(x,y);
	if (t)
		puts("Takahashi");
	else
		puts("Aoki");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define fi first
#define se second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define pi pair<ll,ll>
#define mp make_pair
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
//freopen("explicit.in", "r", stdin);
//freopen("explicit.out", "w", stdout);
 
void SieveOfEratosthenes() 
{ 
    bool prime[10000001];
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=10000000; p++) 
    { 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=10000000; i += p) {
                prime[i] = false; 
            }
        } 
    }  
} 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
ll nCrModpDP(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C));   
    C[0] = 1;
    for (ll i = 1; i <= n; i++) 
    {
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll nCrModp(ll n, ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
  
   return (nCrModp(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p; 
} 
int32_t main() 
{
    fio
	ll j,i,n,t,l,r,c,h,k,m,maxi,d,x;
	string s;
	cin>>s;
	c=0;
	for(j=0;j<s.length();j++)
		c=c+(s[j]-'0');
	if(c%9==0)
		cout<<"Yes";
	else
		cout<<"No";
}





	

		

Measured memory_bytes: 3772
s=input()
s=s.replace('eraser','*')
s=s.replace('erase','*')
s=s.replace("dreamer","*")
s=s.replace("dream","*")
f=1
for i in s:
    if i!='*':
        f=0
        break
if f:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9164
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007
//#define DEBUG 1

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(array, 10, sizeof(int), compare_int)

int array[200100];

int main(){
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%d", &array[i]);
	}

	qsort(array, n, sizeof(int), compare_int);

	long long int sum=0;
	int i=2, now=n-2;
	sum += array[n-1];
	while(i<n){
		if(i==n-1)
			sum += array[now];
		else{
			sum += 2*array[now];
			now--;
		}
		i += 2;
		//printf("%d, %lld\n", i, sum);
	}	
	printf("%lld\n", sum);
	
	
	return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;

int main(void) {
    //解説あり
    int Q;
    cin >> Q;
    rep(i, 0, Q) {
        ll A, B;
        cin >> A >> B;
        ll X = A*B;
        if (A>B) swap(A, B);

        ll l = 0, r = A+B-1;
        while (r-l>1) {
            ll m = (r+l)/2;
            ll k = (m+1)/2;
            ll mx = 0;
            if (m%2==1) {
              ll a = k, b = k;
              if (A<=k) a++;
              if (B<=k) b++;
              mx = a*b;
            } else {
              ll ax = k, ay = k+1;
              ll bx = k, by = k+1;
              if (A<=k+1) ay++;
              if (A<=k) ax++;
              if (B<=k+1) by++;
              if (B<=k) bx++;
             
              
              mx = max(ax*by, ay*bx);
            
            }

            if (mx<A*B) l = m;
            else r = m;
            
        }

       
      
        cout << l << endl;
    }

    return 0;
}





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

int main(){
	int a=0;
	int b=0;
	cin>>a>>b;
	if(a%3==0 ||(a+b)%3==0 ||b%3==0){
		cout<<"Possible"<<endl;
	}else{
		cout<<"Impossible"<<endl;
	}
}

Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int n;in(n);
  vector<ll> A(n);
  loop(i,0,n) in(A[i]);
  ll m = 1000;
  ll s = 0;
  ll prev = A[0];
  loop(i,1,n) {
    if (prev == A[i]) continue;
    if (prev < A[i]) {
      ll num = m/prev;
      s += num;
      m -= num*prev;
      prev = A[i];
      continue;
    }
    
    if (prev > A[i]) {
      m += s*prev;
      s = 0;
      prev = A[i];
      continue;
    }
    assert(false);
  }
  
  m += s*A[n-1];
  print(m);
  return 0;
}


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

template <typename _tp> inline void read(_tp&x){
	char c11=getchar(),ob=0;x=0;
	while(c11!='-'&&!isdigit(c11))c11=getchar();if(c11=='-')ob=1,c11=getchar();
	while(isdigit(c11))x=x*10+c11-'0',c11=getchar();if(ob)x=-x;
}

const int N = 201000, p = 1e9+7;
int a[N],f[N],sm[N],n;

int main(){
	read(n);
	for(int i=1;i<=n;++i) read(a[i]);
	f[0] = 1;
	for(int i=1;i<=n;++i){
		f[i] = f[i-1];
		if(a[i] == a[i-1]) continue;
		f[i] = (f[i] + sm[a[i]])%p;
		sm[a[i]] = (sm[a[i]] + f[i-1])%p;
	}
	printf("%d\n",f[n]);
	return 0;
}

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


using namespace std;
int main()
{
    int a;
    int i=0;
    int currentTime=0;
    int totalprogram=0;
    int programlist[a];
    cin>> a;
     int arr[a],temp;
    multimap<int,int>finish;
    map<int,int>::iterator it;
    for(int i=0; i<a; i++)
    {
        cin>>arr[i]>>temp;
        finish.insert(make_pair(temp,i));

    }

    for(it=finish.begin(); it!=finish.end(); it++)
    {

        int currentFinishtime=it->first;
        int currentActivity=it->second;
        if(arr[currentActivity]> currentTime)
        {
            currentTime=currentFinishtime;
            totalprogram++;
            programlist[i++]=currentActivity;
        }
    }
    cout<<totalprogram<<endl;

    return 0;
}



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

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> a(n);
        for(int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        sort(begin(a), end(a));
        cout << accumulate(begin(a) + 1, end(a) - 1, 0) / (n - 2) << endl;
    }
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e8;
int main() {
    // 方針: 累積和
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> L(N + 1), R(N + 1);
    L[0] = R[0] = 0;
    for(int i = 0; i < N; i++) {
        L[i + 1] = L[i] + (S[i] == 'W' ? 1 : 0);
        R[i + 1] = R[i] + (S[N - 1 - i] == 'E' ? 1 : 0);
    }
    int ans = INF;
    for(int i = 0; i < N; i++) {
        ans = min(ans, L[i] + R[N - 1 - i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3076
//2020.6.14 A

#include<bits/stdc++.h>

#define rep(i,n) for(int i = 0;i < (n);i++)

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


int main(){
	
	vector<int> A;
	A.resize(5);
	int it;
	
	for(int i = 0;i < 5;i++){
		cin >> A[i];
		if(A[i] == 0){
			it = i + 1;
		}
	}
	
	cout << it;
	
	return 0;
	
}

Measured memory_bytes: 3624