akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

int x;

void BubbleSort(int A[],int N){
  bool flag = true;
  while(flag){
    flag = false;

    for(int j = N-1; j>=1; j--){
      if(A[j]<A[j-1]){
        swap(A[j],A[j-1]);
        x++;
        flag = true;
      }
    }
  }
}

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

  int A[100];
  for(int i = 0; i<100; i++){
    cin >> A[i];
  }

  BubbleSort(A,N);

  for(int i = 0; i<N; i++){
    cout << A[i];
    if(i<N-1)
      cout << ' ';
    else
      cout << endl;
  }

  cout << x << endl;

  return 0;
}

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

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

    int n, m;
    cin >> n >> m;

    vector<vector<int>> s(m);
    vector<int> k(m);
    rep(i, m){
        cin >> k[i];
        vector<int> sk(k[i]);
        rep(j, k[i]) cin >> sk[j];

        s[i] = sk;
    }
    vector<int> p(m);
    rep(i, m) cin >> p[i];

    int res = 0;
    rep(i, 1<<n){
        vector<int> on(n, 0);
        rep(j, n){
            if(i & (1<<j)) on[j] = 1;
        }

        bool all_on = true;
        rep(j, m){
            int on_num = 0;
            rep(l, k[j]){
                if(on[s[j][l]-1]) ++on_num;
            }

            if(on_num%2 != p[j]) {
                all_on = false;
                break;
            }
        }
        
        if(all_on) ++res;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	vector<int> a(3);
	cin>>a[0]>>a[1]>>a[2];
	sort(ALL(a));
	cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
}

Measured memory_bytes: 3140
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

void dfs(vector<int> &exception, vector<vector<int>> &group, int curr) {
    exception[curr] = 1;
    for (auto next : group[curr]) {
        if (exception[next] == -1) {
            dfs(exception, group, next);
        }
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    int x, y, z;
    vector<int> exception(N + 1, -2);
    vector<vector<int>> group(N + 1);
    for (int i = 0; i < M; i++) {
        cin >> x >> y >> z;
        exception[x] = -1;
        exception[y] = -1;
        group[x].push_back(y);
        group[y].push_back(x);
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (exception[i] == -2)
            ans += 1;
        else if (exception[i] == -1) {
            ans += 1;
            dfs(exception, group, i);
        }
    }

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


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

int main()
{

        int N;
        cin >> N;

        set<long long> key;
        map<long long, long long> m;

        for (int i = 0; i < N; ++i) {

                long long x;
                cin >> x;
                key.insert(x);
                m[x] += 1;

        }

        long long ans = 0;
        for (auto k: key) {

                if (m[k] == k) {

                }
                else if (m[k] > k) {
                        ans += (m[k] - k);
                }
                else {
                        ans += m[k];
                }

        }
        cout << ans << endl;


}


Measured memory_bytes: 10752
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}//standard output
        static void myerr(Object t){System.err.println(t);}//standard error
        static String getStr(){return sc.next();}
        static int getInt(){return Integer.parseInt(getStr());}
        static long getLong(){return Long.parseLong(getStr());}
        static boolean hasNext(){return sc.hasNext();}
        static char[] mySplit(String str){return str.toCharArray();}
  		static ArrayList<HashSet> group = new ArrayList<HashSet>();
  		static void bfs(int index, Node[] list){
        	if(list[index].group != -1){
       			return;
  			}
    		group.add(new HashSet<Integer>());
  			ArrayDeque<Node> queue = new ArrayDeque<Node>();
          	queue.add(list[index]);
    		while(queue.size() > 0){
        		Node tmp = queue.pollFirst();
      			if(tmp.group != -1){
           			continue;
        		}
      			tmp.group = group.size() - 1;
              	HashSet<Integer> tmpSet = group.get(tmp.group);
              	tmpSet.add(tmp.index);
              	group.set(tmp.group,tmpSet);
        		for(int j = 0; j < tmp.friend.size(); j++){
          			queue.add(list[tmp.friend.get(j)]);
        		}
    		}
        }
        public static void main(String[] args){
          int N = getInt();
          int M = getInt();
          int K = getInt();
          int i;
          Node[] list = new Node[N];
          for(i = 0; i < N; i++){
            list[i] = new Node(i);
          }
          for(i = 0; i < M; i++){
            int mae = getInt() - 1;
            int ato = getInt() - 1;
            myerr(mae + " " + ato);
            list[mae].friend.add(ato);
            list[ato].friend.add(mae);
          }
          for(i = 0; i < N; i++){
            bfs(i,list);
          }
          int[] output = new int[N];
          for(i = 0; i < N; i++){
            HashSet<Integer> tmpSet = group.get(list[i].group);
            output[i] = tmpSet.size() - 1 - list[i].friend.size();
          }
          for(i = 0; i < K; i++){
            int ngMae = getInt() - 1;
            int ngAto = getInt() - 1;
            if(list[ngMae].group != list[ngAto].group){
              continue;
            }
            output[ngMae]--;
            output[ngAto]--;
          }
          for(i = 0; i < N; i++){
            myout(output[i]);
          }
        }
        //Method addition frame start
public static class Node{
  int index;
  ArrayList<Integer> friend = new ArrayList<Integer>();;
  int group = -1;
  public Node(int i){
    index = i;
  }
  int getFriendSize(){
    return friend.size();
  }
  int getGroup(){
    return group;
  }
}
        //Method addition frame end
}


Measured memory_bytes: 125960
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int N, K;
string S;

int main(void) {
    cin >> N >> K;
    cin >> S;

    VL seg;
    REP(i, N) {
        const char c = S[i];
        int cnt = 0;
        while (i < N && S[i] == c) {
            i++;
            cnt++;
        }
        i--;
        seg.EB(cnt);
    }

    LL ans = 0;

    //FORE(e, seg) cerr << e << " ";cerr<<endl;

    const int len = K * 2 + 1;
    LL sum = 0;
    LL normal = 0;
    REP(i, min<int>(seg.size(), len)) {
        sum += seg[i];
    }
    FOR(i, min<int>(seg.size(), len), seg.size()) {
        normal += seg[i] - 1;
    }

    ans = sum - 1 + normal;
    FOR(i, min<int>(seg.size(), len), seg.size()) {
        sum -= seg[i - len];
        sum += seg[i];
        normal += seg[i - len] - 1;
        normal -= seg[i] - 1;
        chmax(ans, sum - 1 + normal);
    }

    cout << ans << endl;
}


Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
long long N;
int main(){
	cin>>N;
	int l=1;int F=1;
	while(N/10!=0){++l;if(N%10!=9)F=0;N/=10;}
	cout<<(l-1)*9+N-1+F;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var input_num = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var stack = new Stack<int>();
            foreach (int num in input_num.Reverse())
            {
                stack.Push(num);
            }
            var i = 1;
            var count = 0;
            while (stack.Count > 0)
            {
                if(stack.Peek() == i) { count += 1; i += 1; };
                stack.Pop();
            }
            Console.WriteLine(count==0?-1:N-count);
        }

    }

}

Measured memory_bytes: 36164
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)


ll p10[]={1,10,100,1000,10000,100000};
ll a[1000000];
int main(){
	ll n,k;
	ll cnt=0;
	while(scanf("%lld%lld",&n,&k),k){
		cnt++;
		ll id=0;
		a[n]=cnt*p10[5]+id;
		while(1){
			id++;
			ll x[10]={};
			rep(i,0,k)x[n/p10[i]%10]++;
			ll m=0;
			for(int crr=0;crr<10;){
				if(x[crr]--)m=m*10+crr;
				else crr++;
			}
			ll M=0;
			rep(i,0,k)M=M*10+(m/p10[i]%10);
			if(a[M-m]/p10[5]==cnt){
				printf("%lld %lld %lld\n",a[M-m]%p10[5],M-m,id-a[M-m]%p10[5]);
				break;
			}else{
				a[M-m]=cnt*p10[5]+id;
			}
			n=M-m;
		}
	}
}


Measured memory_bytes: 2140
def cmb(n, r, mod):
  if ( r<0 or r>n ):
    return 0
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 2*10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
  g1.append( ( g1[-1] * i ) % mod )
  inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
  g2.append( (g2[-1] * inverse[-1]) % mod )
k = int(input())
s = str(input())
l = len(s)
ans = 0
def power(a,n):
  ans = 1
  while n:
    if n%2:
      ans = (ans*a)%mod
    a = (a*a)%mod
    n >>= 1
  return ans%mod  
y = 1
for i in range(l,l+k+1):
  x = power(26,l+k-i)
  ans = (ans+ x*y*cmb(i-1,l-1,mod))%mod
  y = (y*25)%mod
print(ans)

Measured memory_bytes: 201884
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  bool all_even = true;
  for (int64_t i = 0; i < N; ++i) {
    int64_t a;
    cin >> a;
    if (a % 2 == 1) {
      all_even = false;
    }
  }
  if (all_even) {
    cout << "second" << endl;
  } else {
    cout << "first" << endl;
  }
  return 0;
}


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


void solve(std::string S){
  int len = 0;
  for(int i = 0; i < S.size(); i ++){
    for(int l = 1; l <= S.size() - i; l++){
      string sub = S.substr(i, l);
      //cout << sub << endl;
      for(int j = 0; j < l; j++){
        if(sub[j] == 'A' || sub[j] == 'C' || sub[j] == 'G' || sub[j] == 'T'){
          //cout << "ok" << endl;
          if(j == l - 1 && l > len){
            len = l;
            //cout << "ok" << endl;
          }
          continue;
        } else {
          break;
        }
      }
    }
  }
  cout << len << endl;
}

// Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
//B - Collecting Balls (Easy Version) 2017/09/16
#include <iostream>
using namespace std;

int main(int argc , char *argv[]){
    int n , k;
    cin >> n >> k;
    int x[n];
    for(int i=0;i<n;++i) cin >> x[i];
    int min=0; int max=0; //maxいらない
    for(int i=0;i<n;++i){
        if(abs(0-x[i])>=abs(x[i]-k)) {
            min+=2*abs(x[i]-k);
            max+=2*abs(0-x[i]);
        } else {
            min+=2*abs(0-x[i]);
            max+=2*abs(x[i]-k);
        }
    }
    cout << min << endl;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  unsigned int n; cin >> n;
  int imp[3]; for(int i = 2, j = 7; i >= 0; --i, j-=2) imp[i] = j;

  stack<int> s;
  rep(i, 3) s.push(imp[i]);

  int ans = 0;
  while(!s.empty()) {
    int v = s.top(); s.pop();

    rep(i, 3) {
      if(10*v+imp[i] <= n) {
	s.push(10*v+imp[i]);
      }
    }
    
    vector<int> cnt(3, 0);
    for(int i = v; i> 0; i/=10) {
      rep(j, 3) {
	if(i%10 == imp[j]) {
	  ++cnt[j];
	}
      }
    }
    ans += (cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void){

	ios::sync_with_stdio(false);
	int A, B;		cin >> A >> B;
	int ans = 0, keep = 1;
	while(keep < B){
		keep += A;
		ans += 1;
		keep -= 1;
	}

	cout << ans << endl;


    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n,m;
  while(cin>>n>>m,n||m) {
    cin.ignore();
    int table[n];
    map<string, int> mp;
    int parent[n];
    vector<int> children[n];
    REP(i,n) {
      string name;
      getline(cin, name);

      if (i==0) {
        mp[name] = 0;
        table[0] = 0;
        parent[0] = -1;
        continue;
      }
      
      int space = 0;
      while(name[space]==' ') space++;
      name = name.substr(space);
      
      children[table[space-1]].push_back(i);
      parent[i] = table[space-1];
      table[space] = i;
      mp[name] = i;
    }
    // FOR(it, mp)
    //   cout << it->first<< " " <<it->second<<endl;

    REP(i,m) {
      string line;
      getline(cin,line);
      line[line.size()-1] = ' ';
      stringstream ss(line);
      string xx, s, tmp, yy;
      ss >>xx>>tmp>>tmp>>s>>tmp>>yy;
      int x = mp[xx], y = mp[yy];
      bool f = 0;
      if (s=="child") {
        if (parent[x] == y)
          f = 1;
      } else if (s=="parent") {
        if (parent[y] == x)
          f= 1;
      } else if (s=="sibling") {
        if (binary_search(ALL(children[parent[x]]), y))
          f = 1;
      } else if (s=="descendant") {
        while(parent[x]!=-1) {
          x = parent[x];
          if (x==y) {
            f = 1;
            break;
          }
        }
      } else {
        while(parent[y]!=-1) {
          y = parent[y];
          if (x==y) {
            f = 1;
            break;
          }
        }
      }
      if (f)
        cout << "True" << endl;
      else
        cout << "False" << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define cY cout << "Yes" << endl;
#define cN cout << "No" << endl;

ll f(ll x){
  if(x == 1) return 1;
  return f(x/2)*2 + 1;
}

int main() {
  ll h;
  cin >> h;
  cout << f(h) << endl;
  return 0;
}


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

int main() {
	// your code goes here
	long long int n;
	cin>>n;
	if(n%1000==0)
	{
	    cout<<"0"<<endl;
	}
	else
	{
	    cout<<1000-(n%1000)<<endl;
	}
	return 0;
}


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

using namespace std;

int main() {
  int N;
  long long K;
  cin >> N >> K;
  vector<long long> C(100005);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    C[a] += b;
  }
  long long cnt = 0;
  for (int i = 1; i <= 100000; i++) {
    cnt += C[i];
    if (cnt >= K) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 1024
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x)      x.begin(), x.end()
#define rep(i,n)    for (i64 i = 0; i < (n); ++i)
#define reps(i,s,t) for (i64 i = (s); i <= (t); ++i)
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? (a=b,1) : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? (a=b,1) : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);

    int N;
    i64 h[100010];

    cin >> N;

    reps(i, 1, N) {
        cin >> h[i];
    }

    h[0] = -INF;

    bool ok = true;

    reps(i, 1, N) {
        if (h[i-1] <= h[i] - 1) --h[i];

        ok &= (h[i-1] <= h[i]);
    }

    cout << ((ok) ? "Yes" : "No") << endl;

    return 0;
}



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

int main(){
    ll x, i = 1;
    cin >> x;
    while(i * (i+1) / 2 < x) i++;
    cout << i << "\n";
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n; cin>>n; 
    vector <pii> v;
    for (int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        v.emplace_back(a+b,a-b);
    }
    sort(v.begin(), v.end());
    int ans=0,now=-1000000009;
    for (int i=0;i<n;i++)
        if (v[i].ss>=now) now=v[i].ff,ans++;
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 5368
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
using namespace std;

typedef long long int lli;

lli A, B, C, K, ans;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> A >> B >> C >> K;
    ans = min(A, K);
    K -= min(A, K);
    K -= min(B, K);
    ans -= min(C, K);
    cout << ans;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=500025,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,a[N],ans,k;
int stk[N],cnt[N],top;
bool add(int x){
	if (x==0) return false;
	if (stk[top]!=x){
		stk[++top]=x;
		cnt[top]=0;
	}
	if ((++cnt[top])==k){
		top--;
		if (!add(x-1)) return false;
	}
	return true;
}
bool check(){
	if (k==1){
		for (int i=1;i<=n;i++)
		if (a[i]<=a[i-1]) return false;
		return true;
	}
	top=0;
	for (int i=1;i<=n;i++){
		if (a[i]<=a[i-1]){
			while (stk[top]>a[i]) top--;
			if (!add(a[i]))
			return false;
		}
	}
	return true;
}
int main(){
//	freopen("balance.in","r",stdin);
//	freopen("balance.out","w",stdout);
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	int l=1,r=n;
	while (l<r){
		k=(l+r)>>1;
		if (check()) r=k;
		else l=k+1;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

string S;

void input() {
    cin >> S;
}

int solve() {
    int min_diff = 9999;
    for (int i = 0; i + 2 < S.size(); i++) {
        int num = stoi(S.substr(i, 3));
        min_diff = min(min_diff, abs(num - 753));
    }
    return min_diff;
}


int main() {
    input();
    cout << solve() << endl;;
    
    return 0;
}



Measured memory_bytes: 256
INF = 10 ** 20
while True:
  n = int(input())
  if not n:
    break
  cum_sum = [0]
  acc = 0
  for i in range(n):
    acc += int(input())
    cum_sum.append(acc)
  ans = -INF
  for i in range(n):
    ans = max(ans, max(cum_sum[i + 1:]) - cum_sum[i])
  print(ans)


Measured memory_bytes: 5724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
  return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
  template <class C>
  static char test(typename C::const_iterator*);
  template <class C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream& o, const C& c) {
  o << '[';
  for (auto it = c.begin(); it != c.end();)
      o << *it << (++it != c.end() ? ", " : "");
  return o << ']';
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
  return o << '(' << p.fi << ", " << p.se << ')';
}

bitset<(int)1e6 + 10> valid;

void solve() {
  int n;
  cin >> n;
  vi as(n);
  F0R (i, n) cin >> as[i];
  sort(ALL(as));
  int ans = 0;
  F0R (i, n) {
    if (!valid[as[i]]) {
      if (i + 1 == n || as[i + 1] != as[i]) {
        ++ans;
      }
      for (int j = as[i]; j <= (int)1e6; j += as[i]) {
        valid[j] = 1;
      }
    }
  }
  cout << ans << endl;
}

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

  int tt = 1;
  FOR (t, 1, tt + 1) {
      // cout << "Case #" << t << ": ";
      solve();
  }

  return 0;
}


Measured memory_bytes: 4184
#include <bits/stdc++.h>
using namespace std;
void err() {
  cout << "NO" << endl;
  exit(0);
}
int main() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  bool n_odd(n & 1), m_odd(m & 1);
  if (n_odd) n--;
  if (m_odd) m--;
  vector<char> hor(m, '.'), ver(n, '.');
  if (n_odd) {
    for (int y = 0; y < m; y += 2) {
      if (!a) break;
      hor[y] = '<';
      hor[y + 1] = '>';
      a--;
    }
  }
  if (m_odd) {
    for (int x = 0; x < n; x += 2) {
      if (!b) break;
      ver[x] = '^';
      ver[x + 1] = 'v';
      b--;
    }
  }
  bool poke = false;
  if (n_odd && m_odd) {
    if (a & 1 && b & 1) {
      ver.insert(ver.begin(), '>');
      a--;
      poke = true;
    } else {
      ver.push_back('.');
    }
  }
  vector<vector<char>> ret(n, vector<char>(m, '.'));
  if (poke) ret[0][m - 1] = '<';
  for (int x = 0, y = m - 1; b; y--) {
    if (y < 0) x += 2, y = m - 1;
    if (n <= x) err();
    if (ret[x][y] != '.' || ret[x + 1][y] != '.') continue;
    ret[x][y] = '^';
    ret[x + 1][y] = 'v';
    b--;
  }
  for (int x = n - 1, y = m - 2; a; x--) {
    if (x < 0) x = n - 1, y -= 2;
    if (y < 0) err();
    if (ret[x][y] != '.' || ret[x][y + 1] != '.') continue;
    ret[x][y] = '<';
    ret[x][y + 1] = '>';
    a--;
  }
  if (a || b) err();
  if (n_odd) ret.push_back(hor);
  if (m_odd) for (int i = 0; i < n + n_odd; i++) ret[i].push_back(ver[i]);
  cout << "YES" << endl;
  for (int i = 0; i < n + n_odd; i++) {
    for (int j = 0; j < m + m_odd; j++) {
      cout << ret[i][j] << (j < m + m_odd - 1 ? "" : "\n");
    }
  }
  cout << flush;
  return 0;
}


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

using namespace std;

typedef long long int ll;

const int NMax = 2e5 + 5;
const int LIM = 1e9;


int main(){

    /*#ifndef ONLINE_JUDGE
    freopen("debug.in", "r", stdin);
    #endif // ONLINE_JUDGE*/

    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int w, h, n;
    cin >> w >> h >> n;

    int a, b, c, d;
    a = 0; b = w;
    c = 0; d = h;

    for(int i = 1; i <= n; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        if(z == 1) a = max(a, x);
        if(z == 2) b = min(b, x);
        if(z == 3) c = max(c, y);
        if(z == 4) d = min(d, y);
    }

    cout << max(0, (b - a)) * max(0, (d - c));
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int s[110];
int main()
{
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=b;i++)
	{
		int x,y;
		cin>>x>>y;
		if(x>y)swap(x,y);
		s[x]++,s[y]++;
	}
	for(int i=1;i<=a;i++)cout<<s[i]<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;

    int x;
    std::cin >> x;

    int ans = 0;
    for(int i = 0; i <= a; i++) {
        for(int j = 0; j <= b; j++) {
            for(int k = 0; k <= c; k++) {
                int tmp = 500 * i + 100 * j + 50 * k;
                if (tmp == x) ans++;
            }
        }
    }

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

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

typedef long long ll;
typedef long double ld;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int xs,yx,xt,yt;
int n;
int x[1007],y[1007],r[1007];
int used[1007];
long double dist[1007]; //0 : s, n+1 :e

long double d2(int X1,int Y1,int X2,int Y2)
{
    return sqrt((X1-X2)*1.0*(X1-X2)+(Y1-Y2)*1.0*(Y1-Y2));
}

long double d3(int _x,int _y)
{
    return max(ld(0),d2(x[_x],y[_x],x[_y],y[_y])-r[_x]-r[_y]);
}

int32_t main()
{
    IOS
    cin>>xs>>yx>>xt>>yt;
    cin>>n;
    x[0]=xs,y[0]=yx,r[0]=0;
    x[n+1]=xt,y[n+1]=yt,r[n+1]=0;
    for (int i=1;i<=n;i++) cin>>x[i]>>y[i]>>r[i];

    for (int i=1;i<=n+1;i++) dist[i]=1e10;
    dist[0]=0;
    priority_queue<pair<long double,int>,vector<pair<long double,int> >,greater<pair<long double,int> > >pq;
    pq.push(mkp(dist[0],0));
    while (!pq.empty())
    {
        auto now=pq.top();
        pq.pop();
        if (used[now.S]) continue;
        used[now.S]=1;
        for (int i=0;i<=n+1;i++)
        {
            long double dd=d3(i,now.S);
            if (dist[now.S]+dd<dist[i])
            {
                dist[i]=dist[now.S]+dd;
                pq.push(mkp(dist[i],i));
            }
        }
    }
    cout<<fixed<<setprecision(20)<<dist[n+1]<<endl;
}


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

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

    cout << sum << endl;
    return 0;
}

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

struct UnionFind{
    vector<int> par;
    vector<int> dep;

    UnionFind(int siz){
        par.assign(siz,0);
        dep.assign(siz,0);
        for(int i = 0; i < siz; i++){
            par[i] = i;
        }
    };

    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(dep[x] < dep[y]) par[x] = y;
        else{
            par[y] = x;
            if(dep[x] = dep[y]) dep[x]++;
        }
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    UnionFind uf(n);
    for(int i = 0; i < q; i++){
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0) uf.unite(x, y);
        else{
            if(uf.same(x, y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
}


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

char item[200005][15];

void mergsort(int l, int r) {
    if (r - l <= 0) return;
    int mid = l + (r - l >> 1);
    mergsort(l, mid);
    mergsort(mid + 1, r);
    char a[r + 1][15];
    int tl = l, tr = mid + 1;
    for (int i = l; i <= r; i++) {
        memset(a[i], 0, 15);
        if (tl != mid + 1 && (tr == r + 1 || strcmp(item[tl], item[tr]) <= 0)) {
            for (int j = 0; j < strlen(item[tl]); j++)
                a[i][j] = item[tl][j];
            tl++;
        }
        else {
            for (int j = 0; j < strlen(item[tr]); j++)
                a[i][j] = item[tr][j];
            tr++;
        }
    }
    for (int i = l; i <= r; i++) {
        memset(item[i], 0, 15);
        for (int j = 0; j < strlen(a[i]); j++)
            item[i][j] = a[i][j];
    }
    return;
}

int main() {
    int n; scanf("%d", &n);
    int cnt = 0;
    for (int i = 0; i < n; i++)
        scanf("%s", item[i]);
    mergsort(0, n - 1);
    for (int i = 1; i < n; i++)
        if (strcmp(item[i], item[i - 1]) != 0) cnt++;
    printf("%d\n", cnt + 1);
}

Measured memory_bytes: 7556
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int K, X; cin >> K >> X;
    repp(i,X-K+1,X+K) {
        if (i !=X-K+1) cout << " ";
        cout << i;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n;
cin>>n;
ll a[n]={};
ll b[n]={};
rep(i,n){
cin>>a[i];
b[i]=a[i];}
sort(a,a+n);
sort(b,b+n);
ll mi =a[0];
ll ma =a[n-1];
ll mii=b[0];
ll maa=b[n-1];
for(ll i=1; i<n-1; i++){
if(b[i]<0){
maa = maa -b[i];}
else{
mii = mii -b[i];}
}
ll ans = maa -mii;
cout << ans << endl;
for(ll i=1; i<n-1; i++){
if(a[i]<0){
cout << ma << " " << a[i] << endl;
ma = ma -a[i];}
else{
cout << mi << " " << a[i] << endl;
mi = mi - a[i];}
}
cout << ma << " " << mi << endl;}


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

int main() {
  int N;
  cin >> N;
  vector<int> S((1 << N));
  for (int i = 0; i < (1 << N); i++) cin >> S[i];
  sort(S.begin(), S.end(), greater<int>());
  multiset<int> M;
  vector<int> X = {S[0]};
  for (int i = 1; i < (1 << N); i++) M.insert(S[i]);

  for (int i = 0; i < N; i++) {
    int c = X.size();
    for (int j = 0; j < c; j++) {
      auto iter = M.lower_bound(X[j]);
      if (iter != M.begin()) {
        X.push_back(*prev(iter));
        M.erase(prev(iter));
      } else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 13568
n = int(input())
w = [int(i) for i in input().split()]

ans = 100000
l=[]
s=[]
for i in range(1,n+1):
    l.clear()
    s.clear()
    for j in range(1,len(w)+1):
        if i < j:
            l.append(w[j-1])
        else:
            s.append(w[j-1])
    temp = abs(sum(l)-sum(s))
    if ans > temp:
        ans = temp

print(ans)

Measured memory_bytes: 3064
using System;
public class Class1
{
	public static void Main()
	{
		string line;
		int[] alphabet=new int[26];
		
		while((line=Console.ReadLine())!=null)
		{
		char[] cs=line.ToCharArray();
		
		for(int i=0;i<cs.Length;i++)
		{
			if(char.IsLetter(cs[i]))
			{
			if(char.IsUpper(cs[i]))
			{
				cs[i]=char.ToLower(cs[i]);
			}
		
			int num =cs[i]-'a';
			alphabet[num]++;
			}
		}
		}
		for (int j=0;j<26;j++)
		{
			
			Console.WriteLine((char)('a'+j)+" : "+alphabet[j]);
		
		}
	}
}

Measured memory_bytes: 9136
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int H, W, M;
set<int> row[330000];
set<int> col[330000];
set<pll> st;

int main(int argc, char** argv) {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> H >> W >> M;
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b;
		st.insert({ a, b });
		row[a].insert(b);
		col[b].insert(a);
	}
	
	int row_mx = 0, row_mx_cnt = 0, row_mx_idx = 0;
	map<int, int> mp;
	for (int i = 1; i <= 300000; i++) {
		if (row[i].size() == 0) continue;
		if (row[i].size() == row_mx) {
			row_mx_cnt++;
			row_mx_idx = i;
			for (int j : row[i]) mp[j]++;
		}
		else if (row[i].size() > row_mx) {
			row_mx = row[i].size();
			row_mx_cnt = 1;
			row_mx_idx = i;
			mp.clear();
			for (int j : row[i]) mp[j]++;

		}
	}
	
	int ans = 0;
	for (int i = 1; i <= 300000; i++) {
		int col_cnt = col[i].size();
		if (row_mx_cnt == mp[i]) {
			ans = max(ans, row_mx + col_cnt - 1);
		}
		else {
			ans = max(ans, row_mx + col_cnt);
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 95516
from collections import deque

def makegroup(rg, n):
    city = [[] for i in range(N+1)]
    for i in range(n):
        p, q = map(int, input().split())
        city[p].append(q)
        city[q].append(p)

    Q = deque()
    gid = 0
    for i in range(1, N+1):
        if rg[i] == 0:
            gid += 1
            Q.clear()
            Q.append(i)
            rg[i] = gid
            while len(Q) > 0:
                x = Q.popleft()
                for y in city[x]:
                    if rg[y] == 0:
                        rg[y] = gid
                        Q.append(y)

N, K, L = map(int, input().split())
rg = [0] * (N + 1)
makegroup(rg, K)
lg = [0] * (N + 1)
makegroup(lg, L)

dict = {}
for i in range(1, N+1):
    key = (rg[i], lg[i])
    if key in dict:
        dict[key] += 1
    else:
        dict[key] = 1

key = (rg[1], lg[1])
print(dict[key], end="")
for i in range(2,N+1):
    key = (rg[i], lg[i])
    print(" ", dict[key], sep="", end="")
print()


Measured memory_bytes: 50988
import math
import itertools
import statistics
#import numpy as np
import collections

#n = int(input())
x, y, z = list(map(int, input().split()))
a = y
b = x
c = z
#print(str(a)+" "+str(b)+" "+str(c))
tmp = c
c = a
a = tmp
print(str(a)+" "+str(b)+" "+str(c))

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

int main(){
    int l,r;
    cin >> l >> r;
    int left = l % 2019;
    int right = r % 2019;
    int res = 2019;

    if (r - l + 1 >= 2019 || left == 0 || left > right){
	res = 0;	
    }else{
	for (int i = left; i < right; i++){
	    for (int j = i+1; j <= right; j++){
		res = min(res, ((i*j) % 2019));
	    }
	}
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
MAX = 100005
NONE = -1

class Node
	attr_accessor :p, :l, :r
	def initialize(p, l, r)
		@p = p; @l = l; @r = r
	end
end

$t = []
#$d = []
$h = []

def my_print(u)
	if $t[u].p == NONE
		print("node ", u, ": parent = -1, sibling = ", getSibling(u), ", ")
	else
		print("node ", u, ": parent = ", $t[u].p, ", sibling = ", getSibling(u), ", ")
	end
	deg = 0
	deg += 1 if $t[u].l != NONE
	deg += 1 if $t[u].r != NONE
	print("degree = ", deg, ", ")
	print("depth = ", getDepth(u), ", ")
	print("height = ", $h[u], ", ")
	if $t[u].p == NONE
		print("root\n")
	elsif $t[u].l == NONE && $t[u].r == NONE
		print("leaf\n")
	else
		print("internal node\n")
	end
end

$saiki = 0

def setHeight(u)
	#puts $saiki
	#$saiki += 1

	h1 = 0
	h2 = 0
	if $t[u].l != NONE
		h1 = setHeight($t[u].l) + 1 	
	end
	if $t[u].r != NONE
		h2 = setHeight($t[u].r) + 1 
	end
	$h[u] = h1 > h2 ? h1 : h2
	return $h[u]
end

def getSibling(u)
	return NONE if $t[u].p == NONE
	return $t[$t[u].p].l if $t[$t[u].p].l != u && $t[$t[u].p].l != NONE
	return $t[$t[u].p].r if $t[$t[u].p].r != u && $t[$t[u].p].r != NONE
	return NONE
end

def getDepth(u)
	d = 0
	while $t[u].p != NONE
		u = $t[u].p
		d += 1
	end
	return d
end

n = gets.to_i
for i in 0...n do
	$t[i] = Node.new(NONE, NONE, NONE)
end
for i in 0...n do
	v, l, r = gets.split.map &:to_i
	$t[v].l = l
	$t[v].r = r
	$t[l].p = v if l != NONE
	$t[r].p = v if r != NONE
end
for i in 0...n do
	root = i if $t[i].p == NONE
end
setHeight(root)
for i in 0...n do
	my_print(i)
end

Measured memory_bytes: 8736
#include<bits/stdc++.h>
    using namespace std;
     
    #define pfi(a) printf("%d",a);
    #define pfl(a) printf("%lld",a);
    #define pfin(a) printf("%d\n",a);
    #define pfln(a) printf("%lld\n",a);
    #define pfis(a) printf("%d ",a);
    #define pfls(a) printf("%lld ",a);
    #define sfi(a) scanf("%d",&a);
    #define sfl(a) scanf("%lld",&a);
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define pb(a) push_back(a);
    #define mp(a,b) make_pair(a,b)
    #define ll long long
     
    int main()
    {
        int n;
        sfi(n)
     
        int arr[n];
        f(i,0,n)
            sfi(arr[i])
     
        int dp[n];
     
        dp[0]=0;
        dp[1]=abs(arr[1]-arr[0]);
     
        f(i,2,n)
        {
            int val1=dp[i-1]+abs(arr[i]-arr[i-1]);
            int val2=dp[i-2]+abs(arr[i]-arr[i-2]);
     
            dp[i]=min(val1,val2);
        }
     
        pfin(dp[n-1])
     
        return 0;
    }

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int f1[100005],f2[100005],a1[100005],a2[100005];
int n,a[100005],mod=1e9+7;
signed main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	int ans=0;
	cin>>n;
	FOR(i,1,n){
		cin>>a[i];
	}
	FOR(i,1,n){
		a1[i]=(a1[i-1]+a[i])%mod;
	} 
	for(int i=n-1;i>=1;i--){
		a2[i]=(a2[i+1]+a[i])%mod;
	}
	f1[0]=1;
	FOR(i,1,n-1){
		f1[i]=f1[i-1]*i%mod;
	} 
	f2[n-1]=n-1;
	for(int i=n-2;i>=1;i--){
		f2[i]=f2[i+1]*i%mod;
	}
	f2[n]=f2[n+1]=1;
	for(int i=1;i<n-1;i++){
		ans=ans+f2[i+2]*f1[i-1]%mod*(a2[i+1]-a1[n-i-1]);
		ans=ans%mod;
	}
	FOR(i,1,n-1){
		ans=ans+f1[n-i-1]*f2[n-i+1]%mod*(a[n]-a[i]);ans=ans%mod;
	}
	cout<<ans;
	return 0;
}




Measured memory_bytes: 4224
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		x = Math.abs(x);
		long k = sc.nextLong();
		long d = sc.nextLong();
		long div = x/d;
		long ans = 0;
		if(div>k) {
			ans = x-(k*d);
		}
		else {
			k=k-div;
			ans = x - (div*d);
			if(k%2!=0) {
				long a = ans - d;
				long b = ans + d;
				if(Math.abs(a)>Math.abs(b))
					ans = b;
				else
					ans = a;
			}

		}
		System.out.println(Math.abs(ans));
		sc.close();

	}
}


Measured memory_bytes: 35544
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] arg) {
		int MOD = 1000000007;
		int N = sc.nextInt();
		int T = sc.nextInt();
		int[] D = new int[100001];
		for (int i = 0; i < N; ++i) {
			D[sc.nextInt()]++;
		}
		int[] sum = new int[100001];
		long ans = 1;
		for (int i = 1; i <= 100000; ++i) {
			sum[i] = sum[i - 1] + D[i];
			int pos = 1 + sum[i - 1] - (i > T ? sum[i - T - 1] : 0);
			for (int j = 0; j < D[i]; ++j) {
				ans *= pos + j;
				ans %= MOD;
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 64128
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String n = sc.nextLine();
        sc.close();

        // 主処理
        boolean judge = n.contains("1") && n.contains("9") && n.contains("7") && n.contains("4");
        String result = judge ? "YES" : "NO";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
int ans,n;
int a[3];
void dfs(ve<int> &l, string s){
    if(s.size() == n){
        ve<int> l0(4,0),cnt(4,0);
        rep(i,n){
            l0[s[i]-'0'] += l[i];
            cnt[s[i]-'0']++;
        }
        rep(i,3)if(cnt[i] == 0) return;
        int memo = 0;
        rep(i,3) {
            memo += 10 * (cnt[i]-1);
            memo += abs(a[i]-l0[i]);
        }
        ans = min(ans,memo);
        return;
    }
    dfs(l,s+'0');
    dfs(l,s+'1');
    dfs(l,s+'2');
    dfs(l,s+'3');
    return;
}

int main(){
    cin >> n >> a[0] >> a[1] >> a[2];
    ve<int> l(n);
    rep(i,n) cin >> l[i];
    ans = 1e9;
    dfs(l,"");
    cout << ans << endl;
    return 0;
}

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

// ABC060C Sentou

int main() {
    int N, T, t;
    cin >> N >> T;
    int total = T;
    int prev_t = 0;
    for (int i = 0; i < N; ++i){
        cin >> t;
        if (prev_t + T < t){
            total += T;
        }else {
            total += t - prev_t;
        }
        prev_t = t;
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var strArr = ReadLine().Split();
        var a = int.Parse(strArr[0]);
        var b = int.Parse(strArr[1]);

        if (a * b % 2 == 0) WriteLine("Even");
        else WriteLine("Odd");
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const long long mod = 1e9+7;
long long power(long long a, long long b, long long m = mod) {
    long long x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
const int N = 2e5+9;
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    int n, m; cin >> n >> m;
    int ans = n*(n-1)/2 + m*(m-1)/2;
    cout << ans << "\n";




    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

main() {
    int64_t h, w, a, b;
    cin >> h >> w >> a >> b;

    for (auto i : irange(0L, h)) {
        for (auto j : irange(0L, a)) {
            if (i < b) {
                cout << 0;
            } else {
                cout << 1;
            }
        }
        for (auto j : irange(a, w)) {
            if (i < b) {
                cout << 1;
            } else {
                cout << 0;
            }
        }

        cout << "\n";
    }
}

Measured memory_bytes: 1280
/**
 * C - Dubious Document 2
 * https://atcoder.jp/contests/abc076/tasks/abc076_c
 **/
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<numeric>
#include<functional>
#include<sstream>
#include<iomanip>

using namespace std;

int main() {
    string sdash, t;
    cin >> sdash;
    cin >> t;
    int s_size = sdash.length();
    int t_size = t.length();
    vector<string> answers;
    for(int i=0; i<=s_size-t_size; i++) {
        bool flag = true;
        for(int j=0; j<t_size; j++) {
            if(sdash[i+j]=='?') continue;
            if(sdash[i+j]!=t[j]) {
                flag = false;
                break;
            }
        }
        if(flag) {
            string s = "";
            for(int j=0; j<s_size; j++) {
                if(j>=i&j<i+t_size) {
                    s += t[j-i];
                } else {
                    if(sdash[j]=='?') {
                        s += 'a';
                    } else {
                        s += sdash[j];
                    }
                }
            }
            answers.push_back(s);
        }
    }
    if(answers.empty()) {
        cout << "UNRESTORABLE" << endl;
    } else {
        sort(answers.begin(), answers.end());
        cout << answers[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 256