akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define fs first
#define sc second
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<tuple<ll,ll>> vtl;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

void solve(){
    string s;
    cin>>s;
    if(s=="SUN")cout<<7;
    if(s=="MON")cout<<6;
    if(s=="TUE")cout<<5;
    if(s=="WED")cout<<4;
    if(s=="THU")cout<<3;
    if(s=="FRI")cout<<2;
    if(s=="SAT")cout<<1;
}

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


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{   char s1[101],s2[101];
	int i,n1,j,n,flag,g;
	scanf("%s%s",s1,s2);
	n=strlen(s1);
	n1=strlen(s2);
	for(j=0;j<n;j++)
	     {g=s1[0];flag=0;
	      for(i=0;i<n-1;i++)
	         s1[i]=s1[i+1];
	      s1[n-1]=g;
	      for(i=0;i<n;i++)
		  if(s1[i]==s2[i])
		      flag++;
	      if(flag==n)break;  
	 }
	if(flag==n)
	      printf("Yes\n");
	else 
	      printf("No\n");
	
}

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

const int maxn = (int) 1e5 + 5;
const long long inf = (long long)1e18;

int n, W, H;
int x[maxn], y[maxn];
vector<int> xx, yy;
int _x, _y;
long long ans;

long long calc(int X, int Y) {
    long long res = 0;
    int mx = 0;
    for (int i = 0; i < n; i ++) {
        res += 2LL * (abs(X - x[i]) + abs(Y - y[i]));
        mx = max(mx, abs(X - x[i]) + abs(Y - y[i]));
    }
    return res - mx;
}

int main() {
    ///freopen("test.txt", "r", stdin);
    cin >> W >> H >> n;
    for (int i = 0; i < n; i ++) {
        cin >> x[i] >> y[i];
        xx.push_back(x[i]);
        yy.push_back(y[i]);
    }
    sort(xx.begin(), xx.end());
    sort(yy.begin(), yy.end());

    int md = n / 2;
    int lo = max(0, md - 1);
    int hi = min(n - 1, md + 1);
    ans = inf;
    for (int i = lo; i <= hi; i ++) {
        for (int j = lo; j <= hi; j ++) {
            ///cout << i << ' ' << j << ' ' << xx[i] << ' ' << yy[j] << endl;
            long long tmp = calc(xx[i], yy[j]);
            if(tmp < ans) {
                ans = tmp;
                _x = xx[i];
                _y = yy[j];
            }
        }
    }
    cout << ans << '\n' << _x << ' ' << _y << endl;
}

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

struct xy_t {
	int32_t x, y;
};

int cmp(const void* asumikana, const void* kitamuraeri) {
	struct xy_t a = *(const struct xy_t*)asumikana, b = *(const struct xy_t*)kitamuraeri;
	if (a.y < b.y) return -1;
	if (a.y > b.y) return 1;
	if (a.x < b.x) return -1;
	return a.x > b.x;
}

int32_t H, W;
int32_t N;
int32_t a[114514], b[114514];

int32_t masuCount = 0;
struct xy_t masu[114514 * 9];


int main(void) {
	int32_t i, dx, dy, start;
	uint64_t seisuCount[10] = {0};
	uint64_t zero;
	if (scanf("%" SCNd32 "%" SCNd32 "%" SCNd32, &H, &W, &N) != 3) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNd32 "%" SCNd32, &a[i], &b[i]) != 2) return 1;
		for (dy = -1; dy <= 1; dy++) {
			for (dx = -1; dx <= 1; dx++) {
				int32_t x = b[i] + dx, y = a[i] + dy;
				if (1 < x && x < W && 1 < y && y < H) {
					masu[masuCount].x = x;
					masu[masuCount].y = y;
					masuCount++;
				}
			}
		}
	}
	qsort(masu, masuCount, sizeof(*masu), cmp);
	start = 0;
	zero = (uint64_t)(H - 2) * (uint64_t)(W - 2);
	if (masuCount > 0) {
		for (i = 1; i < masuCount; i++) {
			if (cmp(&masu[i - 1], &masu[i]) != 0) {
				int32_t value = i - start;
				if (value < 10) seisuCount[value]++;
				start = i;
			}
		}
		if (i - start < 10) seisuCount[i - start]++;
	}
	for (i = 1; i <= 9; i++) zero -= seisuCount[i];
	printf("%" PRIu64 "\n", zero);
	for (i = 1; i <= 9; i++) printf("%" PRIu64 "\n", seisuCount[i]);
	return 0;
}


Measured memory_bytes: 15228
// LNU_Algotesters
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <fstream>
#include <complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 100 * 10000 + 47;


int W[MAX];
bool U[MAX];
int X[MAX];

int main()
{
    
    //freopen("in.txt", "r", stdin);
    //ios::sync_with_stdio(false); cin.tie(0);
    
    int n;
    cin >> n;
    string S, T;
    cin >> S >> T;
    int idx = n - 1;
    FILL(W, -1);
    RFOR(i, n, 0)
    {
        while(idx >= 0 && (idx > i || S[idx] != T[i]))--idx;
        W[i] = idx;
        U[idx] = 1;
        X[idx] = max(X[idx], i);
    }
    
    if (S == T)
    {
        cout << 0 << endl;
        return 0;
    }
    
    FOR(i, 0, n)
        if (W[i] == -1)
        {
            cout << -1 << endl;
            return 0;
        }
    
    vector<PII> V;
    
    FOR(i, 0, n)
        if (U[i])V.PB(MP(i, X[i]));
    
    int ans = 0;
    
    FOR(i, 0, SZ(V))
    {
        int L = i, R = SZ(V);
        while(R - L > 1)
        {
            int M = (R +  L) / 2;
            if (V[M].first - (M - i - 1) > V[i].second )
                R = M;
            else L = M;
        }
        ans = max(ans, R - i);
    }
    cout << ans << endl;
    
    
}





Measured memory_bytes: 21756
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
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 MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    ll A, V, B, W, T;
    cin >> A >> V >> B >> W >> T;
    ll dif = abs(A - B);
    ll move = V - W;
    cout << (dif <= move * T ? "YES" : "NO") << endl;
}

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

int main()
{
    vector <ll> v ;
    ll n ;
    cin >> n ;
    for(ll i = 0 ; i < n ; i++)
    {
        ll G ;
        cin >> G ;
        v.push_back(G) ;
    }
    for(ll i = v.size() - 1 ; i > 0 ; i--) cout << v[i] << " " ;
    cout << v[0] << endl ;
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
#include <stack>
#include <queue>
using namespace std;
#define lol long long


int main()
{
	int N;
	string s;
	cin >> N >> s;
	int R = 0;
	int B = 0;
	for (int i = 0; i < N; i++) {
		if (s[i] == 'R') {
			R++;
		}
		else {
			B++;
		}
	}
	if (R > B) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define vec(j,n) vector<int>(j(n))
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<int>a(m+1);
    vector<int>ans(n+1,0);
    for(int i=1;i<=m;i++){
        cin >> a.at(i);
    }
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(a.at(i) == j){
                ans.at(j) = 1;
            }
        }
    }
    int count1 = 0;
    int count2 = 0;
    for(int i=1;i<=x;i++){
        if(ans.at(i) == 1){
            count1 ++;
        }
    }
    for(int i=x;i<=n;i++){
        if(ans.at(i) == 1){
            count2 ++;
        }
    }
    cout << min(count1,count2) << endl;
    return 0;
}

Measured memory_bytes: 256
// abc178_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
//struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

random_device rd;
mt19937 mt(rd());

// だめでした。

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<int> A(N), B(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];

    int j=0,bef=-1;
    REP(i,N){
        if(bef!=A[i])j=0;
        if(A[i]==B[i]){
            for(;j<N;j++){
                if(A[j]!=A[i]&&B[j]!=A[i]){
                    swap(B[i],B[j]);
                    break;
                }
            }
            if(A[i]==B[i]){
                cout<<"No\n";
                return 0;
            }
        }
        bef=A[i];
    }
    cout<<"Yes\n";
    REP(i,N){
        if(i)cout<<" ";
        cout<<B[i];
    }
    cout<<"\n";


    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int ans = 1e6;
    int cnt = 0;
    bool turn = true;
    rep(i, s.size()){
        if(turn){
            if(s[i] != '0') cnt++;
        }
        else{
            if(s[i] == '0') cnt++;
        }
        turn ^= 1;
    }
    int size = s.size();
    ans = min(cnt, size-cnt);
    cout << ans << endl;
}


Measured memory_bytes: 512
n = int(input())
rooms = [[[0 for j in range(10)] for i in range(3)] for h in range(4)]

for i in range(n):
    building, flr, room, val= map(int, input().split())
    rooms[building - 1][flr - 1][room - 1] += val

for i in range(4):
    for ii in range(3):
        fl = str()
        for iii in range(10):
            fl = fl + ' ' + str(rooms[i][ii][iii])
        print(fl)
    if i < 3:
        print('####################')



Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define MOD (ll)(1e9 + 7)
#define MAX (ll)(1e6 + 4)
#define INF (ll)(1e17)
using namespace std;
using ll =  long long;
using ld = long double;

ll mult (ll a, ll b) {
	return ((a % MOD) * (b % MOD)) % MOD;
}

ll add (ll a, ll b) {
	b = (b + MOD) % MOD;
	a = (a + MOD) % MOD;
	return (a + b) % MOD;
}

ll pw (ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1) {
			res = mult (res, a);
		}
		b >>= 1;
		a = mult (a, a);
	}
	return res;
}

ll fac[MAX];

int main () {
	fac[0] = 1;
	for (int i = 1; i < MAX; i++) {
		fac[i] = mult (i, fac[i - 1]);
	}
	int x, y;
	cin >> x >> y;
	if ((x + y) % 3 == 0 && abs (x - y) <= (x + y) / 3 && (((x + y) / 3) % 2 == abs (x - y) % 2))  {
		int n = (x + y) / 3;
		int r = (n - abs (x - y)) / 2;
		int ans = mult (fac[n], pw (mult (fac[n - r], fac[r]), MOD - 2));
		cout << ans << "\n";
	}
	else {
		cout << "0\n";
	}
}


Measured memory_bytes: 8064
#include <iostream>

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

    int n = 1;
    for (int i = 0; i < N; i ++) {
        if (n < K) {
            n *= 2;
        } else {
            n += K;
        }
    }
    std::cout << n << std::endl;
}


Measured memory_bytes: 256
// Contest No.: ABC177
// Problem No.: C
// Solver:      Jinmin Goh
// Date:        20200829

#include <cstring>
#include <iostream>
#include <cstdlib>
#include <list>
#include <array>
#include <atomic>
#include <algorithm>
#include <deque>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;

long long int nums[200010];

int main() {
    long long int n, modVal = 1e9 + 7;
    scanf("%lld", &n);
    for(int i = 0; i < n; i++) {
        scanf("%lld", &nums[i]);
    }

    long long allSum = 0, squareSum = 0;
    for(int i = 0; i < n; i++) {
        allSum += nums[i];
        allSum %= modVal;
        squareSum += (nums[i] * nums[i]);
        squareSum %= modVal;
    }
    long long squareVal = (allSum * allSum) % modVal;

    long long ans = squareVal - squareSum;
    
    if(ans < 0) {
        ans += modVal;
    }

    if(ans % 2) {
        ans += modVal;
    }
    ans /= 2;
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 5380
#include <iostream>
#include <queue>
#include <algorithm>
#include <set>
#include <vector>
#include <string>

using namespace std; using ll=long long; const int INF=1e2; using P=pair<int,int>;

ll pow(ll a, ll b) {ll res=1; while(b>0) {if (b&1) res*=a; a*=a, b>>=1;} return res;}
int main() {
  ll x,y; cin>>x>>y;
  int an=0;
  while(x<=y) {
    an++; y/=2;
  }
  cout<<an<<endl;
}

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

using namespace std;
int main(){
  char x,y;
  cin >> x >> y;
  if(x==y){
    cout << "=\n";
  }
  else{
    if(x<y)
      cout << "<\n";
    else
      cout << ">\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define SWAP(a,b) { a += b, b = a - b, a -= b; }
using namespace std;

int main()
{
    int n[5];
    for(int i=0;i<5;++i) scanf("%d",&n[i]);
    sort(n,n+5);
    for(int i=0;i<2;++i) { SWAP(n[i],n[4-i]); }
    for(int i=0;i<4;++i) printf("%d ",n[i]);
    printf("%d\n",n[4]);
    return 0;
}

Measured memory_bytes: 1040
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

vector<ll> factorial(int N){
    vector<ll> fact(N+1,1);
    for(int i=1; i<N; i++){
        fact[i+1]=(i+1)*fact[i]%MOD;
    }
    return fact;
}

map<long long, long long> inv_fact;
long long inv_factorial(long long x){
    if (inv_fact.find(x)!=inv_fact.end()){
        return inv_fact[x];
    }
    long long p=MOD-2;
    long long ret=1;
    long long tmp=x;
    while(p){
        if(p&1)(ret*=tmp)%=MOD;
        (tmp*=tmp)%=MOD;
        p>>=1;
    }
    inv_fact[x]=ret;
    return ret;
}

long long comb(int a, int b, vector<ll> &fact){
    if(b==0){
        return 1;
    }
    long long ret=fact[a]*inv_factorial(fact[a-b])%MOD;
    return ret*inv_factorial(fact[b])%MOD;
}

int main(){
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    vector<ll> fact=factorial(2000002);

    ll ans=0;
    ans=(ans+MOD)%MOD;
    cout << (4*MOD+comb(r2+c2+2, c2+1, fact)-comb(r1+c2+1,c2+1,fact)-comb(r2+c1+1,c1,fact)+comb(r1+c1,c1,fact))%MOD << endl;

}

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int N;
string S;
int mod = 1e9 + 7;

// 拡張ユークリッドの互除法
int extgcd(int a, int b, int &x, int &y) {
    int d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

// mod逆元
int mod_inverse(int a, int m) {
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

pint f(pint ab, int i, int hash) {
    if (S[i] == '+') { return pint(ab.first, (ab.second + 1) % mod); }
    else if (S[i] == '-') { return pint(ab.first, (ab.second - 1 + mod) % mod); }
    else if (S[i] == '>') { return pint(ab.first * hash % mod, ab.second * hash % mod); }
    else if (S[i] == '<') {
        return pint(ab.first * mod_inverse(hash, mod) % mod,
                    ab.second * mod_inverse(hash, mod) % mod);
    }
}

pint finv(pint ab, int i, int hash) {
    if (S[i] == '-') { return pint(ab.first, (ab.second + 1) % mod); }
    else if (S[i] == '+') { return pint(ab.first, (ab.second - 1 + mod) % mod); }
    else if (S[i] == '<') { return pint(ab.first * hash % mod, ab.second * hash % mod); }
    else if (S[i] == '>') {
        return pint(ab.first * mod_inverse(hash, mod) % mod,
                    ab.second * mod_inverse(hash, mod) % mod);
    }
}
signed main() {
    cin >> N >> S;
    const int K = 2;
    vint hash = {114514, 1919, 810};
    map<int, int> mp[K];
    pint b[K], c[K];
    for (int i = 0; i < K; i++) {
        int h = hash[i];
        b[i] = c[i] = pint(1, 0);
        for (int j = N - 1; j >= 0; j--) { b[i] = f(b[i], j, h), mp[i][0] = 1; }
    }
    int ans = 0;
    for (int i = N - 1; i >= 0; i--) {
        int cur = LLONG_MAX;
        for (int j = 0; j < K; j++) {
            int h = hash[j];
            pint cc = finv(pint(1, 0), i, h);
            c[j] = pint(c[j].first * cc.first % mod, (c[j].first * cc.second + c[j].second) % mod);
            int fi = (c[j].first * b[j].second + c[j].second) % mod;
            chmin(cur, mp[j][fi]);
            mp[j][c[j].second]++;
        }
        ans += cur;
    }
    cout << ans << endl;
}

Measured memory_bytes: 62980
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int manx=2333333; 
int n;
char a[manx],b[manx];
int q[manx];
int nxt[manx];
int f[manx];
int top=0;
int la,lb;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
	{
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
	{
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int main()
{
//    freopen("censor.in", "r", stdin);
//    freopen("censor.out", "w", stdout);
	scanf("%s",a+1);
	la=strlen(a+1),lb=2;
	b[1]='S',b[2]='T'; 
	for(int i=2;i<=lb;i++)
	{
		int j=nxt[i-1];
		while(b[j+1]!=b[i]&&j) j=nxt[j];
		if(b[j+1]==b[i]) j++;
		nxt[i]=j;
	}
	for(int i=1,j=0;i<=la;i++)
	{
		q[++top]=i;
		while(b[j+1]!=a[i]&&j) j=nxt[j];
		if(b[j+1]==a[i]) j++;
		f[top]=j;
		if(f[top]==lb)
		{
			top-=lb;
			j=f[top];
		}
	}
	printf("%d",top);
	return 0;
}


Measured memory_bytes: 11264
#include <algorithm>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define double long double
#define INF INT_MAX
#define P pair<int,int>
#define prique priority_queue
using namespace std;
signed main() {
	int n, k;
	cin >> n >> k;
	if (k >= 2)cout << n - k << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define M_PI 3.14159265358979323846
const int MOD=1e9+7;
vector<ll>a(100005);
void solve()
{
    int n;
    cin>>n;
    ll sum=0;
    for(int i=0; i<n; i++)
    {
        int k;
        cin>>k;
        sum+=(ll)k;
        a[k]++;
    }
    int q;
    cin>>q;
    while(q--)
    {
        ll b,c;
        cin>>b>>c;
        sum-=(a[b]*b);
        sum+=(a[b]*c);
        a[c]+=a[b];
        a[b]=0;
        cout<<sum<<endl;
    }

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


Measured memory_bytes: 3872
#include<stdio.h>
int main(void){
	int n,b;
	int c;
	int count;
	int i;
	while(scanf("%d",&n)!=EOF){
		count=0;
	scanf(" %d",&b);
	c=n+b;
	for(i=0;i<1000;i++){
		c=c/10;
		count++;
		if(c<10){
			break;
		}
	}
	printf("%d\n",count+1);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { ll A, B, C,K;
  cin >> A >> B >> C >> K;
  if(K<A){
    cout << K << endl;
    return 0;
  }
  if(K<A+B){
    cout << A << endl;
    return 0;
  }
  cout << A + (K - A - B) * -1 << endl;
}

Measured memory_bytes: 3624
n=int(input())
p=list(map(int,input().split()))
a=sorted(p)

for i in range(n-1):
    for j in range(i,n):
        p[i],p[j]=p[j],p[i]
        if p==a:
            print("YES")
            exit()
        p[i],p[j]=p[j],p[i]
print("NO")

Measured memory_bytes: 39536
#include<bits/stdc++.h>
#define N 100005
using namespace std;
bool dp[N];
int x[N],y[N];
char s[N];
int xx,yy,sum=0,sum1=0;
int main()
{
	scanf("%s",s+1); scanf("%d%d",&xx,&yy);
	int n=strlen(s+1); int opt=0;
	int cntx=0; int cnty=0;
	for (int i=1;i<=n;i++){
		if (s[i]=='T'){
			if (!opt) x[++cntx]=sum;
			else y[++cnty]=sum;
			sum=0; opt=!opt;
		}
		else sum++;
	}
	if (s[n]!='T'){if (!opt) x[++cntx]=sum;else y[++cnty]=sum;}
	sum=0; sum1=0;
	for (int i=1;i<=cntx;i++) sum=sum+x[i];
	for (int i=1;i<=cnty;i++) sum1=sum1+y[i]; dp[x[1]]=true;
	for (int i=2;i<=cntx;i++)
		for (int j=sum;j>=x[i];j--) dp[j]=dp[j]|dp[j-x[i]];
	if (!dp[(sum+xx)/2]||(sum+xx)%2==1){puts("No");return 0;}
	memset(dp,false,sizeof(dp)); dp[0]=true;
	for (int i=1;i<=cnty;i++)
		for (int j=sum1;j>=y[i];j--) dp[j]=dp[j]|dp[j-y[i]];
	if (!dp[(yy+sum1)/2]||(sum1+yy)%2==1){puts("No");return 0;}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>

int main(){
    // 入力-----------------------
    int N,i,j;
    scanf("%d",&N);
    int *A = malloc(sizeof(int)*N);
    int *B = malloc(sizeof(int)*N);
    int *C = malloc(sizeof(int)*(N-1));
    for(i=0;i<N;i++) {
        scanf("%d",&j);
        A[i]=j-1;
    }
    for(i=0;i<N;i++) scanf("%d",&B[i]);
    for(i=0;i<N-1;i++) scanf("%d",&C[i]);
    // 処理------------------------
    int ans = 0;
    for(i=0;i<N;i++){
        ans += B[A[i]];
        if(i != N-1 && A[i]+1==A[i+1]) ans+=C[A[i]];
    }
    // 出力
    printf("%d\n",ans);
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

#define REP(i, N) for (int i = 0; i < N; i++)
#define REP1(i, N) for (int i = 1; i < N; i++)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ANS(a) cout << a << endl;
#define SORT(V) sort(V.begin(), V.end())
#define RSORT(V) sort(V.rbegin(), V.rend())

#define DBG(V) for (auto v : V) cout << v << " "; cout << endl

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

  if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
    ANS("Yes");
  } else if (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) {
    ANS("Yes");
  } else if (S[0] == S[3] && S[1] == S[2] && S[0] != S[1]) {
    ANS("Yes");
  } else {
    ANS("No");
  }
  
  return 0;
}


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

int main(void){
    // Your code here!
    int N, x[8], y[8], factn = 1, factn1 = 1;
    double sum = 0;
    
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        cin >> x[i];
        cin >> y[i];
        factn *= i+1;
        if(i != N-1)
            factn1 *= i+1;
    }
    
    for(int i = 0; i < N; i++)
    {
        for(int j = i+1; j < N; j++)
        {
            double road = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
            sum += road * factn1 * 2;
        }
    }
    
    cout << fixed << setprecision(10) << sum/factn << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
X = S.count("RL")
Y = 0
if S[0] == "L":
    Y += 1
if S[-1] == "R":
    Y += 1

ans = 0
for a, b in zip(S, S[1:]):
    if a == b:
        ans += 1
ans += 2*min(K, X)
if K > X:
    ans += min(Y, K-X)
print(min(N-1, ans))


Measured memory_bytes: 41452
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (1LL<<57)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	int a,b,c;
	cin>>a>>b>>c;
	if(((a == b) && (a != c)) || ((b == c) && (a != c)) || ((a == c) && (a != b)))
	cout<<"Yes\n";
	else cout<<"No\n";
	return;	
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

// #ifndef ONLINE_JUDGE
// 	time_t time_t1, time_t2;
// 	time_t1 = clock();
// #endif

	while(T--)
	solve(T);

// #ifndef ONLINE_JUDGE
// 	time_t2 = clock();
// 	SETF();
// 	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
// 	UNSETF();
// #endif

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
int main()
{
    char str[10000000];
    int w,i;
    scanf("%s",str);
    scanf("%d",&w);
    for(i=0;i<strlen(str);i=i+w)
    {
        printf("%c",str[i]);
    }
    return 0;
}

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

int main () {
  int h,w,n;
  cin >>h>>w>>n;
  int cnt=0;

  if(h>w){
    for(int i=0;i<n;i++){
      if(n>h*i){
        cnt++;
      }else break;
    }
  }else if(h<=w){
    for(int j=0;j<n;j++){
      if(n>w*j){
      cnt++; 
      } else break;
    }
  }

cout<<cnt<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;

int a[500000];
int nx[40][500000];
ll cnt[40][500000];

int main(){
	int n;ll K;cin>>n>>K;
	rep(i,n){
		scanf("%d",&a[i]);
		a[i+n]=a[i];
	}
	map<int,int>mp;
	for(int i=2*n-1;i>=0;i--){
		nx[0][i]=(mp[a[i]]+1)%n;
		cnt[0][i]=mp[a[i]]+1-i;
		mp[a[i]]=i;
	}
	for(int i=1;i<40;i++){
		rep(j,n){
			nx[i][j]=nx[i-1][nx[i-1][j]];
			cnt[i][j]=cnt[i-1][j]+cnt[i-1][nx[i-1][j]];
		}
	}
	ll sum=n*K;
	sum--;
	int pos=0;
	for(int i=39;i>=0;i--){
		while(sum>=cnt[i][pos]){
			sum-=cnt[i][pos];
			pos=nx[i][pos];
		}
	}
	mp.clear();
	int cur=pos;
	stack<int>st;
	rep(i,sum+1){
		if(mp[a[cur]]){
			while(mp[a[cur]]){
				mp[st.top()]--;
				st.pop();
			}
		}
		else{
			st.push(a[cur]);
			mp[st.top()]++;
		}
		cur=(cur+1)%n;
	}
	vector<int>ans;
	while(!st.empty()){
		ans.push_back(st.top());
		st.pop();
	}
	reverse(ans.begin(),ans.end());
	for(int i:ans){
		printf("%d ",i);
	}
	puts("");
}

Measured memory_bytes: 240376
#include <bits/stdc++.h>
using namespace std;
bool ispri[150000];
void pri()
{
    for(int i=2;i<=150000;i++){
        if(ispri[i]==0){
            for(int j=i+i;j<=150000;j+=i){
                ispri[j]=1;
            }
        }
    }
}
int main()
{
    int n;
    cin>>n;
    pri();
    while(ispri[n]){
        n++;
    }
    cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
map <int ,int> mpa,mpb;

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

int selectionSort(int A[], int n){
  int minv=0;
  int cnt=0;
  for(int i=0;i<n;i++){
    minv=i;
    for(int j=i;j<n;j++){
      if(A[minv]>A[j]){
        minv=j;
      }
    }
    swap(A[i],A[minv]);
    if(i!=minv) cnt++;
  }
  return cnt;
}

int main (){
  int N;
  cin >> N;
  int B[N];
  int ans=0;
  for(int i=0;i<N;i++){
    cin >> B[i];
  }
  ans=selectionSort(B,N);
  trace(B,N);
  cout << ans << endl;
  return 0;
}


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

int main() {
    std::cout<<std::fixed<<std::setprecision(10);
    
    int A, B; cin >> A >> B;

    // int ans = 1;
    int ans = 0;

    int nec = ((B-1)+(A-2)) / (A-1);
    if (nec > 0) ans += nec;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,a[200009],m,mi=INT_MAX,k,ans=0,fl=0;
	string s1,s2;
	cin>>s1>>s2;
	n=s1.size();
	m=s2.size();
	for(int i=0;i<=n-m;i++)
	{
		ll ct=0;
		for(int j=0;j<m;j++)
		{
			if(s1[i+j]!=s2[j])
				ct++;
		}
		mi=min(mi,ct);
	}
	cout<<mi<<endl;
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/12/10  Problem: ARC 086 A / Link: http://arc086.contest.atcoder.jp/tasks/arc086_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	LL K; cin >> N >> K;
	VL a(N);
	VL c(N+100, 0);
	int cnt = 0;
	FOR(i, 0, N) {
		cin >> a[i];
		if (c[a[i]] == 0)cnt++;
		c[a[i]]++;
	}
	RSORT(c);
	FOR(i, 0, SZ(c)) {
		if (K > 0) {
			K--;
		}
		else {
			ans += c[i];
		}
	}


	cout << ans << "\n";

	return 0;
}


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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef pair<ll, ll> pint;


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



void print(const vint& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}

vector< bool > primes(ll n){
  vector< bool > rtn(n+1, true);
  // bool checked[n+1];
  // rep(i,n+1) checked[i] = false;

  for(ll i=2; i*i <= n; ++i){
    if(!rtn[i]) continue;
    // checked[i] = true;
    ll j = i;
    while( (j+=i) <= n ){
      rtn[j] = false;
    }
  }

  return rtn;
}

int main() {


  cout<<fixed<<setprecision(10);

  ll n; cin>>n;
  vint R(n); rep(i,n) cin>>R[i];

  vint dp(n, R[1]-R[0]);
  ll min = R[0];

  for(ll i=1; i<n; ++i){
    dp[i] = max(dp[i-1], R[i] - min);

    if(min > R[i]) min = R[i];
  }

  cout<<dp[n-1]<<endl;


}





//




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

int main(){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    
    if((x-r < 0 || w < x+r) || (y-r < 0 || h < y+r)) cout << "No" << endl;
    if((x-r >= 0 && x+r <= w) && (y-r >= 0 && y+r <= h)) cout << "Yes" << endl;
}


Measured memory_bytes: 3116
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

ll a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;


int main()
{
	int n; cin >> n; vector<ll> a(n);cin>> a[0];
	rep(i, n - 1) { cin >> b; a[i + 1] = a[i] + b; }
	ll sum = a[n - 1]; ll  flag = sum / 2;
	for(int i=1;i<n;i++) {
		if (flag <= a[i]&&flag>a[i-1]) {
			cout << min(abs(sum - 2*a[i]),abs (sum - 2*a[i-1])) << endl; return 0;
		}
	}


	return 0;
}


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


using ll = long long int;

using namespace std;




int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a, b;
    
    cin >> a >> b;
    
    cout << (6 - (a + b));
    
    return 0;
}


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

int main()
{
	int n, i, j;
	vector< vector<int> > list(11, vector<int>(11));
	while (cin>>n, n) {
		for (i = 0; i <= n; i++) {
			list[i][n] = 0;
			list[n][i] = 0;
		}
		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				cin>>list[i][j];
				list[i][n] += list[i][j];
				list[n][j] += list[i][j];
				list[n][n] += list[i][j];
			}
		}
		for (i = 0; i <= n; i++) {
			for (j = 0; j <= n; j++) {
				cout<<setw(5)<<right<<list[i][j];
			}
			cout<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

char s[100010];
ll mod = 1e9 + 7, pow3[100010], pow2[100010];
int main() {
	scanf("%s", s);
	int len;
	for (len = 0; s[len]; len++);
	
	pow3[0] = pow2[0] = 1;
	for (int i = 1; i <= len; i++) {
		pow3[i] = pow3[i - 1] * 3 % mod;
		pow2[i] = pow2[i - 1] * 2 % mod;
	}
	
	ll sum = 0, oc = 0;
	for (int i = 0; i < len; i++)
		oc += s[i] == '1';
	sum = pow2[oc];
	for (int i = len - 1; 0 <= i; i--)
		if (s[i] == '1') {
			sum += pow2[--oc] * pow3[len - i - 1];
			sum %= mod;
		}
	printf("%lld\n", sum);
}

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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            if ((str[0] * str[1]) % 2 == 0)
            {
                Console.WriteLine("Even");
            }
            else
            {
                Console.WriteLine("Odd");
            
            }
        }
    }
}


Measured memory_bytes: 11092
n = int(input())
cards = list(map(int, input().split()))
result = 0
result2 = 0

while(cards != []):
    result += max(cards)
    cards.remove(max(cards))
    if cards != []:
        result2 += max(cards)
        cards.remove(max(cards))

print(result-result2)


Measured memory_bytes: 9132
#include<stdio.h>

int main() {
	int a, b;
	char op;

	while (1) {

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

		if (op == '+') {
			printf("%d\n", a + b);
		}
		else if (op == '-') {
			printf("%d\n", a - b);
		}
		else if (op == '*') {
			printf("%d\n", a * b);
		}
		else if (op == '/') {
			printf("%d\n", a / b);
		}
		else {
			break;
		}
	}

	return 0;
}


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

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  int dist = 0, dist_max = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
//    cout << "A.at(i) =" << A.at(i) << endl;
  }
  
  int dist_N_0 = K - A.at(N-1) + A.at(0);
//  cout << dist_N_0 << endl;
  
  for (int i = 0; i < N - 1; i++) {
    if ((A.at(i+1) - A.at(i)) > dist_max) {
      dist_max = A.at(i+1) - A.at(i);
//      cout << "dist_max =" << dist_max << endl;
    }
  }
  if (dist_N_0 > dist_max) {
    dist_max = dist_N_0;
//    cout << dist_max << endl;
  }
  
  cout << K - dist_max << endl;
    
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

const int MAXN = 200005;

int q;
ll n;

struct Segtree{
    struct node {
        ll val, tag;
    };
    node ST[4 * MAXN];

    void init(int l, int r, int id) {
        ST[id].val = ST[id].tag = n;
        if (l == r) {
            return;
        } else {
            int m = (l + r) >> 1, lson = 2 * id + 1, rson = 2 * id + 2;
            init(l, m, lson);
            init(m+1, r, rson);
        }
    }

    void push(int l, int r, int id) {
        if (l == r) {
            ST[id].val = min(ST[id].val, ST[id].tag);
            ST[id].tag = n;
            return;
        }
        ll x = ST[id].tag, lson = 2 * id + 1, rson = 2 * id + 2;
        ST[id].tag = n;
        ST[lson].tag = min(ST[lson].tag, x);
        ST[rson].tag = min(ST[rson].tag, x);
    }

    ll query(int l, int r, int id, int pt) {
        push(l, r, id);
        if (l > pt || r < pt) return n;
        else if (l == r && l == pt) return min(ST[id].val, ST[id].tag);
        else if (l <= pt && pt <= r) {
            push(l, r, id);
            int m = (l + r) >> 1, lson = 2 * id + 1, rson = 2 * id + 2;
            return min(query(l, m, lson, pt), query(m + 1, r, rson, pt));
        }
        else {
            int m = (l + r) >> 1, lson = 2 * id + 1, rson = 2 * id + 2;
            push(l, r, id);
            return min(query(l, m, lson, pt), query(m + 1, r, rson, pt));
        }
    }

    void modify(int l, int r, int id, int xl, int xr, ll val) {
        if (l > xr || r < xl) return;
        else if (xl <= l && r <= xr) {
            ST[id].tag = min(ST[id].tag, val);
            return;
        } else {
            int m = (l + r) >> 1, lson = 2 * id + 1, rson = 2 * id + 2;
            push(l, r, id);
            modify(l, m, lson, xl, xr, val);
            modify(m+1, r, rson, xl, xr, val);
        }
    }
}x, y;

int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    while (cin >> n >> q) {
        n -= 2;
        x.init(1, n, 0);
        y.init(1, n, 0);
        ll ans = n * n;

        while (q--) {
            int op, id;
            ll now;
            cin >> op >> id;
            id--;

            if (op == 1) {
                now = x.query(1, n, 0, id);
                y.modify(1, n, 0, 1, now, id - 1);
                ans -= now;
            } else {
                now = y.query(1, n, 0, id);
                x.modify(1, n, 0, 1, now, id - 1);
                ans -= now;
            }
            //cout << now << ' ';
        }
        //cout << '\n';
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 20080
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
int m[1000], hang[1000], next[1000];
bool vis[1000];
int last[1000], tim[1000];
bool check(int p, int n, int t)
{
	memset(vis, 0, n);
	memset(tim, 0, 4 * p);
	memset(last, 0, 4 * n);
	int ret = 0;
	for (int i = 0; i <= t; ++ i)
	{
		for (int j = 0, k = 0; j < p && k < n; ++ j)
			if (tim[j] <= i)
			{
				while (k < n && (last[k] > i || last[k] + hang[k] < i || vis[k] == 1))
					++ k;
				if (k < n)
				{
					tim[j] = i + m[k];
					if (tim[j] > t)
						return 0;
					vis[k] = 1;
					++ ret;
				}
			}
		for (int k = 0; k < n; ++ k)
			if (!vis[k] && last[k] + hang[k] <= i)
				last[k] += hang[k] + next[k];
	}
	return ret == n;
}
int main()
{
	int n, t;
	while (scanf("%d%d", &n, &t), n)
	{
		int sum = 0;
		for (int i = 0; i < n; ++ i)
		{
			scanf("%d%d%d", &m[i], &hang[i], &next[i]);
			sum += m[i];
		}
		for (int i = max(1, sum / t); i <= n; ++ i)
			if (check(i, n, t))
			{
				printf("%d\n", i);
				break;
			}
	}
	return 0;
}

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

bool check(string s){
  if( s == "ABC" ){
    return true;
  }
  if( s.size() <= 3 ){
    return false;
  }


  string t="";
  for(int i=0;i<s.size();){
    
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
      t+='X';
      i+=3;
    }else{
      t+=s[i];
      i++;
    }
  }
  
  int fa=0,fb=0,fc=0;
  for(int i=0;i<t.size();i++){
    if(t[i]=='A')fa=1;
    if(t[i]=='B')fb=1;
    if(t[i]=='C')fc=1;
  }
  
  if( s == t ){
    return false;
  }
  
  if(fa+fb+fc!=2){
    return false;
  }

  for(int i=0;i<t.size();i++){
    if(t[i]=='X'){
      if(fa==0)t[i]='A';
      if(fb==0)t[i]='B';
      if(fc==0)t[i]='C';
    }
  }

  return check(t);
}

int main(){
  string s;
  cin>>s;
  if( check(s) ){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}



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

namespace Volume0
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                string s = Console.ReadLine();
                if (s == null) break;
                double[] i = s.Split(' ')
                            .Select(e => double.Parse(e))
                            .ToArray();
                double x = (i[2] * i[4] - i[1] * i[5]) 
                              / (i[0] * i[4] - i[1] * i[3]);
                double y = (i[5] * i[0] - i[2] * i[3])
                              / (i[0] * i[4] - i[3] * i[1]);
                Console.WriteLine("{0:F3} {1:F3}", x, y);
            }
        }
    }
}

Measured memory_bytes: 9616
#include <vector>
#include <algorithm>
#include <cstdio>
#define LIMIT 10000
using namespace std;
bool ck(vector<int>&v){
	for(int i=0;i<v.size();i++)if(v[i]!=i+1)return false;
	return true;
}
main(){
	int n,i,j,s,x,l;
	vector<int>tri;
	for(i=1;i<1199;i++)tri.push_back(i*(i+1)/2);
	for(;scanf("%d",&n),n;){
		vector<int>v;
		for(s=i=0;i<n;i++){
			scanf("%d",&x);
			s+=x;
			v.push_back(x);
		}
		vector<int>::iterator idx=find(tri.begin(),tri.end(),s);
		i=LIMIT+1;
		if(idx!=tri.end()){
			for(i=0;i<=LIMIT&&!ck(v);i++){
				l=v.size();
				for(j=0;j<l;j++)v[j]--;
				v.erase(remove(v.begin(),v.end(),0),v.end());
				v.push_back(l);
			}
		}
		printf("%d\n",i>LIMIT?-1:i);
	}
}

Measured memory_bytes: 1068
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));

	String[] strArray = br.readLine().split(" ");
	int A = Integer.parseInt(strArray[0]);
	int B = Integer.parseInt(strArray[1]);
	int C = Integer.parseInt(strArray[2]);
	int K = Integer.parseInt(strArray[3]);
	int sum = 0;

	if (A > 0) {
	    if (K - A > 0) {
		sum += A;
		K -= A;
	    } else {
		sum = K;
		K = 0;
	    }
	}

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

	if (K > 0 && C > 0) {
	    sum = sum + (K * -1);
	}

	System.out.println(sum);
    }
}

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

ll dp[3001][3001];
string str1,str2;

ll solve(ll i,ll j)
{
    if(i>=str1.size() or j>=str2.size())
    {
        return 0;
    }
    if(dp[i][j]!=-1)
    {
        return dp[i][j];
    }
    ll l=0;
    if(str1[i]==str2[j])
    {
        l=1+solve(i+1,j+1);
    }
    else
    {
        l=max(solve(i+1,j),solve(i,j+1));
    }
    return dp[i][j]=l;
}

string getstring()
{
    string ans="";
    ll i=0,j=0;
    ll l=solve(0,0);
    if(l==0)
    {
       return ans;
    }
    while(l)
    {
        if(str1[i]==str2[j])
        {
            ans=ans+str1[i];
            i++;
            j++;
            l--;
        }
        else
        {
            if(dp[i+1][j]>dp[i][j+1])
            {
                i++;
            }
            else
            {
                j++;
            }

        }

    }
    return ans;

}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dp,-1,sizeof(dp));

    cin>>str1>>str2;

    

    cout<<getstring();
return 0;
}


Measured memory_bytes: 74216
#include<stdio.h>
int main(){
	int i,n,c[5][14],m,j;
	char d;
	scanf("%d",&n);
	for(i=1;i<5;i++){
		for(j=1;j<14;j++){
			c[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		scanf(" %c %d",&d,&m);
		if(d=='S'){
			c[1][m]=m;
		}else if(d=='H'){
			c[2][m]=m;
		}else if(d=='C'){
			c[3][m]=m;
		}else if(d=='D'){
			c[4][m]=m;
		}	
	}
	for(i=1;i<5;i++){
		for(j=1;j<14;j++){
			if(i==1 && c[i][j]==0){
				printf("S %d\n",j);
			}else if(i==2 && c[i][j]==0){
				printf("H %d\n",j);
			}else if(i==3 && c[i][j]==0){
				printf("C %d\n",j);
			}else if(i==4 && c[i][j]==0){
				printf("D %d\n",j);
			}
		}
	}
}


Measured memory_bytes: 2084
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int numA, numB, numC, numD, numX, numY, numZ;

    scanf("%d %d %d %d", &numA, &numB, &numC, &numD);
    
    if (numA < numC)
    {
        numX = numC - numA;
    }
    else
    {
        numX = numA - numC;
    }

    if (numA < numB)
    {
        numY = numB - numA;
    }
    else
    {
        numY = numA - numB;
    }

    if (numB < numC)
    {
        numZ = numC - numB;
    }
    else
    {
        numZ = numB - numC;
    }

    if (numX <= numD || (numY <= numD && numZ <= numD))
    {
        printf("%s", "Yes");
    }
    else
    {
        printf("%s", "No");
    }

    return 0;
}

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

int main(){
	int x, y;
	while(cin >> x >> y && (x != 0 || y != 0)){
		if(x > y){
			int tmp = x;
			x = y;
			y = tmp;
		}
		cout << x << ' ' << y << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int INF = 2e9;
 
int main(){
    int n, a, b, c, d;
    bool ans = true, point = false;
    string s;
    cin >> n >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    cin >> s;
    for(int i=a+1; i<max(c,d)-1; i++){
        if(s[i]=='#' && s[i+1]=='#'){
            ans = false;
        }
    }
    if(d<c){
        for(int i=b; i<=d; i++){
            if(d==n-1 && i==d) break;
            if(s[i-1]=='.' && s[i]!='#' && s[i+1]=='.'){
                point = true;
            }
        }
        if(!point){
            ans = false;
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 640