akhauriyash/Code-Regression huggingface dataset:
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll a,b,c,k;
            cin>>a>>b>>c>>k;
            ll ans=0;
            ans=ans+min(k,a);
            k=k-min(k,a);
            if(k==0)
                goto end;
            k=k-min(k,b);
            if(k==0)
                goto end;
            ans=ans-k;
            end:
            cout<<ans<<endl;
        }
        return 0;
    }


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

int main(){
    //入力
    int d;
    cin>>d;
    vector<int> c;
    int all_c=0;
    int tmp;
    rep(i,26){
        cin>>tmp;
        c.push_back(tmp);
        all_c+=tmp;
    }
    vector<vector<int>> s(d, vector<int>(26));
    rep(i,d){
        rep(j,26){
            cin>>s.at(i).at(j);
        }
    }

    //初期化
    vector<int> last;
    rep(i,26){
        last.push_back(0);
    }

    //コンテスト入力
    int score=0;
    int complain;
    rep(i,d){
        //MAXのscoreを算出する
        int ans=0;

        //1-26のコンテストを開いたときのscoreから、最大のものを選択する
        int max_score=0;
        rep(n,26){
            score=0;

            complain=0;
            //不満を算出する
            rep(j,26){
                if(j!=n){
                    complain+=c[j]*(last[j]+1);
                }else{
                    last[j]=0;
                }
            }
            score = score + s[i][n] - complain;
            // cout<<n<<":"<<score<<endl;
            if(score>max_score){
                max_score=score;
                ans = n+1;
            }
        }
        cout<<ans<<endl;
        //lastの計算確定
        rep(j,26){
            if(j!=(ans-1)){
                last[j]+=1;
            }else{
                last[j]=0;
            }
        }
    }


   return 0;

}


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

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

	int n; cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < n; ++i)
		cin >> b[i];
	reverse(b.begin(), b.end());
	int start = -1, fin = -1;
	for (int i = 0; i < n; ++i) {
		if (a[i] == b[i]) {
			if (start == -1) start = i;
			fin = i;
		}
	}
	bool bad = 0;
	if (start != -1) {
		for (int i = 0, j = start; j <= fin; ++i) {
			if (i == start) i = fin + 1;
			if (i >= n) {
				bad = 1;
				break;
			}
			if (a[i] != b[j] && b[j] != b[i]) {
				swap(b[i], b[j]);
				j++;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		if (a[i] == b[i]) bad = 1;
	}
	if (bad) {
		cout << "No" << '\n';
	} 
	else {
		cout << "Yes" << '\n';
		for (int i = 0; i < n; ++i) {
			if (i) cout << " ";
			cout << b[i];
		}
		cout << '\n';
	}

	return 0;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+50;
int gcd(int a,int b){
  return b==0?a:gcd(b,a%b);
}
char s[N],t[N];
int main(){
  int n,m; cin>>n>>m;
  scanf("%s%s",s+1,t+1);
  ll lcm=1ll*n*m/gcd(n,m);
  for (int i=1,j=1; i<=n; ++i){
    while(j<=m&&j*lcm/m<=(i-1)*lcm/n) ++j;
    if (j<=m&&(i-1)*lcm/n==(j-1)*lcm/m&&s[i]!=t[j])
      return puts("-1"),0;
  }
  cout<<lcm;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n; LL K,a[100],x,w;
int main(){
	scanf("%d",&n); K=n-1;
	for (int i=1;i<=n;++i) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	if (a[n]<=K) {puts("0"); return 0;}
	while (a[1]<K){
		a[n]-=n+1; --K; sort(a+1,a+n+1);
		if (a[n]<=K) {printf("%lld\n",-K-1+n); return 0;}
	}
	w=0;
	for (int i=1;i<=n;++i) w+=a[i]; w-=n*K;
	for (;;++w){
		x=0;
		for (int i=1;i<=n;++i) x+=(a[i]-K+w+n)/(n+1);
		if (x==w) {printf("%lld\n",w+n-1-K); return 0;}
	}
	return 0;
}

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v),v.end()));
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<string> v(n);
	REP(i, n)cin >> v[i];
	vi cnt(n, 0);
	REP(i, n) {
		REP(j, n) {
			if (v[i][j] == '#')cnt[i]++;
		}
	}


	vector<bool> bo(n, true);
	int flag = 0;
	REP(i, n)REP(j, n)if (v[i][j] == '#')flag = 1;
	REP(i, n) {
		REP(j, n) {
			if (v[j][i] == '#')bo[i] = false;
		}
	}
	int c = 0;
	REP(i, n) {
		int a = 0;
		REP(j, n) {
			if (v[j][i] == '#')a++;
		}
		if (a == n)c++;
	}
	if (flag == 0)cout << -1 << endl;
	else {
		int cmin = INF;
		REP(i, n) {
			cmin = min(cmin, n - cnt[i]+bo[i]);
		}
		cout << cmin + n - c << endl;
	}
	return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

MOD = 998244353

N = int(input())
S = np.array(list(input().rstrip()),dtype='U1')

counter = {x:0 for x in 'RGB'}
answer = 1
for s in S:
    counter[s] += 1
    x = counter[s]
    y,z = [counter[t] for t in 'RGB' if t != s]
    if y>z:
        y,z = z,y
    if y<x<=z:
        answer *= x*(x-y)*(z-x+1)
        answer %= MOD
print(answer)


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

using namespace std;


#define PI 3.14159265
#define int long long



main(){


	int n; cin >> n;

	string s; cin >> s;

	int ans = 0;

	for(int i = 0; i < n - 2; i++){
		if(s.substr(i, 3) == "ABC"){
			ans++;
		}
	}

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

Measured memory_bytes: 256
#include <stdio.h>
#include <inttypes.h>

int maaya = 0;
int sumipe[114514];

void asumisu(int pos) {
	for (;;) {
		int maxPos = pos;
		int i;
		for (i = 1; i <= 2; i++) {
			int cPos = pos * 2 + i;
			if (cPos < maaya && sumipe[maxPos] < sumipe[cPos]) maxPos = cPos;
		}
		if (maxPos == pos) {
			if (pos == 0) break;
			pos = (pos - 1) / 2;
		} else {
			int t = sumipe[pos];
			sumipe[pos] = sumipe[maxPos];
			sumipe[maxPos] = t;
			pos = maxPos;
		}
	}
}

void mizuhasu(int value) {
	sumipe[maaya++] = value;
	asumisu(maaya - 1);
}

int minorinn(void) {
	return maaya > 0;
}

int mamegu(void) {
	if (minorinn()) {
		int ret = sumipe[0];
		sumipe[0] = sumipe[--maaya];
		if (maaya > 0) asumisu(0);
		return ret;
	} else {
		return 0;
	}
}

int N, M;
int A[114514];

int main(void) {
	int i;
	int64_t hocchann;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &A[i]) != 1) return 1;
	}

	for (i = 0; i < N; i++) {
		mizuhasu(A[i]);
	}
	for (i = 0; i < M; i++) {
		int emirinn = mamegu();
		mizuhasu(emirinn >> 1);
	}
	for (hocchann = 0, i = 0; i < N; i++) {
		hocchann += mamegu();
	}
	printf("%" PRId64 "\n", hocchann);

	return 0;
}


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

int main() {
    string S;
    cin >> S;
    int half = S.size()/2;
    int ans =0;
    for(int i=0;i<half;i++){
        if(S[i] != S[S.size()-1-i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

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

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

void solve() {
    lli n, k;
    cin >> n >> k;
    lli ans = 0;
    for (int i = 0; i < n; ++i) {
        lli x;
        cin >> x;
        if (x >= k) ans++;
    }
    cout << ans << endl;
}

int main()
{
    IOS;
    //comment it out
    //freopen("input.txt", "r", stdin);
    lli t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O20")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = uint16_t; using ld = long double; using namespace std;

#ifndef __GNUC__
string text =
R"X(
8
7 3 5 4 2 1 6 8
3 8 2 5 4 6 7 1
)X";
stringstream iss{text};
#endif

class CountOrder
{
	ll N{0};
	vector<ll> p, q;
	void inp( ) {
		iss >> N; p.resize(N); q.resize(N);
		rep(n, N) { iss >> p[n]; }
		rep(n, N) { iss >> q[n]; }
		//for_each(begin(p), end(p), [](auto x) { cout << x << "\n"; });
	}
	void change( ) {
		long long sa{0};
		if (p > q) swap(p, q);
		do {
			if (p == q) break;
			++sa;
		} while (next_permutation(begin(p), end(p)));
		p(sa);
	}
public:
	void procedures( ) {
		inp( );
		change( );
	}
};
//https://atcoder.jp/contests/abc145/tasks/abc145_c
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	class CountOrder a; a.procedures( );
}

Measured memory_bytes: 3632
fn main(){
    let line = getline();
    let mut ans = 0;
    for c in line.trim().chars() {
        if (c == '+') {
            ans += 1;
        }
        else if (c == '-') {
            ans -= 1;
        }
    }
    println!("{}", ans);
}

fn getline() -> String{
    let mut r = String::new();
    std::io::stdin().read_line(&mut r).ok();
    return r;
}


Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<cmath>
#include<tuple>
#include<queue>
#include<algorithm>

int const MAXN = 50;
double const INF = 1e9;
double const eps = 5e-7;
int x[MAXN], y[MAXN], N;

double min_possible(double cx, double cy, double r) {
  double res = 0.0;
  for(int i = 0; i < N; ++i) {
    double dx = x[i] - cx, dy = y[i] - cy;
    dx = std::max(std::fabs(dx) - r, 0.0);
    dy = std::max(std::fabs(dy) - r, 0.0);
    res = std::max(res, dx*dx + dy*dy);
  }
  return std::sqrt(res);
}

double calc(double cx, double cy) {
  double res = 0.0;
  for(int i = 0; i < N; ++i) {
    double dx = x[i] - cx, dy = y[i] - cy;
    res = std::max(res, dx*dx + dy*dy);
  }
  return std::sqrt(res);
}

int main() {
  std::cin >> N;
  for(int i = 0; i < N; ++i) std::cin >> x[i] >> y[i];
  
  std::queue<std::tuple<double, double, double>> q;
  double ans = INF;
  q.emplace(500.0, 500.0, 500.0);
  while(q.size()>0) {
    double xx, yy, rr; 
    std::tie(xx, yy, rr) = q.front(); q.pop();
    double d = min_possible(xx, yy, rr);
    if(d >= ans - eps*std::max(d, 1.0)) continue; // cut-off no improve
    ans = std::min(ans, calc(xx, yy));
    for(double rx: {-0.5, 0.5}) for(double ry: {-0.5, 0.5}) {
      q.emplace(xx+rx*rr, yy+ry*rr, rr*0.5);
    }
  }
  std::cout << std::setprecision(10) << std::fixed << ans << std::endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>


typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

int main() {
	vector<ll> v;
	v.resize(10);
	for (ll i = 0; i < 10; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end(), greater<ll>());
	for (ll i = 0; i < 3; i++) {
		cout << v[i] << endl;
	}
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

const int mod=1e9+7;

int fact(int N){
    int res=1;
    for(int i=1;i<=N;i++) res=res*i%mod;
    return res;
}

signed main()
{
    int N,M; cin>>N>>M;
    int ans=0;
    if(abs(N-M)<=1){
        if(abs(N-M)==1) ans=fact(N)*fact(M)%mod;
        else ans=fact(N)*fact(M)*2%mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int GCD(int a, int b) {
    return (b > 0) ? GCD(b, a % b) : a;
}

ll LCM(ll a, ll b) {
    return a / GCD(a, b) * b;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)cin >> a[i];
    vector<int> l(n), r(n);
    l[0] = a[0];
    r[n-1] = a[n-1];
    for(int i = 1; i < n; i++){
        l[i] = GCD(l[i-1], a[i]);
    }
    for(int i = n - 2; i >= 0; i--){
        r[i] = GCD(r[i+1], a[i]);
    }
    int ans = 0;
    rep(i, n){
        if(i == 0)ans = max(r[i+1], ans);
        else if(i == n-1)ans = max(l[i-1], ans);
        else ans = max(ans, GCD(l[i-1], r[i+1]));
    }
    cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

signed main(){
    int N; cin >> N;
    vector<int> P(N), Q(N), R(N);
    rep(i,N) cin >> P[i];
    rep(i,N) cin >> Q[i];
    rep(i,N) R[i] = i+1;
    
    int i = 1, a = 0, b = 0;
    do{
        if(P==R) a = i;
        if(Q==R) b = i;
        i++;
    }while(next_permutation(ALL(R)));
    
    cout << abs(a-b) << endl;
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

typedef pair<string, int> P;

int main() {
	int N;
	cin >> N;
	vector <int> X(N, 0);
	int sum = 0;
	for (int ii = 0; ii < N; ++ii){
		cin >> X[ii];
		sum += X[ii];
	}

	int ave = sum / N;
	int hoge = ave + 1;
	int aho = ave - 1;
	int ans1 = 0;
	for (int ii = 0; ii < N; ++ii){
		ans1 += (X[ii] - ave) * (X[ii] - ave);
	}

	int ans2 = 0;
	for (int ii = 0; ii < N; ++ii){
		ans2 += (X[ii] - hoge) * (X[ii] - hoge);
	}

	int ans3 = 0;
	for (int ii = 0; ii < N; ++ii){
		ans3 += (X[ii] - aho) * (X[ii] - aho);
	}

	int ans = min(ans1, min(ans2, ans3));

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
from copy import deepcopy
 
def Partition(A, p, r):
    x = A[r][1]
    i = p-1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i+1
 
def Quicksort(A, p, r):
    if p < r:
        q = Partition(A, p, r)
        Quicksort(A, p, q-1)
        Quicksort(A, q+1, r)
 
 
n = int(input())
cards = []
for i in range(n):
    card = input().split()
    card[1] = int(card[1])
    cards.append(card)
prev_cards = deepcopy(cards)
prev_cards.sort(key=lambda card: card[1])
 
Quicksort(cards, 0, n-1)
 
if cards == prev_cards:
    print("Stable")
else:
    print("Not stable")
 
for card in cards:
    print(' '.join(map(str, card)))


Measured memory_bytes: 47452
from collections import defaultdict
INF = 10**9
while 1:
    N = int(input())
    if N == 0:
        break
    P = [list(map(int, input().split())) for i in range(N)]
    S = defaultdict(list)
    X = set()
    x0 = y0 = INF; x1 = y1 = -INF
    for i in range(4):
        x, y = map(int, input().split())
        x0 = min(x0, x); x1 = max(x1, x)
        y0 = min(y0, y); y1 = max(y1, y)
    S[y0] = [INF]; S[y1] = [INF]
    X.add(x0); X.add(x1)
    for x, y in P:
        S[y].append(x)
        X.add(x)
    xs = sorted(X)
    MP = {x: i for i, x in enumerate(xs)}
    L = len(xs)

    su = 0
    for i in range(N):
        xa, ya = P[i-1]
        xb, yb = P[i]
        su += xa*yb - ya*xb
    su = abs(su) // 2
    res = 0
    *ps, = S.items()
    ps.sort()
    mode = 0
    prv = -1
    U = [0]*L
    for y, vs in ps:
        if mode:
            px = 0; c = 0
            d = y - prv
            for i in range(L):
                if U[i]:
                    x = min(max(xs[i], x0), x1)
                    if c == 1:
                        res += d * (x - px)
                    c ^= 1
                    px = x
        for x in vs:
            if x == INF:
                mode ^= 1
            else:
                U[MP[x]] ^= 1
        prv = y
    print(su - res)


Measured memory_bytes: 6048
<?php
list($N, $X, $Y) = ints();
createG($N);
for($i = 1; $i <= $N-1; $i++)connect2($i, $i+1);
connect2($X, $Y);
$dMap = array_fill(1, $N-1, 0);
for($i = 1; $i <= $N; $i++)
  foreach(bfs($i) as $d)
    if(isset($dMap[$d]))
      $dMap[$d]+=0.5;

echo implode("\n", $dMap);

function connect2($a, $b){global $G;$G[$a][] = $b;$G[$b][] = $a;}
function connect($a, $b){global $G;$G[$a][] = $b;}
function createG($n){
  global $G, $distance;
  $distance = array_fill(1, $n, PHP_INT_MAX);
  return $G = array_fill(1, $n, []);
}
function bfs($current, $G = false){
  if($G === false)$G = $GLOBALS['G'];
  $distance = array_fill(1, count($G), PHP_INT_MAX);
  if(!is_array($current))$current = [$current];
  foreach($current as $c)$distance[$c] = 0;
  for($dist = 1; $current; $dist++){
    $nextArray = [];
    foreach($current as $c){
      foreach($G[$c] as $next){
        if($distance[$next] == PHP_INT_MAX){
          $distance[$next] = $dist;
          $nextArray[] = $next;
        }
      }
    }
    $current = $nextArray;
  }
  return $distance;
}

function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}


Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std; //std::の省略のため
using ll = long long;

int main(){

    int l,r,d;

    cin >> l >> r >> d;

    int count = 0;

    for(int i=l; i<=r; i++){
        if(i%d == 0) count++;
    }

    cout << count;

    return 0;
}

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

int N, s;

int main() {
	int sum = 0, min_not_10_multiple = 101;
	cin >> N;
	for(int i = 1; i <= N; i++){
		cin >> s;
		sum += s;
		if(s % 10 != 0 && s < min_not_10_multiple) min_not_10_multiple = s;
	}
	if(sum % 10 == 0 && min_not_10_multiple == 101) cout << 0 << endl;
	else if(sum % 10 == 0) cout << sum - min_not_10_multiple << endl;
	else cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <typeinfo>
#include <list>
#include <queue>
#include <stack>
#include <limits.h>
#include <unordered_set>
#include <map>
#include <cstring>

using namespace std;

int Compress(int v, vector<int>& f) {
    if (f[v] == v) {
        return v;
    }
    return f[v] = Compress(f[v], f);
}

void Solve(vector<pair<int, int> > A, long long N, int M) {
    vector<long long> ret(M);
    ret[M - 1] = N * (N - 1) / 2;
    vector<int> f(N + 1);
    vector<long long> record(N + 1, 1);
    for (int i = 0; i < N; i++) {
        f[i] = i;
    }
    for (int i = M - 1; i > 0; i--) {
        int l = Compress(A[i].first, f), r = Compress(A[i].second, f);
        if (l == r) {
            ret[i - 1] = ret[i];
        }
        else {
            f[l] = r;
            ret[i - 1] = ret[i] - record[l] * record[r];
            record[l] += record[r];
            record[r] = record[l];
        }
    }
    for (int i = 0; i < M; i++) {
        cout << ret[i] << endl;
    }
}


int main() {
    ios::sync_with_stdio(false);
    long long N;
    int M;
    cin >> N >> M;
    vector<pair<int, int> > A(M);
    for (int i = 0; i < M; i++) {
        int f, s;
        cin >> f >> s;
        A[i] = {f, s};
    }
    Solve(A, N, M);
    return 0;
}


Measured memory_bytes: 4864
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;


import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			long[] as = new long[N];
			for(int i = 0; i < N; i++) {
				as[i] = sc.nextLong();
			}
			
			long xor = 0;
			for(int i = 0; i < N; i++) { xor ^= as[i]; }
			
			for(int i = 0; i < N; i++) {
				System.out.print((i == 0 ? "" : " ") + (xor ^ as[i]));
			}
			System.out.println();
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 63080
N,M = (int(x) for x in input().split())
Lmax = 0
Rmin = N
for i in range(M):
  Li,Ri = (int(x) for x in input().split())
  if Lmax < Li:
    Lmax = Li
  if Rmin > Ri:
    Rmin = Ri
answer = Rmin - Lmax + 1
if answer < 0:
  answer = 0
print(answer)

Measured memory_bytes: 3188
#include <stdio.h>
int main(){

  int i,n,m,p,num[100],mon,sum;

  while(scanf("%d%d%d",&n,&m,&p),n){
    sum=0;

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

    if(num[m-1]==0)printf("0\n");
    else{

      mon = (double)(sum*100*(100-p)/100)/num[m-1];

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

    }
  }

  return 0;

}

Measured memory_bytes: 612
N = int(input())
H = list(map(int,input().split()))
max = 0
cnt = 0
for i in range(N-1):
    if H[i]>=H[i+1]:
        cnt += 1
    else:
        if max<cnt:
            max = cnt
        cnt = 0
if max<cnt:
    max = cnt
print(max)

Measured memory_bytes: 14224
//Kaori Miyazono, did I reach you ?
//"I can't die because... I have to protect you." -Asuna Yuuki
 
#include <bits/stdc++.h>
using namespace std;

int n, a, b;

int sumd(int k) {
	int ans = 0;
	while(k) {
		ans += k % 10;
		k /= 10;
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> a >> b;
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if (sumd(i) >= a && sumd(i) <= b) {
			ans += i;
		}	
	}
	cout << ans;
	return 0;
}







Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false); cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int kx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int ky[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int a[105][105];
int f[105][105];
int main() {
    IO;
 
    int x, y;
    cin >> x >> y;
    for (int i = 1; i <= 50; i++)
    for (int j = 1; j <= 100; j++) a[i][j] = 1;
    for (int i = 51; i <= 100; i++)
    for (int j = 1; j <= 100; j++) a[i][j] = 0;

    for (int i = 1; i <= 100; i++)
    for (int j = 1; j <= 100; j++) f[i][j] = 1;
    int cnt = 0;
    bool flag = 0;
    for (int i = 1; i <= 49; i++) {
        if (cnt == x - 1) break;
        if (flag) break;
        for (int j = 1; j <= 100; j++)
            if (f[i][j]) {
                a[i][j] = 0;
                cnt++;
                if (cnt == x - 1) {
                    flag = 1;
                    break;
                }
                for (int k = 0; k < 8; k++) {
                    int u = i + kx[k];
                    int v = j + ky[k];
                    if (u > 0 && v > 0) f[u][v] = 0;
                }
            }
    }
    cnt = 0;
    flag = 0;
    for (int i = 52; i <= 100; i++) {
        if (cnt == y - 1) break;
        if (flag) break;
        for (int j = 1; j <= 100; j++)
            if (f[i][j]) {
                a[i][j] = 1;
                cnt++;
                if (cnt == y - 1) {
                    flag = 1;
                    break;
                }
                for (int k = 0; k < 8; k++) {
                    int u = i + kx[k];
                    int v = j + ky[k];
                    if (u > 0 && v > 0) f[u][v] = 0;
                }
            }
    }
    cout << 100 << " " << 100 << "\n";
    for (int i = 1; i <= 100; i++) {
        for (int j = 1; j <= 100; j++)
            if (a[i][j] == 0) cout << "."; 
            else cout << "#";
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	int y = b - a;
	if (y > 0 && y > x)  cout << "dangerous";
	else if (y <= 0) cout << "delicious";
	else cout << "safe";
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
V = get_ints
C = get_ints

sum = 0
V.zip(C).each do |v, c|
  if v - c > 0
    sum += v - c
  end
end

puts sum


Measured memory_bytes: 14472
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<set>
#include<math.h>
using namespace std;

int N, M;
vector<pair<int, int> > AB;

int main(){
    cin >> N >> M;
    int tmpa, tmpb;
    auto p = make_pair(0, 0);

    for(int i = 0; i < N; i++){
        cin >> tmpa >> tmpb;
        p = make_pair(tmpa, tmpb);
        AB.push_back(p);
    }

    stable_sort(AB.begin(), AB.end());

    int count = 0;
    int ind = 0;
    long ans = 0;
    long num;

    while(count < M){
        num = min(AB[ind].second, M - count);
        count += num;
        ans += AB[ind].first * num;
        ind++;
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 1908
# 初期入力
import sys
input = sys.stdin.readline
A,B,C,K = list(map(int, input().split()))
a=1
b=0
c=-1
count =K
point =0
if A< K:
    point +=A
    count -=A
    K -=A
else:
    point +=K
    count =0
    print(point)
    exit()

if B < count:
    point +=0
    count -=B
    K -=B
else:
    point +=0
    count =0
    print(point)
    exit()    

if C <= count:
    point -=C
else:
    point -=count
    count =0
    
print(point)

Measured memory_bytes: 9220
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long Int;

int main() {
    Int n;
    scanf("%lld", &n);
    Int p = 1;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            p = i;
        }
    }
    Int q = n / p;
    printf("%lld\n", p + q - 2);
}


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if((a + b) > (c + d)){
    cout << "Left" << endl;
  }
  else if((a + b) == (c + d)){
    cout <<"Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
int N, M, K;
vector<int> A, B;
string S;
void input() {
  int i, j, k, x, y;
  ;
  cin >> S;
}
void solve() {
  int a = 0, b = 0, c = 0;
  for (auto x : S) {
    if (x == 'a')
      a++;
    else if (x == 'b')
      b++;
    else
      c++;
  };
  int mn = min({a, b, c});
  int mx = max({a, b, c});
  int md = a + b + c - mn - mx;

  bool ans = false;
  if (mx - mn <= 1) ans = true;
  cout << (ans ? "YES" : "NO") << endl;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include <utility>

using namespace std;

int main() {
	int N, M, L, R;
	int ans = 0;
	cin >> N >> M;

	int min, max;

	cin >> min >> max;

	for (auto i = 0; i < M-1; i++) {
		cin >> L >> R;

		if (R<min | L> max) {
			cout << 0 << endl;
			return 0;
		}

		if (min <= L && max >= R) {
			min = L;
			max = R;
		}
		else if (L < min && R >= min && R < max) {
			max = R;
		}
		else if (R > max && L <= max && L > min) {
			min = L;
		}
		else if (L<min && R>max) {
			
		}


	}

	ans = max - min + 1;


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

Measured memory_bytes: 256
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial, std.numeric;

void main(){
    auto nt=readln.split.map!(to!long).array;
    auto ts=readln.split.map!(to!long).array;
    auto T=nt[1];
    long last=0;
    long sum=0;
    foreach(t;ts){
        sum+=min(T,t-last);
        last=t;
    }
    sum+=T;
    writeln(sum);
}


Measured memory_bytes: 11096
from collections import deque,Counter
import itertools
h,w=map(int,input().split())
s=[]
for i in range(h):
    si=list(input())
    s.append(si)
bfs_res=0;
que=deque()
visited=[[-1]*w for i in range(h)]

visited[0][0]=0
que.append((0,0,0))
while que:
    y,x,d=que.popleft()
    for i,j in ([1,0],[-1,0],[0,1],[0,-1]):
        newy,newx=y+i,x+j
        if newy<0 or newx<0 or newy>=h or newx>=w:continue
        if s[newy][newx]=="." and visited[newy][newx]==-1:
            visited[newy][newx]=d+1
            que.append((newy,newx,d+1))
            
s=list(itertools.chain.from_iterable(s))
print(-1 if visited[-1][-1]==-1 else Counter(s)['.']-visited[-1][-1]-1)


Measured memory_bytes: 9548
#include<iostream>
#include<algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
	cin.sync_with_stdio(0); cin.tie(0); cout.tie(NULL);

	int l, r, d; cin >> l >> r >> d;
	int ans = 0;
	for (int i = l; i <= r; i++) {
		if (i % d == 0) {
			ans += 1;
		}
	}
	cout << ans << '\n';
	


}


Measured memory_bytes: 3192
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f

int main()
{
    ll n,k;
    scanf("%lld%lld",&n,&k);
    ll cnt=0;
    while(n)
    {
        n/=k;
        cnt++;
    }
    printf("%lld\n",cnt);
}


Measured memory_bytes: 256
#include "stdio.h"

void swap(int[],int,int);

int main(void)
{
	int height[10];
	int i,j;
	for(i=0;i<10;i++){
		scanf("%d",&height[i]);
	}

	for(i=0;i<10;i++){
		for(j=9;j>i;j--){
			if(height[j]>height[j-1]) swap(height,j,j-1);
		}
	}
	
	printf("%d\n",height[0]);
	printf("%d\n",height[1]);
	printf("%d\n",height[2]);

	return 0;
}

void swap(int array[],int l,int r){

	int t;
	t = array[l];
	array[l] = array[r];
	array[r] = t;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
string radixconvert(ll x, int radix)
{
    x = abs(x);
    ll r = 0, q = 0;
    string ans = "";
    while (x >= 1)
    {
        r = x / radix;
        q = x % radix;
        ans.push_back((char)(q + '0'));
        x = r;
    }
    reverse(all(ans));
    return ans;
}

ll convert(string s)
{
    int n = s.size();
    string str;
    int count = 0;
    rep(i, n)
    {
        switch (s[i])
        {
        case '1':
            str[i] = '3';
            break;
        case '2':
            str[i] = '5';
            break;
        case '3':
            str[i] = '7';
            break;
        default:

            break;
        }
    }
    return atoll(str.c_str());
}

bool ok(string s)
{
    int n3 = 0, n5 = 0, n7 = 0, n0 = 0;
    int n = s.size();
    rep(i, n)
    {
        if (s[i] == '1')
            n3++;
        if (s[i] == '2')
            n5++;
        if (s[i] == '3')
            n7++;
        if (s[i] == '0')
            return false;
    }
    return n3 > 0 and n5 > 0 and n7 > 0;
}
int main()
{
    ll N;
    cin >> N;

    ll ans = 0;
    string str = to_string(N);
    map<ll, bool> dup;

    for (int i = 27;; i++)
    {
        string str = radixconvert(i, 4);
        if (str == "123000")
        {
            int c = 0;
        }
        ll num = -1;
        if (ok(str))
        {
            num = convert(str);
        }
        else
        {
            continue;
        }
        if (ans > 26484)
        {
            int k = 0;
        }
        if (dup.count(num) == 1)
        {
            continue;
        }
        if (num <= N and num != -1)
        {
            ans++;
            dup[num] = true;
        }
        else
        {
            break;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1920
use std::io;

fn main() {

    let _n = get_num();
    let mut a = read_line();
    a.sort_by(|a, b| b.cmp(a));
    let a = a;

    let mut alice: i32 = 0;
    let mut bob = 0;

    for (index, card) in a.iter().enumerate() {
        if index % 2 == 0 {
            alice += *card;
        } else {
            bob += *card;
        }
    }

    println!("{}", alice - bob);
}

fn read_line() -> Vec<i32> {

    let input_str = get_input();
    let vec: Vec<&str> = input_str.trim().split_whitespace().collect();

    let mut int_vec: Vec<i32> = Vec::new();
    for v in vec {
        int_vec.push(to_i(v));
    }

    int_vec
}

fn get_num() -> i32 {
    to_i(&get_input())
}

fn to_i(s: &str) -> i32 {
    let input_num: i32 = match s.trim().parse() {
        Ok(num) => num ,
        Err(_)  => panic!("input wrong number."),
    };
    input_num
}

fn get_input() -> String {
    let mut input_str = String::new();
    io::stdin().read_line(&mut input_str)
        .expect("Failed to read line")
        ;
    input_str
}


Measured memory_bytes: 4352
#include<cstdio>
const int N = 1e5+5;
char s[N];

int main(){
	//wa, 边界条件没考虑
	int n,k;
	scanf("%d%d%s",&n,&k,s+1);
	int a = 0, b = 0, ans = 0;
	for(int i = 1; i <= n; i++){
		if(i!=1){
			if(s[i]=='L' && s[i-1]=='R'){ 
				a++;
				if(b && k){
					a--;
					b--;
					k--;
					ans += 2;
				}
			}
			if(s[i]=='R' && s[i-1]=='L'){ 
				b++;
				if(a && k){
					b--;
					a--;
					k--;
					ans += 2;
				}
			}
			if(s[i]==s[i-1]) ans++;
		}
	}
	if(s[1]=='L' && b && k) b--, k--, ans++;
	if(s[1]=='R' && a && k) a--, k--, ans++;
	if(s[n]=='R' && b && k) b--, k--, ans++;
	if(s[n]=='L' && a && k) a--, k--, ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<utility>
#include<vector>

using namespace std;

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

typedef long long int ll;

int main(){
  int n;
  ll T,t1,t2,sum;
  sum=0;
  scanf("%d %lld",&n,&T);
  scanf("%lld",&t2);
  FOR(i,1,n){
    scanf("%lld",&t1);
    if(t1-t2<T) sum = sum - (T-(t1-t2));
    t2 = t1;
  }
  printf("%lld", n*T+sum);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;


int main() {
    string S;
    cin >> S;
    int64_t ans = 0;
    for (int i = 0; i < S.size(); i++){
        ans+= S.at(i) - '0';
        ans %= 9;
    }
    if (ans == 0){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3748
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

a, b, c, d = na()

while a > 0 and c > 0:
    c -= b
    if c <= 0:
        break
    a -= d
    if a <= 0:
        break

if a <= 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9260
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

ll mod=1e9+7;

ll com(ll N, ll K, ll L) {
  ll d=1,e=(L*K)%mod, m_=mod-2;
  while(m_!=0) {
    if(m_&1) d=(d*e)%mod;
    e=e*e%mod;
    m_=m_ >> 1;
  }
  return (N*d)%mod;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k,ans=0;cin>>n>>k;
  lvector A(n,0),mf(n+1,0);
  rep(i,n) cin>>A[i];sort(ALL(A));mf[0]=1;
  for(ll i=1;i<=n;++i) mf[i]=(mf[i-1]*i)%mod;
  for(ll pos=0;pos<=n-k;++pos) ans=(ans-A[pos]*com(mf[n-1-pos],mf[k-1],mf[n-k-pos]))%mod;
  for(ll pos=k-1;pos<n;++pos) ans+=(A[pos]*com(mf[pos],mf[k-1],mf[pos+1-k]))%mod;
  ans%=mod;
  while(ans<0) ans+=mod;
  print(ans);
  return 0;
}

Measured memory_bytes: 1792
from sys import stdin
S = stdin.readline().rstrip()
zen, kou = int(S[:2]), int(S[2:])
if 13 <= zen <= 99 and 1 <= kou <= 12:
    print('YYMM')
elif zen == 0 and 1 <= kou <= 12:
    print('YYMM')
elif 1 <= zen <= 12 and 13 <= kou <= 99:
    print('MMYY')
elif 1 <= zen <= 12 and kou == 0:
    print('MMYY')
elif 1 <= zen <= 12 and 1 <= kou <= 12:
    print('AMBIGUOUS')
else:
    print('NA')


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

int main(){
	int n, x, cnt, l, s;
	cin >> n >> x;
	cnt = 1;
	s = 0;
	for(int i=0; i<n; i++){
		cin >> l;
		s += l;
		if(s <= x){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int n;
	scanf("%d",&n);
	if(n==17 || n==13 || n==10 || n==9 || n==6 || n==5 || n==3 || n==2 || n==1){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


void solve(long long N, std::vector<long long> A){
    map <int , int> m;
    REP(i, N)m[A[i]]++;
    LL cnt=0;
    REP(i, N){
        if(m[A[i]]!=0 && m[A[i]]%2==0)m[A[i]] = 2;
        if(m[A[i]]!=0 && m[A[i]]%2==1)m[A[i]] = 1;
    }
    REP(i,N){
        if(m[A[i]]==2){cnt++;m[A[i]]=0;}
    }
    if(cnt%2==1)cout<<m.size()-1<<endl;
    else cout<<m.size()<<endl;
}

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


Measured memory_bytes: 5760
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int n, m;
	cin >> n >> m;
	cout << (n - 1) * (m - 1);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define inf 0x7fffffff

using namespace std;

typedef long long ll;

struct Edge {
  int t,next;
  Edge() {}
  Edge(int a,int b):t(a),next(b) {}
};

Edge e[400005];
int head[200005];
bool num[200005];

int dep[200005],dep2[200005],dis[200005],size[200005];
bool in[200005];

void dfs1(int x,int fa) {
  size[x]=in[x]=num[x];
  dis[x]=(num[x])?0:inf;
  for(int i=head[x];i;i=e[i].next)
    if (e[i].t!=fa) {
    	int u=e[i].t;
    	dfs1(u,x);
    	in[x]|=in[u];
    	if (dep[u]+1>=dep[x]) {
    		dep2[x]=dep[x];dep[x]=dep[u]+1;
		}
		else dep2[x]=max(dep2[x],dep[u]+1);
    	if (in[u]) dis[x]=min(dis[x],dep[u]+1);
    	size[x]+=size[u];
	}
}

int up[200005],cnt;
ll ans;

void dfs2(int x,int fa) {
  ans+=max(min(dep[x],dep2[x]+2)-dis[x],0);
  int max1=up[x],max2=0;
  for(int i=head[x];i;i=e[i].next)
    if (e[i].t!=fa) {
    	int u=e[i].t;
    	if (dep[u]+1>=max1) {
    		max2=max1;max1=dep[u]+1;
		}
		else max2=max(max2,dep[u]+1);
	}
  for(int i=head[x];i;i=e[i].next)
    if (e[i].t!=fa) {
    	int u=e[i].t;
    	up[u]=(dep[u]+1==max1)?max2+1:max1+1;
    	if (up[u]>=dep[u]) {
    		dep2[u]=dep[u];dep[u]=up[u];
		}
		else dep2[u]=max(dep2[u],up[u]);
    	if (cnt-size[u]) dis[u]=min(dis[u],up[u]);
    	dfs2(u,x);
	}
}

char s[200005];

int main() {
  int n;
  scanf("%d",&n);
  for(int i=1;i<n;i++) {
  	int x,y;
  	scanf("%d%d",&x,&y);
  	e[2*i-1]=Edge(y,head[x]);
  	head[x]=2*i-1;
  	e[2*i]=Edge(x,head[y]);
  	head[y]=2*i;
  }
  scanf("%s",s+1);
  for(int i=1;i<=n;i++) {
  	num[i]=(s[i]=='1');
  	cnt+=num[i];
  }
  dfs1(1,0);
  dfs2(1,0);
  printf("%lld\n",ans+1);
  return 0; 
}

Measured memory_bytes: 18048
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,A,B,count,countB;
    cin>>N>>A>>B;
    count=countB=0;
    string S;
    cin>>S;
    for(int i=0;i<N;i++){
        if(S.at(i)=='a'){
            if(count<A+B){
                count++;
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
        }
        if(S.at(i)=='b'){
            if(count<A+B&&countB<B){
                count++;
                countB++;
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
        }
        if(S.at(i)=='c'){
            cout<<"No"<<endl;
        }
    }
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int mod = 998244353;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;

int main(){
	int n;
	scanf("%d",&n);
	ll ans = 0;
	for(int i = 1;i <= n;i++){
		if(i % 3 != 0 && i % 5 != 0){
			ans += i;
		}
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 3764