akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define REP(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define fi first
#define sc second
#define pb push_back
#define all(x) x.begin(), x.end()
 
using namespace std;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<int, int> pii;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
 
const i64 MOD = 1000000007;
const int INF = 2000000000;
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 
	int n;
	cin >> n;
  
	double mul = 0;
 
	REP(i, 0, n-1) {
		double x;
      	cin >> x;
      
      	mul += 1 / x;
	}
 
	cout << 1 / mul << endl;
 
	return 0;
}

Measured memory_bytes: 256
/**
 * @File   : atcoder.cpp
 * @Author : pasnger 
 * @Date   : 13/9/2020, 5:10:33 pm 
 */

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

#define INF 2e18
#define int long long
#define f(i, a, b) for(int i=(a); i<(b); (i)++)
#define fe(i, a, b) for(int i=(a); i<=(b); (i)++)
#define rf(i, a, b) for(int i=(a); i>(b); (i)--)
#define rfe(i, a, b) for(int i=(a); i>=(b); (i)--)
#define ff(ele, cont) for(auto (ele): (cont))
#define pb push_back;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef set<int> si;
typedef multiset<int> msi;

const int mxn = 1e6+4;
const int mod = 1e9+7;
const double pi = acos(-1);

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() {
  cerr << "]\n";
}
template<typename T, typename ...Args> void DBG(T first, Args... args) {
  cerr << first; if (sizeof...(args))cerr<<", "; DBG(args...);
}
int mul(int x,int y){
    int res = x*y;
    if(res >= mod)res%=mod;
    return res;
}


int power(int x, int y){
    int res = 1;
    while(y){
        if(y&1)res = mul(res,x);
        y = y>>1;
        x = mul(x,x);
    }
    return res;
}
int add(int x, int y){
    int res = x+y;
    if(res >= mod)res-=mod;
    return res;
}

/////////////////////////// GLOBAL ///////////////////////////
 int dp[20004];
/////////////////////////// GLOBAL ///////////////////////////

void solve() {
  int n;
  cin>>n;
 
  memset(dp, 0, sizeof(dp));
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
  fe(i, 6, n){
    fe(j, 3, n){
      if(i-j>=3) dp[i] = add(dp[i-j], dp[i]);
    }
    dp[i]++;
  }
  cout<<dp[n]<<"\n";
}


int32_t main() {
  #ifndef ONLINE_JUDGE
  clock_t tStart = clock();
  freopen("in.txt", "r", stdin);
  //freopen("output.txt","w",stdout);
  #endif 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  // cin >> t;
  for (int tt=1;tt<=t;tt++) {
    //cout << "Case #"<<tt<<": ";
    solve();
  }
  #ifndef ONLINE_JUDGE
    cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
  #endif
}


Measured memory_bytes: 3780
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>

double md(int n, std::vector<double> x, std::vector<double> y){
    double sum = 0.0;
    for(int i = 0; i < n; i++) sum += std::abs(x[i] - y[i]);
    return sum;
}

double ed(int n, std::vector<double> x, std::vector<double> y){
    double sum = 0.0;
    for(int i = 0; i < n; i++) sum += std::pow(std::abs(x[i] - y[i]), 2);
    sum = std::pow(sum, 0.5);
    return sum;
}

double cd(int n, std::vector<double> x, std::vector<double> y){
    double sum = 0.0;
    for(int i = 0; i < n; i++) sum +=  std::pow(std::abs(x[i] - y[i]), 3);
    double index = 1.0 / 3.0;
    sum = std::pow(sum, index);
    return sum;
}

double Ched(int n, std::vector<double> x, std::vector<double> y){
    double ans = 0.0;
    for(int i = 0; i < n; i++) ans = std::max(ans, std::abs(x[i] - y[i]));
    return ans;
}

int main(){
    int n;
    std::cin >> n;
    
    std::vector<double> x(n), y(n);
    for(int i = 0; i < n; i++) std::cin >> x[i];
    for(int i = 0; i < n; i++) std::cin >> y[i];
    
    double Manhattan_distance = md(n, x, y);
    printf("%lf\n", Manhattan_distance);
    
    double Euclidean_distance = ed(n, x, y);
    printf("%lf\n", Euclidean_distance);
    
    double cube_distance = cd(n, x, y);
    printf("%lf\n", cube_distance);
    
    double Chebyshev_distance = Ched(n, x, y);
    printf("%lf\n", Chebyshev_distance);
    
}


Measured memory_bytes: 3428
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sc.useDelimiter("\n");

        int n = Integer.parseInt(sc.nextLine());
        HashMap<String, Integer> map = new HashMap<>();

        for (int i = 0; i < n; i++) {
            String line = sc.nextLine();
            if (!map.containsKey(line)) {
                map.put(line, 1);
            } else {
                map.replace(line, map.get(line) + 1);
            }
        }

        int m = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < m; i++) {
            String line = sc.nextLine();
            if (!map.containsKey(line)) {
                map.put(line, 1);
            } else {
                map.replace(line, map.get(line) - 1);
            }
        }

        int max = map.values().stream().mapToInt(x -> x).filter(value -> value >= 0).max().orElse(0);
        System.out.println(max);
    }
}

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

int main(void) {
    int A,B,res=INT_MIN;
    cin >> A >> B;
    res = max(A+B,res);
    res = max(A-B,res);
    res = max(A*B,res);
    cout << res << endl;
    return 0;
}


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

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

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;


int main(){
  int N,K;
  cin >> N >> K;
  Vi H(N);
  rep(i,N){
    cin >> H[i];
  }
  
  
  Vi dp(N, 1000000000);
  dp[0]=0;
  
  rep2(i, 1, N){
    
   rep2(j, 1, K+1){
    
    if(i>j-1){
     if(dp[i]>dp[i-j]+abs(H[i]-H[i-j])){
      dp[i] = dp[i-j]+abs(H[i]-H[i-j]);
     }
    }
     
   }
  }
  cout << dp[N-1] << endl;
}

      
      
       




Measured memory_bytes: 4048
#include <stdio.h>
#include <string.h>

#define MAX 1000

int getlcs(char *X, char *Y,int m,int n)
{
  int DATA[MAX+1][MAX+1];
  int maxlcs;

  for(int i=0;i<m;i++) DATA[i][0]=0;
  for(int j=1;j<n;j++) DATA[0][j]=0;

  for(int i=1;i<=m;i++)
  {
    for(int j=1;j<=n;j++)
    {
      if(X[i]==Y[j]) DATA[i][j]=DATA[i-1][j-1]+1;
      else if(DATA[i-1][j]>DATA[i][j-1]) DATA[i][j]=DATA[i-1][j];
      else DATA[i][j]=DATA[i][j-1];
      maxlcs=DATA[i][j];
    }
  }

  return maxlcs;
}

int main()
{
  char s1[MAX];
  char s2[MAX];
  int n;
  char change;
  int s1_l,s2_l;

  scanf("%d",&n);
  for(int i=0;i<n;i++)
  {
    scanf("%s %s", s1,s2);
    s1_l=strlen(s1);
    s2_l=strlen(s2);

    for(int j=s1_l;j>0;j--)
    {
      s1[j]=s1[j-1];
    }
    s1[0]=' ';

    for(int j=s2_l;j>0;j--)
    {
      s2[j]=s2[j-1];
    }
    s2[0]=' ';
    printf("%d\n",getlcs(s1,s2,s1_l,s2_l));
  }
  return 0;
}



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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    if ( a[m-1] * 4 * m < sum ) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

class DIJKSTRA {
public:
    ll V;

    struct edge {
        ll to;
        ll cost;
    };

    typedef pair<ll, ll> PI; //firstは最短距離、secondは頂点の番号
    vector<vector<edge> >G;
    vector<ll> d; //これ答え。d[i]:=V[i]までの最短距離
    vector<ll> prev; //経路復元

    DIJKSTRA(ll size) {
        V = size;
        G = vector<vector<edge> >(V);
        prev = vector<ll> (V, -1);
    }

    void add(ll from, ll to, ll cost) {
        edge e = {to, cost};
        G[from].push_back(e);
    }

    void dijkstra(ll s) {
        //greater<P>を指定することでfirstが小さい順に取り出せるようにする
        priority_queue<PI, vector<PI>, greater<PI> > que;
        d = vector<ll> (V, LLINF);
        d[s] = 0;
        que.push(PI(0, s));

        while(!que.empty()) {
            PI p = que.top();
            que.pop();
            ll v = p.second;
            if(d[v] < p.first) continue;
            for(ll i = 0; i < G[v].size(); i++) {
                edge e = G[v][i];
                if(d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    prev[e.to] = v;
                    que.push(PI(d[e.to], e.to));
                }
            }
        }
    }
    
    void show() {
        for(ll i = 0; i < d.size()-1; i ++) {
            cout << d[i] << " ";
        }
        cout << d[d.size()-1] << endl;
    }
};

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

    ll n;
    cin>>n;
    ll a,b,c;
    DIJKSTRA wa(n);
    rep(i,n-1){
        cin>>a>>b>>c;
        a--;b--;
        wa.add(a,b,c);
        wa.add(b,a,c);
    }
    ll q,k;
    cin>>q>>k;
    ll x,y;
    k--;
    wa.dijkstra(k);

    // wa.show();
    rep(i,q){
        cin>>x>>y;
        x--;y--;
        fin((ll)wa.d[x]+(ll)wa.d[y]);
    }

//////////////////////////////////////////////////////
return 0;}



Measured memory_bytes: 11888
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T lcm(T x,T y){
    return x*y/GCD(x,y);
}
int main(){
    int n; cin >> n; 
    vector<long long> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int b,e; cin >> b >> e;
        reverse(a.begin()+b,a.begin()+e);
    }
    for(int i = 0; i < n; i++){
        if (i == n-1) cout << a[i];
        else cout << a[i] << " ";
    }
    cout << endl;
}
  




Measured memory_bytes: 3120
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std;

using ll = long long;
using boost::irange;

#define MOD 1000000007
#define L true
#define R false

ll factorial(int n){
    ll ans = 1;
    for(auto i : irange(1,n+1)){
        ans *= i;
        ans %= MOD;
    }

    return ans;
}

int main(void){
    
    int N;
    string S;
    cin >> N >> S;
    vector<bool> d(2*N, false);
    vector<int> ind;

    if(S[0] == 'W' || S[d.size()-1] == 'W'){
        cout << "0" << endl;
      	return 0;
    }

    d[0] = L;
    for(const auto i : irange(0, 2*N-1)){
        if(S[i] == S[i+1]){
            d[i+1] = !d[i];
        }else{
            d[i+1] = d[i];
        }
        if(d[i+1] == R){
            ind.push_back(i+1);
        }
    }

    ll ans = 1;
    int l = 0;
    int r = 0;
    bool flag = false;
    for(int i = 0; i < 2*N; i++){
        if (d[i] == L){
            l++;
        }else{
            ans *= (l - r);

            if (ans <= 0){
                flag = false;
                break;
            }

            ans %= MOD;
            r++;
            flag = true;
        }      
    }

    if(flag == false || l != r){
        cout << "0" << endl;
        return 0;
    }


    ans *= factorial(N);
    ans %= MOD;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
#include <string.h>
#include <math.h>
struct typestr{
	char str[16];
	int allow; 
};

int main()
{
	int n,h,i,len,miss,position;
	double typing=0,total_miss=0,rate;
	char tmp[16],c[2];
	struct typestr string[101];

	scanf("%d %d",&n,&h);
	fflush(stdin);
	if(h<=0){
		printf("! Game Over\n"); 
		fflush(stdout);
		return 0;
	}
	for(i=0;i<n;i++){	
		scanf("%s %d",&string[i].str,&string[i].allow);
		fflush(stdin);
	}
	
	for(i=0;i<n;i++){
		len=strlen(string[i].str);
		position=0;
		miss=0;

		while(1){
			strcpy(tmp,string[i].str);
			memset(tmp,'_',position);
			printf("? %s\n",tmp);
			fflush(stdout);

			memset(c,'0',2);
			scanf("%s",&c);
			fflush(stdin);
			typing++;
			if(string[i].str[position]==c[0] || string[i].str[position]==(c[0]-32)) position++;
			else{
				miss++;
				total_miss++;
			}
			if(position>=len) break;
			if(string[i].allow<miss){
				h--;
				break;
			}
		}

		if(h<=0){
			printf("! Game Over\n"); 
			fflush(stdout);
			return 0;
		}
	}
	rate=floor(((typing-total_miss)/typing)*1000)/10;
	printf("! Game Clear %.1f\n", rate); 
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1300
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    if (n % 2 == 0) {
      pw.println(n / 2);
    } else {
      pw.println(n / 2 + 1);
    }
  }
}


Measured memory_bytes: 21716
#include <stdio.h>
int main(){
	int a[10000],n,i,saidai=0,saisyou=0;
	long long int goukei=0;
	scanf("%d",&n);
	if(0>n){
		return 0;
	}
	if(10000<n){
		return 0;
	}
	if(n==0){
		printf("0 0 0");
		return 0;
	}
	saidai=-1000000;
	saisyou=1000000;
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]<-1000000){return 0;}
		if(a[i]>1000000){return 0;}
	}
	for(i=0;i<n;i++){
		if(saidai<a[i]){saidai=a[i];}
		if(saisyou>a[i]){saisyou=a[i];}
		goukei+=a[i];
	}
	printf("%d %d %ld\n",saisyou,saidai,goukei);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
int main(){
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	bool a=false;
	if(0<=x-r&&0<=y-r&&x<=w-r&&y<=h-r)
		a=true;
	if(a==true)
		cout<<"Yes"<<endl;
	if(a==false)
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
using namespace std;
using ll = long long;

int main(){
    ll N;
    cin >> N;
    ll A[N];
    vector <ll> a;
    for (int i=0;i<N;i++){
        cin >> A[i];
        a.push_back(A[i]);
    }
    vector<ll>::iterator iter = max_element(a.begin(), a.end());
    size_t index = distance(a.begin(), iter);
    
    
    for (int i=0;i<N;i++){
        if (i!=index){
            cout << a[index] << endl;
        }
        else {
            int max =  0;
            for(int j=0;j<N;j++){
                if(i!=j){
                    if(max < A[j]){
                        max = A[j];
                    }
 
                }   
            }
            cout << max << endl;
        }      
    
    }
}

Measured memory_bytes: 5360
"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};

function main(input) {
  const o = new I(input, String);

  const N = Number(o.a());
  const Q = Number(o.a());
  const s = o.a();
  const t = [];
  const d = [];

  for (let i=0; i<Q;i++) {
    t.push(o.a());
    d.push(o.a());
  }

  function testStatus(index) {
    let currentIndex = index;
    let currentChar = s[currentIndex];
    for ( let i = 0; i < Q; i++) {
      if (t[i] === currentChar) {
        if (d[i] === 'L') {
          currentIndex -= 1;
          if (currentIndex < 0) return "LDis";
          currentChar = s[currentIndex];
        } else {
          currentIndex += 1;
          if (currentIndex >= N) return "RDis";
          currentChar = s[currentIndex];
        }
      }
    }

    return 'Alive';
  }

  let leftDis = 0;
  let LHead = 0;
  let LTail = N - 1;
  if (testStatus(LTail) === "LDis") {
    leftDis = N;
  } else if (testStatus(LHead) === "LDis") {
    let middle = Math.floor((LHead + LTail)/2);
    while (LHead < LTail - 1) {
      if (testStatus(middle) === "LDis") {
        LHead = middle;
      } else {
        LTail = middle;
      }

      middle = Math.floor((LHead + LTail)/2);
    }
    leftDis = middle + 1;
  }

  let rightDis = 0;
  let RHead = 0;
  let RTail = N - 1;
  if (testStatus(RHead) === "RDis") {
    rightDis = N;
  } else if (testStatus(RTail) === "RDis") {
    let middle = Math.floor((RHead + RTail)/2);
    while (RHead < RTail - 1) {
      if (testStatus(middle) === "RDis") {
        RTail = middle;
      } else {
        RHead = middle;
      }

      middle = Math.floor((RHead + RTail)/2);
    }

    rightDis = N - middle - 1;
  }
  console.log(N - leftDis - rightDis);
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 56008
#include<bits/stdc++.h>
using namespace std;
int main(){
    bool p[1000000];int n,i,j;
    fill(p,p+1000000,1);p[0] = p[1] = 0;
    for(i=2;i<=999;i++){
        if(!p[i]) continue;
        for(j=i+i;j<1000000;j+=i) p[j] = 0;
    }
    while(cin >> n) cout << accumulate(p,p+n+1,0) << "\n";
}


Measured memory_bytes: 4072
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
using P = std::pair<int,int>;
const int INF = 1e17;
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<P> a,b;
	int sum=0;
	rep(i,n) {
		std::string s;
		std::cin >> s;
		int A=0;
		int D=0;
		for(auto c:s) {
			A += (c=='(')?1:-1;
			D=std::min(D,A);
		}
		if(A>=0) a.emplace_back(D,A);
		else b.emplace_back(D-A,-A);
		sum+=A;
	}
	std::sort(a.rbegin(),a.rend());
	std::sort(b.rbegin(),b.rend());
	int ok=true;
	int curr=0;
	for(auto p:a) {
		if(curr+p.first<0) ok=false;
		curr+=p.second;
	}
	for(int i=b.size()-1;i>=0;i--) {
		auto p = b[i];
		if(curr+p.first-p.second<0) ok=false;
		curr-=p.second;
	}
	if(sum==0 && ok) print("Yes");
	else print("No");
	return 0;
}


Measured memory_bytes: 18980
#include <iostream>

using namespace std;

int main()
{
	int n, k;
	
	while(scanf("%d%d", &n, &k), (n|k)){
		int blood[100];
		for(int i=0 ; i<k ; ++i)
			scanf("%d", &blood[i]);
		
		bool no = false;
		for(int i=0 ; i<n ; ++i){
			for(int j=0 ; j<k ; ++j){
				int a;
				scanf("%d", &a);
				blood[j] -= a;
				if(blood[j] < 0)
					no = true;
			}
		}
		
		puts(no ? "No" : "Yes");
	}
	
	return 0;
}

Measured memory_bytes: 852
N = int(input())
A = 1
B = 1
for _ in range(N):
    a, b = map(int, input().split())
    if a == b:
        A = max(A, B)
        B = max(A, B)
    else:
        if A%a == 0:
            aa = A//a
        else:
            aa = A//a + 1
        if B%b == 0:
            bb = B//b
        else:
            bb = B//b + 1
        tmp = max(aa, bb)
        A = tmp*a
        B = tmp*b

print(A+B)

    

Measured memory_bytes: 9096
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    string S;
    cin >> S;
    lint L=S.length();
    lint alf[26]={};
    lint ans=1;
    rep(i,L) alf[S[i]-'a']++;
    rep(i,L){
        ans+=L-i-alf[S[i]-'a'];
        alf[S[i]-'a']--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 720
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

int N,L,ans=0;
int a[210];

bool cmp(int x,int y)
{
	return abs(x)<abs(y);
}

int main()
{
	cin>>N>>L;
	for(int i=1;i<=N;i++)
		a[i]=L+i-1;
	sort(a+1,a+N+1,cmp);
	for(int i=2;i<=N;i++)
		ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int n;
    cin >>n;
    vector<int> S(n, 0);
    for (int i=0; i<n; i++)
        cin >>S.at(i);
    int q;
    cin >>q;
    vector<int> T(q, 0);
    for (int i=0; i<q; i++)
        cin >>T.at(i);
    sort(S.begin(), S.end());
    sort(T.begin(), T.end());
    int is=0;
    int it=0;
    int SS=0;
    for(;;) {
        if (S.at(is)==T.at(it)) {
            SS++;
            it++;
        } else if (S.at(is)>T.at(it))
            it++;
        else
            is++;
        if (it==T.size())
            break;
        if (is==S.size())
            break;
    }
    cout <<SS <<endl;
    return 0;
}


Measured memory_bytes: 3320
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

ll INF = 1e5, a[100010], dp[100010];

ll solve(ll pos){
  if(pos < 0) return INF;
  if(!pos) return 0;
  ll &r = dp[pos];
  if(r >= 0) return r;
  r = abs(a[pos]-a[pos-1]) + solve(pos-1);
  if(pos-2 >= 0) r = min(r, abs(a[pos]-a[pos-2])+solve(pos-2));
  return r;
}

int main(){FIN;
  memset(dp,-1,sizeof(dp));
  int n; cin >> n;
  fore(i,0,n) cin >> a[i];
  cout << solve(n-1) << "\n";
}

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

#define Fast            ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define LL              long long
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define all(a)          a.begin(),a.end()
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

int main()
{
    int n,m;
    cin >> n >> m;
    int arr[n+10]={0};
    int pen[n+10]={0};
    int corr=0,penalty=0;
    FOR(i,1,m){
        int p;
        string s;
        cin >> p >> s;
        if(arr[p]==1) continue;
        if(s=="WA") pen[p]++;
        else{
            arr[p]=1;
            corr++;
            penalty+=pen[p];
        }
    }
    cout << corr << ' ' << penalty;
}



Measured memory_bytes: 1152
import java.util.*;
public class Main {
 
  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int[] arr = new int[n];
      for(int i = 0 ;i < n; i++)
        arr[i] = sc.nextInt();
      Arrays.sort(arr);
      int sum = 0;
      for(int i = 0; i < k; i++)
        sum += arr[i];
      System.out.println(sum);
  }
}

Measured memory_bytes: 38832
a_info = list(map(int, input().split()))
b_info = list(map(int, input().split()))
time = int(input())

if a_info[0] < b_info[0]:
    a_last = a_info[0] + a_info[1] * time
    b_last = b_info[0] + b_info[1] * time
    if a_last >= b_last:
        print('YES')
    else:
        print('NO')
else:
    a_last = a_info[0] + a_info[1] * time * -1
    b_last = b_info[0] + b_info[1] * time * -1
    if a_last <= b_last:
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 9200
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <deque>
using namespace std;
typedef long long ll;
using P=pair<ll,int>;
ll MOD = 1e9+7;
P sm[100000];
ll a[100000];
ll b[100000];
int main()
{
	int n;
	ll ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
		sm[i]=P(a[i]+b[i],i);
	}
	sort(sm,sm+n);
	reverse(sm,sm+n);
	bool f=true;
	for(int i=0;i<n;i++)
	{
		if(f)
			ans+=a[sm[i].second];
		else
			ans-=b[sm[i].second];
		f=!f;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;


class primeFactorClass {// 素因数分解をする
public:
	primeFactorClass() {
		factorNum = 0;
	}
	~primeFactorClass() {
		reset();
	}

	int factorNum;// 素因数の個数
	vector<long> prime;// 素因数
	vector<int> degree;// 次数

	void factorize(long n) {// 素因数分解
		reset();
		if (n < 0) { n = -n; }
		if (n <= 1) { return; }

		if (n % 2 == 0) {
			factorNum++;
			prime.push_back(2);
			int count = 0;
			while (n % 2 == 0) { count++; n /= 2; }
			degree.push_back(count);
		}

		long M = (long)sqrt((double)n) + 1;
		for (long i = 3; i <= M; i += 2) {
			if (n % i == 0) {
				factorNum++;
				prime.push_back(i);
				int count = 0;
				while (n % i == 0) { count++; n /= i; }
				degree.push_back(count);
				M = (long)sqrt((double)n) + 1;
				if (n == 1) { break; }
			}
		}

		if (n != 1) {
			factorNum++;
			prime.push_back(n);
			degree.push_back(1);
		}
	}

private:
	void reset() {
		factorNum = 0;
		prime.clear();
		degree.clear();
	}
};


long N;
long sum = 0;
primeFactorClass p;

void func(int depth, long param) {
	if (depth == p.factorNum) {
		long a = N / param;
		long m = param - 1;
		if (m > a) {
			sum += m;
		}

		return;
	}

	for (int i = 0; i <= p.degree[depth]; i++) {
		func(depth + 1, param);
		param *= p.prime[depth];
	}
}

int main() {
	cin >> N;
	p.factorize(N);

	func(0, 1);

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
int n,m,k,mx,i,j,h,g,y,x;
int a[1000001],b[1000002],c[1000001];
int ten[100001],cnt[100001],sz[100001],nb[100001];
typedef pair<int,int> P;
int main(void)
{
	priority_queue<P> pri; //降順
	P p;
	cin>>n>>m>>k;
	for(i=1;i<=m;i++) cin>>a[i]>>b[i]>>c[i];
	for(i=1;i<=n;i++) ten[i]=0,cnt[i]=0;
	b[m+1]=k; i=1; 
	while(i<=m){
		for(i;i<=m;i++){
			cnt[a[i]]+=c[i];
			pri.push(P(cnt[a[i]],a[i]));
			//cout<<"A"<<i<<endl;
			if(b[i]!=b[i+1]) break;
		}
		//cout<<"I"<<" "<<i<<endl;
		x=-10000000; y=100001; g=0;
		while(pri.size()!=0){
			p=pri.top();
			if(p.f!=cnt[p.s]) pri.pop();
			else if(y>p.s&&x<=p.f) {
				y=p.s; x=p.f;
				pri.pop();
				sz[g]=p.f;
				nb[g]=p.s;
				g++;
			}
			else break;
		}
		for(j=0;j<g;j++){
			pri.push(P(sz[j],nb[j]));
		}
		//printf("%d %d\n",b[i],b[i-1]);
		ten[y]+=b[i+1]-b[i];
		//cout<<p.f<<" "<<p.s<<endl;
		i++;
	}
	mx=0;
	h=1;
	//for(i=1;i<=n;i++) cout<<ten[i]<<endl;
	for(i=1;i<=n;i++) if(mx<ten[i]) mx=ten[i],h=i;
	printf("%d\n",h);
	return 0;
}


Measured memory_bytes: 19464
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

s = [list(input())[:-1] for i in range(2)]

for i in range(3):
    if s[0][i] != s[1][2-i]:
        print("NO")
        break
else:
    print("YES")

Measured memory_bytes: 3316
def ope_all(l):
    cnt=[1 if sum(l)==64 else 0]
    return print(*cnt)

def ope_any(l):
    cnt=[0 if sum(l)==0 else 1]
    return print(*cnt)

def ope_none(l):
         cnt=[1 if sum(l)==0 else 0]
         return print(*cnt)    
         
li=[0]*64
n=int(input())
ope=[input().split() for i in range(n)]
ope =[[int(j) for j in ope[i]] for i in range(len(ope))]
for i in range(n):
    if ope[i][0]==0:
        n=[1 if li[ope[i][1]]==1 else 0]
        print(*n)
    elif ope[i][0]==1:
        li[ope[i][1]]=1
    elif ope[i][0]==2:
         li[ope[i][1]]=0       
    elif ope[i][0]==3:
        if li[ope[i][1]]==1:
            li[ope[i][1]]=0
        else:
            li[ope[i][1]]=1
    elif ope[i][0]==4:
        ope_all(li)
    elif ope[i][0]==5:
        ope_any(li)
    elif ope[i][0]==6:
         ope_none(li)
    elif ope[i][0]==7:
         print(li.count(1))
    else:
        int_li ="".join(map(str, li))
        int_li ="".join(list(reversed(int_li)))
        print(int(int_li,2))
         


Measured memory_bytes: 61588
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int n, d, x;
	int a[105];
	scanf("%d %d %d", &n, &d, &x);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	int ans = 0;
	for(int i = 1; i <= n; i++)
	{
		ans = ans + d / a[i];
		if(d % a[i] != 0) ans++;
	}
	ans += x;
	printf("%d\n", ans);
}

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

#define REP(i,a) for(long i=0;i<(a);++i)

typedef std::vector<int>  VI;
typedef std::vector< VI > VI2;

typedef struct {
    int from, dest;
    int cost;
} Edge;

int N, M;
VI2 g;
std::vector<Edge> edges;
const int inf = std::numeric_limits<int>::max() - 1;
int main() {
    std::cin >> N >> M;
    g.resize(N, VI(N, inf));
    REP(i, N) g[i][i] = 0;
    edges.resize(M);

    REP(i, M) {
        int a, b, c;
        std::cin >> a >> b >> c;
        a--, b--;
        
        edges[i].from = a;
        edges[i].dest = b;
        edges[i].cost = c;

        g[a][b] = c;
        g[b][a] = c;
    }

    REP(k, N) REP(i, N) REP(j, N) {
        if(g[i][k] == inf || g[k][j] == inf) continue;
        g[i][j] = std::min(g[i][j], g[i][k]+g[k][j]);
    }

    int ans = 0;
    for(auto e: edges) {
        if(g[e.from][e.dest] == e.cost) continue;
        else {
            bool f = true;
            REP(k, N) {
                if(g[k][e.dest] - g[k][e.from] == e.cost) {
                    f = false;
                    break;
                }
            }
            ans += (int)f;
        }
    }
    std::cout << ans << std::endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;

int N, M;
string S;
map<string, bool> p;
bool s;

int main(void) {
  cin >> N;
  REP(i, 0, N) {
    cin >> S;
    p[S] = false;
  }
  cin >> M;
  s = false;
  REP(i, 0, M) {
    cin >> S;
    if(p.count(S)) {
      if(s == false) {
        cout << "Opened by " << S << endl;
        s = true;
      } else {
        cout << "Closed by " << S << endl;
        s = false;
      }
    } else {
      cout << "Unknown " << S << endl;
    }
  }
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int n;
  cin >> n;
  ll p=1000000007;
  ll ans=0;
  ll a,b,c,d;
  a=1;
  b=1;
  c=1;
  d=1;
  rep(i,n)a=(a*10%p);
  rep(i,n)b=(b*9%p);
  rep(i,n)c=(c*8%p);
  cout << (2*p+a-(2*b-c))%p << endl;
}


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

struct E{ int to, cost; };

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<std::vector<E>> G(N);
  for(int i = 0; i < N-1; ++i) {
    int u, v, w; std::cin >> u >> v >> w; --u; --v; w%=2;
    G[u].push_back({v, w});
    G[v].push_back({u, w});
  }
  std::vector<int> color(N, 0);
  auto dfs = [&](auto&& f, int v, int p)->void {
    for(E const& e: G[v]) if(e.to != p) {
      color[e.to] = color[v]^e.cost;
      f(f, e.to, v);
    }
  };
  dfs(dfs, 0, -1);
  for(int c: color) std::cout << c << "\n";
  return 0;
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string s,t;
    cin >> s >> t;

    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());

    if(s < t)
        cout << "Yes"  << endl;
    else
        cout << "No" << endl;
}

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

typedef long long ll;
typedef long double ld;

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

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

int main(){

    ll A, B, X;

    cin >> A >> B >> X;

    cout << (X < A || X > A + B ? "NO" : "YES") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	string s;
	cin >> s;
	
	int n = (int)s.size();
	vector<int> cnt(3, 0);
	for(int i = 0; i < n; ++i) {
		int x = (int)(s[i] - 'a');
		cnt[x]++;
	}
	
	int mi = *min_element(cnt.begin(), cnt.end());
	
	for(int i = 0; i < 3; ++i) {
		if( cnt[i] - mi > 1 ) {
			cout << "NO" << endl;
			return 0;
		}			
	}
	
	cout << "YES" << endl;
	
	return 0;
}


Measured memory_bytes: 3700
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<ll, ll> II;
typedef pair<int, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 2010;
const int MAXM = 10010;
const int MAXK = 110;
const int MAXQ = 200010;
const int MAX = 1000000000;
const int oo = 0x3c3c3c3c;

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

    int n;
    cin >> n;
    FOR(i,1,9)
        FOR(j,1,9) 
            if (n == i * j) {
                cout << "Yes";
                return 0;
            }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>

using namespace std;

typedef pair<long long , long long > P;

int main(){
    long long n, a[100009];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    bool ans=true;
    a[0]--;
    for(int i=1;i<n;i++){
        if(a[i]<a[i-1]){
            ans=false;
            break;
        }
        else{
            if(a[i]==a[i-1]){
                a[i]=a[i];
            }
            else{
                a[i]--;
            }
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

void print_vector(vector<int> v){
  rep(i, sz(v)){
    cout << v[i] << " ";
  }
  cout << endl;
  return;
}

int N, M, X;
vector<ll> C(12);
vector<vector<ll>> A;

bool check(vector<ll> scores){
  rep(i, M){
    if(scores[i] < X){
      return false;
    }
  }
  return true;
}

ll dfs(int depth, ll cost, vector<ll> scores){
  if(depth==N){
    if(check(scores)){
      return cost;
    }else{
      return INF;
    }
  }
  ll not_used = dfs(depth+1, cost, scores);
  rep(i, M){
    scores[i] += A[depth][i];
  }
  ll used = dfs(depth+1, cost+C[depth], scores);

  return min(not_used, used);
}

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

  C.resize(N);

  rep(i, N){
    ll c;
    cin >> C[i];
    vector<ll> tmp_A(M);
    rep(i, M) cin >> tmp_A[i];
    A.push_back(tmp_A);
  }

  vector<ll> scores(M);

  ll ans = dfs(0, 0, scores);
  if(ans == INF){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3628
/*
* Author:sam51305
*/
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define mp make_pair
#define ll long long
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pb push_back
#define ary array

#define Yes cout << "Yes" <<endl;
#define No cout << "No" << endl;
int main() {
    fastio
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int votes = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        votes += a[i];
    }
    double limitVotes = (double)votes / (double)(4 * m);
    int cntM = m;
    for(int i = 0; i < n; i++){
        if(cntM == 0)
            break;
        if(a[i] >= limitVotes)
            cntM--;
    }
    if(cntM == 0){
        Yes
    } else {
        No
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long N, std::vector<long long> P){
    vll a(N);
    ll tmp = INF;
    REP(i, N){
        if(P[i] < tmp){
            tmp = P[i];
        }
        a[i] = tmp;
    }
    ll cnt = 0;
    REP(i, N){
        if(a[i] == P[i])
            cnt++;
    }
    cout<<cnt<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
    }
    solve(N, std::move(P));
    return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
#include<limits.h>
int A[500005],N,c=0,i,tmp[2][250005];
void marge(int l,int m,int r)
{
	int i,j,c1=m-l,c2=r-m;
	for(i=0;i<c1;i++)tmp[0][i]=A[l+i];
	for(i=0;i<c2;i++)tmp[1][i]=A[m+i];
	tmp[0][c1]=tmp[1][c2]=INT_MAX;
	for(i=j=0;i<c1||j<c2;c++)
	{
		if(tmp[0][i]<tmp[1][j])
		{
			A[l+i+j]=tmp[0][i];
			i++;
		}
		else
		{
			A[l+i+j]=tmp[1][j];
			j++;
		}
	}
}

void margeSort(int l,int r)
{
	int m;
	if(l+1<r)
	{
		m=(l+r)/2;
		margeSort(l,m);
		margeSort(m,r);
		marge(l,m,r);
	}
}

int main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%d",A+i);
	margeSort(0,N);
	for(i=0;i<N;i++)
		printf("%d%c",A[i],i==N-1?'\n':' ');
	printf("%d\n",c);
	return 0;
}



Measured memory_bytes: 5608
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 2123456;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

ll dp[110][500][110],w[110],v[110];
void solve()
{
    ll i,j,n,W,x,ans,k;
    cin>>n>>W;
    rep1(i,1,n)
    {
        cin>>w[i]>>v[i];
        if(i==1)
            x=w[1];
        w[i]-=x;
    }

    memset(dp,-1,sizeof(dp));

    for(i=0;i<=n;i++)
        dp[i][0][0]=0;

    for(i=1;i<=n;i++)
    {
        for(j=0;j<=301;j++)
        {
            for(k=1;k<=i;k++)
            {
                dp[i][j][k] = dp[i-1][j][k];
                if(j>=w[i] and dp[i-1][j-w[i]][k-1]!=-1)
                    dp[i][j][k] = max(dp[i][j][k], dp[i-1][j-w[i]][k-1] + v[i]);
            }
        }
    }

    ans = 0;
    for(i=0;i<=301;i++)
    {
        for(j=1;j<=n;j++)
        {
            if(i+j*x<=W)
                ans=max(ans,dp[n][i][j]);
        }
    }

    cout<<ans<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    //cin>>tt;
    while(tt--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 47616
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 10e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1 << 9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

constexpr int N_MAX = 100;
constexpr int V_MAX = 1000;
int dp[N_MAX + 1][V_MAX * N_MAX + 1];

signed main()
{
  ios();
  string S ;
  cin >> S;
  if(S[5] == '0' && S[6] <= '4')
  {
    cout << "Heisei" << endl;
  }
  else {
    cout << "TBD" << endl;
  }
}


Measured memory_bytes: 256