akhauriyash/Code-Regression huggingface dataset:
#----------------------------------------------------------
P = 10**9 + 7
N = 200000 #使える最大値、値に注意
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b:
        return -1 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------

n, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a, key=lambda x: x, reverse=False)
ans = 0
# a[i]が最小値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[i] < 0:
        ans = (ans + (abs(a[i])*tmp)%P)%P
    else:
        ans = (ans - (abs(a[i])*tmp)%P + P)%P

# a[i]が最大値になる場合の数
for i in range(len(a)):
    tmp = comb(n-1-i, k-1)
    if tmp<0:
        continue
    if a[n-1-i] < 0:
        ans = (ans - (abs(a[n-1-i])*tmp)%P + P)%P
    else:
        ans = (ans + (abs(a[n-1-i])*tmp)%P)%P
print(ans)


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

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

    struct Point { int x, y; };

    auto students = vector<Point>(N);
    for (auto& p : students) cin >> p.x >> p.y;

    auto checkpoints = vector<Point>(M);
    for (auto& p : checkpoints) cin >> p.x >> p.y;

    const auto distance = [](const Point p, const Point q)
    {
        return abs(q.x-p.x) + abs(q.y-p.y);
    };

    for (const auto s : students)
    {
        auto closest = 0;
        for (auto i = 0; i < M; i++)
            if (distance(s, checkpoints[i]) < distance(s, checkpoints[closest]))
                closest = i;
        cout << closest+1 << endl;
    }
}


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

int main() {
        int i, j;
        int n, r;
        while (cin >> n >> r) {
                if (n == 0 && r == 0) break;
                vector<int> a(n);
                vector<bool> ok(n);
                for (i = 0; i < n; i ++) {
                        a[i] = i + 1;
                        ok[i] = true;
                }
                for (i = 0; i < r; i ++) {
                        int p, c;
                        cin >> p >> c;
                        int cnt = 0;
                        int pp = a.size() - 1;
                        while (cnt < p - 1) {
                                if (ok[pp]) cnt ++;
                                pp --;
                        }
                        cnt = 0;
                        vector<int> tmp;
                        vector<bool> tmpok;
                        while (cnt < c) {
                                if (ok[pp]) {
                                        cnt ++;
                                        ok[pp] = false;
                                        tmp.push_back(a[pp]);
                                        tmpok.push_back(true);
                                }
                                pp --;
                        }
                        for (j = tmp.size() - 1; j >= 0; j --) a.push_back(tmp[j]);
                        for (j = tmpok.size() - 1; j >= 0; j --) ok.push_back(tmpok[j]);
                        //cout << "================" << endl;
                        //for (j = 0; j < a.size(); j ++) {
                        //        cout << a[j] << ' ' << endl;
                        //}
                }
                cout << a.back() << endl;
        }
        return 0;
}

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

       if (a>b){
   printf("a > b\n");
    }

    if (a==b){
   printf("a == b\n");
    }
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

ll getcomb(ll x, ll y) {
  ll ans = 1, n = x - y + 1, r = 1;
  while (n <= x) {
    while (r <= y && ans % r == 0) {
      ans /= r;
      r++;
    }
    ans *= n;
    n++;
  }
  while (r <= y) {
    ans /= r;
    r++;
  }
  return ans;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];

  sort(v.begin(), v.end(), greater<ll>());
  vector<ll> sum(b - a + 1);
  ll res = 0;
  rep(i, a) res += v[i];
  rep(i, b - a + 1) {
    sum[i] = res;
    res += v[a + i];
  }

  vector<ll> ans;
  ll idx = 0;
  rep(i, b - a + 1) {
    if (sum[i] * (idx + a) > sum[idx] * (i + a)) {
      ans.clear();
      ans.push_back(i + a);
      idx = i;
    }
    else if (sum[i] * (idx + a) == sum[idx] * (i + a)) {
      ans.push_back(i + a);
    }
  }

  long double ave = (long double)sum[idx] / (long double)(idx + a);
  cout << setprecision(20) << ave << endl;

  ll m = ans.size();
  ll comb = 0;
  rep(i, m) {
    ll x = 0, y = 0, id = ans[i] - 1;
    while (id >= 0 && v[id] == v[ans[i] - 1]) {
      x++;
      y++;
      id--;
    }
    id = ans[i];
    while (id < n && v[id] == v[ans[i] - 1]) {
      x++;
      id++;
    }
    comb += getcomb(x, y);
  }
  cout << comb << endl;







  
  return 0;
}

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

int main() {
    int a, b;
    char op;
    cin >> a >> op >> b;

    int ans;
    if (op == '+') {
        ans = a + b;
    } else {
        ans = a - b;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPP(i,m,n) for(ll i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[N+1] = {};
    REPP(i,1,N+1) cin >> A[i];
    vector<ll> V(1000000,0),W;

    for(ll i = N; i >= 1; i--){
        if(i >= (N+2)/2){
            if(A[i] == 1){
                V[i] = 1;
            }
        }
        else{
          	ll cnt = 0;
            ll j = i;
            while(j <= N){
                j += i;
                if(V[j] == 1) cnt++;
                if(j >= N){
                    bool flag = 0;
                    if(cnt % 2 == 1) flag = 1;
                    if(A[i] == 1 && flag == 1){
                        V[i] = 0;
                    }
                    else if(A[i] == 1 && flag == 0){
                        V[i] = 1;
                    }
                    else if(A[i] == 0 && flag == 1){
                        V[i] = 1;
                    }
                    else{
                        V[i] = 0;
                    }
                }
            }
        }
    }
    ll c = 0;
    REPP(i,1,V.size()+1){
        if(V[i] == 1){
            W.pb(i);
            c++;
        }
    }
    cout << c << endl;
    REP(i,W.size()){
        cout << W[i] << ' ';
    }
}

Measured memory_bytes: 11508
N = int(input())
As = list(map(int, input().split()))

Asum = sum(As)

ans = 0
for index, A in enumerate(As):
    ans += (A * (Asum - A))
    ans = ans % (10**9+7)
    Asum -= A
#    print(
#    print(As)

print(ans)

Measured memory_bytes: 31432
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int main(){
    int n; string s;
    while(cin>>n>>s){
        // vvi dp(n, vi(n));
        // dp[pos][last num] represents the count at pos having last number as 'l'
        // dp[0][0] = 1;
        // for(int pos=1; pos<n; ++pos){
        //     for(int l=0; l<=pos; ++l){
        //         if(s[pos-1]=='<'){ // ..x_4, x= {1,2,3} so that x<4 is maintained
        //             for(int k=0; k<l; ++k)
        //                 add_self(dp[pos][l], dp[pos-1][k]);
        //         }else{ // ...x_4,  x > 4, x = {5,6,7,8}
        //             for(int k=l; k<=pos; ++k)
        //                 add_self(dp[pos][l], dp[pos-1][k]);
        //         }
        //     }
        // }

        vi dp(n);
        dp[0] = 1;
        for(int pos=1; pos<n; ++pos){
            vi ndp(n);
            vi pre(n+1);
            fore(i,1,n+1) add_self(pre[i], pre[i-1] + dp[i-1]);

            for(int l=0; l<=pos; ++l){
                if(s[pos-1]=='<'){ // ..x_4, x= {1,2,3} so that x<4 is maintained
                    add_self(ndp[l], pre[l] - pre[0]);
                }else{ // ...x_4,  x > 4, x = {5,6,7,8}
                    add_self(ndp[l], pre[pos+1] - pre[l]);
                }
            }
            dp = ndp;
        }

        int ans = 0;
        for(int i=0; i<n; ++i)
            add_self(ans, dp[i]);
        
        // print_vv(dp);
    
        cout<<ans<<endl;
    } 
    return 0;
}


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

using namespace std;

const char *TABLE[] = {
	"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
	"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
	"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"
};

int fetch(const string &s, int p){
	for(int i = 37; i >= 0; --i){
		const char *w = TABLE[i];
		if(s[p] == w[0] && s[p + 1] == w[1]){ return i; }
		if(s[p] == w[0] && w[1] == '\0'){ return i; }
	}
	return -1;
}

int main(){
	int n;
	cin >> n;
	string word;
	int counter[39][39] = { { 0 } };
	while(cin >> word){
		int prev = 38, p = 0;
		while(p < word.size()){
			int l = fetch(word, p++);
			if(l >= 26){ ++p; }
			++counter[prev][l];
			prev = l;
		}
	}
	for(int i = 0; i < 38; ++i){
		int maxidx = 0;
		for(int j = 0; j < 38; ++j){
			if(counter[i][j] > counter[i][maxidx]){ maxidx = j; }
		}
		cout << TABLE[i] << " " << TABLE[maxidx] << " "
		     << counter[i][maxidx] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
 
int main() {
	string n;
	cin >> n;
 
	for (int i = 0; i < n.length(); ++i) {
		if ('7' == n[i]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
 
	cout << "No" << endl;
 
	return 0;
}

Measured memory_bytes: 3132
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

#[allow(non_snake_case)]
fn main() {
    input! {
        N:usize
    }
    let mut sum = 0;
    for i in 1..N + 1 {
        if i % 3 == 0 || i % 5 == 0 {
            continue;
        }
        sum += i;
    }
    println!("{}", sum);
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

void solve() {
    int n;
    std::cin >> n;
    std::vector<int> rabbits(n);
    rep(i, n) {
        int t;
        std::cin >> t;
        t--;
        rabbits[i] = t;
    }
    int cnt = 0;
    rep(i, n) {
        if(rabbits[rabbits[i]] == i) {
            cnt++;
        }
    }
    std::cout << cnt / 2 << std::endl;
}

int main() {
    // std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 640
from collections import deque
n=int(input())
a=list(map(int,input().split()))
b=deque()
for i in range(n):
    if i%2==0:
        b.appendleft(a[i])
    else:
        b.append(a[i])
if n%2!=0:
    for i in range(n):
        print(b[i],end=' ')
else:
    for i in reversed(range(n)):
        print(b[i],end=' ')

Measured memory_bytes: 25540
def main():
    S = input()
    T = input()
    m = 10000
    for i in range(len(S) - len(T) + 1):
        c = 0
        for s, t in zip(S[i:], T):
            if s != t:
                c += 1
        m = min(c, m)
    return m

print(main())


Measured memory_bytes: 9036
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#define N (1<<15)
using namespace std;
int dis[N];
int main(){
	int n,m,k,x,i,j;
	int p[20],q[20],start=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d",&x);
		start=start<<1|x;
	}
	for(i=0;i<m;i++) scanf("%d",&p[i]);
	queue<int> que;
	que.push(start);
	memset(dis,0x3f,sizeof(dis));
	dis[start]=0;
	while(!que.empty()){
		k=que.front();
		que.pop();
		x=0;
		int cnt=0;
		int l=k;
		int num=n;
		while(num){
			if(l&1) q[cnt]=__lg((l+1)&-(l+1));
			else if(l>0) q[cnt]=__lg(l&-l);
			else q[cnt]=num;
			l>>=q[cnt];
			num-=q[cnt++];
		}
		bool flag=true;
		if(m!=cnt) flag=false;
		for(i=0;i<m;i++) if(p[m-1-i]!=q[i]) flag=false;
		if(flag){
			printf("%d\n",dis[k]);
			break;
		}
		for(i=0;i<n-1;i++){
			if((k&(1<<i))&&!(k&(1<<i+1))){
				if(dis[k+(1<<i)]>dis[k]+1){
					dis[k+(1<<i)]=dis[k]+1;
					que.push(k+(1<<i));
				}
			}
			else if(!(k&(1<<i))&&(k&(1<<i+1))){
				if(dis[k-(1<<i)]>dis[k]+1){
					dis[k-(1<<i)]=dis[k]+1;
					que.push(k-(1<<i));
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1348
# -*- coding: utf-8 -*-
n = int(input())
txy = []
for i in range(n):
    txy.append([int(i) for i in input().split()])

ans = "Yes"
tmp_x = 0
tmp_y = 0
tmp_t = 0
for i in range(n):
    #print((abs(tmp_x - txy[i][1]) + abs(tmp_y - txy[i][2])))
    if (abs(tmp_x - txy[i][1]) + abs(tmp_y - txy[i][2])) % 2 != (txy[i][0] - tmp_t) % 2 or (abs(tmp_x - txy[i][1]) + abs(tmp_y - txy[i][2])) > txy[i][0] - tmp_t:
        ans = "No"
    tmp_x = txy[i][1]
    tmp_y = txy[i][2]
    tmp_t = txy[i][0]
print(ans)


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

const int INF = 1e9 + 7;

int main() {
  int h, n;
  cin >> h >> n;
  int a[n], b[n];
  int mx = 0;
  for ( int i = 0; i < n; i++ ) {
    cin >> a[i] >> b[i];
    mx = max(mx, a[i]);
  }

  vector<int> dp(h+mx+1, INF);
  dp[0] = 0;
  for ( int i = 0; i < h+mx; i++ ) {
    for ( int k = 0; k < n; k++ ) {
      int tmp = dp[i] + b[k];
      int pos = i + a[k];
      if ( pos <= h+mx ) {
        dp[pos] = min(tmp, dp[pos]);
      }
    }
  }

  int ans = INF;
  for ( int i = h; i <= h+mx; i++ ) {
    ans = min(dp[i], ans);
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
  long long n,a,b;cin>>n>>a>>b;
  if(abs(a-b)%2==0)cout<<(abs(a-b)+1)/2<<endl;
  else
  {
    cout<<min(a+b-1,n*2-a-b+1)/2<<endl;
  }
}


Measured memory_bytes: 256
/*
 *
 *  1. sprawdz corner cases
 *  2. sprawdz limity, jesli sie da pozamieniaj wszystkie lokalne zmienne na LL!
 *  3.  MINIMALNE I MAKSYMALNE WEJŚCIE I WYJŚCIE
 *  4. lokalne zmienne, iteracja po tablicach dwuwymiarowych uwazaj
 *  5. SPRAWDZ CZY input jest POSORTOWANY jaki jest niezmiennik
 *
 *
 */
#include <algorithm>
#include <cstdio>
#include <iomanip> // std::setprecision
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>
#include <numeric>
#define FOR(x, y, z) for (int x = (y); x < (z); x++)
#define FORD(x, y, z) for (int x = (y); x >= z; x--)
#define REP(r, n) for (int r = 0; r < (n); r++)
#define MP make_pair
#define ST first
#define ND second
#define SIZE(c) ((int)((c).size()))
#define FOREACH(i, x) for (__typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define ALL(u) (u).begin(), (u).end()
#define RALL(u) (u).rbegin(), (u).rend()
#define PB push_back
#define PF push_front
#define SZ(x) long long((x).size())
#define IS_IN(x, t) (t.find(x) != t.end())
#define BIT(n, i) (((n) >> (i)) & 1)

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) \
    {              \
    }
#endif

#define TYPEMAX(type) std::numeric_limits<type>::max()
#define TYPEMIN(type) std::numeric_limits<type>::min()

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<LL> VI;
typedef pair<LL, LL> PR;

inline LL GCD(LL a, LL b)
{
    LL r;
    while (b) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
};
inline LL LCM(LL a, LL b) { return a / GCD(a, b) * b; };
inline LL fpow(LL n, LL k, LL p)
{
    LL r = 1;
    for (; k; k >>= 1) {
        if (k & 1)
            r = r * n % p;
        n = n * n % p;
    }
    return r;
};
inline LL inv(LL a, LL p) { return fpow(a, p - 2, p); }

[[maybe_unused]] const LL MOD = (LL)1e9 + 7;
[[maybe_unused]] const LL MAXUS = TYPEMAX(LL);
[[maybe_unused]] const LD PI = acos((LD)-1);
[[maybe_unused]] const LD epsilon = 1e-9;

template <typename T>
T input()
{
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e)
{
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

int main()                       
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    cout << max(0, n-k)*y+min(n,k)*x << endl;
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll a(n);
    vll sum(n+1);
    sum[0]=0LL;
    REP(i,n){
        cin >> a[i];
        sum[i+1] = sum[i]+a[i];
    }
    ll ans = LLINF;
    for(int i=1;i<=n-3;++i){
        int c1,c2,c3;
        c2 = i;
        if(sum[1]>=sum[i+1]-sum[1]){
            c1 = 0;
        }else if(sum[i]<=a[i]){
            c1 = i-1;
        }else{
            ll ok = i-1;
            ll ng = 0;
            while(abs(ok-ng)>1){
                ll mid = (ok+ng)/2;
                if(sum[mid+1]>=sum[i+1]-sum[mid+1]){
                    ok = mid;
                }else{
                    ng = mid;
                }
            }
            c1 = ok;
            if(abs(sum[i+1]-sum[c1+1]-sum[c1+1])>abs(sum[i+1]-sum[c1]-sum[c1])){
                c1--;
            }
        }
        if(a[i+1]>=sum[n]-sum[i+2]){
            c3 = i+1;
        }else if(a[n-1]>=sum[n-1]-sum[i+1]){
            c3 = n-2;
        }else{
            ll ok = n-2;
            ll ng = i+1;
            while(abs(ok-ng)>1){
                ll mid = (ok+ng)/2;
                if(sum[mid+1]-sum[i+1]>=sum[n]-sum[mid+1]){
                    ok = mid;
                }else{
                    ng = mid;
                }
            }
            c3 = ok;
            if(abs(sum[n]-sum[c3+1]-(sum[c3+1]-sum[i+1]))>abs(sum[n]-sum[c3]-(sum[c3]-sum[i+1]))){
                c3--;
            }
        }
        ll mx = max({sum[c1+1], sum[c2+1]-sum[c1+1], sum[c3+1]-sum[c2+1], sum[n]-sum[c3+1]});
        ll mn = min({sum[c1+1], sum[c2+1]-sum[c1+1], sum[c3+1]-sum[c2+1], sum[n]-sum[c3+1]});
        ans = min(ans, mx-mn);
        //cout << c1 << "-" << c2 << "-" << c3 << ":" << mx << "-" << mn << endl; 
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>

#include <stack>
#include <queue>
// #include <deque>
// #include <set>
// #include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

#include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;


typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef pair<long long, long long> pllll;
typedef pair<long long, int> plli;
typedef pair<int,long long> pill;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';
const ll M = 1000000007;
ll nchoose[200001];

/*
Edge cases:

when n = 2?
*/

ll modexp(ll b, ll p) {
    //invariant: C*base^pow = b^p
    ll C = 1; ll base = b, pow = p;

    while (pow>0) {
        if (pow%2==0) {
            base*=base;
            base%=M;
            pow/=2;
        } else {
            C*=base;
            C%=M;
            --pow;
        }
    }

    return C;
}

ll choose(int n, int k) {

    if (k==n) return (ll)1;
    ll num = 1;
    ll denom = 1;

    for (ll i = 1; i<=(ll)k; ++i) {
        num *= ((ll)n+1-i);
        num %= M;

        denom *= i;
        denom %= M;
    }

    ll denominv = modexp(denom,M-2);

    num *= denominv;
    num %= M;
    return num;


}

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

    int n,a,b; cin>>n>>a>>b; cin.ignore();



    if (n==2) {
        cout<<0<<el;
        return 0;
    } else {
        auto ans = modexp(2,n);
        ans += (M-1);
        ans %= M;
        //can't choose 0 flowers;
        //also can't include (n choose a):
        ans -= choose(n,a);
        ans += M;
        ans %= M;

        ans -= choose(n,b);
        ans += M;
        ans %= M;
        
        // or (n choose b)
        cout<<ans<<el;
    }
}

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

void rec( char c, char* map, int x, int y, int w, int h )
{
	static int diff[][ 2 ] = { { 0, -1 }, { 1, 0 }, { 0, 1 }, { -1, 0 } };

	if( map[ y * w + x ] != c ){
		return;
	}

	map[ y * w + x ] = 0;

	for( int i = 0; i < 4; ++i ){
		rec( c, map, x + diff[ i ][ 0 ], y + diff[ i ][ 1 ], w, h );
	}

	return;
}

int main()
{
	int h, w;

	while( cin >> h >> w && !( h == 0 && w == 0 ) ){
		if( h == 0 || w == 0 ){
			cout << 0 << endl;
			continue;
		}

		int hh = h + 2;
		int ww = w + 2;
		char* map = new char[ ww * hh ]();

		for( int i = 0; i < h; ++i ){
			cin >> &map[ ( i + 1 ) * ww + 1 ];
		}

		int areaCount = 0;
		for( int i = 1; i < hh; ++i ){
			for( int j = 1; j < ww; ++j ){
				char c =  map[ i * ww + j ];
				if( c == 0 ){
					continue;
				}
				rec( c, map, j, i, ww, hh );
				++areaCount;
			}
		}

		cout << areaCount << endl;

		delete[] map;
	}

	return 0;
}

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

using ll = long long;

int main() {
    // 各bitに於いて多数決をとって，少ない方のビットを選択する
    // 1e12はたかだか40bit程度なので，1e5個集計しても終わる
    ll n, k;
    cin >> n >> k;

    if(k == 0) {
        ll sum;
        rep(i, n) {
            ll tmp;
            cin >> tmp;
            sum += tmp;
        }
        cout << sum << endl;
        return 0;
    }

    int kbitn = int(log2(k)) + 1;
    vector<int> bitc(kbitn, 0);
    vector<ll> a(n);

    rep(i, n) {
        ll tmp;
        cin >> a[i];
        rep(j, kbitn) {
            int bit = (a[i] & (1LL << j)) >> j;

            if(bit == 1)
                bitc[j]++;
        }
    }

    vector<ll> bits(kbitn, 0);
    rep(i, kbitn) {
        if(bitc[i] > n / 2) {
            bits[i] = 0LL;
        } else {
            bits[i] = 1LL;
        }
    }

    bool flag = false;
    for(int i = kbitn - 1; i >= 0; i--) {
        int bit = (k & (1LL << i)) >> i;
        if(bit == 1LL && bits[i] == 0LL) {
            break;
        }
        if(bit == 0LL && bits[i] == 1LL) {
            bits[i] = 0LL;
            flag = true;
        }
    }

    ll target = 0LL;
    rep(i, kbitn) { target += bits[i] << i; }

    ll ans = 0;
    rep(i, n) { ans += a[i] ^ target; }
    cout << ans << endl;

    return 0;
}


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

int main(void) {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	int fx1 = tx - sx;
	int fy1 = ty - sy;
	string f_route1 = string(fy1, 'U') + string(fx1, 'R');
	string r_route1 = string(fy1, 'D') + string(fx1, 'L');
	string f_route2 = "L" + string(fy1 + 1, 'U') + string(fx1 + 1, 'R') + "D";
	string r_route2 = "R" + string(fy1 + 1, 'D') + string(fx1 + 1, 'L') + "U";
	string ans = f_route1 + r_route1 + f_route2 + r_route2;

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


Measured memory_bytes: 256
def setup_edges(matrix)
  edges = []
  matrix.each_with_index do |row, index_row|
    row.each_with_index do |column, index_column|
      if column >= 0
        edges.push([index_column+1, index_row+1, column])
      end
    end
  end
  sorted_edges = edges.sort_by {|edge| edge[2]}
  return sorted_edges
end


def solve(edges)
  sum = 0
  vertices = Hash.new
  (edges.size).times do |i|
    vertices[i] = i
  end

  until edges.empty? do
    edge = edges.shift
    v1, v2 = vertices[edge[0]-1], vertices[edge[1]-1]
    next if v1 == v2
    sum += edge[2]
    min_id = [v1, v2].min
    vertices.each do |key, val|
      vertices[key] = min_id if val == v1 || val == v2
    end
  end
  return sum
end


# main
n = gets.chomp.to_i
matrix = []
n.times do
  matrix.push(gets.chomp.split.map(&:to_i))
end

edges = setup_edges(matrix)
puts solve(edges)

Measured memory_bytes: 9280
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[])
{
	int n, m, j;
	int i, count = 0;
	cin >> n >> m;
	vector<int> left;
	vector<int> right;
	int tmp1, tmp2;
	int left_limit, right_limit;
	for (i = 0; i < m; i++) {
		cin >> tmp1 >> tmp2;
		left.push_back(tmp1);
		right.push_back(tmp2);
	}

	sort(left.begin(), left.end());
	sort(right.begin(), right.end());

	left_limit = left[left.size() - 1];
	right_limit = right[0];

	for (i = 1; i <= n; i++) {
		if (i >= left_limit && i <= right_limit)
			count++;
	}

	cout << count << endl;
				   
	return 0;
}


Measured memory_bytes: 1276
#include<stdio.h>
int main(void)
{
	int a,r,t,kei=0,min=100,i;
	for(i=0; i<4; i++)
	{
		scanf("%d", &a);
		kei+=a;
		if(min>a)
		min=a;
	}
	kei-=min;
	scanf("%d %d", &r, &t);
	if(r<t)
	r=t;
	kei+=r;
	printf("%d\n", kei);
	
	return 0;
}


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

int main(){
	int n,A=0,B=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(i%2==0) A+=a[n-i-1];
		else B+=a[n-i-1];
	}
	cout<<A-B;
	return 0;
}


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

int main(){
	int n, x;
	while (1){
		int count = 0;
		cin >> n >> x;
		if (n == 0 && x == 0) break;
		for (int i = 1; i <= n; i++){
			for (int j = i+1; j <= n; j++){
				for (int k = j+1; k <= n; k++){
						if (i + j + k == x){
							//cout << i << " " << j << " " << k << endl;
							count++;
					}
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
def main():
    a = int(input()) # 500
    b = int(input()) # 100
    c = int(input()) #  50
    x = int(input())

    ans = 0
    kmax = c * 50

    for i in range(a+1):
        I = i*500
        if I > x:
            break
        for j in range(b+1):
            IJ = I + j*100
            if IJ > x:
                break
            if x <= IJ + kmax:
                ans +=1

    print(ans)

if __name__ == '__main__':
    main()


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

template <class T>
class SegmentTree {
    public:
        int N;
        vector<T> dat;
        T def;
        std::function<T(T, T)> operation;

        SegmentTree(int _n, T _def=1001001001, function<T(T, T)> _operation=[](T a, T b){return min(a, b);});
        T query(int a, int b, int k=0, int l=0, int r=-1);
        void update(int k, T a);
};

template <class T>
SegmentTree<T>::SegmentTree(int _n, T _def, function<T(T, T)> _operation):
    def(_def), operation(_operation) {
    N = 1;
    while (N < _n) N *= 2;
    dat = vector<T>(2*N-1, def);
}

template <class T>
T SegmentTree<T>::query(int a, int b, int k, int l, int r) {
    if (r < 0) r = N;

    if (r <= a || b <= l) return def;
    if (a <= l && r <= b) return dat[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return operation(vl, vr);
}

template <class T>
void SegmentTree<T>::update(int k, T a) {
    k += N - 1;
    dat[k] = a;

    while (0 < k) {
        k = (k - 1) / 2;
        dat[k] = operation(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
}

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

    vector<int> c(N);
    for (auto &i : c) cin >> i, i--;

    vector<tuple<int, int, int>> q(Q);
    rep(i, Q) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        q[i] = make_tuple(i, l, r);
    }
    sort(q.begin(), q.end(), [](auto a, auto b){return get<2>(a) < get<2>(b);});

    // v[i] := 最も右にある色 i の玉のインデックス
    vector<int> v(N, -1);

    SegmentTree<int> st(N, 0, [](auto a, auto b){return a + b;});

    vector<int> ans(Q);
    int qi = 0;
    rep(i, N) {
        int color = c[i];

        st.update(v[color], 0);

        v[color] = i;

        st.update(v[color], 1);

        while (get<2>(q[qi]) < i) qi++;

        while (get<2>(q[qi]) == i) {
            int j = get<0>(q[qi]);
            int l = get<1>(q[qi]), r = get<2>(q[qi]) + 1;
            ans[j] = st.query(l, r);
            qi++;
        }
    }

    for (auto &i : ans) cout << i << endl;
}

Measured memory_bytes: 19556
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;
const double PI=3.14159265358979323846;

int main(){
  int N,K,S;
  cin>>N>>K>>S;
  vector<int>ans(N,S);
  int count = 0;
  for(int i = 0;i<N;i++){
    count++;
    if(count>K){
      ans.at(i)=1000000000;
      if(S==1000000000)ans.at(i)=1;
    }
  }
  for(int i = 0;i<N;i++){
    cout<<ans.at(i)<<" ";
  }

}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>

using namespace std;
using ll = long long;
const int BIG = 100000007;

set<ll> calcDivisors(ll l){
    ll k = sqrt(l);
    set<ll> divisors;
    for(ll i = 1;i <= k;++i){
        if(l % i == 0){
            divisors.insert(i);
            divisors.insert(l / i);
        }
    }
    return divisors;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> nums(n,0);
    vector<int> dupl(1000001,0);
    vector<bool> numExists(1000001,false);
    for(int i = 0;i < n;++i){
        cin >> nums[i];
        numExists[nums[i]] = true;
        ++dupl[nums[i]];
    }

    ll outc = 0;

    for(int i = 0;i < n;++i){
        if(dupl[nums[i]] > 1)continue;
        set<ll> divs = calcDivisors(nums[i]);
        bool flag = true;
        for(auto itr = divs.begin();itr != divs.end();++itr){
            if(*itr == nums[i])continue;
            if(numExists[*itr]){
                flag = false;
                break;
            }
        }
        if(flag)++outc;
    }

    cout << outc << endl;
}




Measured memory_bytes: 8364
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

P = [None] + P
C = [None] + C

all_max = C[1]
for st in range(1, N + 1):
    scores = []
    visit = set()
    p = st

    while p not in visit and len(visit) < K:
        next_p = P[p]
        scores.append(C[next_p])
        visit.add(p)
        p = next_p

    num_elem = len(scores)
    all_sum = sum(scores)

    q, r = divmod(K, num_elem)

    max_ = scores[0]
    temp = scores[0]

    max_r = scores[0]
    temp_r = scores[0]
    for x in range(1, num_elem):
        if x < r:
            temp_r += scores[x]
            max_r = max(max_r, temp_r)

        temp += scores[x]
        max_ = max(max_, temp)

    temp_max = scores[0]
    if all_sum > 0 and q > 0:
        if r > 0:
            temp_max = max(all_sum * (q - 1) + max_, all_sum * q + max_r)
        else:
            temp_max = all_sum * (q - 1) + max_
    else:
        temp_max = max_

    all_max = max(all_max, temp_max)


print(all_max)


Measured memory_bytes: 143144
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <list>

using namespace std;

//#define EPS (1e-10)
//
//struct Point{
//    Point(double _x = 0, double _y = 0){
//        x = _x;
//        y = _y;
//    }
//    double x;
//    double y;
//
//    Point operator + (Point p){
//        return Point(x + p.x, y+ p.y);
//    }
//
//    Point operator - (Point p){
//        return Point(x - p.x, y - p.y);
//    }
//
//    Point operator * (double a){
//        return Point(a * x, a * y);
//    }
//
//    Point operator / (double a){
//        return Point(x / a, y / a);
//    }
//
//    double abs(){
//        return sqrt(norm());
//    }
//
//    double norm(){
//        return x * x + y * y;
//    }
//
//    bool operator < (const Point &p) const{
//        return x!=p.x ? x < p.x : y < p.y;
//    }
//
//    bool operator == (const Point &p) const{
//        return fabs(x - p.x) && fabs(y - p.y) < EPS;
//    }
//
//};
//
//typedef Point Vector;
//
//double dot(Vector a, Vector b){
//    return a.x * b.x + a.y * b.y;
//}

int main() {


    int count = 0;
    string str;cin >> str;

    for(int i=0;i<3;i++){
        if(str[i]=='1'){
            count++;
        }
    }

    printf("%d\n",count);

    return 0;

}

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

using namespace std;

int32_t main()
{
  string A, B;
  cin >> A;
  cin >> B;

  if (A.size() > B.size()) {
    cout << "GREATER" << endl;
    return 0;
  } else if (A.size() < B.size()) {
    cout << "LESS" << endl;
    return 0;
  } else {
    for (uint32_t i = 0; i < A.size(); i++) {
      if (A[i] > B[i]) {
        cout << "GREATER" << endl;
        return 0;
      } else if (A[i] < B[i]) {
        cout << "LESS" << endl;
        return 0;
      }
    }
    cout << "EQUAL" << endl;
    return 0;
  }
}


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

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  long long a = 0;
  for(int i = 0; i < n; ++i){
    cin >> l[i];
    if(i % 2 & 1) a -= l[i];
    else a += l[i];
  }
  vector<long long> ans(n);
  ans[0] = a / 2;
  for(int i = 1; i < n; ++i){
    ans[i] = l[i - 1] - ans[i - 1];
  }
  for(int i = 0; i < n; ++i){
    cout << (i ? " " : "" ) << ans[i] * 2;
  }
  cout << endl;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main()
{
int cou = 0;
int n;
cin >> n;
int a=1; int b=1; 
while(1){
if(a>n){break;}
int b=1;
while(1){
  if(n>a*b){
  cou++;
           }
else if(n<=a*b){break;}
b++;
        }
a++;
}

cout << cou << endl;
 
 
}

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

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = scanner.nextInt();
        int[] arr = new int[n-1];
        for(int i = 0; i< n-1; i++) arr[i] = scanner.nextInt();
        int sum = arr[0] + arr[n-2];
        for(int i = 1; i < n-1; i++) {
            sum += Math.min(arr[i], arr[i-1]);
        }
        out.println(sum);
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
#include <queue>

using namespace std;

typedef long long ll;

int N, cnt[100005];
int main() {
  scanf("%d", &N);
  for (int i = 1;i <= N; i++) {
    int n;
    scanf("%d", &n);
    cnt[n]++;
  }
  int res = 0, evenCnt = 0;
  for (int i = 1; i <= 100000; i++) {
    if (cnt[i]) {
      res++;
      if (cnt[i] % 2 == 0) {
        evenCnt++;
      }
    }
  }
  printf("%d\n", res - (evenCnt % 2));
  return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, m;


int main() {
    cin >> n >> m;
    if(m==0)throw;
    if (n % 2 > 0) {
        rep(i, m) {
            cout << (i + 1) << " " << (2 * m - i) << endl;
        }
        return 0;
    } else {
        rep(i, m) {
            if (n - i - i - 1 <= n / 2) {
                cout << (i + 2) << " " << (n - i) << endl;
            } else {
                cout << (i + 1) << " " << (n - i) << endl;
            }
        }
    }


    return 0;
}

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

struct Card{char suit;int value;};

int main(int argc, const char * argv[]) {
    //read
    int n;
    cin>>n;
    Card C1[n],C2[n];
    
    
    for(int i=0;i<n;i++){
        cin>>C1[i].suit>>C1[i].value;
    }
    for(int i = 0;i<n;i++){
        C2[i] = C1[i];
    }
    
    //bubble sort
    bool flag = true;
    while(flag){
        flag = false;
        for(int i = n-1;i>0;i--){
            if(C1[i].value<C1[i-1].value){
                Card tmp = C1[i];
                C1[i]=C1[i-1];
                C1[i-1]=tmp;
                flag = true;
            }
        }
    }
    cout<<C1[0].suit<<C1[0].value;
    for(int i = 1;i<n;i++){
        cout<<' '<<C1[i].suit<<C1[i].value;
    }
    cout<<endl;
    cout<<"Stable"<<endl;
    
    //selection sort
    for(int i=0;i<n;i++){
        int minj = i;
        for(int j=i;j<n;j++){
            if(C2[j].value<C2[minj].value){
                minj = j;
            }
        }
        if(C2[i].value!=C2[minj].value){
            Card tmp = C2[i];
            C2[i]=C2[minj];
            C2[minj]=tmp;
        }
    }
    //output
    cout<<C2[0].suit<<C2[0].value;
    for(int i = 1;i<n;i++){
        cout<<' '<<C2[i].suit<<C2[i].value;
    }
    cout<<endl;
    
    //isStable
    string isStable = "Stable";
    for(int i = 0;i<n;i++){
        if((C1[i].suit==C2[i].suit)&&(C1[i].value==C2[i].value)){
            continue;
        }else{
            isStable = "Not stable";
            break;
        }
    }
    cout<<isStable<<endl;
}

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int main(){
    int n,m;
    cin>>n>>m;
    ll a[n];
    rep(i,n) cin>>a[i];

    ll sum[n+1];
    memset(sum,0,sizeof(sum));
    map<ll,ll> x;
    x[0]++;
    rep(i,n){
        sum[i+1]=sum[i]+a[i];
        x[sum[i+1]%m]++;
    }
    ll ans=0;
    for(auto it=x.begin();it!=x.end();++it){
        ans+=(it->second)*((it->second)-1)/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5760
# coding: utf-8
# Your code here!
import math

line=input().split(" ")
n=int(line[3])
r=int(line[0])
g=int(line[1])
b=int(line[2])
nline=sorted([r,g,b])
x=int(nline[2])
y=int(nline[1])
z=int(nline[0])

answers=0
#print(x,y,z,n)


for i in range(math.ceil(n/x)+1):
    a=i
    if z!=1:
        for j in range(math.ceil((n-a*x)/y)+1):
            b=j
            c=(n-a*x-b*y)/z
            if c>=0 and (n-a*x-b*y)%z==0:
                answers+=1
                #print(a,b,c)
    else:
        if n-a*x>=0:
            if n-a*x==0:
                answers+=1
                #print('a', 1)
            elif (n-a*x)%y!=0:
                answers+=math.ceil((n-a*x)/y)
                #print('b', math.ceil((n-a*x)/y))
            else:
                answers+=(math.ceil((n-a*x)/y)+1)
                #print('c', math.ceil((n-a*x)/y)+1)
            

print(answers)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int num = 1;
  int N, K;
  cin >> N >> K;
  while(N > 0)
  {
    int countUp = num;
    if(countUp > K)
    {
      countUp = K;
    }
    num += countUp;
    N--;
  }
  cout << num << endl;
}


Measured memory_bytes: 256
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string s;
  cin >> s;
  int ans = 700;
  for (auto &i : s) {
    if (i == 'o') ans += 100;
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3532