akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
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; }


struct edge{
    ll to,cost;
};
ll n;
vector<edge>  G[100010];
ll d[100010];

void  dijkstra(int s){
    priority_queue<pll,vector<pll>,greater<pll>> que;
    fill(d,d+n,LLINF);
    d[s]=0;
    que.push(pll(0,s));

    while(!que.empty()){
        pll p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    } 
}


void solve(){
    ll x,y;
    cin>>n>>x>>y;
    ll ans[200010]={};
    rep(i,n){
        G[i].pb({i+1,1});
        G[i+1].pb({i,1});
    }
    G[x-1].pb({y-1,1});
    G[y-1].pb({x-1,1});
    rep(i,n){
        dijkstra(i);
        rep2(j,i+1,n){
            // if(d[j]==LLINF) cout<<i<<" "<<j<<endl;
            if(d[j]<LLINF)ans[d[j]]++;
        }
    }
    rep2(i,1,n){
        cout<<ans[i]<<endl;
    }
}



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);


    solve(); 


    return 0;
}


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

using namespace std;

int h[100002]; /// Heights
int dp[100002]; /// dp table
int k;

int go(int pos) {
    if (pos == 0) return 0;

    if(dp[pos] != -1) return dp[pos];

    int ans = 1 << 30;

    for (int i = 1; i <= k; i++) {
        if (pos - i < 0) break;

        ans = min(ans, abs(h[pos] - h[pos - i]) + go(pos - i));
    }

    return dp[pos] = ans;
}

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

    int n;
    cin >> n >> k;

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

    memset(dp, -1, sizeof dp);

    cout << go(n - 1) << endl;
}

/**
 * Frog 2
 */

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;

int main() {
                fast
                // #ifndef ONLINE_JUDGE
                // freopen("input.txt","r",stdin);
                // freopen("output.txt","w",stdout);
                // #endif
               set<ll>s;
               ll n;
               cin>>n;
               s.insert(n);
               for(ll i=2;i*i<=n;i++)
               {
                ll x=n;
                   while(x%i==0)
                   {
                    x/=i;
                   }
                   if(x%i==1)
                    s.insert(i);
                   
               }
               n-=1;
               s.insert(n);
                for(ll i=2;i*i<=n;i++)
               {
                    if(n%i==0 )
                    {
                        s.insert(n/i);
                        s.insert(i);
                    }
               }
               ll count=0;
               // for(auto it:s)
               //  cout<<it<<endl;
               if(n==1)
                cout<<1<<endl;
                else
               cout<<s.size();

                return 0;
            }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
//#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
const int MAX = 5100000;
const int MOD = 1000003;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

void _main()
{
    COMinit();

    int Q;
    cin >> Q;
    rep(i, 0, Q)
    {
        ll x, d, n;
        cin >> x >> d >> n;

        ll ans;
        if (d == 0)
        {
            ans = modpow(x, n, MOD);
        }
        else
        {
            if (n >= MOD)
            {
                ans = 0;
            }
            else
            {
                x = x * modinv(d, MOD) % MOD;
                ans = modpow(d, n, MOD) * fac[x + n - 1] % MOD * finv[x - 1] % MOD;
            }
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 120448
x = [0]*6

for i in range(0,6,2):
    x[i-1], x[i] = map( int, input().split() )


town = [1,2,3,4]

yes = True
for ti in town:
    yes &= x.count(ti) == 2 or x.count(ti) == 1


print('YES' if yes else 'NO')

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

ll ans= 0;
ll n , a[maxn] , fact[maxn] , inv[maxn] , k;

ll ent(ll r ,ll n){
    if(r > n or r < 0 or n < 0){
        return(0);
    }
    return((fact[n]*inv[r])%mod*inv[n - r]%mod);
}

int main(){
    migmig
    cin >> n >> k;
    for (int i = 0 ; i < n ; i ++){
        cin >> a[i];
    }
    fact[0] = inv[0] = 1;
    for(int i = 1; i <= 5e5 ; i ++){
        fact[i] = fact[i - 1] * i;
        fact[i]%=mod;
        inv[i] = pw(fact[i] , mod - 2);
    }
    sort(a , a + n);
    for (int i = 0 ; i < n ; i ++){
        ans+= a[i] * (ent(k - 1 , i) - ent(k - 1 , n - i - 1));
        ans%=mod;
        ans+=mod*mod;
        ans%=mod;
    }
    cout << ans;


    return(0);
}


//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Measured memory_bytes: 12544
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int max = 0; int count = 0; boolean flag = true;
		int[][] state = new int[n][n];
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			for (int j = 0; j < n; j++) {
				state[i][j] = -1;
			}
			for (int j = 0; j < a; j++) {
				state[i][sc.nextInt()-1] = sc.nextInt();
			}
		}
		int[] s = new int[n];

		for (int i = 0; i < (1<<n); i++) {
			flag = true;
			count = 0;
			int I = i;
			for (int j = n-1; j >= 0 ; j--) {
				if((I&1) == 1) {
					s[j] = 1;
					count++;
				}else s[j] = 0;
				I = I>>1;
			}

			for (int j = 0; j < n; j++) {
				if(s[j] == 1) {
					for (int k = 0; k < n; k++) {
						if(state[j][k] == 1) {
							if(s[k] == 0) flag = false;
						}else if(state[j][k] == 0) {
							if(s[k] == 1) flag = false;
						}
					}
				}
			}
			if(flag) max = Math.max(max, count);
		}

		System.out.println(max);
		sc.close();
	}
}

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

int main(){
  int n; string s; cin>>n>>s;
  for(int i=0; i<s.size(); ++i){
    if(s[i]+n<='Z')s[i]+=n;
    else s[i]+=n-26;
  }
  cout<<s<<endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
#define ll long long


int main() {
	string s;
	cin >> s;
	int now = 0, cont = 0, ans[100000] = { 0 };
	for (int i = 0; i < s.size()+1; i++) {
		if (s[i] != s[now]||i==s.size()) {
			if (s[now] == 'R') {
				if ((i - now) % 2 == 0) {
					ans[i] += (i - now) / 2;
					ans[i - 1] += (i - now) / 2;
				}
				else {
					ans[i] += (i - now) / 2;
					ans[i - 1] += (i - now) / 2 + 1;
				}
			}
			else {
				if ((i - now) % 2 == 0) {
					ans[now] += (i - now) / 2;
					ans[now - 1] += (i - now) / 2;
				}
				else {
					ans[now] += (i - now) / 2 + 1;
					ans[now - 1] += (i - now) / 2;
				}
			}
			now = i;
		}
	}
	for (int i = 0; i < s.size(); i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

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

int main(){
  
  long int n,k,ans=0;
  cin >> n >> k;
  vector<int>h(n);
  
  rep(i,n){
    cin >> h[i];
  }
  
  sort(h.begin(),h.end());
  
  if(k>=n) cout << 0;
  
  else{
  rep(i,n-k){
    ans+=h[i];
  }
  cout << ans;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
char s[SIZE];
int main(){
    RS(s);
    int n=LEN(s);
    DRI(K);
    REP(i,n-1){
        if(s[i]=='a')continue;
        if('z'-s[i]+1<=K){
            K-='z'-s[i]+1;
            s[i]='a';
        }
    }
    s[n-1]='a'+((s[n-1]-'a'+K)%26);
    puts(s);
    return 0;
}


Measured memory_bytes: 512
(defun Frog-1 (n)
  (let
   ((h
     (make-array 0 :fill-pointer 0 :adjustable t))
    (dp
     (make-array 0 :fill-pointer 0 :adjustable t))
     )
   (loop :repeat n
         :do (vector-push-extend (read) h))
   (vector-push-extend 0 dp)
   (vector-push-extend (abs (- (aref h 0) (aref h 1))) dp)
   (if (> n 2)
       (loop :for i :from 2 :to (- n 1)
           	 :do (let ((tmp1
                        (+ (aref dp (- i 1)) (abs (- (aref h i) (aref h (- i 1)))))) 
                   	   (tmp2
                        (+ (aref dp (- i 2)) (abs (- (aref h i) (aref h (- i 2)))))))
                  	  (if (< tmp1 tmp2)
                          (vector-push-extend tmp1 dp)
                      	  (vector-push-extend tmp2 dp)))))
   (aref dp (- n 1))))

(print (Frog-1 (read)))

Measured memory_bytes: 57704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

vector<ll> ans;
set<ll> st;

void build(int x, ll a) {
    if (x == 0) {
        st.insert(a);
        ans.push_back(a);
        return;
    }

    ll c = a % 10;
    if (a == 0) {
        for (int i = 1; i < 10; i++) build(x - 1, i);
    } else if (c == 9) {
        build(x - 1, a * 10 + 8);
        build(x - 1, a * 10 + 9);
    } else if (c == 0) {
        build(x - 1, a * 10 + 0);
        build(x - 1, a * 10 + 1);
    } else {
        build(x - 1, a * 10 + c - 1);
        build(x - 1, a * 10 + c);
        build(x - 1, a * 10 + c + 1);
    }
}

int main() {
    int K;
    cin >> K;
    if (K < 10) {
        cout << K << endl;
        return 0;
    }
    vector<vector<ll>> dp(10, vector<ll>(20, 0));
    ll cnt = 9, digit;
    for (int i = 0; i < 10; i++) dp[i][1] = 1;
    for (int x = 2; x < 20; x++) {
        ll k0 = cnt;
        for (int i = 0; i < 10; i++) {
            if (i == 9)
                dp[i][x] = dp[i - 1][x - 1] + dp[i][x - 1];
            else if (i == 0)
                dp[i][x] = dp[i][x - 1] + dp[i + 1][x - 1];
            else
                dp[i][x] = dp[i - 1][x - 1] + dp[i][x - 1] + dp[i + 1][x - 1];
            if (i) cnt += dp[i][x];
        }
        if (cnt >= K) {
            digit = x;
            K -= k0;
            break;
        }
    }
    build(digit, 0);
    sort(ans.begin(), ans.end());
    cout << ans[K - 1] << endl;
    return 0;
}

Measured memory_bytes: 7412
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define amari (x) x % 1000000007;

#define fillInt(xs, x)        \
  for (int i = 0; i < x; i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < x; i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < x; i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end());
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>());
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin();
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin();

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

int N, M;
int sx, sy;
int gx, gy;
char maze[500][500];
int d[500][500];

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

  string A;
  cin >> A;

  int res = 0;

  for (int i=0; i < A.size(); i++) {
    for (int j=i; j < A.size(); j++) {
      bool a = true;
      for (int k = i; k <= j; k++) {
        if (A[k] != 'A' && A[k] != 'C' && A[k] != 'G' && A[k] != 'T') a = false;
      }
      if (a) res = max(res, j-i+1);
    }
  }

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

  return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
#define MAX 36
typedef struct{
  char mark;
  int num;
}CARD;

void bubblesort(CARD*,int);
void selectionsort(CARD*,int);

int main()
{
  int n,flag=0,i;
  CARD A[101],B[101];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&A[i].mark,&A[i].num);
    
    B[i].mark=A[i].mark;
    B[i].num=A[i].num;
   
                  }
  bubblesort(A,n);
 for(i=0;i<n;i++){
    printf("%c%d",A[i].mark,A[i].num);
    
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  printf("Stable\n");
  
  selectionsort(B,n);

  for(i=0;i<n;i++){
    printf("%c%d",B[i].mark,B[i].num);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  
  for(i=0;i<n;i++){
    if(A[i].mark!=B[i].mark)flag=1;
    else if(A[i].num!=B[i].num)flag=1;
  }
  if(flag==0)printf("Stable\n");
  else printf("Not stable\n");

  return 0;
}

void bubblesort(CARD*A,int n)
{
  int i,j;
  CARD x;
  for(i=0;i<=n-1;i++){
    for(j=n-1;j>=i+1;j--){
      if(A[j].num<A[j-1].num){
	x=A[j];
	A[j]=A[j-1];
	A[j-1]=x;            }
	                 }
                    }
}

void selectionsort(CARD*B,int n)
{
  int i,j,mini;
  CARD x;
  for(i=0;i<=n-1;i++){
    mini=i;
    for(j=i;j<n;j++){
      if(B[j].num<B[mini].num)mini=j;
                   }
    x=B[i];
    B[i]=B[mini];
    B[mini]=x;
                    }
}




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

int N,M,C,S,G;

int dist[21][101][101];
vector<pair<int,int>> g[101];

const int INF=1e9;

int dijkstra(){
    priority_queue<pair<int,int>> PQ;
    int dis[N+1]={};
    for(int i=1;i<=N;i++) dis[i]=INF;
    dis[S]=0;
    PQ.push(make_pair(0,S));

    while(!PQ.empty()){
        int co,now;
        tie(co,now)=PQ.top();
        PQ.pop();
        co*=(-1);

        if(dis[now]<co) continue;
        if(now==G) return co;

        for(int i=0;i<g[now].size();i++){
            int nex=g[now][i].first;
            int neco=g[now][i].second;

            if(dis[nex]<=co+neco) continue;
            dis[nex]=co+neco;
            PQ.push(make_pair(-dis[nex],nex));
        }
    }
    return -1;
}

void solve(){
    for(int i=1;i<=C;i++){
        for(int j=1;j<=N;j++){
            for(int k=1;k<=N;k++){
                dist[i][j][k]=INF;
            }
        }
    }
    for(int i=1;i<=N;i++) g[i].clear();

    for(int i=0;i<M;i++){
        int x,y,d,c;
        cin>>x>>y>>d>>c;
        dist[c][x][y]=min(d,dist[c][x][y]);
        dist[c][y][x]=min(d,dist[c][y][x]);
    }
    vector<int> P(C+1,0);
    vector<int> Q[51];
    vector<int> R[51];

    for(int i=1;i<=C;i++) cin>>P[i];
    for(int i=1;i<=C;i++){
        Q[i].resize(P[i]+1,0);
        R[i].resize(P[i]+1,0);
        for(int j=1;j<P[i];j++) cin>>Q[i][j];
        Q[i][P[i]]=INF;
        for(int j=1;j<=P[i];j++) cin>>R[i][j];
    }

    vector<int> sum[21];
    for(int i=1;i<=C;i++){
        sum[i].push_back(0);
        for(int j=1;j<P[i];j++){
            int x=sum[i][j-1]+(Q[i][j]-Q[i][j-1])*R[i][j];
            sum[i].push_back(x);
        }
        sum[i].push_back(INF);
    }

    for(int c=1;c<=C;c++){
        for(int k=1;k<=N;k++){
            for(int i=1;i<=N;i++){
                for(int j=1;j<=N;j++){
                    dist[c][i][j]=min(dist[c][i][j],dist[c][i][k]+dist[c][k][j]);
                }
            }
        }
    }

    for(int c=1;c<=C;c++){
        for(int i=1;i<=N;i++){
            for(int j=i+1;j<=N;j++){
                if(dist[c][i][j]==INF) continue;
                int z=upper_bound(Q[c].begin(),Q[c].end(),dist[c][i][j])-Q[c].begin();
                //int z=upper_bound(sum[c].begin(),sum[c].end(),dist[c][i][j])-sum[c].begin();
                z--;
                int cost=sum[c][z]+(dist[c][i][j]-Q[c][z])*R[c][z+1];
                g[i].push_back(make_pair(j,cost));
                g[j].push_back(make_pair(i,cost));
            }
        }
    }

    cout<<dijkstra()<<endl;
}

int main(){
  while(1){
      cin>>N>>M>>C>>S>>G;
      if(N==0&&M==0&&C==0&&S==0&&G==0) break;
      solve();
  }

  return 0;
}



Measured memory_bytes: 5544
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int 		long long
#define vi 			vector<int>
#define vec(x) 		vector<x>
#define matrix 		vector<vector<int>>
#define pii 		pair<int,int>
#define rep(i,s,e)  for(int i=s;i<e;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define MOD			1000000007
#define pb 			push_back
#define ff 			first
#define ss 			second		
#define w(x)		int x; cin>>x; while(x--)
const int INF=1e18;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k-1)  returns iterator to kth element starting from 0; Returns the kth smallest element
// order_of_key(k) returns count of elements strictly smaller than k;Returns the number of elements less than k
// erase,insert same as normal set


void solve(){
	int x,y,z;
	cin>>x>>y>>z;

	cout<<z<<' '<<x<<' '<<y<<endl;
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
// #endif
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 256
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [0] * N
dp[1] = abs(H[1]-H[0])

for i in range(2, N):
    dp[i] = min([dp[i-k] + abs(H[i-k]-H[i]) for k in range(1, 1+K) if 0 <= i-k])

print(dp[-1])

Measured memory_bytes: 52448
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
int L[2001];

int main(void){
    int N, ab, cIdx, ans=0;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) scanf("%d", &L[i]);
    sort(L, L+N);
    for (int i = 0; i < N-2; i++) {
        for (int j = i + 1; j < N-1; j++) {
            ab = L[i] + L[j]-1;
            //cIdx = int(upper_bound(L, L+N, ab)-L);
            for (int k = j + 1; k < N; k++) {
                if (L[i]+L[j] > L[k] && L[i] + L[k] > L[j] && L[j] + L[k] > L[i]) ans++;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1736
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 998244353;

#define MAX_V 200000

struct edge{
	int to;
	long long int cost;
};

vector<edge> G[MAX_V];
long long int d[MAX_V];

// O(ElogV)

void shortest_path(int s, int V){
	
	priority_queue<P, vector<P>, greater<P> > que;
	
	for(int i = 0; i < V; i++){
		d[i] = INF;
	}
	d[s] = 0;
	
	que.push(P(0, s));
	
	while(!que.empty()){
		
		P p = que.top();
		que.pop();
		
		int v = p.second;
		
		if(d[v] < p.first){
			continue;
		}
		
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > e.cost + d[v]){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){
	
	int V, E;
	cin >> V >> E;
	
	for(int i = 0; i < E; i++){
		int u, v, cost;
		cin >> u >> v >> cost;
		u -= 1;
		v -= 1;
		
		edge e;
		e.cost = cost;
		e.to = v;
		G[u].push_back(e);
	}

	for(int i = 1; i < V; i++){
		edge e;
		e.cost = 0;
		e.to = i - 1;
		G[i].push_back(e);
	}
	
	shortest_path(0, V);

	if(d[V - 1] == INF){
		cout << -1 << endl;
	}else{
		cout << d[V - 1] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 11772
def main():
    N = int(input())
    A = list(map(int, input().split()))

    if N == 0:
        if A[0] == 1:
            print(1)
        else:
            print(-1)
        exit()

    bound = [0] * (N+1)
    bound[0] = 1
    flag = True

    for i in range(1, N+1):
        bound[i] = (bound[i-1] - A[i-1]) * 2
        if bound[i] < A[i]:
            flag = False

    if not flag:
        print(-1)
        exit()

    B = [0] * (N+2)
    for i in range(N, -1, -1):
        tmp = min(bound[i], B[i+1] + A[i])
        B[i] = tmp

    print(sum(B))


if __name__ == "__main__":
    main()


Measured memory_bytes: 679892
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, M;
    cin >> N >> M;
    int cntAC = 0, cntWA = 0;
    vector<int> isAC(N+1, 0);
    vector<int> WA(N+1, 0);
    for (int i = 0; i < M; i++) {
        int num;
        string S;
        cin >> num >> S;
        if (S == "AC" && isAC[num] == 0) cntAC++, isAC[num] = 1;
        else if (S == "WA" && isAC[num] == 0) WA[num]++;
    }
    for (int i = 1; i <= N; i++)
        if (isAC[i]) cntWA += WA[i];
    cout << cntAC << ' ' << cntWA << '\n';
}


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

int main()
{
  string s;
  cin>>s;
  vector<int> v;
  for(auto i:s)
  {
    if(i=='B')
    {
      if(v.empty()) continue;
      v.pop_back();
    }
    else if(i=='1')
      v.push_back(1);
    else
      v.push_back(0);
  }
  for(auto i:v) cout<<i;
  cout<<"\n";
  
  
  return 0;
}

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

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

  int prev = -1;

  vector<int> buf;
  {
    char c;
    cin >> c;
    if (c == '0') {
      prev = 0;
      buf.push_back(1);
    } else {
      prev = 1;
      buf.push_back(0);
      buf.push_back(1);
    }
  }

  for (int i = 1; i < N; i++) {
    char c;
    cin >> c;
    if (c == '0') {
      if (prev == 0) {
        buf[buf.size()-1]++;
      } else {
        prev = 0;
        buf.push_back(1);
      }
    } else {
      if (prev == 0) {
        prev = 1;
        buf.push_back(1);
      } else {
        buf[buf.size()-1]++;
      }
    }
  }

  int max = 0;

  for (int i = 0; i < buf.size(); i+=2) {
    int total = 0;
    if (i > 0) {
      total += buf[i-1];
    }
    int j;
    for (j = 0; j < K; j++) {
      int jj = i + j*2;
      if (jj > buf.size() - 1) {
        break;
      }
      total += buf[jj];
      if (jj+1 < buf.size()) {
        total += buf[jj+1];
      }
    }
    if (total > max) {
      max = total;
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int>         vi;
const int mod = 1000000007;






int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,odd=0,even=0,div4=0;
    cin>>n;
    for(int i =0;i<n;i++){
        int no;
        cin>>no;

        if(no%2!=0){
            odd++;
        }
        else if (no%4==0){
            div4++;
        }
        else{
            even++;
        }
    }
    if(odd-div4==1 && even==0){
        cout<<"Yes"<<endl;
        return 0;
    }
    else if(div4>=odd){
        cout<<"Yes"<<endl;
        return 0;
    }
    else{
        cout<<"No"<<endl;
        return 0 ;
    }













    }















































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

using namespace std;

typedef long long int ll;

int n;
int a[3010];
ll dp[3010][3010];

int main() {

	scanf("%d", &n);

	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);

	for (int i = n; i >= 1; i--)
		for (int j = i; j <= n; j++)
			dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]);

	printf("%lld", dp[1][n]);

	return 0;
}

Measured memory_bytes: 70016
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

string rev(string s) {
    reverse(s.begin(), s.end());
    return s;
}

int main() {
    int m;
    cin >> m;
    while (m--) {
        string s; cin >> s;
        set<string> st;
        st.insert(s);
        st.insert(rev(s));
        for (int i=1; i<(int)s.size(); ++i) {
            string s1, s2, s3, s4;
            s1 = s.substr(0,i);
            s2 = s.substr(i);
            s3 = rev(s1);
            s4 = rev(s2);
            st.insert(s3 + s2);
            st.insert(s1 + s4);
            st.insert(s3 + s4);
            st.insert(s2 + s1);
            st.insert(s4 + s1);
            st.insert(s2 + s3);
        }
        cout << st.size() << endl;
    }
    return 0;
}

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

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

		// 整数の入力
		int a = sc.nextInt();//種類数
		int b = sc.nextInt();//買う数
		
		int[] c = new int[a];
		
		for(int i = 0; i < a; i++) {
			c[i] = sc.nextInt();
		}
		
		Arrays.sort(c);
		
		int d = 0;
		
		for(int i = 0; i < b; i++) {
			d += c[i];
		}
		System.out.println(d);
	}
}

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

int main() {
    int n;
    cin >> n;
    vector<long long> a(n);
    vector<long long> c(n, 0);
    for (auto& e : a) cin >> e;
    
    long long ans = 0;
    while (true) {
        fill(c.begin(), c.end(), 0);
        for (int i = 0; i < n; i++) {
            if (a[i] < n) continue;
            long long p = a[i] / n;
            a[i] %= n;
            ans += p;
            for (int j = 0; j < n; j++) {
                if (i != j) c[j] += p;
            }
        }
        
        bool ok = true;
        for (int i = 0; i < n; i++) {
            a[i] += c[i];
            if (a[i] >= n) ok = false;
        }
        
        if (ok) break;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
	int n,m;
	cin >> n >> m;
	vector<vector<int>> g(n);
	rep(i, m) {
			int a, b; cin >> a >> b;
			g[a-1].push_back(b-1);
	}
	UnionFind uf(n);
	rep(i,n) {
		for (int to : g[i]) {
			uf.merge(i,to);
		}
	}
	int ans = 1;
	rep(i,n) {
		int now = uf.size(i);
		ans = max(ans, now);
	}
	cout << ans << endl;
}


Measured memory_bytes: 17252
#include <iostream>

using namespace std;


int n;
int r[4][3][10];


using namespace std;

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        r[a-1][b-1][c-1]+=d;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                cout<<" "<<r[i][j][k];
            }
            cout<<endl;
        }
        if(i!=3)cout<<"####################"<<endl;
    }
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(void){
	int s;
	scanf("%d",&s);
	printf("%d",s/3600);
	printf("%*s", 1,":");
	printf("%d",(s-s/3600*3600)/60);
	printf("%*s",1,":");
	printf("%d\n",(s-s/3600*3600)-(s-s/3600*3600)/60*60);
	return 0;
}

Measured memory_bytes: 596
a = list(map(int,input().split()))
while True:
  a[2] = a[2] - a[1]
  if a[2] < 1:
    print("Yes")
    exit(0)
  a[0] = a[0] - a[3]
  if a[0] < 1:
    print("No")
    exit(0)

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a==0)
    cout<<(b!=100?b:101);
  else if(a==1)
    cout<<(b!=100?b*100:10100);
  else
    cout<<(b!=100?b*10000:1010000);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
ll f(ll n,ll x){
    if(n==0){
        return 1;
    }
    ll t=(1LL<<(n+2))-3,p=(1LL<<(n+1))-1;
    ll h=(t+1)/2;
    if(x==1){
        return 0;
    }
    else if(x<h){
        return f(n-1,x-1);
    }
    else if(x==h){
        return (1LL<<n);
    }
    else if(x<t){
        return f(n-1,x-h)+(1LL<<n);
    }
    else{
        return p;
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x;cin >> n >> x;
    cout << f(n,x) << endl;
}

Measured memory_bytes: 3652
#include<iostream>

using namespace std;

int main()
{
	char ch;
	int n, a, c[200];
	string s;
	c['S'] = 0, c['H'] = 1, c['C'] = 2, c['D'] = 3;
	int ary2[5][15];
	for(int i = 0; i < 5; i++)
	{
		for(int j = 0; j < 15; j++)
		{
			ary2[i][j] = 0;
		}
	}
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> ch >> a;
		ary2[c[ch]][a]++;
		
	}
	for(int i=0;i<4;i++)
	{
		for(int j=1;j<14;j++)
		{
    		if (ary2[i][j] == 0)
    		{
    			if(i == 0)
				{
    				cout << "S "; 
				}
    			if(i == 1)
				{
    				cout << "H "; 
				}
    			if(i == 2)
				{
    				cout << "C "; 
				}
    			if(i == 3){
    				cout << "D "; 
				}
			cout << j << endl;
			}	
		}
	}
	return 0;
	
	
}


Measured memory_bytes: 3092
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int(): return int(input())

def map_int_input(): return map(int, input())

MII = map_int_input

def MII_split(): return map(int, input().split())

def MII_to_index(): return map(to_index, input())

def MII_split_to_index(): return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs(): return list(map(int, input()))

LII = list_int_inputs

def LII_split(): return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number): return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)]

N = input_int()
Ss = [input() for _ in range(N)]

print(len(set(Ss)))

Measured memory_bytes: 35608
#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(){
    int n;
    cin >> n;
    int cnt=0;
    rep(i,n){
        if((i+1) % 2 == 1){
            cnt++;
        }
    }
    double res = (double)cnt / (double)n;
    cout << fixed << setprecision(10) << res << endl;
    return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define ar array
#define pb push_back
#define mp make_pair
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
lld n,m;
lld arr[300000];
lld brr[300000];
lld crr[300000];
string st;
ar<lld,2> ans;
priority_queue<lld,vector<lld>, greater<lld> > pq[2];
int main()
{
     ios;
     lld TESTS,q,a,s,b,r,k,c,p,h,w,d,x,y,z,xs,ys,t;
     TESTS=1;
//     ans=0;
     //cin>>TESTS;
   //  memset(dpt,0,sizeof(dpt));memset(dput,0,sizeof(dput));
    // memset(dsu1,0,sizeof(dsu1));
     while(TESTS--)
     {
         cin>>x>>y>>a>>b>>c;
         rep(i,0,a-1)cin>>arr[i];rep(i,0,b-1)cin>>brr[i];rep(i,0,c-1)cin>>crr[i];
         sort(arr,arr+a);sort(brr,brr+b);sort(crr,crr+c);
         ans[0]=ans[1]=0;
         repr(i,a-1,a-x){pq[0].push(arr[i]);ans[0]+=arr[i];}
         repr(i,b-1,b-y){pq[1].push(brr[i]);ans[1]+=brr[i];}
         repr(i,c-1,0){
            if (pq[0].top()<pq[1].top()){
                if (crr[i]>pq[0].top()){ans[0]+=crr[i]-pq[0].top();pq[0].pop();pq[0].push(crr[i]);}
                else break;
            }
            else {
                if (crr[i]>pq[1].top()){ans[0]+=crr[i]-pq[1].top();pq[1].pop();pq[1].push(crr[i]);}
                else break;
            }
         }
         cout<<ans[0]+ans[1];
     }
    return 0;
}


Measured memory_bytes: 7412
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
import copy
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

n = int(input())
print(1-n)



Measured memory_bytes: 68700
#![allow(unused_imports)]
// using Rust(1.42.0)
// My Library Repo is at "https://github.com/Loptall/prcn_lib"
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"

/*
    AtCoder Language Update 2020204 お疲れ様でした! 有難いです
*/

// Dep crates are...
use std::cmp::{max, min, Ordering};
use std::collections::{HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::mem::swap;
use std::ops::*;
use std::str::FromStr;

fn input<T: FromStr>() -> Result<T, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse()
}

fn input_vec<T: FromStr>() -> Result<Vec<T>, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().split_whitespace().map(|x| x.parse()).collect()
}

// code...
fn main() {
    let (mut a, mut b, mut c) = {
        let v: Vec<usize> = input_vec().unwrap();
        (v[0], v[1], v[2])
    };

    let sum = a + b + c;
    if a > b { swap(&mut a, &mut b) }
    if b > c { swap(&mut b, &mut c) }
    if a > b { swap(&mut a, &mut b) }

    let ans = match (a % 2, b % 2, c % 2) {
        (1, 1, 1) => (3 * c - sum) / 2,
        (0, 0, 0) => (3 * c - sum) / 2,
        (1, 1, 0) => (3 * c - sum) / 2,
        (0, 0, 1) => (3 * c - sum) / 2,
        (1, 0, 1) => (3 * (c+1) - sum) / 2,
        (0, 1, 0) => (3 * (c+1) - sum) / 2,
        (1, 0, 0) =>(3 * (c+1) - sum) / 2,
        (0, 1, 1) => (3 * (c+1) - sum) / 2,
        _ => unreachable!()
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}




int main(){

  ll A,B,C,K;
  cin >> A >> B >> C >> K;

  ll ans = 0;

  if(A<=K){
    ans += A;
    K -= A;
  }else{
    ans = K;
    K = 0;
  }

  if(B<K){
    K -= B;
  }else{
    K = 0;
  }

  ans -= K;

  cout << ans << endl;

}


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

using namespace std;

struct point
{
    double x,y;
};

void chmin(double &x, double y)
{
    if(x>y) x=y;
}

constexpr double sq3=sqrt(3);

void solve()
{
    int n,k; cin>>n;
    if(!n) exit(0);
    cin>>k;
    k=n-k;
    vector<point> pnt(n);

    for(point &e:pnt)
    {
        cin>>e.x>>e.y;
    }
    sort(begin(pnt), end(pnt),
    [](point p1, point p2)
    {
        if(p1.y==p2.y)
        {
            return p1.x>p2.x;
        }
        return p1.y>p2.y;
    });

    struct left_comp
    {
        bool operator()(point p1, point p2)
        {
            return p2.y-sq3*p2.x>p1.y-sq3*p1.x;
        }
    };
    auto lpnt=pnt;
    sort(begin(lpnt),end(lpnt), left_comp());

    struct right_comp
    {
        bool operator()(point p1, point p2)
        {
            return p2.y+sq3*p2.x>p1.y+sq3*p1.x;
        }
    };
    auto rpnt=pnt;

    sort(begin(rpnt), end(rpnt), right_comp());

    double ans=1e5;

    for(auto i=begin(pnt),j=i; i!=end(pnt); i=j)
    {
        const double nowy=i->y;
        vector<point> clf,crg;
        for(auto &p: lpnt)
        {
            if(p.y>=nowy) clf.emplace_back(p);
        }
        // for(auto &p: rpnt)
        // {
        //     if(p.y>=nowy) crg.emplace_back(p);
        // }
        // auto itr=end(crg);
        priority_queue<point,vector<point>,right_comp> que;

        for(const auto &p: clf)
        {
                // cerr << "p: " << p.x << " " << p.y << endl;

            if(que.size()<k || right_comp()(p,que.top()))
            {
                que.emplace(p);
            }
            if(que.size()>k) que.pop();
            if(que.size()==k) // update
            {
                const double lx=p.x-(p.y-nowy)/sq3;
                auto tp=que.top();
                const double rx=tp.x+(tp.y-nowy)/sq3;
                // cerr << nowy << endl;
                // cerr << "p: " << p.x << " " << p.y << endl;
                // cerr << "tp: " << tp.x << " " << tp.y << endl;
                chmin(ans, rx-lx);
            }
        }

        while(j!=end(pnt) && i->y==j->y) ++j;
    }

    cout << fixed << setprecision(10) << ans*3 << "\n";
}

main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(true) solve();
}


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


//---------- べき乗 ----------
Int power(Int a, Int n){
    Int MOD = 1e9+7;
    if(a == 0) return 0;
    if(n == 0) return 1;
    
    Int res = 1;
    while(n > 0){
        if(n % 2 == 1) res = res * a % MOD;
        a = a * a % MOD; n /= 2;
    }
    return res;
}


int main(){
    int N; cin >> N;
    vector<Int> A(N+1);
    rep(i,N+1) cin >> A[i];

    if(N == 0 && A[0] != 1) {cout << -1 << endl; return 0;}

    vector<pair<Int,Int>> minmax_v(N+1);
    minmax_v[N] = {A[N], A[N]};

    for(int d = N-1; d>=0; d--){
        Int M = minmax_v[d+1].second + A[d];
        Int m = max((Int)1, minmax_v[d+1].first/2 + A[d]);

        if(d < 30 && m > power(2,d)) {cout << -1 << endl; return 0;}

        minmax_v[d] = {m,M}; 
    }


    vector<Int> v(N+1); Int ans = 1;
    v[0] = 1;
    rep1(d,N){
        v[d] = min((v[d-1]-A[d-1]) * 2, minmax_v[d].second);
        if(d < 30) v[d] = min(v[d], power(2,d));

        if(v[d] < A[d]) {cout << -1 << endl; return 0;}
        ans += v[d];
    }

    cout << ans << endl;
}

Measured memory_bytes: 6344
#include <iostream>

using namespace std;

const int MAX = 1001;
 
typedef struct{
    int x,y;
} Point;
 
int main(){
    int T;
 
    cin >> T;
    while(T--){
	int dist = 0;
	int x = 0,y = 0;
	Point p,q;
	p.x = p.y = 0;
 
	while(cin >> q.x >> q.y){
	    if(q.x == 0 && q.y == 0) break; 
	    x += q.x; y += q.y;
 
	    if(dist < (x*x+y*y)){
		p.x = x;
		p.y = y;
		dist = x*x+y*y;
	    }
	    else if(dist == (x*x+y*y) && p.x < x){
		p.x = x;
		p.y = y;
		dist = x*x+y*y;
	    }
	}
	cout << p.x << " " << p.y << endl;
    }
    return 0;
}

Measured memory_bytes: 3004
N = int(input())
L = list(map(int, input().split()))
T = 0
if N > 2:
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            for k in range(j + 1, N):
                a = L[i]
                b = L[j]
                c = L[k]
                abc = sorted(list({a, b, c}))
                if len(abc) == 3 and abc[0] + abc[1] > abc[2]:
                    T += 1
print(T)

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

using namespace std;

#define LL long long

const int AMAX = 100000 + 1;
LL cnt[AMAX];

int main() {
    long long n, k;
    cin >> n >> k;

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

    for (int i = 0; i < AMAX; ++i) {
        k -= cnt[i];
        if (k <= 0) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

void Main()
{
    int n;
    cin >> n;
    if (n == 1)
    {
        cout << "1" << endl;
    }
    else if (n % 2 == 0)
    {
        cout << 1.0 / 2.0 << endl;
    }
    else
    {

        cout << (((n - 1.0) / 2.0) + 1.0) / n << endl;
    }
}

int main()
{
    std::cout << std::fixed << std::setprecision(15);
    Main();
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,K;
int A[111111];

int S[111111];
int T[111111];
signed main(){
    cin>>N>>K;
    rep(i,N)cin>>A[i];
    rep(i,N){
        if(A[i]>0)S[i+1]+=A[i];
        T[i+1]+=A[i];
        S[i+1]+=S[i];
        T[i+1]+=T[i];
    }

    int ans=0;
    for(int i=0;i+K<=N;i++){
        chmax(ans,S[i]+S[N]-S[i+K]+max(0ll,T[i+K]-T[i]));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560