akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,sub;
  cin >> s;
  long long int sum = 0,si;
  int n = s.size(),m,kata;
  for(int i=0; i<s.size(); i++){
    for(int j=1; j<s.size()-i+1; j++){
      sub = s.substr(i,j);
      m = sub.size();
      //cout << sub << endl;
      si = stoll(sub);
      if(i!=0 && j!=n-i){
        kata = max(n-m-2,0);
      }else{
        kata = max(n-m-1,0);
      }
      sum += si*pow(2,kata);
    }
  }
  cout << sum << endl;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/e.in", "right", stdin);
//  freopen("../IO/e.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

constexpr int N = (int)2e5 + 105;
char s[N];
int n, k, c;

void solve(std::istream &in, std::ostream &out) {
  in >> n >> k >> c >> (s + 1);
  int index = 1;
  vector<int>l;
  while(l.size()<k){
    if(s[index]=='o'){
      l.push_back(index);
      index+=c+1;
    }else{
      index+=1;
    }
  }
  index=n;
  vector<int>r;
  while(r.size()<k){
    if(s[index]=='o'){
      r.push_back(index);
      index-=c+1;
    }else{
      index-=1;
    }
  }
  reverse(r.begin(),r.end());
  for(int i=0;i<k;++i){
    if(l[i]==r[i]){
      out<<l[i]<<'\n';
    }
  }
}



Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
int main(void){
    ll n,cnt = 0;
    cin >> n;
    vector<ll> a(n+10),b(n+10);
    for(ll i = 0;i <= n;i++) cin >> a[i];
    for(ll i = 0;i < n;i++) cin >> b[i];
    
    for(ll i = n-1;i >= 0;i--){
        if(a[i+1] < b[i]){
            cnt += a[i+1];
            b[i] -= a[i+1];
            a[i+1] = 0;   // 1回目
            
            if(a[i] > b[i]){
                cnt += b[i];
                a[i] -= b[i];
                //b[i] = 0;
            }else{
                cnt += a[i];
                a[i] = 0;
            }
        }else if(a[i+1] > b[i]){
            cnt += b[i];
            a[i+1] -= b[i];
            b[i] = 0;
        }else{
            cnt += a[i+1];
            a[i+1] = 0;
            b[i] = 0;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
ll i, j, k,ans;

int main(){
    scanf("%lld",&N);
    ans = 1e15;
    fornum(i,0,1000000){
        if(N%(i+1))
            continue;
        ans = min(ans,i + (N / (i + 1)) - 1);
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <boost/range/algorithm.hpp>
#include <boost/integer/common_factor_rt.hpp>

using namespace std;

int N, M;

int main() {

    while (cin >> N >> M) {
        int k[M];
        vector<vector<int>> s_v;
        for (int i = 0; i < M; i++) {
            cin >> k[i];
            int s[k[i]];
            for (int j = 0; j < k[i]; j++) {
                cin >> s[j];
            }
            s_v.push_back(vector<int> (s, s + k[i]));
        }
        int p[M];
        for (int i = 0; i < M; i++) {
            cin >> p[i];
        }

        int ret = 0;
        for (int i = 0; i < (1 << N); i++) {
            bool n[N];
            for (int j = 0; j < N; j++) {
                n[j] = i & (1 << j);               
            }
            int j;
            for (j = 0; j < M; j++) {
                int tmp = 0;
                for (int l = 0; l < k[j]; l++) {
                    if (n[s_v.at(j).at(l) - 1]) {
                        tmp++;
                    }
                }
                if (p[j] != tmp % 2) {
                    break;
                }
            }
            if (j == M) {
                ret++;
            }
        }
        cout << ret << endl;
    }

    return 0;
}


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

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

void solve() {
    int n;
    cin >> n;
    VI p(n), index(n);
    REP(i,0,n) {
        cin >> p[i];
        index[p[i] - 1] = i;
    }
    int ans = n;
    bool b = true;
    REP(i,0,n) {
        if (p[i] != i + 1) {
            b = false;
            break;
        }
    }
    /*
    REP(i,0,n) {
        cerr << i << " " << index[i] << endl;
    }
    */
    if (b || n == 1) {
        ans = 0;
    }
    VI dpf(n,1), dpb(n,1);
    REP(i,1,n) {
        if (index[i] > index[i-1]) dpf[i] = dpf[i-1] + 1;
    }
    //cerr << *max_element(all(dpf)) << endl;
    cout << n - *max_element(all(dpf)) << endl;
    // REP(i,0,n) cerr << dpf[i] << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 3328
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void){
	const int len = sizeof(char) * 20 * 3 * 100000;
	uint64_t M = 1000000007llu;
	char* buffer = malloc(len);
	fgets(buffer, len, stdin);
	const int N = atoi(buffer);
	fgets(buffer, len, stdin);
	char* p = 0;
	
	uint64_t* A_list = malloc(sizeof(uint64_t) * N);
	
	for(int i = 0; i < N; i ++){
		if(i == 0){
			p = strtok(buffer, " ");
		}else{
			p = strtok(0, " ");
		}
		A_list[i] = strtoull(p, 0, 10);
	}
//	for(int i = 0; i < N; i ++){
//		printf("%llu\n", A_list[i]);
//	}
	
	uint64_t* counts = malloc(sizeof(uint64_t) * N + 1);
	uint64_t total = 0;
	for(int i = 0; i < 60; i ++){
		counts[N] = 0;
		for(int j = N - 1; j >= 0; j --){
			counts[j] = counts[j + 1] + ((A_list[j] >> i) & 1);
		}
		uint64_t count = 0;
		for(int j = 0; j < N - 1; j ++){
			if(((A_list[j] >> i) & 1) == 1){
				count += N - j - counts[j];
			}else{
				count += counts[j];
			}
		}
//		printf("%llu\n", count);
		
		for(int j = 0; j < i; j ++){
			count = (count * 2) % M;
		}
		total = (total + count) % M;
//		total = (total + ((1llu << i) % M) * count) % M;
	}
	
	printf("%llu\n", total);
	
	return 0;
}


Measured memory_bytes: 10368
#include <stdio.h>

int main(void)
{
	int n,x,i,j,k,cnt;
	
	while(1)
	{
		cnt = 0;
		
		scanf("%d %d",&n,&x);
		if(n==0 && x==0)
			break;
			
		for(i=1;i<=n;i++)
		{	
			if(i >= x)
				break;
			
			for(j=i+1;j<=n;j++)
			{
				if(i+j >= x)
					break;
					
				for(k=j+1;k<=n;k++)
				{
					if(i+j+k == x)
						cnt++;
					else if(i+j+k >x)
						break;
				}
			}
		}
		printf("%d\n",cnt);	
	}
		
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

long long MOD = 1000000007;

void solve(long long N, vector<long long> C){
  vector<long long> C_;
  C_.push_back(C[0]);
  for (int i = 1; i < C.size(); i++) {
    if (C[i] != C[i-1]) {
      C_.push_back(C[i]);
    }
  }
  vector<long long> dp(C_.size(), 0);
  vector<long long> A(200000, 0);
  dp[0] = 1;
  A[C_[0]] = 1;
  for (int i = 1; i < C_.size(); i++) {
    dp[i] = dp[i-1];
    dp[i] += A[C_[i]];
    dp[i] %= MOD;
    A[C_[i]] += dp[i-1];
    A[C_[i]] %= MOD;
  }
  std::cout << dp[C_.size()-1] << std::endl;
}

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


Measured memory_bytes: 8176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  int x;
  cin >> a >> b;
  x = (a * b) % 2;
  if (x == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

static large solve(const string& s) {
    const auto n = int(s.length());

    auto positions = unordered_map<int, vector<int>>();
    auto m = vector<int>(n + 1);
    m[n] = 0;
    m[n - 1] = s[n - 1] - '0';
    positions[0].push_back(n);
    positions[m[n - 1]].push_back(n - 1);

    auto ten = 10;
    for (auto i = n - 2; i >= 0; --i, ten = ten * 10 % 2019) {
        auto digit = s[i] - '0';
        m[i] = (digit * ten + m[i + 1]) % 2019;
        positions[m[i]].push_back(i);
    }
  
    auto cnt = 0LL;
    for (auto&& [m, v] : positions) {
        if (v.size() <= 1)
            continue;
        cnt += large(v.size()) * (v.size() - 1) / 2;
    }
    return cnt;
}

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

    cout << solve(s) << endl;
    return 0;
}


Measured memory_bytes: 5640
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<functional>
using namespace std;
long long inf=1000000000000;
int main(){
  int n;
  long double a[55];
  cin >> n;
  int i;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  for(i=0;i<n-1;i++){
    sort(a,a+n);
    a[0]=(a[0]+a[1])/2;
    a[1]=inf;
  }
  cout << fixed << setprecision(6) << a[0];
  return(0);
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var array = Console.ReadLine().Split().Select(long.Parse).ToArray();

            var ret = 0L;

            for (var i = 0; i < N; i++)
                ret ^= array[i];

            if (ret == 0)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");

        }
    }
}


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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef gp_hash_table<int, null_type,hash<int>, equal_to<int>, direct_mask_range_hashing<int>, linear_probe_fn<>,
    hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>,true>> hash_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define MOD 998244353
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 3005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

const ld PI = (ld)4*atanl(1);

mt19937 g1(chrono::steady_clock::now().time_since_epoch().count());

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len,S,arr[MAXN];
ll dp[MAXN][MAXN],res;

int main(){
    scanf("%d %d",&len,&S);
    for(int i=1; i<=len; i++)
        scanf(" %d",&arr[i]);
    for(int i=1; i<=len; i++){
        dp[i][arr[i]] = i;
        for(int tot=0; tot<=S; tot++){
            if(tot <= arr[i]) dp[i][tot] = (dp[i][tot]+dp[i-1][tot])%MOD;
            else dp[i][tot] = (dp[i-1][tot]+dp[i-1][tot-arr[i]])%MOD;
        }
        if(arr[i] <= S) res = (res+dp[i-1][S-arr[i]]*(len-i+1))%MOD;
        if(arr[i] == S) res = (res+1LL*i*(len-i+1))%MOD;
    }
    printf("%lld\n",res);
}

Measured memory_bytes: 70656
#include<iostream>
using namespace std;
int main() {
	int n;
	int a[100];
	int end;
	cin >> n;
	if (n == 0) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0;i < 100;i++){
		if (n == 1) {
			a[i] = 1;
			end = i;
			break;
		}
		if (n%-2 != 0 &&
			n < 0) {
			n -= 1;
			a[i] = 1;
			n = n / -2;
		}
		else {
			a[i] = n%-2;
			n = n / -2;
		}
	}
	for (int i = end;i >= 0;i--) {
		cout << a[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
B = list(map(int, input().split()))
A = [B[0], B[0]]

for b in B[1:]:
    if A[-1] <= b:
        A += [b]
    else:
        A[-1] = b
        A += [b]
# print(f"A:{A}", file=sys.stderr)
print(sum(A))    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    ll x,a,b;
    cin>>x>>a>>b;
    if (b-a<=0)
        cout<<"delicious\n";
    else if (b-a<=x)
        cout<<"safe\n";
    else
        cout<<"dangerous\n";
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define dump(x)  cout << #x << " = " << (x) << endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

struct pair_hash {
    inline std::size_t operator()(const std::pair<int,int> & v) const {
        return v.first*31+v.second;
    }
};

ll d[102][102];
ll p[102][102];
bool visited[102][102];
unordered_set<pl,pair_hash> usedEdges;
void col(ll a, ll b){
    if(a == b) return;
    if(p[a][b] == -1){
        if(a < b) swap(a,b);
        usedEdges.insert({a,b});
    }
    else {
        if(!visited[a][p[a][b]])
            col(a,p[a][b]);
        if(!visited[p[a][b]][b])
            col(p[a][b],b);
    }
    visited[a][b] = true;
    visited[b][a] = true;
}

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

    ll n,m;
    cin >> n >> m;
    ll a,b,w;
    rp(i,m){
        cin >> a >> b >> w;
        d[a-1][b-1] = w;
        d[b-1][a-1] = w;
    }
    rp(i,n) rp(j,n) if(i != j && d[i][j] == 0) d[i][j] = INF;
    rp(i,n) rp(j,n) p[i][j] = -1;

    rp(i,n) rp(x,n) rp(y,n){
        if(d[x][i] + d[i][y] < d[x][y])
        {
            d[x][y] = d[x][i] + d[i][y];
            p[x][y] = i;
        }
    }
    rp(i,n) rp(j,n) col(i,j);

    cout <<m -usedEdges.size()<<"\n";
   return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

int main() { /* ここに書く */
  
  string S,T;
  
  cin >> S >> T;
  
  int N;
  N = T.size();
  N--;
  T.erase(N);
  
  if(S == T){
    cout << "Yes" <<endl;}
  
  else{
    cout << "No" << endl;}
}


Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):

    count = 0
    for i in range(N - 2):
        if S[i : i + 3] == "ABC":
            count += 1
    print(count)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == "__main__":
    main()


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


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

    int n, k, s;
    cin>>n>>k>>s;

    for (int i=0; i<k; i++) cout<<s<<" ";
    for (int i=k; i<n; i++) cout<<(s==1000000000 ? s-1 : s+1)<<" ";
}

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

int main(){
  int i,j,cnt=0;
  string s,t;
  cin>>s>>t;
  int n=s.size();
  char p;
  for(i=0;i<26;i++){
    p='A';
    for(j=0;j<n;j++){
      if(s[j]==(char)('a'+i)){
        if(p=='A')p=t[j];
        else if(p!=t[j]){
          cout<<"No";
          return 0;
        }
      }
    }
  }
  swap(s,t);
  for(i=0;i<26;i++){
    p='A';
    for(j=0;j<n;j++){
      if(s[j]==(char)('a'+i)){
        if(p=='A')p=t[j];
        else if(p!=t[j]){
          cout<<"No";
          return 0;
        }
      }
    }
  }
  cout<<"Yes";
}

Measured memory_bytes: 776
n,a,b = map(int,input().split())
mod = 10**9+7

def Cmod(n,k):
    X = 1
    Y = 1
    for i in range(k):
        X = X*(n-i)%mod
        Y = Y*(k-i)%mod
    Yn = pow(Y,mod-2,mod)
    return X*Yn%mod

print((pow(2,n,mod) - 1 - Cmod(n,a) - Cmod(n,b))%mod)


Measured memory_bytes: 3060
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

string s;
int zero;
int one;

signed main(){
    in(s);
    rep(i,s.size()){
        if(s[i]=='0') zero++;
        else one++;
    }
    out(min(zero,one)*2);

    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>

int n;
int L[2000];

/*
\sum_{i<j<k} I{Li + Lj > Lk} I{Li + Lk > Lj} I{Lj + Lk > Li}
*/

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

  std::sort(L, L+n);

  long long int sum = 0;
  for(int i = 0; i < n; i++){
    for(int j = i + 1; j < n; j++){
      int k0 = j+1;
      int k1 = std::lower_bound(L+k0, L+n, L[i]+L[j]) - L;
      sum += k1-k0+(k1 < n && L[k1] < L[i] + L[j]);
    }
  }
  printf("%lld\n",sum);

  return 0;
}


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

using namespace std;

int main () {
    
    int n, k;
    cin >> n >> k;
    vector<int> costs(n);
    for (int i = 0; i < n; ++i) {
        cin >> costs[i];
    }
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for (int i = 1; i < n; ++i) {
        for (int j = 1; j < k+1; ++j) {
            if (i-j >= 0) {
                dp[i] = min(dp[i], dp[i-j]+abs(costs[i]-costs[i-j]));
            }
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;


// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

class Main {
    public static void main(String args[] ) throws Exception {
       
        Scanner s = new Scanner(System.in);
        int n=s.nextInt();
      int m=s.nextInt();
      System.out.println((n*(n-1))/2+(m*(m-1))/2);
    

        // Write your code here

    }
}

Measured memory_bytes: 21716
use std::collections::HashMap;
fn main() {
    let n = read::<usize>();
    let a = read_vec::<i32>();
    let mut hs = HashMap::new();
    for i in 0..n {
        let count = hs.entry(&a[i]).or_insert(0);
        *count += 1;
    }

    let mut ans = 0;
    for &k in hs.keys() {
        let mut c = 0;
        if let Some(&c0) = hs.get(k) {
            c += c0;
        }
        let k1 = *k + 1;
        if let Some(&c1) = hs.get(&k1) {
            c += c1;
        }
        let k2 = *k - 1;
        if let Some(&c2) = hs.get(&k2) {
            c += c2;
        }
        ans = std::cmp::max(ans, c);
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 12540
import java.util.*;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int a = sc.nextInt();
    int count = 0;

    while (h > 0) {
        h = h-a;
        count++;
    }

    System.out.println(count);
  }
}


Measured memory_bytes: 22612
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007


int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	if(a == 1){
		if(b == 2) printf("3\n");
		else printf("2\n");
	}
	else if(a == 2){
		if(b == 1) printf("3\n");
		else printf("1\n");
	}
	else{
		if(b == 1) printf("2\n");
		else printf("1\n");
	}

	return 0;
}

Measured memory_bytes: 128
//Date of submission: 14-06-2020

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 1e5 + 5;
const double E= 1e-9;

//------------------------------------------------------------------------------

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x,y;
    cin>>x>>y;
    ll maxx=x*4;
    ll minn=x*2;
    if(y>=minn&&y<=maxx)
    {
        if(y%2==0)
        {
            cout<<"Yes\n";
            return 0;
        }
        else
        {
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}

//------------------------------------------------------------------------------


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

vector<ll> to[200010];
vector<ll> ans;

void dfs(int v, int p) {
  for (int u : to[v]) {
    if (u == p) { continue; }
    ans[u] += ans[v];
    dfs(u, v);
  }
}

int main(int argc, char** argv) {
  int N, Q;
  cin >> N >> Q;
  rep(i, N-1) {
    ll a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(N);
  rep(i, Q) {
    ll p, x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0, -1);

  rep(i, N) {
    cout << ans[i];
    if (i != N-1) {
      cout << " ";
    }
  }
  cout << endl;
}


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

int main()
{
  int n, m, i;
  cin >> n >> m;
  vector<int> x(n);
  for (i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    x[a - 1]++;
    x[b - 1]++;
  }
  for (i = 0; i < n; i++)
  {
    cout << x[i] << endl;
  }
}

Measured memory_bytes: 3600
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    A = list(map(int, input().split()))
    if sum(A[j]*B[j] for j in range(M)) + C > 0:
        ans += 1
print(ans)

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

using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll A[300001];
int main()
{
    ll n,k;
    cin>>n>>k;

    for(int i=0; i<n; i++)
        cin>>A[i];
    sort(A,A+n);
    ll ans=1,f=0;
    int l=0,r=n-1;
    if(k%2)
    {
        ans=A[r];
        r--;
        --k;
        if(ans<0)
            f=1;
    }
    while(k)
    {
        ll two=A[l]*A[l+1];
        ll one=A[r]*A[r-1];
        if(f)
        {
            if(two>=one)
            {
                ans=one%mod*ans%mod;
                r-=2;
            }
            else
            {
                ans=two%mod*ans%mod;
                l+=2;
            }
        }
        else
        {
            if(two<=one)
            {
                ans=one%mod*ans%mod;
                r-=2;
            }
            else
            {
                ans=two%mod*ans%mod;
                l+=2;
            }
        }
        k-=2;
    }
    cout<<(ans+mod)%mod<<endl;
    return 0;
}


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

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    cout << pow(n, 3) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}

const int INF = 100000; 

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

    if(x < 1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	long long int a,b,c,x,y,ans=0;
	cin>>a>>b>>c>>x>>y;
	if(a+b<2*c){
		cout<<a*x+b*y<<endl;
	}
	else if(x>y){
		if(a<2*c){
			cout<<a*(x-y)+2*c*y<<endl;
		}
		else{
			cout<<2*c*x<<endl;
		}
	}
	else{
		if(b<2*c){
			cout<<b*(y-x)+2*c*x<<endl;
		}
		else{
			cout<<2*c*y<<endl;
		}
	}
	return 0;
	
}

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

int main(){
  int x,y;
  cin>>x>>y;
  if(y%2!=0) cout<<"No"<<endl;
  else{
    y/=2;
    if(y-x>=0 && 2*x-y>=0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

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

int main() {
  int r,c, rs, tmp;
  cin >> r >> c;
  int cs[c];
  for(int i = 0; i <= c; i++) cs[i] = 0;
  for (int i = 0; i < r; i++)
  {
    rs = 0;
    for (int j = 0; j < c; j++)
    {
      cin >> tmp;
      cs[j]+= tmp;
      rs += tmp;
      cout << tmp << ' ';
    }
    cout << rs << endl;
    cs[c] += rs;
  }
  for(int i=0; i < c; i++) cout << cs[i] << ' ';
  cout << cs[c] << endl;
  
  return 0;
}


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

using namespace std;

const int MAXN = 1E5;
pair<int, int> pts[2 * MAXN];
pair<int, int> pos[MAXN];

bool onEdge(int x, int y, int r, int c)
{
    return x == 0 || y == 0 || x == r || y == c;
}

int convert(int x, int y, int r, int c)
{
    if (y == 0)
        return x;
    if (x == r)
        return x + y;
    if (y == c)
        return r + c + (r - x);
    return 2 * r + c + (c - y);
}

bool isGood(int s, int t)
{
    if (s > t)
        return true;
    int id = pts[s].second;
    if (pos[id].first != s)
        return false;
    if (pos[id].second > t)
        return false;
    int sec = pos[id].second;
    return isGood(s + 1, sec - 1) && isGood(sec + 1, t);
}

int main()
{
    int r, c, n;
    cin >> r >> c >> n;
    // m = num edge points
    int m = 0;
    for (int i = 0; i < n; i++)
    {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if (onEdge(x1, y1, r, c) && onEdge(x2, y2, r, c))
        {
            pts[m] = make_pair(convert(x1, y1, r, c), m / 2);
            pts[m + 1] = make_pair(convert(x2, y2, r, c), m / 2);
            m += 2;
        }
    }
    sort(pts, pts + m);
    fill(pos, pos + m / 2, make_pair(-1, -1));
    for (int i = 0; i < m; i++)
    {
        int ind = pts[i].second;
        if (pos[ind].first == -1)
            pos[ind].first = i;
        else
            pos[ind].second = i;
    }
    if (isGood(0, m - 1))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define ll long long  
#define pb push_back
#define mk make_pair
#define mod 998244353
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define all(x) x.begin(),x.end()
int main()
{
    ios::sync_with_stdio(0) ;
    cin.tie(0); 
    ll x;
    cin>>x;
    ll ans=0;
    ll u=x/500;
    ans=1000*u;
    x%=500;
    u=x/5;
    ans=ans+5*u;
    cout<<ans;
    return 0;
}
//make all values ll



Measured memory_bytes: 384
while line = gets
  n = line.chomp.to_i
  break if n == 0
  
  scores = []
  
  n.times do
    c1, m1, s1, m2, s2, m3, s3, m4, s4 = gets.chomp.split.map(&:to_i)
    scores << [c1, (m1 + m2 + m3 + m4) * 60 + s1 + s2 + s3 + s4]
  end

  scores.sort! do |a, b|
    a[1] <=> b[1]
  end

  puts scores[0][0]
  puts scores[1][0]
  puts scores[-2][0]
end

Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int main(){
  ll X,t;
  cin >> X >> t;
  if(X < t) cout << 0 << endl;
  else cout << X -t << endl;
  

 }

Measured memory_bytes: 256
s = input()

lst = [0,0,0]

for i in range(len(s)):
    if s[i]=="a":
        lst[0]=1
    if s[i]=="b":
        lst[1]=1
    if s[i]=="c":
        lst[2]=1
if lst[0]+lst[1]+lst[2]==3:
    print("Yes")
else: print("No")

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

int subr(string input){
	multiset<int> num;
	int count=0;
	string::iterator ita=input.begin();
	++ita;
	while(true){
		if(*ita==']'){
			//最終脱出
			int ret=0;
			multiset<int>::iterator itb=num.begin();
			for(int i=0;i<(count-1)/2+1;++i){
				ret+=*itb;
				++itb;
			}
			return ret;
		}
		if(*ita=='['){
			++ita;
			if(*ita=='['){
				//再帰呼
				string::iterator subbeg=ita;
				int leng=0,depth=1;
				string sub="[";
				do{
					sub.push_back(*ita);
					if(*ita=='[')++depth;
					if(*ita==']')--depth;
					++ita;
				}while(depth);
				num.insert(subr(sub));
				count++;
			}
			else{
				int tmp=0;
				do{
					tmp=tmp*10;
					tmp+=*ita-'0';
					++ita;
				}while(*ita!=']');
				num.insert((tmp-1)/2+1);
				++count;
				++ita;
			}
		}
	}
}

int main(){
	int n;
	string in;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>in;
		cout<<subr(in)<<endl;
	}
	return 0;
}

			

Measured memory_bytes: 1376
#include<bits/stdc++.h>
using namespace std;
#define int long long  
#define mod 1000000007
#define am 998244353
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
int abs(int a,int b){
 return max(a,b)-min(a,b);
}
int gcd(int a,int b){//最大公約数
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
}
int lcm(int a,int b){//最小公倍数
    return (a*b)/gcd(a,b);
}
signed main(){
// __builtin_ctz(N); Nを２で何回割り切れるかを返す
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    int c,d;
    int b[1000000];
    cin>>a;
    for(int i=0;i<a;i++) cin>>b[i];
    c=a-1,d=0;
    int q=0,w=0;
    int p=0,o=0;
    int h=0;
    if(a%2==1) h=1;
    while(true){
	p=0,o=0;
      
	if(q<w) q+=b[d],p=1;
	else w+=b[c],o=1;
	if(c==d) break;
	if(p){
	    d++;
	    if(h) if(d==((a+1)/2)-1) d++;
	}
	
	if(o){
	    c--;
	    if(h) if(c==((a+1)/2)-1) c--;
	}
	
    }
    if(h){
	if(q<w) q+=b[(a+1)/2-1];
	else w+=b[(a+1)/2-1];
    }
    
    
    /*  int y=q,u=w;
    while(true){
	if(abs(y,u)<abs(q,w)) break;
	y=q,u=w;
	if(q<w){
	    q+=b[c-1],w-=b[c-1],c++;
	}
	else{
	    w+=b[d+1],q-=b[d+1],d--;
	}
	
	}*/
    cout<<abs(q,w)<<"\n";
}


Measured memory_bytes: 3712
//134_c
#include <stdio.h>
typedef long long ll;
#define rep(i,a,b,c) for(ll i=(a);i<(b);i+=(c))

int main(void){
    ll N,F,S,Fi,Si;
    scanf("%lld",&N);
    ll a[N+5];
    scanf("%lld",&a[0]);
    scanf("%lld",&a[1]);
    if(a[0]>a[1]){
        F=a[0];Fi=0;
        S=a[1];Si=1;
    }else {
        F=a[1];Fi=1;
        S=a[0];Si=0;
    }
    rep(i,2,N,1){
        scanf("%lld",&a[i]);
        if(a[i]>F){
            S=F;Si=Fi;
            F=a[i];Fi=i;
        }else if(S<a[i]&&a[i]<=F){
            S=a[i];Si=i;
        }
    }
    rep(i,0,N,1){
        if(i==Fi){
            printf("%lld\n",S);
        }else{
            printf("%lld\n",F);
        }
    }
    return 0;
}

Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

set<int> cur;

set<int> hoge[2];

set<int> g[100005];

const int OK = 2000000;
const int NG = -1;

int dfs(int v, int from = -1){
  cur.insert(v);

  for(auto to : g[v]) if(to != from){
    int r = -1;
    if(cur.count(to) == 1) {
      r = to;
    }
    else {
      r = dfs(to, v);
    }
    if(r == OK){ return OK; }
    if(r > -1){
      hoge[0].insert(v);
      g[v].erase(to);
      g[to].erase(v);
      if(r == v) return OK;
      else return r;
    }
    if(r == NG) return NG;
  }
  return NG;
}

bool solve(){
  int n,m;
  cin>>n>>m;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].insert(b);
    g[b].insert(a);
  }

  int cnt = 0;
  rep(i,n){
    while(g[i].size() > 0) {
      cur.clear();
      int r = dfs(i);
      if(r == OK) {
        cnt++;
        swap(hoge[0], hoge[1]);
      }
      else {
        assert(r == NG);
        return false;
      }
    }
  }

  if(cnt == 2) {
    int xx = 0;
    for(auto x : hoge[0]) if(hoge[1].count(x) ==1 ) xx++;
    if(xx>=3) cnt++;
  }

  return cnt >= 3;
}

int main(){
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fill(a,v) memset(a,v,sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a,b) cout << a << " " << b << "\n"
#define d3(a,b,c) cout << a << " " << b << " " << c << "\n"
#define d4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
	fast;
	int x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	vi P(a) , Q(b) , R(c);
	f(i,0,a)	cin >> P[i];
	f(i,0,b)	cin >> Q[i];
	f(i,0,c)	cin >> R[i];
	sort(P.rbegin() , P.rend());
	sort(Q.rbegin() , Q.rend());
	sort(R.rbegin() , R.rend());

	vi F;
	f(i,0,x) F.pb(P[i]);
	f(i,0,y) F.pb(Q[i]);
	f(i,0,min(c , x + y)) F.pb(R[i]);

	sort(F.rbegin() , F.rend());
	int ans = 0;
	f(i,0,x+y)	ans += F[i];
	cout << ans;
}

Measured memory_bytes: 8688
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/



int main() {
int K,T;
cin>>K>>T;
pair<int,int> A[T];
int a;
rep3(i,T){
cin>>a;
A[i-1]=make_pair(a,i);
}
sort(A,A+T);
int pre=0,count=0;
rep(i,K){
    if(A[T-1].second==pre){
        if((T>=2)&&(A[T-2].first!=0)){
            pre=A[T-2].second;
            A[T-2]=make_pair(A[T-2].first-1,A[T-2].second);
            sort(A,A+T);
        }
        else{
            count++;
            pre=A[T-1].second;
            A[T-1]=make_pair(A[T-1].first-1,A[T-1].second);
            
        }
    }
    else{
        pre=A[T-1].second;
        A[T-1]=make_pair(A[T-1].first-1,A[T-1].second);
        sort(A,A+T);
        
    }

}
cout<<count<<endl;

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int N, M;
	cin >> N >> M;
	string A[50], B[50];
	rep(i, N) cin >> A[i];
	rep(i, M) cin >> B[i];

	int OK = 0;

	rep(i, N - M + 1) {
		rep(ii, N - M + 1) {
			int kariOK = 1;
			rep(j, M) {
				string kari = A[i + j].substr(ii, M);
				if (B[j] != kari) kariOK = 0;
			}

			if (kariOK) OK = 1;
		}
	}

	if (OK) co("Yes");
	else co("No");

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;register bool _=0;register T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){register bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;


int main(){
    
    int n;
    scan(n);
    for(int i= 1; i <= 9; i++){
        if(n % i == 0){
            int j = n/i;
            if(j <= 9){
                puts("Yes");
                return 0;
            }
        }
    }
    
    puts("No");
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  
  int n =S.size();
  int x = 999;
  for(int i=0;i<n-2;i++){
    int w = (S[i] - '0') * 100 + (S[i+1] - '0') * 10 + (S[i+2] - '0');
    x = min(x, abs(w-753));
  }
  
  cout << x;
  
  return 0;
}






Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int a,b,c;
inline void solve(){
  IN3(a,b,c);
  OUT(b-a==c-b?"YES":"NO");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] h = new long[n];
        
        for(int i = 0; i < n; i++){
            h[i] = sc.nextLong();
        }

        long res = 0;
        if(n<=k){
            System.out.println(0);
        }else {
            Arrays.sort(h);
            for(int i = 0; i < n-k; i++){
                res+=h[i];
            }
            System.out.println(res);
        }
    }
}

Measured memory_bytes: 81168
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ;i++)

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

int main() {
  string s,t;
  cin >> s >> t ;
  cout << t + s << endl;

  return 0;

}

Measured memory_bytes: 3600
from collections import defaultdict

n = int(input())
reds = [tuple(int(x) for x in input().split())for _ in range(n)]
blues = [tuple(int(x) for x in input().split())for _ in range(n)]

blue_dict = defaultdict(list)
for c, d in blues:
    for a, b in reds:
        if a < c and b < d:
            blue_dict[c, d].append((a, b))
for val in blue_dict.values():
    val.sort(key=lambda x:-x[1])

red_dict = {}
for blue, red_list in sorted(blue_dict.items(), key=lambda x:x[0][0]):
    for red in red_list:
        if red in red_dict:
            continue
        red_dict[red] = blue
        break

print(len(red_dict))

Measured memory_bytes: 3564