akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N),q,w;
  for(int i=0;i<N;i++)cin >> A[i];
  sort(A.begin(),A.end());
  for(int i=1;i<N-1;i++){
    if(A[i]>=0){
      q.push_back(A[0]); w.push_back(A[i]);
      A[0]-=A[i];
    }
    else{
      q.push_back(A[N-1]); w.push_back(A[i]);
      A[N-1]-=A[i];
    }
  }
  q.push_back(A[N-1]); w.push_back(A[0]);
  cout << A[N-1]-A[0] << endl;
  int s=q.size();
  for(int i=0;i<s;i++)cout << q[i] << " " << w[i] << endl;
}

Measured memory_bytes: 4460
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


signed main(){
    FAST;
    int n, x;
    cin>>n>>x;
    int a[n+1], s=0;
    a[0]=0;
    for(int i=1; i<=n; i++) {
        int k;
        cin>>k;
        s+=k;
        a[i]=s;
    }
    int c=0;
     for(int i=0; i<=n; i++) if(a[i]<=x) c++;
     cout<<(c==0 ? 1: c);
}



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

ll N, M, X;

ll dfs(ll deps, vector<ll> C, vector<vector<ll>> A, vector<ll> rikaido_now){
    ll ans = LLONG_MAX;
    if(deps > N) return -1;
    for(ll i = deps; i <= N; i++){
        bool check = true;
        vector<ll> rikaido = rikaido_now;
        for(ll j = 1; j <= M; j++){
            rikaido[j] += A[i][j];
            if(rikaido[j] < X){
                check = false;
            }
        }

        if(check){
            ans = min(ans, C[i]);
        }else{
            ll rec = dfs(i + 1, C, A, rikaido);
            if(rec != -1){
                ans = min(ans, C[i] + rec);
            }
        }
    }

    if(ans == LLONG_MAX){ ans = -1; }
    return ans;
}

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

    vector<ll> C(N+1);
    vector<vector<ll>> A(N+1, vector<ll>(M+1));
    for(ll i = 1; i <= N; i++){
        cin >> C[i];
        for(ll j = 1; j <= M; j++){
            cin >> A[i][j];
        }
    }

    vector<ll> rikaido(M+1, 0);
    cout << dfs(1, C, A, rikaido) << endl;
}

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

int main() {

	int n, m; cin >> n >> m;
	vector<ll> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	vector<ll> nextToPointMaxh(n, 0);
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		--a;
		--b;
		nextToPointMaxh[a] = max(nextToPointMaxh[a], h[b]);
		nextToPointMaxh[b] = max(nextToPointMaxh[b], h[a]);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (nextToPointMaxh[i] < h[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4804
package main
import (
  "fmt"
  "bufio"
  "strings"
  "os"
  "strconv"
  "sort"
)

func main() {
  sc.Buffer(make([]byte, 64*1024*1024), 64*1024*1024)

  N := nextInt()
  snd := nextLine()
  sndArray := strings.Split(snd, " ")
  A := make([]int, N)
  for i:= 0; i<N; i++ {
    A[i], _ = strconv.Atoi(sndArray[i])
  }
  sort.Ints(A)
  sum := 0
  last := 0
  for i:=0; i<N; i++ {
    if sum*2 < A[i] {
      last = i
    }
    sum += A[i]
  }
  fmt.Println(N-last)
}


var sc = bufio.NewScanner(os.Stdin)


func nextLine() string {
  sc.Scan()
  return sc.Text()
}

func nextInt() int {
  sc.Scan()
  i, err := strconv.Atoi(sc.Text())
  if err != nil {
    panic(err)
  }
  return i
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, l[1002], r[1002], sum=0;
    cin >> N;

    for(int i=0; i<N; i++){
        cin >> l[i] >> r[i];
        sum += r[i] - l[i] + 1;
    }
    cout << sum << endl;
}


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

int main(){
    long long int A,B,C,K;
    cin>>A>>B>>C>>K;
    if(K<A){
        cout<<K<<endl;
        return 0;
    }
    if(A+B>=K){
        cout<<A<<endl;
        return 0;
    }else{
        cout<<A-(K-(A+B))<<endl;
    }


}

Measured memory_bytes: 3636
n,m = map(int, input().split())
A = [[int(a) for a in input().split()] for _ in range(n)]
B = [int(input()) for _ in range(m)]

C = [0]*n
for i in range(n):
    for j in range(m):
        C[i] += A[i][j]*B[j]
        
for i in range(n):
    print(C[i])


Measured memory_bytes: 6024
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main() {
    int A, B, M;
    cin >> A >> B >> M;
    int a[100005], b[100005], x[100005], y[100005], c[100005];
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];
    rep(i, M) {
        cin >> x[i] >> y[i] >> c[i];
        x[i]--;
        y[i]--;
    }

    int mn_a = 100005, mn_b = 100005;
    rep(i, A) mn_a = min(mn_a, a[i]);
    rep(i, B) mn_b = min(mn_b, b[i]);
    int mn_cost = mn_a + mn_b;

    rep(i, M) {
        int cst = a[x[i]] + b[y[i]] - c[i];
        mn_cost = min(mn_cost, cst);
    }

    cout << mn_cost << endl;
    return 0;
}

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

inline long long read(){    //快读
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}
long long n, r, g, b;
unsigned long long ans; //usnigned 用不用好像都无所谓……
char s[4040];           //千万不能用string，不然会炸掉
int main(){
    n = read();
    for (int i = 1; i <= n; i++){
        s[i] = getchar();
        if (s[i] == 'R') r++;    //对r, g, b计算一个初始值，方便使用乘法原理
        if (s[i] == 'G') g++;
        if (s[i] == 'B') b++;
    }
    ans = r * g * b;  //乘法原理预处理ans，但多出来很多的不符合条件的答案
    int _n = (n - 3) >> 1;  //计算(n-3)/2
    for (int i = 0; i <= _n; i++){  //枚举两个字符之间的差
        for (int j = 1; j + 2 * i + 2 <= n; j++){  //枚举j的大小
            if (s[j] != s[j+i+1] && s[j] != s[j+i*2+2] && s[j+i+1] != s[j+i*2+2]){  //如果满足条件1，就将ans--
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
S = input()
T = input()
N = len(S)
x = 0
if S == T:
    print('Yes')
    exit()
while S != T:
    if x > N:
        print('No')
        exit()
    else:
        S = S[N - 1] + S
        S = S[0:N]
        x += 1
        if S == T:
            print('Yes')
            exit()


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

void printArray(int array[],int n){
	for(int i=0;i<n;i++){
		if(i>0) cout<<" ";
		cout << array[i];
	}
	cout << endl;
}

void insertionSort(int array[],int n){
	int tmp,j;
	for(int i=1;i<n;i++){
		tmp = array[i];
		for(j=i-1;j>=0 && array[j]>tmp;j--){
			array[j+1]=array[j];
		}
		array[j+1]=tmp;
		printArray(array,n);
	}
}

int main(){
	int array[1001];
	int n;
	cin >>n;
	for(int i=0;i<n;i++){
		cin >> array[i];
	}
	printArray(array,n);
	insertionSort(array,n);
	return 0;
}

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

double dp[3002][3002], p[3002];

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

	for(int i = 1; i <= n; ++i)
		cin >> p[i];

	dp[0][0] = 1;
	for(int pos = 1; pos <= n; ++pos) {
		for(int heads = 0; heads <= pos; ++heads) {
			dp[pos][heads] += dp[pos-1][heads-1] * p[pos];
			dp[pos][heads] += dp[pos-1][heads] * (1 - p[pos]);

			//cerr << pos << " " << heads << " -> " << dp[pos][heads] << endl;
		}
	}

	double ans = 0;
	for(int heads = 1; heads <= n; ++heads)
		if(heads > n - heads)
			ans += dp[n][heads];

	cout << setprecision(10) << ans << endl;
	return 0;
}


Measured memory_bytes: 68992
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<51)
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define all(c) (c).begin(),(c).end()
#define N 100500

int dp[N];
int n;
vi v(N);
int k;

int rec(int i)
{

    if(i>=n)
        return inf;
    if(i == n - 1)
        return 0;
    if(dp[i] == -1)
    {
        int ans = inf;
        for(int j = 1;j <=k;j++ )
            {ans = min(ans,abs(v[i+j]-v[i]) + rec(i+j));}
        dp[i] = ans;
        return ans;
    }
    else
        return dp[i];
}
int32_t main()
{                
    IOS;
    
   
    memset(dp,-1,sizeof(dp));
    cin>>n;
    cin>>k;
    v[n] = 1e9;
    v[n+1] = 1e9;
    for(int i = 1; i<= k;i++)
        v[n-1+i] = 1e9;
    for(int i = 0;i  < n;i++)
    {
        cin>>v[i];
    }
    cout<<rec(0);
    return 0;

}

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

int main() {
	ll N,r=0;
	string S;
	map<char,vector<int>> m;
	cin >> N >> S;

	m['R'] = vector<int>(N,0);
	m['G'] = vector<int>(N,0);
	m['B'] = vector<int>(N,0);

	rep(i,N) {
		m.at(S.at(N-1-i)).at(N-1-i) = 1;

		if(i != 0) {
			m['R'].at(N-1-i) += m.at('R').at(N-i);
			m['G'].at(N-1-i) += m.at('G').at(N-i);
			m['B'].at(N-1-i) += m.at('B').at(N-i);
		}
	}

	// rep(i,N)
	// 	cout << m.at('R').at

	rep(i,N)
		for(int j=i+1; j<N-1; ++j) {
			if(S.at(i) == S.at(j))
				continue;
			string t=""; t+=S.at(i); t+=S.at(j);
			char p;
			sort(t.begin(), t.end());

			if(t == "BG")
				p = 'R';
			else if(t == "BR")
				p = 'G';
			else
				p = 'B';

			r += m.at(p).at(j+1);
			
			if(j+(j-i)<N && S.at(j+(j-i)) == p)
				--r;
		}

	cout << r << endl;
}

Measured memory_bytes: 3704
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	ll k, a, b;
	scanf("%lld%lld%lld", &k, &a, &b);
	if (b - a <= 2 or k < a - 1) printf("%lld\n", k + 1);
	else {
		ll res = a;
		k -= a - 1;
		if (k % 2 == 1) ++res, --k;
		res += (b - a) * (k / 2);
		printf("%lld\n", res);
	}

	Please AC;
}


Measured memory_bytes: 504
#include <stdio.h>

#define SIZE 2000000

int main() {
  setvbuf(stdout, NULL, _IOFBF, 1000);
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp, n;
  char com[21], buf[20];
  buf[19]='\n';
  char *p,*c1,*c2;
  c1 = com+1;
  c2 = com+2;
  do {
    fgets(com, 20, stdin);
    if (*com == 'i') {
      n = 0;
      p = com+7;
      while (*p!='\n') {
        n = n*10+*p-'0';
        p++;
      }
      A[++H] = n;
      for (i=H; i>1 && A[i>>1]<A[i];i>>=1) {
        tmp = A[i>>1];
        A[i>>1] = A[i];
        A[i] = tmp;
      }

    } else if (*c1=='x') { // extract
      n = A[1];
      for (i=18; n>0; n/=10) buf[i--]=(n%10)+'0';
      fputs(buf+i+1, stdout);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i<<1;
        if (l < H && A[l] > A[i])        largest = l;
        else         largest = i;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (*c2!='d');
  return 0;
}


Measured memory_bytes: 5528
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io;
use std::str::FromStr;
use std::iter::FromIterator;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::mem::{replace, swap};


// abcde
fn read_string() -> String {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    line
}

// -3.2
fn read_as_primitive<T: FromStr>() -> T {
    let s = read_string();
    s.trim().parse().ok().expect("failed to parse input")
}

// 1 -3 0 999
fn read_as_collection<U: FromStr, T: FromIterator<U>>() -> T {
    let s = read_string();
    s.trim().split_whitespace().map(|s| s.parse().ok().expect("failed to parse")).collect()
}

// #.#.###..
fn read_as_chars<T: FromIterator<char>>() -> T {
    let s = read_string();
    s.trim().chars().collect()
}

// 1 abc
fn read_as_pair<T: FromStr, U: FromStr>() -> (T, U) {
    let s = read_string();
    let elems: Vec<_> = s.trim().split_whitespace().collect();
    (
        elems[0].parse().ok().expect("failed to parse"),
        elems[1].parse().ok().expect("failed to parse"),
    )
}

// 1.5 -2 abc
fn read_as_triple<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let s = read_string();
    let elems: Vec<_> = s.trim().split_whitespace().collect();
    (
        elems[0].parse().ok().expect("failed to parse"),
        elems[1].parse().ok().expect("failed to parse"),
        elems[2].parse().ok().expect("failed to parse"),
    )
}

fn collaz(x: i32) -> i32 {
    let ans = if x % 2 == 0 {x / 2} else {3 * x + 1};
    ans
}

fn main() {
    let s: i32 = read_as_primitive();
    let mut idx: usize = 1;
    let mut x: i32 = s;
    let mut bag: HashSet<i32> = HashSet::new();
    while !bag.contains(&x) {
        bag.insert(x);
        x = collaz(x);
        idx += 1;
    }
    println!("{}", idx)
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin  >> n >>k;
  int ans = 1;
  for(int i = 0;i<n;i++){
    if(ans <=k){
      ans *=2;
    }
    else{
      ans += k;
    }
  }
  cout << ans;
}

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

using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;

	int both_max = min(a, b);
	int both_min = max(a + b - n, 0);

	cout << both_max << " " << both_min << endl;

	return 0;
}


Measured memory_bytes: 256
n, _, w = map(int, input().split())
a = list(map(int, input().split()))
a = [w] + a
dp = [[0 for _ in range(2)] for _ in range(n+1)]
for i in range(n, 0, -1):
    dp[i][0] = abs(a[n] - a[i-1])
    dp[i][1] = abs(a[n] - a[i-1])
    for j in range(1, n-i+1):
        dp[i][0] = max(dp[i][0], dp[i+j][1])
        dp[i][1] = min(dp[i][1], dp[i+j][0])
print(dp[1][0])

Measured memory_bytes: 43500
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
char g[101][101];
int dp[101][101];
void solve(){
	string s = "";
	int n; 
	cin>>n; 
	if(n==0){
		cout<<0<<endl;
		return ;
	}
	while(n){
		if(n%2!=0){
			s+='1';
			n--;
		}
		else{
			s+='0';
		}
		n*=-1;
		n/=2;
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}

/*
5 5
#####
#.#.#
####.
#.#.#
###.#
*/




/// 1100111011
/// 0123456789
/// 00000000001


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

const int N = 100009;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;

int main() {
  int n;
  cin>>n;
  
  int dp[100009];
  rep(i,100009) dp[i]=i;
  rep(i,n+1){
    int c6=6;
    while(i+c6<=n){
      chmin(dp[i+c6],dp[i]+1);
      c6*=6;
    }
    int c9=9;
    while(i+c9<=n){
      chmin(dp[i+c9],dp[i]+1);
      c9*=9;
    }
  }
  
  //rep(i,n) cout<<i<<" "<<dp[i]<<endl;
  cout<<dp[n]<<endl;  
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(ll, n);
  vector<ll> transportation(5);
  rep(i, 5) cin >> transportation[i];
  vector<ll> population(6);
  population[0] = n;
  ll ans = 0;
  ll last_change = 0;
  while (population[5] < n) {
    ++ans;
    vector<ll> change(6);
    rep(i, 5) {
      ll c = min(transportation[i], population[i]);
      change[i] -= c;
      change[i + 1] += c;
    }
    rep(i, 6) population[i] += change[i];
    if (last_change > 0 && change[5] == last_change) {
      out(ans + (n - population[5] + last_change - 1) / last_change);
      return 0;
    }
    last_change = change[5];
  }
  out(ans);
}


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

using namespace std;
#define taskname "TEST"
#define pb	push_back
typedef long double ld;
typedef long long ll;
const int maxn = 1e2 + 5 + 5;
int n , a[maxn] , k;
const int mod = 1e9 + 7;
void add(int & x , int y)
{
    x += y;
    if(x >= mod)x -= mod;
    if(x < 0)x += mod;
}
int dp[2][(int)1e5 + 5];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r"))
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
    cin >> n >> k;
    for(int i = 1 ; i <= n ; ++i)cin >> a[i];
    bool bit = 0;
    dp[0][0] = 1;
    for(int i = 1 ; i <= k ; ++i)dp[0][i] = 1;
    for(int i = 1 ; i <= n ; ++i)
    {
        bit ^= 1;
        for(int j = 0 ; j <= k ; ++j)
        {
            dp[bit][j] = 0;
            add(dp[bit][j] , dp[bit ^ 1][j] - dp[bit ^ 1][max(j - a[i] - 1 , 0)]);
            if(j - a[i] <= 0)add(dp[bit][j],1);
            add(dp[bit][j],dp[bit][j-1]);
        }
    }
    int res = 0;
    add(res , dp[bit][k]-dp[bit][k-1]);
    cout << res;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define fr first
#define se second
#define ll long long
#define pb push_back
using namespace std;
 
const ll INF = 1e16 + 1;
const ll N = 2e3 + 5;			
const ll mod = 1e9 + 7;
const long double eps = 1E-7;
 
int res;
int main()
{
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	if ( a == 0 ){
		cout << 1 << endl;
	}
	if ( b == 0 ){
		cout << 2 << endl;
	}
	if ( c == 0 ){
		cout << 3 << endl;
	}
	if ( d == 0 ){
		cout << 4 << endl;
	}
	if ( e == 0 ){
		cout << 5 << endl;
	}
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, m;
  cin >> n >> m;
  for(int i = m, j = 0; i >= 1 && i > j; --i, ++j) {
    cout << j + 1 << ' ' << i + 1 << '\n';
  }
  for(int i = 2 * m, j = m + 1; i >= 1 && i > j; --i, ++j) {
    cout << j + 1 << ' ' << i + 1 << '\n'; 
  }
}

Measured memory_bytes: 3664
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main(){
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans = 1LL<<60;
    for(ll i = 0; i <= max(x,y); i++){
        ll xx = x-i;
        ll yy = y-i;
        ans = min(ans,c*2*i+max(0LL,xx)*a+max(0LL,yy)*b);
    }
    cout << ans << endl;
}

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

vector<vector<int>>memo{
	{ 1,0,1,0,1,1,1,1 },
	{ 1,0,1,1,0,1,1,1 },
	{ 1,0,1,1,1,0,1,1 },
	{ 1,0,1,1,1,1,0,1 },
	{ 1,0,1,1,1,1,1,0 },
	{ 0,1,1,0,1,1,1,1 },
	{ 0,1,1,1,0,1,1,1 },
	{ 0,1,1,1,1,0,1,1 },
	{ 0,1,1,1,1,1,0,1 },
	{ 0,1,1,1,1,1,1,0 },
};
int main() {
	string N;
	bool flag = false;
	while (cin >> N) {
		if (flag)cout << endl;
		flag = true;
		int num = 5 - N.size();
		for (int i = 0; i < num; ++i) {

			N.insert(N.begin(), '0');
		}
		vector<string>field(8, "     ");
		for (int i = 0; i < 5; ++i) {
			for (int j = 0; j < 8; ++j) {
				field[j][i] = j == 2 ? '=' : memo[N[i] - '0'][j] ? '*' : ' ';
			}
		}
		for (int i = 0; i < field.size(); ++i) {
			cout << field[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

vector<pair<int,int>> f(int n, vector<int> a, vector<int> b){
    vector<int> c(n+1,0),c1(n+1,0);
    for(int i=0;i<n;i++){
        c[a[i]]++;
        c[b[i]]++;
        c1[a[i]]++;
    }
    sort(full(a),[&c, &c1](const int& xx, const int& yy)->bool{
        return c[xx]>c[yy] || (c[xx]==c[yy] && c1[xx]>c1[yy]) || (c[xx]==c[yy] && c1[xx]==c1[yy] && xx<yy);
    });
    sort(full(b),[&c, &c1](const int& xx, const int& yy)->bool{
        return c[xx]>c[yy] || (c[xx]==c[yy] && c1[xx]>c1[yy]) || (c[xx]==c[yy] && c1[xx]==c1[yy] && xx<yy);
    });
    vector<pair<int,int>> ans(n,{0,0});
    queue<int> q;
    for(int i=0,j=0;i<n;i++){
        ans[i].first=a[i];
        while(j<n && a[i]==b[j]){
            q.push(b[j]);
            j++;
        }
        if(j<n){
            ans[i].second=b[j];
            j++;
        }
        else{
            ans[i].second=q.front();
            q.pop();
        }
    }
    return ans;
}

void solve(){
    int n;
    cin>>n;
    vector<int> a(n,0),b(n,0);
    vector<int> c(n+1,0);

    for(int i=0;i<n;i++){
        cin>>a[i];
        c[a[i]]++;
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        c[b[i]]++;
    }
    for(int i=0;i<n;i++){
        if(c[i]>n){
            cout<<"No\n";
            return;
        }
    }
    vector<pair<int,int>> ans=f(n,a,b);
    bool flag=true;
    for(int i=0;i<n;i++) if(ans[i].first==ans[i].second) flag=false;
    if(!flag){
        ans=f(n,b,a);
        for(int i=0;i<n;i++) swap(ans[i].first,ans[i].second);
    }
    flag=true;
    for(int i=0;i<n;i++) if(ans[i].first==ans[i].second) flag=false;

    if(!flag){
        cout<<"No\n";
        return;
    }
    cout<<"Yes\n";
    sort(full(ans),[](const pair<int,int>& a,const pair<int,int>& b) -> bool{
        return a.first<b.first;
    });
    for(int i=0;i<n;i++) cout<<ans[i].second<<(i+1<n?" ":"\n");
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    return 0;
}

Measured memory_bytes: 10748
/* Coached by Dukkha */
#include <stdio.h>
#include <stdlib.h>

#define M 100000

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

int main() {
	static int xx[M], gaps[M - 1];
	int n, m, i, moves;

	scanf("%d%d", &n, &m);
	for (i = 0; i < m; i++)
		scanf("%d", &xx[i]);
	qsort(xx, m, sizeof *xx, compare);
	for (i = 0; i < m - 1; i++)
		gaps[i] = xx[i + 1] - xx[i];
	qsort(gaps, m - 1, sizeof *gaps, compare);
	moves = 0;
	for (i = 0; i < (m - 1) - (n - 1); i++)
		moves += gaps[i];
	printf("%d\n", moves);
	return 0;
}


Measured memory_bytes: 1396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int h,w;
    cin>>h>>w;
    vector<string> a(h);
    for(int i=0;i<h;i++)cin>>a[i];
    vector<bool> hb(h),wb(w);
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]=='#'){
                hb[i]=true;
                wb[j]=true;
            }
        }
    }
    for(int i=0;i<h;i++){
        if(!hb[i])continue;
        for(int j=0;j<w;j++){
            if(!wb[j])continue;
            cout<<(a[i][j]);
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

n = int(input())
child_list = [[] for i in range(n)]

for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    child_list[a].append([b,i])

ans = [None]*(n-1)


def rec(node, parent_color_id):
    default_color_id = 1
    color_id = default_color_id

    for child_node, no in child_list[node]:
        if parent_color_id == color_id:
            color_id += 1
        ans[no] = color_id
        rec(child_node, color_id)
        color_id += 1


rec(0, 0)
print(max(ans))
print(*ans, sep="\n")


Measured memory_bytes: 70960
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>
 
using namespace std;
 
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 2000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;

int digit(ll n){
	int ans = 0;
	while(n>0){
		ans++;
		n/=10;
	}
	return ans;
}

int main(void){
	ll N;
	cin>>N;
	int ans = INF;
	repl(i,1,sqrt(N)+1){
		if(N%i==0){
			ans = min(ans,max(digit(i),digit(N/i)));
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <set>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;


int main() {
    ll N;
    cin >> N;
    vl A(N);
    map<ll, ll> a;
    ll sum = 0;
    for(ll i=0; i<N; i++){
        cin >> A.at(i);
        sum += A.at(i);
        a[A.at(i)] += 1;
    }

    ll Q;
    cin >> Q;
    ll b, c;
    ll tmp;
    for(ll i=0; i<Q; i++){
        cin >> b >> c;
        if(a.find(b) != a.end()) {
            tmp = a.at(b);
            sum -= b*a.at(b);
            a.at(b) = 0;
            a[c] += tmp;
            sum += c*tmp;
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 8588
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int I = N;
    int ans = 0;
    while(true){
      ans += N %10;
      N = N/10;
      if(N == 0){
        break;
      }
    }
    if(I %ans == 0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23380
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    vector<int> v(n, 0);
    int len = 0;
    for(int i=0; i<n; ++i){
        if(s[i] == 'R'){
            ++ len;
        }
        else{
            v[i-1] += (len + 1) / 2;
            v[i] += len / 2;
            len = 0;
        }
    }
    for(int i=n-1; i>=0; --i){
        if(s[i] == 'L'){
            ++ len;
        }
        else{
            v[i+1] += (len + 1) / 2;
            v[i] += len / 2;
            len = 0;
        }
    }

    cout << v[0];
    for(int i=1; i<n; ++i)
        cout << ' ' << v[i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  long X;
  cin >> N >> X;
  vector<int> M(N);
  long sum = 0;
  for (int i=0; i<N; i++){
    cin >> M[i];
    sum += M[i];
  }
  sort(M.begin(), M.end());
  int ans = N;
  ans += (X-sum)/M[0];
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N;
string str[100];
set<string> ss;

int main() {
	cin >> N;
	REP(i, N) cin >> str[i];
	
	bool ans = true;
	REP(i, N) {
		if (ss.find(str[i]) != ss.end()) ans = false;
		ss.insert(str[i]);
		if (i && str[i - 1].back() != str[i].front()) ans = false;
	}
	
	puts(ans ? "Yes": "No");
	
	return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 2968.cc: Non-trivial Common Divisor
 */

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

/* constant */

const int MAX_N = 1000;
const int MAX_P = 31700;

/* typedef */

typedef long long ll;
typedef vector<int> vi;

/* global variables */

bool primes[MAX_P + 1];
int as[MAX_N], pnums[MAX_P];

/* subroutines */

int gen_primes(int maxp, int pnums[]) {
  memset(primes, true, sizeof(primes));
  primes[0] = primes[1] = false;

  int p, pn = 0;
  for (p = 2; p * p <= maxp; p++)
    if (primes[p]) {
      pnums[pn++] = p;
      for (int q = p * p; q <= maxp; q += p) primes[q] = false;
    }
  for (; p <= maxp; p++)
    if (primes[p]) pnums[pn++] = p;
  return pn;
}

bool prime_decomp(int n, int pn, int pnums[], vi& pds) {
  pds.clear();

  for (int i = 0; i < pn; i++) {
    int pi = pnums[i];
    if (pi * pi > n) {
      if (n > 1) pds.push_back(n);
      return true;
    }

    if (n % pi == 0) {
      while (n % pi == 0) n /= pi;
      pds.push_back(pi);
    }
  }
  return false;
}

/* main */

int main() {
  int pn = gen_primes(MAX_P, pnums);

  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  ll maxsum = 0;
  for (int i = 0; i < n; i++)
    if (as[i] > 1) {
      vi pds;
      prime_decomp(as[i], pn, pnums, pds);
      //printf("pds=%lu\n", pds.size());

      for (vi::iterator vit = pds.begin(); vit != pds.end(); vit++) {
	int p = *vit;
	ll sum = as[i];
	for (int j = i + 1; j < n; j++)
	  if (as[j] % p == 0) sum += as[j];
	if (maxsum < sum) maxsum = sum;
      }
    }

  printf("%lld\n", maxsum);
  return 0;
}



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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int D = scan.nextInt();
        StringBuilder answer = new StringBuilder("Christmas");
        if (D < 25) {
            for (int i = D; i < 25; i++) {
                answer.append(" Eve");
            }
        }
        System.out.println(answer.toString());
    }
}


Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.FileReader;
import java.io.FileWriter;

import java.util.*;
import java.util.stream.LongStream;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /* 標準入力数値配列用 long */
    static long[] inputLongArr() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        long[] longarray = new long[strarray.length];
        for (int i = 0; i < longarray.length; i++) {
            longarray[i] = Long.parseLong(strarray[i]);
        }
        return longarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer 降順ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /*標準入力long*/
    static long inputLong() throws Exception {
        return Long.parseLong(br.readLine());
    }

    /*標準入力long*/
    static int inputInt() throws Exception {
        return Integer.parseInt(br.readLine());
    }




    public static void main(String[] args) throws Exception {
        // write your code here
        int [] abc = inputval();
        int cnt = 0;
        while(abc[0] != abc[1] || abc[1] != abc[2] ){
            if (abc[0] % 2== abc[1]%2 && abc[1]%2 == abc[2]%2){
                Arrays.sort(abc);
                cnt += (Math.abs(abc[2]-abc[0]) + Math.abs(abc[2]-abc[1]))/2;
                break;
            }else if(abc[0] % 2 == abc[1]%2 && abc[1]%2 != abc[2]%2){
                abc[0] += 1;
                abc[1] += 1;
                cnt += 1;
            }else if(abc[0] % 2 == abc[2]%2 && abc[1]%2 != abc[2]%2){
                abc[0] += 1;
                abc[2] += 1;
                cnt += 1;
            }else if(abc[1] % 2 == abc[2]%2 && abc[1]%2 != abc[0]%2){
                abc[1] += 1;
                abc[2] += 1;
                cnt += 1;
            }
        }
        System.out.println(cnt);

    }

}



Measured memory_bytes: 32508
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>

using namespace std;

int N,M;
string s;
int cum[2][1000005]; // I O

int main(){
  while(cin >> N, N){
    cin >> M >> s;
    memset(cum, 0, sizeof cum);
    cum[0][0] = (s[0]=='I');
    cum[0][1] = (s[1]=='I');
    cum[1][0] = (s[0]=='O');
    cum[1][1] = (s[1]=='O');
    for(int i=2;i<M;i++){
      cum[s[i]!='I'][i] = cum[s[i]!='I'][i-2]+1;
    }

    int res = 0;
    for(int i=1;i<M;i++) if(cum[0][i] >= N+1 && cum[1][i-1] >= N) res++;
    cout << res << endl;
  }
}

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

using namespace std;
using llint = long long;
using pint = pair<int,int>;

#define LOG(x) cout << "# " << #x <<" => "<< (x) <<endl

const int INF = 1<<28;
const llint LLINF = 1LL<<60;

int n, k, ans;

int main() {
    // Input
    cin >> n >> k;

    // Solve
    if (k == 1)
    {
        ans = 0;
    } else {
        ans = n-k;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=100005;
int pa[N],a[N],b[N],c[N],n,Q,c1,sz;
ll m;

int getpa(int x){
	return pa[x]==x?x:pa[x]=getpa(pa[x]);
}

int main(){
	read(n),read(m),read(Q);
	rep(i,1,n)pa[i]=i;
	rep(i,1,Q){
		read(a[i]),read(b[i]),read(c[i]);
		a[i]++,b[i]++;
		if(c[i])c1++;
		else pa[getpa(a[i])]=getpa(b[i]);
	}
	rep(i,1,Q)
		if(c[i]&&getpa(a[i])==getpa(b[i])){
			puts("No");
			return 0;
		}
	if(m==n-1&&c1){
		puts("No");
		return 0;
	}
	rep(i,1,n)if(pa[i]==i)++sz;
	if(sz==2){
		puts(m==n-1&&!c1?"Yes":"No");
		return 0;
	}
	if(m<=n+(ll)sz*(sz-3)/2)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
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(int argc, char const *argv[]) {
  int x, y; cin >> x >> y;
  for (int i = 0; i <= x; i++){
    int a = i * 2, b = (x - i) * 4;
    if(a+b==y){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i=0; i<N;++i) cin >> S[i];
    int a=0,b=0,c=0,d=0;
    for (int i=0; i<N;++i) {
        if (S[i]=="AC") a++;
        else if (S[i]=="WA") b++;
        else if (S[i]=="TLE") c++;
        else if (S[i]=="RE") d++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;
}

Measured memory_bytes: 6420
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 18500000
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main()
{
    RUN_FAST; cin.tie(nullptr);
    int n, sum=0, tmp;
    cin >> n;
    tmp=n;
    while (n) {
        sum+=n%10;
        n/=10;
    }
    if (tmp%sum) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

int main()
{
	bool num[1000000] ;
	for( int i = 0 ; i < 1000000 ; i ++ )
	{
		num[i] = false ;
	}

	int count = 0 ;
	int get ;
	while( cin >> get )
	{
		for( int i = 2 ; i <= get ; i ++ )
		{
			if( num[i] == false )
			{
				for( int j = 1 ; j < (get/i) ; j ++ )
				{
					num[i+(j*i)] = true ;
				}

				count ++ ;
			}
		}
		cout << count << endl ;
		count =  0 ;

		for( int i = 0 ; i < get ; i ++ )
		{
			num[i] = false ;
		}
	}

	return 0 ;
}

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

struct T{
    int loc;
    int l = -1,r = -1;
};
struct p{
    int id,x,y;
    bool operator<(const p&a)const{
        return id<a.id;
    }
};
bool lessx(const p&a,const p&b){
    return a.x<b.x;
}
bool lessy(const p&a,const p&b){
    return a.y<b.y;
}

struct kDtree{
    vector<T> Tree;
    vector<p> P;
    vector<p> ans;
    int n_;
    int np = 0;
    kDtree(int n):Tree(n),P(n){
        n_ = n;
    }
    void init(){
        rep(i,n_){
            P[i].id = i;
            cin>>P[i].x>>P[i].y;
        }
    }
    int make_tree(int l,int r,int depth = 0){
        if(!(l<r))return -1;
        if(depth % 2 == 0){
            sort(P.begin()+l,P.begin()+r,lessx);
        }else{
            sort(P.begin()+l,P.begin()+r,lessy);
        }
        int t = np++;
        int mid = (l+r)/2;
        Tree[t].loc = mid;
        Tree[t].l = make_tree(l,mid,depth+1);
        Tree[t].r = make_tree(mid+1,r,depth+1);
        return t;
    }
    void find(int v,int ax,int bx,int ay,int by,int depth = 0){
        int x = P[Tree[v].loc].x;
        int y = P[Tree[v].loc].y;
        if(ax<=x && x<=bx && ay<=y && y<=by){
            ans.push_back(P[Tree[v].loc]);
        }
        if(depth % 2 == 0){
            if(Tree[v].l != -1 && ax<=x){
                find(Tree[v].l,ax,bx,ay,by,depth+1);
            }
            if(Tree[v].r != -1 && x <= bx){
                find(Tree[v].r,ax,bx,ay,by,depth+1);
            }
        }else{
            if(Tree[v].l != -1 && ay<=y){
                find(Tree[v].l,ax,bx,ay,by,depth+1);
            }
            if(Tree[v].r != -1 && y <= by){
                find(Tree[v].r,ax,bx,ay,by,depth+1);
            }
        }
    }
    void solve(){
        init();
        make_tree(0,n_);
        int q;cin>>q;
        rep(i,q){
            int ax,bx,ay,by;cin>>ax>>bx>>ay>>by;
            find(0,ax,bx,ay,by);
            sort(ans.begin(),ans.end());
            for(int j=0;j<ans.size();j++){
                printf("%d\n",ans[j].id);
            }
            cout<<endl;
            ans.clear();
        }
    }
};

int main(){
    int n;cin>>n;
    kDtree t(n);
    t.solve();
    return 0;
}


Measured memory_bytes: 14076
#include <iostream>

using namespace std;

int main(void){
	
	int n,x;
	cin >> n;
	cin >> x;
	
	int i;
	int l[100];
	
	for(i = 0; i < n; ++i){
		cin >> l[i];
	}
	
	int d[100] = {};
	int cnt = 1;
	for(i = 1; i <= n; ++i){
		d[i] = d[i-1] + l[i-1];
		if(d[i] <= x){
			cnt++;
		}
	}
	
	printf("%d\n", cnt);
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int p;

ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = (ans * x) % p;
        x = (x * x) % p;
        y >>= 1;
    }
    return ans;
}

int main(void)
{
    int n;
    string s;
    int dp;
    ll ans = 0;
    map<ll, ll> count;

    cin >> n >> p >> s;

    vector<int> m(n + 1, 0), sum(n + 1, 0);

    if (10 % p == 0)
    {
        for (int i = 0; i < n; i++)
        {
            if ((s[i] - '0') % p == 0)
            {
                ans += i + 1;
            }
        }
    }
    else
    {
        for (int i = 0; i < n; i++)
        {
            m[i] = ((s[i] - '0') % p) * power(10, n - i - 1);
            m[i] %= p;
        }

        count[0]++;

        for (int i = n; i > 0; i--)
        {
            sum[i - 1] = sum[i] + m[i - 1];
            sum[i - 1] %= p;
            count[sum[i - 1]]++;
        }

        for (auto x : count)
        {
            ans += x.second * (x.second - 1) / 2;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 2564