akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;


main(){
	int n;
	cin>>n;
	while(n--){
		int score=0,ace=0;
		char a,b;
		cin>>a>>b;
		if(isdigit(a))score+=a-'0';
		else if(a=='A'){
			score+=11;
			ace++;
		}else{
			score+=10;
		}
		if(isdigit(b))score+=b-'0';
		else if(b=='A'){
			if(score>10){
				score++;
			}else{
				score+=11;
				ace++;
			}
		}else score+=10;
		
		
		char in[8];
		for(int i=0;i<8;i++){
			cin>>in[i];
		}
		
		if(score==21){
			puts("blackjack");
			continue;
		}
		
		for(int i=0;i<8;i++){
			if(score<17 || (ace>0 && score==17)){
				int hit=in[i];
				if(isdigit(hit)){
					score+=hit-'0';
				}else if(hit=='A'){
					if(score>10)score++;
					else{
						score+=11;
						++ace;
					}
				}else score+=10;
			}else break;
			if(score>21 && ace>0){
				--ace;
				score-=10;
			}
			if(score>21)break;
		}
		if(score>21)puts("bust");
		else printf("%d\n",score);
	}
}

Measured memory_bytes: 0
#include <cstdio>
#include <functional>
#include <vector>
#include <algorithm>

int main()
{
    int N = 0, Y = 0;
    int x = -1; // number of 10000円
    int y = -1; // number of 5000円
    int z = -1; // number of 1000円

    scanf("%d%d", &N, &Y);
    bool found = false;
    x = Y / 10000;
    while (x >= 0 && !found)
    {
        y = (Y - 10000 * x) / 5000;
        while (y >= 0)
        {
            z = (Y - 10000 * x - 5000 * y) / 1000;
            if ((x + y + z == N) && x >= 0 && y >= 0 && z >= 0)
            {
                found = true;
                break;
            }
            y--;
        }
        if (!found)
        {
            x--;
        }
    }

    // Output
    if (found)
    {
        printf("%d %d %d\n", x, y, z);
    }
    else
    {
        printf("-1 -1 -1\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define IOSF ios::sync_with_stdio(false)
typedef long long LL;
using namespace std;
const int INF=0x3f3f3f3f;
const int MAX=10e3+5;

int n,match[1000]={0};

struct node{
    int x,y;
}a[150];

int book[1000]={0};

int dfs(int u){
    int i;
    for(i=n+1;i<=2*n;i++){
        if(book[i]==0&&a[u].x<a[i].x&&a[u].y<a[i].y){
            book[i]=1;

            if(match[i]==0||dfs(match[i])){
                match[i]=u;
                return 1;
            }
        }
    }
    return 0;
}


int main()
{
    IOSF;
    mem(match,0);
    mem(book,0);
    int sum=0;
    cin>>n;
    for(int i=1;i<=2*n;i++){
        cin>>a[i].x>>a[i].y;
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=2*n;j++) book[j]=0;
        if(dfs(i))
            sum++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k,s;
    cin >> k >> s;
    long long ans =0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            if(i+j>s||s-i-j>k) continue;
            ans++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
	int A, B, X;
	scanf("%d %d", &A ,&B);
	if (A == B) {
		X = A + B;
	}
	else {
		X = 2 * max(A, B);
		X = X - 1;
	}
	printf("%d", X);
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	if(s == "Sunny") cout << "Cloudy" << endl;
	else if(s == "Cloudy") cout << "Rainy" << endl;
	else cout << "Sunny" << endl;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  ll n;
  cin >> n;
  cout << (n*(n+1))/2<<endl;
}


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

int main(){
    int n,m,r=300000000,ans=51;
    cin>>n>>m;
    vector<int> sx(n),sy(n),cx(m),cy(m);
    for(int i=0;i<n;i++) cin>>sx.at(i)>>sy.at(i);
    for(int i=0;i<m;i++) cin>>cx.at(i)>>cy.at(i);
    for(int i=0;i<n;i++){
        for(int j=m-1;j>=0;j--){
            int l=max(cx.at(j)-sx.at(i),sx.at(i)-cx.at(j))+max(cy.at(j)-sy.at(i),sy.at(i)-cy.at(j));
            if(r>=l){
               r=l;
               ans=j+1;
            }
        }
        r=300000000;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
const int MAXN=1e5+10;
int a[MAXN];
int m,n,l,p,k;
long long ans,tot;
int inline 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*10+ch-'0';ch=getchar();}
    return x*f;
}
int main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+1+n);
	if (n%2==1)
	{
		//jishuwei a
		p=n/2;
		for (int i=p+2;i<=n;i++) ans=ans+a[i]*2;
		for (int i=1;i<=p;i++) ans=ans-a[i]*2;
		tot=ans+a[n/2]-a[(n+1)/2];
		ans=ans-a[p+2]+a[p+1];
		ans=max(ans,tot);
		printf("%lld",ans);
		
		return 0;	
	}
	
	p=n/2;
	for (int i=p+1;i<=n;i++) ans=ans+a[i]*2;
	for (int i=1;i<=p;i++) ans=ans-a[i]*2;
	ans=ans+a[p]-a[p+1];
	printf("%lld",ans);
	
	
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int N, M;
int D[SIZE];
pair<int,int> O[SIZE];

vector<pair<int,int>> G[SIZE];
int ans[SIZE], dist[SIZE];
bool c[SIZE];

int main() {

  scanf("%d%d", &N, &M);

  for (int i=0; i<N; i++) {
    scanf("%d", D+i);
    O[i] = {D[i], i};
  }

  sort(O, O + N);

  for (int i=0; i<M; i++) {
    int U, V;
    scanf("%d%d", &U, &V);
    U--; V--;
    G[U].push_back({V, i});
    G[V].push_back({U, i});
  }

  for (int i=0; i<M; i++)
    ans[i] = -1;

  for (int i=0; i<N; i++) {
    int p = O[i].second;
    int d = O[i].first;

    bool isB = true;
    pair<int,int> q;

    for (auto e : G[p]) {
      int to = e.first;
      if (c[to] || (dist[to] && dist[to] < d)) {
        isB = false;
        q = e;
      }
    }

    if (isB) {
      c[p] = true;
    } else {
      c[p] = false;
      assert(ans[q.second] == -1);
      ans[q.second] = d - dist[q.first];
      dist[p] = d;
    }
  }

  int e9 = 1000000000;

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

  for (int i=0; i<M; i++) {
    if (ans[i] == -1) ans[i] = e9;
  }


  for (int i=0; i<N; i++) {
    if (!c[i]) continue;
    int mindist = INF;

    for (auto e : G[i]) {
      mindist = min(mindist, ans[e.second]);
    }

    int d = D[i];
    if (mindist > d) {
      for (auto e : G[i]) {
        int to = e.first;
        if (dist[to] >= d && ans[e.second] == INF && !c[to] && D[to] <= d) {
          ans[e.second] = d;
          dist[i] = d;
          mindist = d;
          break;
        }
      }
    }

    if (mindist != D[i]) {
      puts("-1");
      return 0;
    }
  }

  for (int i=0; i<N; i++) {
    printf("%c", "WB"[c[i]]);
  }

  puts("");

  for (int i=0; i<M; i++) {
    printf("%d\n", ans[i]);
  }


  return 0;
}


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

using namespace std ;

const int MAX = 1e5 + 10 ;

int n , m ;
int arr[MAX] ;
string s ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	if(n >= 10)
		return cout<<m<<"\n" , 0 ;
	else
		return cout<<m + 100 * (10-n) <<"\n" , 0 ;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
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());
        StringTokenizer st=new StringTokenizer(br.readLine());
        int[] a=new int[2*n];
        for(int i=0;i<2*n;i++){ a[i]=Integer.parseInt(st.nextToken()); }
        Arrays.parallelSort(a);
        int sum=0;
        for(int i=0;i<2*n;i+=2){ sum+=a[i]; }
        System.out.println(sum);
    }
}

Measured memory_bytes: 8276
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]
    cd = [list(map(int, input().split())) for _ in range(m)]

    for a, b in ab:
        arr = []
        for c, d in cd:
            arr.append(abs(a-c)+abs(b-d))
        print(arr.index(min(arr))+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
# B - ... (Triple Dots)

# 文字列Sの長さがK以下ならSをそのまま出力
# Kより長いならば、先頭K文字を切り出し、末尾に...をつけて出力

K = int(input())
S = input()

len_S = len(S)

if len_S <= K:
    print(S)
else:
    print(S[:K] + '...')


Measured memory_bytes: 9152
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
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; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}


/* math_method */
int ceil(int a, int b){return a / b + (a % b > 0);}


/* main */

int n;
vi x;
vi y;
set<pi> tmp;
void in(){
    cin >> n;
    rep(i,0,n){
        x.push_back(input());
        y.push_back(input());
        tmp.insert(pi(x[i], y[i]));
    }
}

void solve(){

    int ans = inf;
    rep(i,0,n){
        rep(j,0,n){
            set<pi> s = tmp;
            int dx = x[i] - x[j];
            int dy = y[i] - y[j];
            int cnt = 0;

            while(not s.empty()){
                cnt++;
                int tx = s.begin() -> first;
                int ty = s.begin() -> second;
                s.erase(pi(tx, ty));
                while(exist(s, pi(tx + dx, ty + dy))){
                    tx += dx;
                    ty += dy;
                    s.erase(pi(tx, ty));
                }
            }
            chmin(ans, cnt);
        }
    }

    print(ans);

}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

string solve()
{
    string t,p;
    cin >>t >>p;

    int T = t.size(), P = p.size();

    vector<int> a,b;
    int idx = 0;
    rep(i,T)
    {
        if(idx<P && t[i] == p[idx])
        {
            a.pb(i);
            ++idx;
        }
    }

    if(a.size()!=P) return "no";

    idx = P-1;
    for(int i=T-1; i>=0; --i)
    {
        if(idx>=0 && t[i]==p[idx])
        {
            b.pb(i);
            --idx;
        }
    }
    reverse(all(b));

    rep(i,a.size())if(a[i]!=b[i]) return "no";
    return "yes";
}

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

Measured memory_bytes: 9012
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        List<Integer> h = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            h.add(sc.nextInt());
        }

        int result = 0;
        for(int height : h){
            if (k <= height){
                result++;
            }
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 58260
#include <iostream>

using namespace std;

int main()
{
    int k , a , b;
    cin >> k >> a >> b;
    for (int i = a ; i <= b ; i++){
        if (i % k == 0){
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    ll n;
    cin >> n;
    for (int x = 1; x <= 3500; ++x) {
        for (int y = 1; y <= 3500; ++y) {
            if (4 * x * y - n * x - n * y == 0) continue;
            if (n * x * y % (4 * x * y - n * x - n * y) == 0) {
                ll z = n * x * y / (4 * x * y - n * x - n * y);
                if (z < 1) continue;
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
n,m=map(int,input().split())
ans = [0]*n
tmp = [0]*n
pen = [0]*n
for i in range(m):
  inp = input().split()
  if inp[1] == "AC":
    ans[int(inp[0])-1] = 1
    pen[int(inp[0])-1] = tmp[int(inp[0])-1]
  elif inp[1] == "WA":
    if ans[int(inp[0])-1] == 0:
      tmp[int(inp[0])-1] += 1
        
print("{0} {1}".format(sum(ans),sum(pen)))

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define maxn 30001
#define int long long int
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b) { return a / gcd(a, b) * b; }

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

signed main() {
    int N;
    cin >> N;
    for(double i = 1;i < 50001;i++){
        int X = i*1.08;
        if(X== N){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" <<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> A(N, vector<int>(M));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			cin >> A[i][j]; --A[i][j];
		}
	}
	int res = 1 << 30;
	vector<int> use(M, 1);
	int loop = M;
	while (loop) {
		vector<int> cnt(M, 0);
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < M; ++j) {
				if (use[A[i][j]]) {
					++cnt[A[i][j]];
					break;
				}
			}
		}
		auto iter = max_element(cnt.begin(), cnt.end());
		res = min(res, *iter);
		int del_sp = iter -cnt.begin();
		use[del_sp] = 0;
		--loop;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 640
import itertools

N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]
class_list = ["A", "B", "C", "D"]

a_list = list(itertools.product(class_list, repeat=N))
# print(a_list)

A_sum = 0
B_sum = 0
C_sum = 0
A_count = 0
B_count = 0
C_count = 0

min_score = 10**9
for a in a_list:
    for idx, b in enumerate(a):
        # print(b)
        if b == "A":
            A_sum += L[idx]
            A_count += 1
        elif b == "B":
            B_sum += L[idx]
            B_count += 1
        elif b == "C":
            C_sum += L[idx]
            C_count += 1
    if A_count > 0 and B_count > 0 and C_count > 0:
        score = (A_count-1+B_count-1+C_count-1) * 10 + abs(A-A_sum) + abs(B-B_sum) + abs(C-C_sum)
        # print(A_sum, B_sum, C_sum, score)
        min_score = min(min_score, score)
    A_sum = 0
    B_sum = 0
    C_sum = 0
    A_count = 0
    B_count = 0
    C_count = 0

print(min_score)

Measured memory_bytes: 52164
# frozen_string_literal: true

a, b, c, d = gets.split.map(&:to_i)

class Integer
  def anti_div(x, y)
    self - self / x - self / y + self / x.lcm(y)
  end
end

puts b.anti_div(c, d) - (a - 1).anti_div(c, d)

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

using namespace std;

int main()
{
    double w,h,x,y;
    cin>>w>>h>>x>>y;
    cout <<setprecision(6)<<fixed<<(w*h/2.0)<<' '<<(x==w/2&&y==h/2) << endl;
    return 0;
}


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 H1 = Integer.parseInt(sc.next());
	  int count = 0;
	  int max = 0;
	  for(int i = 0; i < N - 1; i++) {
		  int H2 = Integer.parseInt(sc.next());
		  if(H1 >= H2) {
			  count++;
			  if(count > max) {
				  max = count;
			  }
		  }
		  else {
			  count = 0;
		  }
		  H1 = H2;
	  }
	  System.out.println(max);
	  sc.close();
	  
  }
}


Measured memory_bytes: 47236
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <climits>
#include <set>
#include <queue>

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {

	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";

    return out;

}


int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

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

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

	vector<long long> min_dists; 
	min_dists.reserve(n - k +1);
	for (int l = 0, r = k - 1; r < n; ++l, ++r) {
		long long way1 = abs(candle_positions[r]) + abs(candle_positions[r] - candle_positions[l]);
		long long way2 = abs(candle_positions[l]) + abs(candle_positions[l] - candle_positions[r]);
		min_dists.push_back(min(way1, way2));
	}

	cout << *min_element(min_dists.begin(), min_dists.end()) << "\n";


	return 0;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,n) for(int i=0;i<n;i++)
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> vx(n);
    vector<ll> vy(n);
    // f(i,n){
    	// cin  >> vx[i] >>  vy[i] ;
    // }
    // sort(vx,vx+n);
    // sort(vy,vy+n);
    ll mxp=-10000000000, mxm = -10000000000, mnp = 10000000000, mnm = 10000000000;
    f(i,n){
    	cin >> vx[i] >> vy[i];
    	mxp = max(mxp, vx[i] + vy[i]);
    	mxm = max(mxm, vx[i] - vy[i]);
    	mnp = min(mnp, vx[i] + vy[i]);
    	mnm = min(mnm, vx[i] - vy[i]);
    }
    // cout << mxp << " " << mnp << " " << mxm << " " << mnm << endl;
    cout << max(mxp-mnp,mxm-mnm) << endl;

	return 0;
}

Measured memory_bytes: 6284
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
      	int m = scn.nextInt();
      	int x = scn.nextInt();
		int[] c = new int[n];
      	int[][] a = new int[n][m];
		for(int i=0; i<n; i++){
			c[i] = scn.nextInt();
          	for(int j=0; j<m; j++){
              a[i][j]=scn.nextInt();
            }
		}
      	ArrayList<Integer> money = new ArrayList<>();
		for(int i=0; i<1<<n; i++) {
			int[] sum = new int[m];
			int check  = 0;
			int cost = 0;
			for(int j=0; j<n; j++) {
				if((1 & i >> j) == 1) {
					for(int k = 0; k < m; k++) {
						sum[k] += a[j][k];
					}
					cost += c[j];
				}
			}
			for(int j = 0; j < m; j++) {
				if(sum[j] < x) {
					check = 1;
					break;
				}
			}
			if(check==0) {
				money.add(cost);
			}
		}
		if(money.isEmpty()) {
			System.out.println(-1);
			return;
		}
		Collections.sort(money);
		System.out.println(money.get(0));

	}
}

Measured memory_bytes: 37612
#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	D = defaultdict(int)
	for i in range(N):
		S = input()
		D[S] += 1

	L = []
	for i in D:
		L.append([D[i], i])
	L = sorted(L)
	X = len(L)
	c = L[-1][0]
	ans = []
	for i in range(X):
		if L[-1 - i][0] == c:
			ans.append(L[-1 - i][1])
		else:
			break

	M = len(ans)
	for i in range(M):
		print(ans[-1 - i])


if __name__ == '__main__':
	main()

Measured memory_bytes: 52484
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	auto S=vecin(N);

	int M=in();
	REP(i,M){
		int u=in(),v=in(),k=in();
		for(int x=u,y=k;x<v;x++,y++){
			swap(S[x],S[y]);
		}
	}

	REP(i,N-1){
		cout << S[i] << ' ';
	}
	out(S[N-1]);
	return 0;
}


Measured memory_bytes: 3160
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	char S[500010];
	int N = fread(S, 1, 500002, stdin);
	if (S[N - 1] < 'a') N--;

	int Z[500000];
	Z[0] = N;
	int i = 1;
	int j = 0;
	while (i < N) {
		while (i + j < N && S[j] == S[i + j]) j++;
		Z[i] = j;
		if (j == 0) {
			i++;
			continue;
		}
		int k = 1;
		while (i + k < N && k + Z[k] < j) {
			Z[i + k] = Z[k];
			k++;
		}
		i += k;
		j -= k;
	}
	if (N == 1) {
		printf("%d\n", N);
		printf("%d\n", 1);
		return 0;
	}
	if (Z[1] == N - 1) {
		printf("%d\n", N);
		printf("%d\n", 1);
		return 0;
	}
	bool mae[500000] = {};
	rep1(i, N / 2) {
		for (int j = i + i - 1; j < Z[i] + i; j += i) {
			//そうなの解説さん？
			if (mae[j]) break;
			mae[j] = 1;
		}
	}
	if (!mae[N - 1]) {
		printf("%d\n", 1);
		printf("%d\n", 1);
		return 0;
	}
	Z[0] = N;
	i = 1;
	j = 0;
	while (i < N) {
		while (i + j < N && S[N - 1 - j] == S[N - i - j - 1]) j++;
		Z[i] = j;
		if (j == 0) {
			i++;
			continue;
		}
		int k = 1;
		while (i + k < N && k + Z[k] < j) {
			Z[i + k] = Z[k];
			k++;
		}
		i += k;
		j -= k;
	}

	bool ato[500000] = {};
	rep1(i, N / 2) {
		for (int j = i + i - 1; j < Z[i] + i; j += i) {
			if (ato[N - j - 1]) break;
			ato[N - j - 1] = 1;
		}
	}
	int kotae = 0;
	rep(i, N - 1) {
		kotae += (!mae[i] && !ato[i + 1]);
	}
	printf("%d\n", 2);
	printf("%d\n", kotae);


	Would you please return 0;
}

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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i<N; ++i) cin >> A[i];

    vector<int> r(N);
    r[0] = 0;
    for (int i=1; i<N; ++i) {
        r[i] = (A[i-1] - r[i-1]/2) * 2;
    }

    vector<int> r2(N);
    r2[0] = A[N-1] - r[N-1]/2;
    for (int i=1; i<N; ++i) {
        r2[i] = (A[i-1] - r2[i-1]/2) * 2;
    }

    for (int i=0; i<N; ++i) {
        cout << (i == 0 ? "" : " ") << r2[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    long long x,y;
    cin >> x >> y;
    if(x==0){
        if(y>0) cout << y << endl;
        else cout << -y+1 << endl;
        return 0;
    }
    if(y==0){
        if(x<0) cout << -x << endl;
        else cout << 1+x << endl;
        return 0;
    }
    if(x>=0 && y>=0){
        if(y>x) cout << y-x << endl;
        else cout << 2+x-y << endl;
    }
    else if(x>=0 && y<0){
        if(-x<y) cout << 1+x+y << endl;
        else cout << 1-y-x << endl;
    }
    else if(x<0 && y>=0){
        if(-x<y) cout << 1+x+y << endl;
        else cout << 1-y-x << endl;
    }
    else{
        if(x<y) cout << y-x << endl;
        else cout << 2+abs(x-y) << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
S = list(input())

L_count = {}
L_count[0] = 0
for i in range(1,N):
    if S[i-1] == "W":
        L_count[i] = L_count[i-1] + 1
    else:
        L_count[i] = L_count[i-1]

R_count = {}
R_count[N-1] = 0
for i in range(N-2,-1,-1):
    if S[i+1] == "E":
        R_count[i] = R_count[i+1] + 1
    else:
        R_count[i] = R_count[i+1]

leader_i = 0
turn_num = N+1

for i in range(N):
    #print(L_count[i] + R_count[i],"i is",i,"leader_i is",leader_i)
    if L_count[i] + R_count[i] < turn_num:
        leader_i = i
        turn_num = L_count[i] + R_count[i]


R_sort = sorted(R_count.items(), key=lambda x: x[0])
#print(L_count)
#print(R_sort)
#print(leader_i)
print(L_count[leader_i] + R_count[leader_i])

Measured memory_bytes: 90144
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  string s;cin>>s;
  string t;cin>>t;
  if (s[0]==t[0])ans++;
  if (s[1]==t[1])ans++;
  if (s[2]==t[2])ans++;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}, dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n, y;
	cin >> n >> y;
	rep(i, n + 1) {
		rep(j, n + 1) {
			int a = i, b = j, c = n - i - j;
			if (a < 0 or b < 0 or c < 0) continue;
			if (a * 1000 + b * 5000 + c * 10000 == y) {
				cout << c << " " << b << " " << a << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1\n";
	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);
		while (sc.hasNext()) {
			int n = sc.nextInt();
			int cnt = 0;
			for (int a = 0; a <= 9; ++a) {
				for (int b = 0; b <= 9; ++b) {
					for (int c = 0; c <= 9; ++c) {
						int d = n - (a + b + c);
						if (0 <= d && d <= 9) ++cnt;
					}
				}
			}
			System.out.println(cnt);
		}
		sc.close();
	}
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ull n,a,b;
  cin>>n>>a>>b;
  if (n == 1) {
    if (a == b) {
      cout << 1;
    } else {
      cout << 0;
    }
    return 0;
  }
  if (a > b) {
    cout << 0;
    return 0;
  }
  // b(n-1)+a - a(n-1)+b + 1
  cout << (b * (n-1) + a) - (a * (n-1) + b) + 1;
}


Measured memory_bytes: 3640
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
//#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

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

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define reps(i, j, k) for(auto i = j; i < k; ++i)
#define rep(i, j) reps(i, 0, j)
#define decs(i, j, k) for(auto i = j; i >= k; --i)
#define dec(i, j) decs(i, j, 0)
#define iter(i, j) for(auto i = j.begin(); i != j.end(); ++i)
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int, int>
#define vpi vector<pi>
#define vb vector<bool>
#define F first
#define S second
#define mp make_pair
#define um unordered_map
#define all(x) (x).begin(), (x).end()  
#define fast_io ios::sync_with_stdio(0); cin.tie(0);
#define file_io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define IMAX std::numeric_limits<int>::max()
#define IMIN std::numeric_limits<int>::min()
using namespace std;

int main()
{
	char c;
	cin >> c;
	if(c >= 65 && c <= 90) cout << 'A';
	else cout << 'a';
	return 0;
}


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

typedef long long ll;

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

    int n,m;
    cin >> n >> m;
    vector<int> h(n);
    vector<bool> ok(n);
    for(int i=0;i<n;i++) ok[i] = true;
    for(int i=0;i<n;i++) cin >> h[i];
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        if(h[a]<=h[b]) ok[a] = false;
        if(h[b]<=h[a]) ok[b] = false;
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(ok[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3724
#!/usr/bin/ruby
# encoding: utf-8

# ABC 111 B

N = gets.chomp.to_i

if 100 <= N and N <= 111 then 
  p 111
elsif 111 < N and N <= 222 then
  p 222
elsif 222 < N and N <= 333 then
  p 333
elsif 333 < N and N <= 444 then
  p 444
elsif 444 < N and N <= 555 then
  p 555
elsif 555 < N and N <= 666 then
  p 666
elsif 666 < N and N <= 777 then
  p 777
elsif 777 < N and N <= 888 then
  p 888
elsif 888 < N and N <= 999 then
  p 999
end


Measured memory_bytes: 1788
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
b = []
i = 0
while i+1<N:
    if len(b)==2:
        break
    if a[i] == a[i+1]:
        b += [a[i]]
        i += 2
    else:
        i += 1

if len(b)<2:
    print(0)
else:
    print(b[0]*b[1])

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

#define int long long

using namespace std;

#ifdef LOCAL 
#include "/media/brayand/BrayanD/debugger.h"
#else
template<typename... Args>
void db(Args... args){}
#endif

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

    int N, M, K;
    cin >> N >> M >> K;

    vector<int> va, vb;

    for(int i = 0 ; i < N ; i++)
    {
    	int n;
    	cin >> n;
    	va.push_back(n);
    }

    for(int i = 0 ; i < M ; i++)
    {
    	int n;
    	cin >> n;
    	vb.push_back(n);
    }

    for(int i = 1 ; i < N ; i++)
    {
    	va[i] += va[i-1];
    }

    for(int i = 1 ; i < M ; i++)
    {
    	vb[i] += vb[i-1];
    }

    int res = upper_bound(vb.begin(),vb.end(),K)-vb.begin();

    for(int i = 0 ; i < N ; i++)
    {
    	if(va[i] > K)break;
    	int temp = K-va[i];

    	int pos = upper_bound(vb.begin(),vb.end(),temp)-vb.begin();

    	res = max(res,i+1+pos);
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 7944
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using ll = long long;
vector<int> lis(200005, 1e9), G[200005];
int ans[200005], a[200005], seen[200005];
void DFS(const int& v, stack<pair<int, int>>& s) {
	seen[v] = 1;
	int k = lower_bound(lis.begin(), lis.end(), a[v]) - lis.begin();
	s.push({k, lis[k]});
	lis[k] = a[v];
	ans[v] = lower_bound(lis.begin(), lis.end(), 1e9) - lis.begin();
	for (auto nv : G[v]) {
		if (seen[nv] == 0) DFS(nv, s);
	}
	int p = s.top().first, q = s.top().second;
	s.pop();
	lis[p] = q;
	return;
}
int main() {
	int n;
	scanf("%d", &n);
	rep(i, n) scanf("%d", &a[i]);
	rep(i, n - 1) {
		int u, v;
		scanf("%d%d", &u, &v);
		u--, v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	stack<pair<int, int>> s;
	DFS(0, s);
	rep(i, n) printf("%d\n", ans[i]);
	return 0;
}


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

using namespace std;
#define ll long long


int main(){
    string s, t; cin >> s >> t;
    int n = s.size(), m = t.size();
    
    int dp[n+1][m+1];
    memset(dp, 0, sizeof(dp));
    
    for(int i = 0; i <= n; i++){
    for(int j = 0; j <= m; j++){
    if(i == 0 || j == 0)
        dp[i][j] = 0;
    else{
    if(s[i-1] == t[j-1])
        dp[i][j] = dp[i-1][j-1] + 1;
    else 
        dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
}
}
}
  
string lcs ;
int i = n, j = m;
while(i > 0 && j > 0){
    if(s[i-1] == t[j-1]){ //cout << i-1 << " " << j-1 << endl;
    lcs += s[i-1]; 
     i-- , j--;
}
else{
    if(dp[i-1][j] > dp[i][j-1]){
    i--;
}
else
    j--;
}
        
}

reverse(lcs.begin(), lcs.end());
cout << lcs;
}




Measured memory_bytes: 38748
#include<iostream>
#include<string>
using namespace std;
 
bool valid(string line){
  string t[3] = {"the", "this", "that"};
  for ( int i = 0; i < 3; i++ ){
    if ( line.find(t[i]) != string::npos ) return true;
  }
  return false;
}
 
void move(string &line){
  for ( int i = 0; i < line.size(); i++ ){
    if ( line[i] == 'a' ) line[i] = 'z';
    else if ( 'b' <= line[i] && line[i] <= 'z' ){
      line[i] = (char)(line[i]-1);
    }
  }
}
int main(){
  string line;
  while(1){
    getline(cin, line);
    if ( cin.eof() ) break;
    while(1){
      if ( valid(line) ) {
    cout << line << endl;
    break;
      }
      move(line);
    }
  }
  return 0;
}

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

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Console.ReadLine();
            var inputs = Console.ReadLine().Split(' ');

            var nums = Array.ConvertAll(inputs,long.Parse);
            var sum = nums.Sum();
            var min = nums.Min();
            var max = nums.Max();

            Console.WriteLine("{0} {1} {2}", min,max, sum);
        }
    }
}

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

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

        String s = "";

        try {
            s = in.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }

        long d = Long.parseLong(s.split(" ")[0]);
        long a = Long.parseLong(s.split(" ")[1]);
        long b = Long.parseLong(s.split(" ")[2]);

        if(a >= b){
       System.out.println("delicious");
        } else if(b - a <= d){
       System.out.println("safe");
        } else {
       System.out.println("dangerous");
        }
    }
 }

Measured memory_bytes: 21076
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


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

  int count = 0;
  FOR(i, 1, s.size()){
    if(s[i-1] != s[i]) ++count;
  }

  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cctype>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define id(a,b) (a*n-n+b)
#define reg register
typedef long long ll;
template<typename T>inline T read(){
    reg T x=0;reg short f=1;reg char c=getchar();
    for(;!isdigit(c);f=c=='-'?-1:1,c=getchar());
    for(;isdigit(c);x=x*10+(c^48),c=getchar());
    return x*f;
}
const int inf=0x3f3f3f3f;
int n,m,h[2005][2005],stk[2005];
bool mp[2005][2005],a[2005][2005];
int main(){
	n=read<int>();m=read<int>();reg int ans=max(n,m);
	for(reg int i=1;i<=n;i++)
		for(reg int j=1;j<=m;j++){
			reg char ch=getchar();
			while(ch!='#'&&ch!='.')ch=getchar();
			mp[i][j]=(ch=='#');
		}
	for(reg int i=1;i<n;i++)
		for(reg int j=1;j<m;j++){
			reg int cnt=(mp[i][j]+mp[i+1][j]+mp[i][j+1]+mp[i+1][j+1])&1;
			if(!cnt)a[i][j]=1;
		}
	for(reg int i=1;i<n;i++)
		for(reg int j=1;j<m;j++)
			h[i][j]=(a[i][j]?h[i-1][j]+1:0);
	for(reg int i=1;i<=n;i++){
		reg int top=0;
		for(reg int j=1;j<=m;j++){
			while(top&&h[i][j]<h[i][stk[top]])
				ans=max(ans,(j-stk[top-1])*(h[i][stk[top]]+1)),top--;
			stk[++top]=j;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 23680
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
template <class T>
using Graph = vector<vector<T>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
inline T Gcd(T a, T b) {
    T c;
    while (b) {
        c = b;
        b = a % b;
        a = c;
    }
    return a;
}

Int Lcm(Int a, Int b) {
    if (a < b) {
        swap(a, b);
    }

    return a / Gcd(a, b) * b;
}

vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(all(ret));

    return ret;
}

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

    Int n;
    cin >> n;

    Int ans = 0;
    for (auto e : divisor(n)) {
        Int m = e - 1;
        if (m == 0) {
            continue;
        }

        if (n / m == n % m) {
            ans += m;
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
	int n,m;
	cin >> n >> m;
	int a,b;
	vector<int> hc(n),ans(n);
	vector<lint> cc(100*m);
	rep(i,n)
		cin >> hc[i];
	rep(i,m){
		cin >> a >> b;
		if (hc[a-1] >= hc[b-1])
			ans[b-1] = 1;
		if (hc[a-1] <= hc[b-1])
			ans[a-1] = 1;
		// cc[10 * a + b]++;
		// cc[10 * b + a]++;
		// if (cc[10 * a + b] > 1 || cc[10 * b + a] > 1){
		// 	ans[b-1]=1;
		// 	ans[a-1]=1;
		//}
	}
	int c  = 0;
	rep(i,n){
		if (ans[i] == 0)
			c++;
		//cout << ans[i] << endl;
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 82112
<?php

fscanf(STDIN, "%d", $n);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));

$map = [];
for ($i = 0; $i < $n; ++$i) {
    $map[] = $A[$i] - ($i + 1);
}
sort($map);

$x = intdiv(count($map), 2);

$ans = 0;
for ($i = 0; $i < $n; ++$i) {
    $ans += abs($A[$i] - ($map[$x] + $i + 1));
}
echo $ans, PHP_EOL;


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

const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}

ll lcm(ll a,ll b){return a / gcd(a,b) * b;}

int main(){
    ll n;
    cin >> n;
    ll ans = 1;

    for(ll i = 0; i < n; i++){
        ll t;
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <functional>
#include <iterator>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#ifdef _MSC_VER
using ll = __int64;
using ull = unsigned __int64;
#else
using ll = long long int;
using ull = unsigned long long int;
#endif

// 二乗を計算する。
ll sq(ll x) { return x * x; }

// 領域内にいるか。
bool within(ll x, ll min, ll max) {
	return min <= x && x <= max;
}

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T& container, typename T::key_type& key) {
	typename T::iterator prev = container.lower_bound(key);
	if (prev == container.begin()) prev = container.end();
	else prev--;
	return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T& container, typename T::key_type& key) {
	return container.upper_bound(key);
}

// b^e (mod m) を求める
ll modpow(ll b, ll e, ll m) {
	ll result = 1;
	while (e > 0) {
		if ((e & 1) == 1) result = (result * b) % m;
		e >>= 1;
		b = (b * b) % m;
	}
	return result;
}


// ここから解法

int main(void) {
	string S;
	cin >> S;
	map<char, int> count;
	for (int i = 0; i < S.size(); ++i) {
		count[S[i]]++;
	}
	bool ok = true;
	for (auto c : count) {
		if (c.second != 2) ok = false;
	}

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

	return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target ("tune=native")

#include <x86intrin.h>
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for (auto& i : h) cin >> i;
    sort(h.begin(), h.end());
    int res = INT_MAX;
    for (int i = 0; i < N - K + 1; i++) {
	int foo = h[K + i - 1] - h[i];
	if (foo < res) res = foo;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
d = [-1 for i in range(n)]
e = [[] for i in range(n)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    e[a - 1].append([b - 1, c])
    e[b - 1].append([a - 1, c])
q, k = map(int, input().split())
def dfs(cur, par, di):
    d[cur] = di
    for i in e[cur]:
        if d[i[0]] == -1:
            if i == par:
                continue
            dfs(i[0], cur, di + i[1])
dfs(k - 1, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    print(d[x - 1] + d[y - 1])

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

using namespace std;

int main(void){
    int N;
    cin>>N;
    vector<double> v(N);
    for(int i=0;i<N;i++){
        cin>>v[i];
    }
    double sum=0.0;
    sort(v.begin(),v.end());
    for(int i=0;i<N-1;i++){
        v[i+1]=(v[i+1]+v[i])/2;
    }
    cout<<fixed;
    cout<<setprecision(6)<<v[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 256