akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#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)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	double t, x; cin >> t >> x;

	cout << t / x << endl;


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
typedef struct{int first, second, pi, pj;} P;
int upcmpllp(const void *a, const void *b){
    if(((P*)a)->first != ((P*)b)->first) 
        return (((P*)a)->first > ((P*)b)->first?1:-1);
    else
        return (((P*)a)->second == ((P*)b)->second ? 0 : (((P*)a)->second > ((P*)b)->second ? 1 : -1));
}
void sort_up(P *a, int n){ qsort(a, n, sizeof(P), upcmpllp); }

int main(){
    int n;
    scanf("%d", &n);
    int x[55], y[55];
    P diff[2525];
    rep(i, n) scanf("%d%d", &x[i], &y[i]);

    int ans = 55;
    int idx = 0;
    for(int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            if(i == j) continue;
            diff[idx].first = x[j] - x[i];
            diff[idx].second = y[j] - y[i];
            diff[idx].pi = i;
            diff[idx].pj = j;
            idx++;
        }
    }
    sort_up(diff, idx);
    int ch[55];
    rep(i, n) ch[i] = 1;
    rep(i, idx){
        ch[diff[i].pj] = 0;
        if(i+1 < idx 
           && diff[i].first == diff[i+1].first
           && diff[i].second == diff[i+1].second){
        }else{
            int tmp = 0;
            rep(j, n) tmp += ch[j];
            ans = min(ans, tmp);
            rep(j, n) ch[j] = 1;
        }
    }
    if(n == 1) ans = 1;
    printf("%d\n", ans);
}

Measured memory_bytes: 1788
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long x,y;
    cin >> x >> y;

    int ans = 1;
    while (x*2 <= y) {
        x *= 2; ans++;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
int mo[4][2] = { -1,0,1,0,0,-1,0,1 };
//int mo[8][2] = { -1,0,1,0,-1,-1,1,1,0,-1,0,1,1,-1,-1,1 };
const int maxn = 1e5 + 10;
int n, m, is, t, ans, p[maxn];
int main() {
#ifdef ONLINE_JUDGE
#else
	//freopen("input.txt", "r", stdin);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(2);
	set<int>q;
	int a;
	for (int i = 0; i < 3; i++)cin >> a, q.insert(a);
	if (q.size() == 2)cout << "Yes" << "\n";
	else cout << "No" << "\n";
	return 0;
	//good job!
}
/*
author: keke
Update log:
2020/2/20 2:46:17  A bug is found...
*/

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        Long[] a = new Long[n];
        for (int i = 0; i < n; i++) {
            a[i] = Long.parseLong(sc.next());
        }
        sc.close();

        // 主処理
        List<String> list = new ArrayList<>();
        for (int i = k; i < n; i++) {
            long first = a[i - k];
            long last = a[i];
            String s = first < last ? "Yes" : "No";
            list.add(s);
        }
        String result = String.join("\r\n", list);

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


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

using namespace std;

const int NS = (int)2e5 + 5;
int nS, dp[NS][3];
string s;

string getS(int l, int r) {
    string ret = "";
    for (int i = l; i <= r; ++i) ret += s[i];
    return ret;
}

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

    cin >> s; nS = (int)s.size(); s = ' ' + s;

    for (int i = 1; i <= nS; ++i) {
        for (int j = 0; j < min(3, i); ++j) {
            if (i - j == 1) {
                dp[i][j] = 1;
                continue ;
            }
            string s_1 = getS(i - j, i);

            int i2 = i - j - 1;
            for (int j2 = 0; j2 < min(3, i2); ++j2) {
                string s_2 = getS(i2 - j2, i2);
                if (s_1 == s_2) continue ;
                dp[i][j] = max(dp[i][j], dp[i2][j2] + 1);
            }
        }
    }

    int ans = 0;
    for (int j = 0; j < 3; ++j) ans = max(ans, dp[nS][j]);

    cout << ans;

    return 0;
}


Measured memory_bytes: 2896
import java.util.Scanner;

public class Main {

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

		int[][] grid = new int[8][8];// oなら1、xなら-1を入れておく
		int[] dir = { -1, 0, 1 };

		for (int i = 0; i < grid.length; i++) {
			String line = scanner.next();
			for (int j = 0; j < grid[i].length; j++) {
				char piece = line.charAt(j);
				if (piece == 'o') {
					grid[i][j] = 1;
				} else if (piece == 'x') {
					grid[i][j] = -1;
				}
			}
		}

		int turn = 0;
		int pass = 0;
		while (pass < 2) {
			int max = 0;
			int x = -1;
			int y = -1;
			int me = 1;
			if (turn % 2 == 1) {
				me = -1;
			}
			for (int i = 0; i < grid.length; i++) {
				for (int j = 0; j < grid[i].length; j++) {
					int gain = 0;
					int pi = i;
					int pj = j;
					if (turn % 2 == 1) {
						pi = 7 - i;
						pj = 7 - j;
					}
					if (grid[pi][pj] != 0) {
						continue;
					}

					for (int d1 = 0; d1 < dir.length; d1++) {
						for (int d2 = 0; d2 < dir.length; d2++) {
							if (dir[d1] == 0 && dir[d2] == 0) {
								continue;
							}
							int distance = 1;
							while (pi + dir[d1] * distance >= 0
									&& pi + dir[d1] * distance < 8
									&& pj + dir[d2] * distance >= 0
									&& pj + dir[d2] * distance < 8) {
								if (grid[pi + dir[d1] * distance][pj + dir[d2]
										* distance] == -1 * me) {
									distance++;
								} else if (grid[pi + dir[d1] * distance][pj
										+ dir[d2] * distance] == me) {
									gain += distance - 1;
									break;
								} else {
									break;
								}
							}
						}
					}

					if (max < gain) {
						max = gain;
						x = pi;
						y = pj;
					}

				}

			}
			if (x != -1) {
				pass = 0;
				grid[x][y] = me;
				for (int d1 = 0; d1 < dir.length; d1++) {
					for (int d2 = 0; d2 < dir.length; d2++) {
						if (dir[d1] == 0 && dir[d2] == 0) {
							continue;
						}
						int distance = 1;
						while (x + dir[d1] * distance >= 0
								&& x + dir[d1] * distance < 8
								&& y + dir[d2] * distance >= 0
								&& y + dir[d2] * distance < 8) {
							if (grid[x + dir[d1] * distance][y + dir[d2]
									* distance] == -1 * me) {
								distance++;
							} else if (grid[x + dir[d1] * distance][y + dir[d2]
									* distance] == me) {
								for (int dist = 1; dist < distance; dist++) {
									grid[x + dir[d1] * dist][y + dir[d2] * dist] = me;
								}
								break;
							} else {
								break;
							}
						}
					}
				}
			} else {
				pass++;
			}
			turn++;
		}

		for (int i = 0; i < grid.length; i++) {
			for (int j = 0; j < grid[i].length; j++) {
				if (grid[i][j] == 1) {
					System.out.print("o");
				} else if (grid[i][j] == -1) {
					System.out.print("x");
				} else {
					System.out.print(".");
				}
			}
			System.out.println();
		}

	}
}

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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    ll A[N][N]; rep(i, N) rep(j, N) cin >> A[i][j];
    
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            for(int k = 0; k < N; k++){
                if(A[j][k] > A[j][i] + A[i][k]){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }

    bool use[N][N]; rep(i, N) rep(j, N) use[i][j] = true;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            for(int k = 0; k < N; k++){
                if(i == j || i == k) continue;
                if(A[j][k] == A[j][i] + A[i][k]) use[j][k] = false;
            }
        }
    }
    ll ans = 0;
    rep(i, N) rep(j, N) if(use[i][j]) ans += A[i][j];
    cout << ans/2 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

/*ソートの時に使う
int sort(const void *a, const void *b){
    return *(int*)a-*(int*)b ;
}
    qsort (data,sizeof(data),sizeof(int),sort); 
*/

int main(void){
    long long n,m=0,a=0,r=0,c=0,h=0;
    scanf("%lld",&n);
    char s[n][12];
    for (int i=0; i<n; i++){
        scanf("%s",s[i]);
        if (s[i][0]=='M'){
            m++;
        } else if (s[i][0]=='A'){
            a++;
        } else if (s[i][0]=='R'){
            r++;
        } else if (s[i][0]=='C'){
            c++;
        } else if (s[i][0]=='H'){
            h++;
        }
    }
    long long ans;
    ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c +a*r*h + a*c*h +r*c*h ;
    printf ("%lld\n",ans);
	return 0 ;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	char a;
	cin >> a;
	cout << ((a - 'A') <= 26 ? "A" : "a");
}

int main()
{
	fastio;
	solve();

	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    vector<queue<int>> A(n);
    int a;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n-1; ++j) {
            cin >> a;
            A[i].push(a-1);
        }
    }

    vector<int> v1, v2;
    for (int i = 0; i < n; ++i) {
        v1.push_back(i);
    }

    int res = 0;
    while (1) {
        bool fin = true;
        bool loop = true;
        vector<bool> checked(n, false);
        for (auto i : v1) {
            if (checked[i]) continue;

            if (A[i].empty()) {
                continue;
            } else {
                fin = false;
            }

            if (A[A[i].front()].front() == i && !checked[A[i].front()]) {
                checked[i] = true;
                checked[A[i].front()] = true;
                v2.push_back(i);
                v2.push_back(A[i].front());

                A[A[i].front()].pop();
                A[i].pop();
                loop = false;
            }
        }
        if (fin) break;
        if (loop) {
            cout << -1 << endl;
            return 0;
        }
        v1.clear();
        v1.swap(v2);
        res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 7992
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

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

int main() {
  int H, W; cin >> H >> W;
  vector<string> S(H); REP(i, H) cin >> S[i];
  int ans = 0;
  REP(i, H) {
    REP(k, W) {
      if(S[i][k] == '#') continue;
      vector<vector<int>> f(H, vector<int>(W, 0));
      f[i][k] = 1;
      auto p = make_pair(i, k);
      queue<pair<pair<int, int>, int>> Q; Q.push(make_pair(p, 0));
      while(!Q.empty()) {
        auto x = Q.front(); Q.pop();
        for(int q = 0; q < 4; ++q) {
          int a = x.first.first + dx[q];
          int b = x.first.second + dy[q];
          if(a < 0 || a >= H) continue;
          if(b < 0 || b >= W) continue;
          if(S[a][b] == '#') continue;
          if(f[a][b] == 1) continue;
          f[a][b] = 1;
          auto m = make_pair(a, b);
          Q.push(make_pair(m, x.second + 1));
          if(ans < x.second + 1) ans = x.second + 1;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s= sc.next();
 
        if(s.contains("a") && s.contains("b") && s.contains("c")) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23892
#include <stdio.h>

int main(void)
{
    int n,a[100],i,t=1,s=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&a[i]);
    for(i=1;i<n;i++){
        if(a[i-1]!=a[i]){
            s+=t/2;
            t=0;
        }
        t++;
    }
    s+=t/2;
    printf("%d",s);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define s second
using T=std::pair<int,int>;
T*P=new T[1<<19],*p;
int BIT[1<<17],j,k,l,r,x,M;
int main(){
	p=P;
	while(~scanf("%d%d",&p->first,&p->s)) p++;
	M=P->s;
	++P;
	sort(P,p,[](T a,T b){return a.s-a.first<b.s-b.first;});
	--p;
	while(x++<M){
		while(std::tie(l,r)=*P, l&&r-l<x){
			for(j=l; j<=M; j+=j&-j) BIT[j]++;
			for(j=r+1; j<=M; j+=j&-j) BIT[j]--;
			P++;
		}
		k=p-P;
		for(j=0; j<=M; j+=x) {
			for(l=j; l; l-=l&-l)
				k+=BIT[l];
		}
		printf("%d\n",k+1);
	}
	j=0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x7f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
const int mod = 1e9+7;
const int maxn = 1e5+5;
const double EPS = 1e-6;
using namespace std;
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int v[maxn];
int main()
{
    mt(v,0);
    int n;
    scanf("%d",&n);
    ll ans=0;
    rep(i,0,n){
        int l,r;
        scanf("%d%d",&l,&r);
        for(int i=l;i<=r;i++)
        {
            if(!v[i])
            {
                v[i]=1;
                ans++;
            }
        }

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    for (char &c : s) if (c == '?') c = 'D';
    cout << s;
    return 0;
}

Measured memory_bytes: 3716
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] price = new int[n];

		for (int i = 0; i < n; i++) {
			price[i] = Integer.parseInt(br.readLine());
		}

		int max = - Integer.MIN_VALUE;
		int minPrice = price[0];
		for (int i = 1; i < n; i++) {
			if (max < price[i] - minPrice) {
				max = price[i] - minPrice;
			}
			if (minPrice > price[i]) {
				minPrice = price[i];
			}
		}
		System.out.println(max);
	}
}

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

int main(void){

  int a, b, c;

  scanf("%d %d %d", &a, &b, &c);

  if(a <= b && b <= c){
    printf("%d %d %d\n", a, b, c);
  }else if(a <= c && c <= b){
    printf("%d %d %d\n", a, c, b);
  }else if(b <= a && a <= c){
    printf("%d %d %d\n", b, a, c);
  }else if(b <= c && c <= a){
    printf("%d %d %d\n", b, c, a);
  }else if(c <= a && a <= b){
    printf("%d %d %d\n", c, a, b);
  }else if(c <= b && b <= a){
    printf("%d %d %d\n", c, b, a);
  }
    
  return 0;
}


Measured memory_bytes: 2068
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    H = int(input())
    W = int(input())
    N = int(input())

    res = 0
    black = 0

    if H >= W:
        D = W
        E = H
    else:
        D = H
        E = W

    for i in range(D):
        if black >= N:
            break
        black += E
        res += 1

    print(res)



main()


Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
const int NMAX = 1 << 18;
ll N, n, dat[2*NMAX-1];
void init(int n_) {
  n = 1;
  while(n < n_) n *= 2;
  FOR(i,0,2*n-1) dat[i] = 1e9;
}
void update(int k, int a) {
  k += n - 1;
  dat[k] = a;
  while(k > 0) {
    k = (k - 1) / 2;
    dat[k] = min(dat[k*2+1],dat[k*2+2]);
  }
}
int query(int a, int b, int k, int l, int r) {
  if(r <= a || b <= l) return 1e9;
  if(a <= l && r <= b) return dat[k];
  else {
    int vl = query(a,b,k*2+1,l,(l+r)/2);
    int vr = query(a,b,k*2+2,(l+r)/2,r);
    return min(vl, vr);
  }
}

int mnidx[200005]; // 数字 - > インデックス

ll dfs(ll l, ll r) {
  if(r - l < 0) return 0;
  int mn = query(l,r+1,0,0,n);
  ll i = mnidx[mn];
  ll ret = mn * (i - l + 1) * (r - i + 1);
  ret += dfs(i+1,r);
  ret += dfs(l,i-1);
  return ret;
}

int main()
{
  cin >> N;
  init(N);
  FOR(i,0,N+1) mnidx[i] = 0;
  FOR(i,0,N) {
    int a;
    cin >> a;
    mnidx[a] = i;
    update(i,a);
  }
  cout << dfs(0,N-1) << endl;
  return 0;
}

Measured memory_bytes: 17664
#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
#define setnow clock_t tStart;
#define setTime tStart = clock();
#define time0 (double)(clock() - tStart)/CLOCKS_PER_SEC
#define setin(x) ifstream cin(x);
#define setout(x) ofstream cout(x);
#define NMAX 30
typedef long long ll;
typedef long long int lli;
typedef pair < int, int> dbl;
const int maxInt = 1e9*2;
const lli maxLong = 1e18*2;
int main(){
    int x, y, z;
    cin >> x >> y >> z;
    int ans = x/(y+z);
    if ( x - ans*(y+z) < z)
        ans--;
    cout << ans;
	return(0);
}


Measured memory_bytes: 256
// --------------
// Tejas Pandey  |
// 13 - 06 - 20  |
// ATcoder RC    |
// --------------

#include <bits/stdc++.h>
using namespace std;
     
#define mod 1000000007
#define lim 200007
#define vi vector<int>
typedef long long int ll;

ll bit[lim];

void upd(int pos,int val){
	while(pos < lim){
		bit[pos] += val;
		pos += (pos&(-pos));
	}
}

void rupd(int l,int r,int val){
	upd(l,val);
	upd(r + 1,-val);
}

ll gans(int pos){
	ll sum = 0;
	while(pos > 0){
		sum += bit[pos];
		pos -= (pos&(-pos));
	}
	return sum;
}
     
int main (void){
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,k;
  cin >> n >> k;
  int a[n];
  for(int i = 0;i < n;i++) cin >> a[i],rupd(max(1,i + 1 - a[i]),min(n,i + 1 + a[i]),1);
  int cnt = 0,ops= 0;
  k--;
  while(ops < k && cnt < n){
	cnt = 0;
	int newa[n];
	for(int i = 0;i < n;i++){
		int f = gans(i + 1);
		if(f == n) cnt++;
		newa[i] = f;
	}
	ops++;
	for(int i = 0;i < n;i++) rupd(max(1,i + 1 - a[i]),min(n,i + 1 + a[i]),-1),a[i] = newa[i],rupd(max(1,i + 1 - a[i]),min(n,i + 1 + a[i]),1);
  }
  for(int i = 0;i < n;i++) cout << gans(i + 1) << " ";
  cout << "\n";
  return 0;
}


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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long LL;

const int INF = 0x3f3f3f3f;


int main(void) {
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

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

    for (int i = 0; i < N; ++i) {
        if (a[i] %2 == 0) {
            if (a[i] % 3 != 0 && a[i] % 5 != 0) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

    cout << "APPROVED" << endl;
    return 0;
}



Measured memory_bytes: 256
//This is my solution bitch.

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;

const int INF = 1LL << 40;
const int MOD = 1e9 + 7;
const int N = 3000;
double head[N], tail[N];
double dp[N][N]; //p[from][to][head/tail]
int n;

double get(int l, int r) {
    return head[r] / head[l - 1];
}

double f(int l, int t) {
    if(l > n) 
        return 1.0;
    double &ans = dp[l][t];
    if(ans != -1) return ans;
    double he = head[l] * f(l + 1, t);
    double ta = 0.0;
    if(t > 0)
        ta = (1 - head[l]) * f(l + 1, t - 1);
    ans = he + ta;
    return ans;
}

signed main() {
    
    cout << fixed << setprecision(10);
    
    cin >> n;
    int minHeads = n / 2;
    minHeads++;
    int maxTails = n - minHeads;
    
    for(int i = 1; i <= n; i++) 
        cin >> head[i]; 
    
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
            dp[i][j] = -1;
    
    cout << f(1, maxTails) << endl;
    
    return 0;
}

Measured memory_bytes: 70784
#include <cstdio>
int arr[605][605], app[5]; 
void work(int n, int d, int mask)
{
	int cnt = 0; 
	while (!(d & 3))
	{
		d >>= 2; 
		cnt++; 
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (((i >> cnt) ^ (d & 1 ? j >> cnt : 0)) & 1)
				arr[i][j] |= mask;
		}
	}
}
int main()
{
	// freopen("AGC025-D.in", "r", stdin); 
	int n, d1, d2;
	scanf("%d%d%d", &n, &d1, &d2); 
	work(n << 1, d1, 1); 
	work(n << 1, d2, 2); 
	for (int i = 0; i < n << 1; i++)
	{
		for (int j = 0; j < n << 1; j++)
			app[arr[i][j]]++; 
	}
	int val = 0, rem = n * n; 
	for (int i = 0; i < 4; i++)
	{
		if (app[i] >= rem)
			val = i; 
	}
	for (int i = 0; i < n << 1; i++)
	{
		for (int j = 0; j < n << 1; j++)
		{
			if (rem && arr[i][j] == val)
			{
				printf("%d %d\n", i, j);
				rem--;
			}
		}
	}
	return 0; 
}


Measured memory_bytes: 2304
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
int GCD(int a, int b) {
	return b ? GCD(b, a%b) : a;
}
//sort(a, a + N, greater<int>())   // descend
//sort(a, a+N)                    //  ascend

using ll = long long;
using namespace std;


int main() {
	int r, d, x;
	cin >> r >> d >> x;
	for (int i = 0; i < 10; i++) {
		int p = r * x - d;
		cout << r * x - d<<endl;
		x = p;
	}
}

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

 using namespace std;

 int main() {
 int M, D; cin >> M >> D;
 int ans = 0;
 for (int m = 1; m <= M; ++m) {
 for (int d = 10; d <= D; ++d) {
 int d_1 = d % 10, d_10 = d / 10;
 if (d_1 >= 2 && d_10 >= 2 && d_1 * d_10 == m) {
 ++ans;
}
 }
 }
cout << ans << endl;
return 0 ;}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h=sc.nextInt(),w=sc.nextInt();;
		//long n=sc.nextLong(),y=sc.nextLong();
		int count=0;
		while(h-w*count>0)count++;
		System.out.println(count);

	}

}


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

// 0-indexed
template <class T>
struct SegmentTree {
  // a,b,c: T, e:T(unit)
  // abc = (ab)c = a(bc)
  // ae = ea = a
  int n;
  T unit;
  vector<vector<int>> dat;
  SegmentTree(){};
  void init(int newn) {
    n = 1;
    while(n < newn) n <<= 1;
    dat.assign(n << 1, vector<int>());
  }

  void build(const vector<T> &v) {
    int newn = v.size();
    init(newn);
    for(int i = 0; i < newn; ++i) dat[n + i] = {v[i].y};
    for(int i = n - 1; i; --i) {
      int lid = 0, rid = 0, lsize = dat[i << 1].size(),
          rsize = dat[(i << 1) | 1].size();
      for(int j = 0; j < lsize + rsize; ++j) {
        if(lid < lsize && rid < rsize) {
          if(dat[i << 1][lid] <= dat[(i << 1) | 1][rid])
            dat[i].push_back(dat[i << 1][lid++]);
          else
            dat[i].push_back(dat[(i << 1) | 1][rid++]);
        }
        else if(lid < lsize)
          dat[i].push_back(dat[i << 1][lid++]);
        else
          dat[i].push_back(dat[(i << 1) | 1][rid++]);
      }
    }
  }
  // [a,b)
  int query(int a, int b, int d, int u) {
    int ans = 0;
    for(int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) {
        ans +=
            upper_bound(dat[l].begin(), dat[l].end(), u) -
            lower_bound(dat[l].begin(), dat[l].end(), d);
        ++l;
      }
      if(r & 1) {
        --r;
        ans +=
            upper_bound(dat[r].begin(), dat[r].end(), u) -
            lower_bound(dat[r].begin(), dat[r].end(), d);
      }
    }
    return ans;
  }
};

struct cod {
  int x, y;
};
bool operator<(const cod &l, const cod &r) {
  if(l.x != r.x) return l.x < r.x;
  return l.y < r.y;
}

int n, m;
vector<cod> v;
SegmentTree<cod> seg;

void solve();

int main() {
  cin >> n >> m;
  v.resize(n);
  for(int i = 0; i < n; ++i) cin >> v[i].x >> v[i].y;
  sort(v.begin(), v.end());
  seg.build(v);
  for(int i = 0; i < m; ++i) {
    int d, u, lid, rid;
    cod l, r;
    l.y = -1e9 - 1;
    r.y = 1e9 + 1;
    cin >> l.x >> d >> r.x >> u;
    lid = lower_bound(v.begin(), v.end(), l) - v.begin();
    rid = upper_bound(v.begin(), v.end(), r) - v.begin();
    cout << seg.query(lid, rid, d, u) << endl;
  }
  return 0;
}



Measured memory_bytes: 4016
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	int num, cnt;
	unsigned int i, j, k, data_num;
	int data[50];
	unsigned int sq_num;
	unsigned int *prime;

	for (data_num = 0; data_num < 50; data_num++) {
		data[data_num] = -1;
		scanf("%d", &data[data_num]);
		if (data[data_num] < 0) {
			break;
		}
	}

	for (k = 0; k < data_num; k++) {
		sq_num = (int)sqrt((double)data[k]);
		prime = (unsigned int*)malloc(sizeof(unsigned int) * data[k]);

		for (i = 0; i < data[k]; i++) {
			prime[i] = 1;
		}

		prime[0] = 0;
		for (i = 1; i < sq_num; i++) {
			if (prime[i] == 1) {
				for (j = (i + 1); (i + 1) * j <= data[k]; j++) {
					prime[(i + 1) * j - 1] = 0;
				}
			}
		}

		cnt = 0;
		for (i = 0; i < data[k]; i++) {
			if (prime[i] == 1) {
				cnt++;
				//printf("%d", i + 1);
			}
		}

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

		free(prime);
	}

	return 0;

}

Measured memory_bytes: 5252
#include <algorithm>
 #include <iostream>
 #include <vector>
 using namespace std;
 typedef long long ll;
 const int INF = 1 << 30;
 const ll INFll = 1ll << 60;
 
 int main() {
	 int x,a;
	 cin >> x >> a;
 	cout << (x < a ? 0 : 10) << endl;
 	return 0;
 }

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int32 cnt = 0;
  REP(i,s.size()){
    if(s[i] == 'o')cnt++;
  }
  YES(8 - cnt <= 15 - s.size());
  return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
A = list(map(int, input().split()))

bottom, top = 0, max(A)

def cut(x):
    cnt = 0
    for Length in A:
        if Length % x == 0:
            cnt += Length // x
        else:
            cnt += Length // x + 1
        cnt -= 1
    return cnt <= k

while top - bottom > 1:
    middle = (top + bottom) // 2
    if cut(middle):
        top = middle
    else:
        bottom = middle
    
print(top)

Measured memory_bytes: 104176
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  var a = lines[0].split(" ");
  var b = lines[1].split(" ");
  console.log((a[0] - b[0]) * (a[1] - b[1]));
});

Measured memory_bytes: 7500
def mod(val, mod_base):
  if val >= mod_base:
    return val%mod_base
  return val

# 配るDP
def resolve():
  base = 998244353
  N, K = map(int, input().split(" "))

  LRs = []
  for _ in range(K):
    (L, R) = map(int, input().split(" "))
    LRs.append((L, R))

  dp = [0] * (N+1)
  dp[1] = 1

  for i in range(1, N):
    dp[i] += dp[i-1]

    for lr in LRs:
      left = i + lr[0]
      right = i + lr[1] + 1
      if left <= N:
        dp[left] += dp[i]
        dp[left] = mod(dp[left], base)
      if right <= N:
        dp[right] -= dp[i]
        dp[right] = mod(dp[right], base)
  print(mod(dp[-1], base))

if __name__ == "__main__":
  resolve()

Measured memory_bytes: 75292
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;

class P
{
  static void Main()
  {
    int[] ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int x = ab[1] - ab[0];
    Console.WriteLine(x*(x+1)/2-ab[1]);
  }
}


Measured memory_bytes: 13524
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int n;
    cin>>n;
    string s;
    int ans=n;
    cin>>s;
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            ans--;
            }
    }
    cout<<ans<<endl;
    return 0;
}


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

int n,m;
int t[50010],s[50010];
bool f;

int oct(string x){
  if(x == "C") return 0;
  if(x == "C#")return 1;
  if(x == "D") return 2;
  if(x == "D#")return 3;
  if(x == "E") return 4;
  if(x == "F") return 5;
  if(x == "F#")return 6;
  if(x == "G") return 7;
  if(x == "G#")return 8;
  if(x == "A") return 9;
  if(x == "A#")return 10;
  if(x == "B") return 11;
  else return 12;
}

void rec(int stair,int music){
  if(music<0){
    if(stair==-1)f = true;
    return;
  }
  if(stair<0 || n-1<stair)return;

  int o = s[music];
  if(o==t[stair])rec(stair-1,music-1);
  if(o==(t[stair]+1)%12)rec(stair-2,music-1);
  if(o==(t[stair]+11)%12)rec(stair+1,music-1);
}

int main(){

  int casenum;
  string tmp;

  cin >> casenum;

  while(casenum--){
    cin >> n >> m;
    for(int i=0;i<n;i++){
      cin >> tmp;
      t[i] = oct(tmp);
    }

    for(int i=0;i<m;i++){
      cin >> tmp;
      s[i] = oct(tmp);
    }

    f = false;
    rec(n-1,m-1);
    if(!f)rec(n-2,m-1);

    if(f)cout << "Yes\n";
    else cout << "No\n";
  }
}

    

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

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

  vector<int> alphabet(26, 0);

  for (int i = 0; i < S.length(); i++) {
    int index = S[i] - 1;
    alphabet[index]++;

    if (alphabet[index] > 1) {
      cout << "no" << endl;
      return 0;
    }
  }

  cout << "yes" << endl;
}


Measured memory_bytes: 3548
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 15
#define rep(i,n) for(int i=0;i<int(n);i++)
int nn,m;
vector<int> g[MAX],r[MAX];
bool used[1<<MAX][MAX];
struct Q{
  bool is_move;
  bool is_on;
  int s;
  Q(){}
  Q(bool i,bool o,int s_):is_move(i),is_on(o),s(s_){}
};
struct P{
  int u,n;
  vector<Q> v;
  P(int u_,int n_,const vector<Q>& v_):u(u_),n(n_),v(v_){}
};
void solve(int u)
{
  memset(used,0,sizeof(used));
  queue<P> q;
  vector<Q> v;
  q.push( P(u,0,vector<Q>()) );
  used[u][0]=true;
  bool can=false,all=false;
  if( !(u&1) )goto END;
  while( !q.empty() ){
    P p=q.front(); q.pop();
    int n=p.n;
    u=p.u;
    if( n==nn-1 ){
      can=true;
      if( u==(1<<(nn-1)) ){
        all=true;
        v=p.v;
        goto END;
      }
    }
    //move
    rep(i,g[n].size()){
      //printf("%d -> %d %d\n",n,g[n][i],i);
      if( u&(1<<g[n][i]) && !used[u][g[n][i]] ){
        used[u][g[n][i]]=true;
        vector<Q>&v=p.v;
        v.push_back( Q(true,false,g[n][i]) );
        q.push( P(u,g[n][i],v) );
        v.pop_back();
      }
    }
    //switch
    rep(i,r[n].size()){
      bool is_on=!(u&(1<<r[n][i]));
      int uu=u^(1<<r[n][i]);
      if( !used[uu][n] ){
        used[uu][n]=true;
        vector<Q>&v=p.v;
        v.push_back( Q(false,is_on,r[n][i]) );
        q.push( P(uu,n,v) );
        v.pop_back();
      }
    }
  }
END:;
  if( !can ){
    puts("Help me!");
  } else if( !all ){
    puts("You can not switch off all lights.");
  } else {
    printf("You can go home in %d steps.\n",v.size());
    rep(i,v.size()){
      Q& q=v[i];
      if(q.is_move){
        printf("Move to room %d.\n",q.s+1);
      } else {
        printf("Switch %s room %d.\n",q.is_on?"on":"off",q.s+1);
      }
    }
  }
}
int main(void)
{
  for(;;){
    scanf("%d%d",&nn,&m); if(!nn)break;
    int s,t;
    rep(i,m){
      scanf("%d%d",&s,&t);
      s--; t--;
      g[s].push_back(t);
      g[t].push_back(s);
    }
    int a,u=0;
    rep(i,nn){
      scanf("%d",&a);
      u|=a<<i;
    }
    int k,l;
    rep(i,nn){
      scanf("%d",&k);
      rep(j,k){
        scanf("%d",&l); l--;
        if(l==i)continue;
        r[i].push_back(l);
      }
      sort(r[i].begin(),r[i].end());
    }
    solve(u);
    rep(i,nn)g[i].clear();
    rep(i,nn)r[i].clear();
  }
}

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

struct Node{
    int to, weight;
    Node(int t, int w){
        to = t;
        weight = w;
    };
};

const int inf = 200000;

vector<Node> G[100];
int d[100];
bool color[100];

int main(){
    int n, u, k, v, c, minc, tag;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            cin >> v >> c;
            G[u].push_back(Node(v, c));
        }
        d[i] = inf;
        color[i] = false;
    }
    d[0] = 0;
    while(true){
        minc = inf;
        for(int i = 0; i < n; i++){
            if(!color[i] && d[i] < minc){
                minc = d[i];
                tag = i;
            }
        }
        if(minc == inf) break;
        color[tag] = true;
        for(int i = 0; i < G[tag].size(); i++){
            if(!color[G[tag][i].to] && d[tag] + G[tag][i].weight < d[G[tag][i].to])
                d[G[tag][i].to] = d[tag] + G[tag][i].weight;
        }
    }
    for(int i = 0; i < n; i++) cout << i << " " << d[i] << endl;
    return 0;
}


Measured memory_bytes: 3160
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>

using namespace std;

 main(){
  int n , k;
  int panelx, panely;
  scanf("%d%d", &n, &k);
  for(int i = 0; i < k; i++){
    scanf("%d%d", &panelx, &panely);
    if(panelx > n / 2)
      panelx = n + 1 - panelx;
    if(panely > n / 2)
      panely = n + 1 - panely;
    int small = panelx < panely ? panelx : panely;
    //cout << "small:" << small << " x:" << panelx << " y:" << panely << endl;
    small %= 3;
    if(small == 0)
      small = 3;
    printf("%d\n", small);
  }
  return 0;
}

Measured memory_bytes: 1188
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        int N;
        cin >> N;
        vector<int> A(N);
        for (int i = 0; i < N; ++i) {
            cin >> A[i];
        }

        multiset<int> ms;
        for (int i = 0; i < N; ++i) {
            auto it = ms.lower_bound(A[i]);
            if (it == ms.begin()) {
                ms.insert(A[i]);
            } else {
                it--;
//                cerr << "delete " << *it << endl;
                ms.erase(it);
                ms.insert(A[i]);
            }
//            cerr << "size" << ms.size() << endl;
        }

        cout << ms.size() << endl;


    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 5376
using System;
using System.Linq;

class Program {
  static void Main() {
    var arr= Console.ReadLine().Split().Select(int.Parse).ToArray();
    int n = arr[0];
    int m = arr[1];
    int x = arr[2];
    var a = Console.ReadLine().Split().Select(int.Parse);
    var L = Enumerable.Range(0, x);
    var r = Enumerable.Range(x, n - x + 1);
    Console.WriteLine(Math.Min(a.Intersect(L).Count(), a.Intersect(r).Count()));
  }
}

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

int main() {
    int a , b, c, k;
    cin >>a >>b >>c >>k ;
    if(k <= a) cout << k ;
    else if( k <= a+b) cout << a ;
    else cout <<  a - (k-a-b) ;
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5+5;
int n, a[N];

main() {
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> a[i];
    int ans = 0;
    for(int i=1; i<n; i++) {
        ans += max(0LL, a[i-1]-a[i]);
        a[i] = max(a[i-1], a[i]);
    }
    cout << ans;

}


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

int main()
{
	int n;
	int ret[8];
	cin>>n;
	while(n-- > 0){
		string s;
		cin>>s;
		for(int i=0;i<8;i++) ret[i] = s[i] - '0';
		int Min=0, Max=0;
		sort(ret, ret+8);
		for(int i=0;i<8;i++){
			Max += pow(10, i)*ret[i];
		}
		
		for(int i=7;i>=0;i--){
			Min +=  pow(10,i)*ret[7-i];
		}
		int differential = Max - Min;
		
		cout<<differential<<endl;
	}
	return 0;
}

Measured memory_bytes: 1268
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long,long>>;

int A,B,C;

int main() {
    cin >> A >> B >> C;
    int ans = 0;
    if((A%2 == 0 && B%2 == 0 && C%2 == 0) || (A%2 != 0 && B%2 != 0 && C%2 != 0)) {
        int m = max(max(A,B),C);
        ans = (m-A)/2 + (m-B)/2 + (m-C)/2;
    } else {
        ans++;
        if(A%2 == B%2 && A%2 != C%2) {
            A++;
            B++;
        }
        if(A%2 == C%2 && A%2 != B%2) {
            A++;
            C++;
        }
        if(A%2 != B%2 && B%2 == C%2) {
            B++;
            C++;
        }
        //cout << A << " " << B << " " << C << endl;
        int m = max(max(A,B),C);
        ans += (m-A)/2 + (m-B)/2 + (m-C)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int n, w;

	void run(){
		n=sc.nextInt();
		w=sc.nextInt();
		solve();
	}

	boolean[] flag;
	int[] count;
	int sum, left, right;

	void solve(){
		flag=new boolean[n+1];
		count=new int[n+1];
		sum=0;
		left=1;
		right=w+1;
		for(int i=1; i<w; i++){
			for(int k=1; k*k<=i; k++){
				if(i%k==0){
					count[k]++;
					update(k);
					if(i/k!=k){
						count[i/k]++;
						update(i/k);
					}
				}
			}
		}
		for(int i=0; i<n-w+1; i++){
			left=i+1;
			right=i+w+1;
			for(int k=1; k*k<=i; k++){
				if(i%k==0){
					count[k]--;
					update(k);
					if(i/k!=k){
						count[i/k]--;
						update(i/k);
					}
				}
			}
			for(int k=1; k*k<=i+w; k++){
				if((i+w)%k==0){
					count[k]++;
					update(k);
					if((i+w)/k!=k){
						count[(i+w)/k]++;
						update((i+w)/k);
					}
				}
			}
			update(left-1);
			update(right-1);
//			debug("i", i, "i+w-1", i+w-1);
//			debug("count", count);
//			debug("flag", flag);
//			debug("sum", sum);
//			debug(sum);
//			debug();
			print(sum+(i<n-w?" ":"\n"));
		}
		// iの約数が減って
		// i+wの約数が増える
		// iが確定じゃなくなった
		// i+wが確定する
	}

	void update(int i){
		boolean det=left<=i&&i<right;
		if(flag[i]&&!det&&count[i]<2){
			flag[i]=false;
			sum--;
		}
		if(!flag[i]&&(det||count[i]>=2)){
			flag[i]=true;
			sum++;
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
		System.out.flush();
	}
}

Measured memory_bytes: 46288
MOD = 1000000007
import collections
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)

def chk(c, n):
    if n % 2:
        if 0 not in c or c[0] != 1:
            return False
        for i in range(2, (n//2)*2+1, 2):
            if i not in c or c[i] != 2:
                return False
    else:
        for i in range(1, n, 2):
            if i not in c or c[i] != 2:
                return False
    return True

if chk(c, N):
    ans = 2 ** (N//2) % MOD
else:
    ans = 0

print(ans)


Measured memory_bytes: 14820
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int n;
  cin >> n;
  string ans = "No";
  rep(i,25){
    rep(j,25){
      if(i*4 + j*7 == n) ans = "Yes";
    }
  }
  cout << ans << endl;
}

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

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define endl "\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

ll const inf = 1e18;
ll const maxn = 1e6+5;
ll const mod = 1e9+7;

// code begins here

int main(){
    fast;

    ll n,k;
    cin>>n>>k;
    
    vector<ll> arr(n);
    for(auto &u: arr)
        cin>>u;
    
    for(ll j=0;j<min(k,43LL);j++){
        vector<ll> prefix(n+1, 0);
        
        for(ll i=0;i<n;i++){
            ll x = (i - arr[i] + 0.4);
            ll y = (i + arr[i] + 0.5);
            prefix[max(0LL,x)]++;
            prefix[min(y+1,n)]--;
        }
        
        for(ll i=1;i<n;i++)
            prefix[i] += prefix[i-1];
            
        for(ll i=0;i<n;i++)
            arr[i] = prefix[i];
    }
    
    for(ll i=0;i<n;i++)
        cout<<arr[i]<<" ";
    cout<<endl;
    
    return 0;
}


Measured memory_bytes: 6360
N = int(input())
H = [int(i) for i in input().split()]
judge = []
for n in range(N-1):
    if H[n] >= H[n+1]:
        judge.append("Y")
    else:
        judge.append("N")
cnt = 0
ans = 0
for n in range(N-1):
    if judge[n]=="Y":
        cnt += 1
    if judge[n]=="N":
        ans = max(ans,cnt)
        cnt = 0
ans = max(ans,cnt)
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <string>

int main(int argc, char **argv) {
        long long int a, b;
        std::cin >> a >> b;

        long long int ret = 0;
        if (b >= a * 2) {
                ret = a;
                b -= a*2;
                ret += b / 4;
        } else {
                ret = b / 2;
        }
        std::cout << ret << std::endl;
        return 0;
}


Measured memory_bytes: 256