akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N,H;
	cin>>N>>H;
	vector<P> ab;
	rep(i,N){
		int a,b;
		cin>>a>>b;
		ab.push_back({a,1});
		ab.push_back({b,0});
	}
	ll ans = 0;
	sort(all(ab));
	rep(i,2*N){
		cerr<<H<<endl;
		int x = ab[2*N-1-i].first;
		int y = ab[2*N-1-i].second;
		cerr<<x<<" "<<y<<endl;
		if(y){
			if(H%x ==0)ans+=H/x;
			else{
				ans+=H/x+1;
			}
			break;
		}
		H -= x;
		ans++;
		if(H<=0)break;
	}
	printpair(ab);
	cout<<ans<<endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int INF = 1e9;
const int V = 100010;

int n, m;
vector<int> G[100010];
int d[100010], dr[100010];

struct dijkstra{
    vector<int> d;
    dijkstra(){}
    dijkstra(int V){
        d.resize(V, INF);
    }
    void calc(int s){
        d[s] = 0;
        priority_queue<P, vector<P>, greater<P> > q;
        q.push(P(d[s], s));
        while(!q.empty()){
            P p = q.top(); q.pop();
            int from = p.second;
            int cost = p.first;
            if(d[from] < cost) continue;
            rep(i, 0, G[from].size()){
                int next = G[from][i];
                int newCost = cost + 1;
                if(d[next] > newCost){
                    d[next] = newCost;
                    q.push(P(newCost, next));
                }
            }
        }
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    rep(i, 0, m){
        int x, y;
        cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dijkstra d1(n), d2(n);
    d1.calc(s);
    d2.calc(t);
    int MIN = d1.d[t];
    int ans = 0;
    map<P, int> mp;
    map<int, int> mp1, mp2;
    rep(i, 0, n){
        mp[P(d1.d[i], d2.d[i])]++;
        mp1[d1.d[i]]++;
        mp2[d2.d[i]]++;
    }
    rep(i, 0, MIN){
        // ans += mp[P(i, MIN - i)] * mp[P(i + 2, MIN - i - 2)];
        ans += mp1[i] * mp2[MIN - i - 2];
    }
    cout << ans << endl;
}


Measured memory_bytes: 13368
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
#define DEB(variable) cout << #variable << '=' << variable << endl

#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

using llint = long long int;

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr long long int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    llint n;
    cin>>n;
    vector<llint> v(n);
    REP(i,n){
        cin>>v[i];
    }
    llint h, l, result = 0;

    for (llint i = 1; i < (1ll << 62ll);(i<<=1)){
        h = 0;
        l = 0;
        REP(j,n){
            if(i&v[j]){
                h++;
            }else{
                l++;
            }
        }
        result += (((i%mod) * (h%mod))%mod * (l%mod))%mod;
        result %= mod;
    }
    result += mod;
    result %= mod;
    cout << result << endl;
    return 0;
}


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

int main(){
while(1){//start	
	
	int e;
	int ans = 10000000;
	cin >> e;
	
	if(e == 0) break;
	
	int x;
	for(int y = 0; y <= 1000; y++){
		for(int z = 0; z <= 100; z++){
			if(y*y + z*z > e)break;
			x = e - y*y - z*z*z;
			if(x + y*y + z*z*z > e) break;
			if(x >= 0 and x + y*y + z*z*z == e){
				ans = min(ans, x + y + z);
				//cout << "ans = " << ans << endl;
			}
		}
	}
	
	
	cout << ans << endl;
	
}//end	
	return 0;
}


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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

PQ<PL> pq;

signed main() {
    SCIN(S);
    string pre = "", now = "";
    ll ans = 0;
    REP(i, S.length()) {
        if(pre == now || now == "") {
            now += S[i];
        } else {
            i--;
            ans++;
            pre = now;
            now = "";
        }
    }
    if(pre != now) ans++;
    cout << ans << "\n";
}

Measured memory_bytes: 640
c = []
for _ in range(3):
    tmp = [int(x) for x in input().split()]
    c.append(tmp)

ans = True

for i in range(2):
    if (c[0][i] - c[0][i+1]) == (c[1][i] - c[1][i+1]) == (c[2][i] - c[2][i+1]):
        pass
    else:
        ans = False
        break
for i in range(2):
    if (c[i][0] - c[i+1][0]) == (c[i][1] - c[i+1][1]) == (c[i][2] - c[i+1][2]):
        pass
    else:
        ans = False
        break

if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

ll gcd(ll a,ll b){
    if(b ==0) return a;
    return gcd(b,a%b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[200],b[200],c[200],d[200],ans=0;
    vector<ll> v[200];
    bool used[200]={};
    pll R[200],B[200];
    cin>>n;
    rep(i,n){
        cin>>a[i]>>b[i];
        R[i]=pll(a[i],b[i]);   
    }
    rep(i,n){
        cin>>c[i]>>d[i];
        B[i]=pll(c[i],d[i]);
    }
    sort(B,B+n);
    rep(i,n){
        ll now=-1,index=-1;
        rep(j,n){
            if(!used[j] && B[i].first>R[j].first && B[i].second>R[j].second){
                if(now<R[j].second){
                    now=R[j].second;
                    index=j;
                }
            }
        }
        if(index!=-1){
            ans++;
            used[index]=true;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K=sc.nextInt();
		int ki[]=new int[]{1, 1, 1, 2, 1, 2, 1
				, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1,
				15, 2, 2, 5, 4, 1, 4, 1,51};
		System.out.println(ki[K-1]);

	}
}


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

int main() {
  char N, M, L;
  cin >> N >> M >> L;

  if(N=='A'&& M=='A' && L=='A'){
    cout << "No" << endl;
      }

  else if(N=='B' && M=='B' && L=='B'){
    cout << "No" << endl;
      }
  
  else{
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
$S = trim(fgets(STDIN));
//list($A,$B) =  explode(" ",trim(fgets(STDIN)));
//$d = explode(" ",trim(fgets(STDIN)));

$l = $S[0];
$tot = 1;
for($i=1;$i<$N;$i++) {
  if ($l != $S[$i]) {
    $l = $S[$i];
    $tot++;
  }
}
printf("%d\n",$tot);


Measured memory_bytes: 4728
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    vvi x(h, vi(w));
    rep(i, h) {
        rep(j, a) {
            x[i][j] ^= 1;
        }
    }
    rep(i, b) {
        rep(j, w) {
            x[i][j] ^= 1;
        }
    }

    rep(i, h) {
        rep(j, w) {
            cout << x[i][j];
        } cout << '\n';
    }
}

Measured memory_bytes: 5248
a = []
while True:
    try:
        a.append(float(input()))
    except EOFError:
        break

for i in range(len(a)):
    count = 0
    x = a[i]
    sum = a[i]
    for j in range(9):
        if count % 2 == 0:
            x *= 2
            sum += x
        else:
            x /= 3
            sum += x
        count += 1
    print(sum)

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

long long f(vector<long long>& A, long long x){
    long long total = 0;
    for(long long i= 0 ; i < A.size(); i++){
        long long val = A[i];
        if( val >= 0 ){
            long long l = -1;
            long long r = A.size();
            while( l+1<r) {
                long long m= l + (r-l)/2;
                if( val * A[m] <= x ){
                    l = m;
                }else{
                    r = m;
                }
            }
            total+= (l+1);
            if( val * val <= x ){
                total--;
            }
        }else{
            long long l = -1;
            long long r = A.size();
            while( l+1<r) {
                long long m= l + (r-l)/2;
                if( val * A[m] <= x ){
                    r = m;
                }else{
                    l = m;
                }
            }
            total+= (A.size()-r);
            if( val * val <= x ){
                total--;
            }
        }
    }
    return total/2;
}

int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> A(N);
    for(int i = 0 ; i < N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    long long INF = (long long)pow(10, 18)+1;

    long long l = -INF;
    long long r = INF;
    while(l+1 < r){
        long long m = l + (r-l)/2;
        if( f(A, m) < K ){
            l = m;
        }else{
            r = m;
        }
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

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

	int n, cnt = 0;
	string s;
	cin >> n >> s;

	for (int left = 0; left < n; left++)
		if (s[left] == 'A' && s[left + 1] == 'B' && s[left + 2] == 'C')
			cnt++;

	cout << cnt << endl;
}


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

void solve()
{
	int n, k;
	cin >> n >> k;
	
	vector<int> s(n+1, 1);
	for(int i = 0; i<k; i++)
	{
		int t;
		cin >> t;
		for(int j = 0; j<t; j++)
		{
			int tt;
			cin >> tt;
			s[tt]--;
		}
	}
	int ans = 0;
	for(int i = 1; i<=n; i++)
	{
		if(s[i] == 1)
		{
			ans++;
		}
	}
	cout << ans;
			
	
}

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


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int gcd(int x, int y) {
    if (x < y) return gcd(y, x);
    else if (y == 0) return x;
    else return gcd(y, x % y);
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int A[100010];
    rep(i, N) cin >> A[i];
    sort(A, A + N);
    if (A[N - 1] < K) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    int G = A[0];
    rep(i, N) G = gcd(G, A[i]);
    if (K % G == 0) {
        cout << "POSSIBLE" << endl;
    }  else {
        cout << "IMPOSSIBLE" << endl;
    }


    return 0;
}


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

using int64 = long long;

const int MAX_N = int(1e5) + 10;

int n, pos;
int id[MAX_N], in[MAX_N];
int64 b[MAX_N], l[MAX_N], u[MAX_N], X, all, val[MAX_N];

int main() {
	scanf("%d%lld", &n, &X);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld%lld%lld", b + i, l + i, u + i);
		all -= b[i] * l[i];
		val[i] = (X - b[i]) * u[i] + b[i] * l[i];
	}

	for (int i = 1; i <= n; ++i) {
		id[i] = i;
	}
	std::sort(id + 1, id + n + 1, [&](const int &x, const int &y) { return val[x] > val[y]; });
	int64 sum = 0LL;
	for (int i = 1; i <= n; ++i) {
		sum += val[id[i]];
		if (sum + all >= 0) {
			pos = i - 1;
			sum -= val[id[i]];
			break;
		}
		in[id[i]] = true;
	}

	all = sum + all;
	int64 ans = (pos + 1) * X;
	for (int i = 1; i <= n; ++i) {
		int64 tmp = all;
		if (in[i]) {
			tmp -= val[i];
			tmp += val[id[pos + 1]];
		}

		int64 ql = 0LL, qr = X + 1;
		while (ql < qr) {
			int64 mid = (ql + qr) >> 1, s = 0LL;
			if (mid >= b[i])
				s = (mid - b[i]) * u[i];
			else
				s = (mid - b[i]) * l[i];
			if (tmp + b[i] * l[i] + s >= 0)
				qr = mid;
			else
				ql = mid + 1;
		}
		if (qr <= X) {
			ans = std::min(ans, pos * X + qr);
		}
	}

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

Measured memory_bytes: 7564
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    char c[101];
    cin>>c;
    //
    bool cFound = false, fFound = false;
    
    for(int i = 0;c[i] != '\0';i++){
        if(c[i] == 'C' && !fFound) cFound = true;
        if(c[i] == 'F' && cFound) fFound = true;
    }
    if(cFound && fFound) cout<<"Yes";
    else cout<<"No";
}

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

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

    string S2 = S1;
    reverse(S2.begin(), S2.end());
    int cnt = 0;
    for (int i = 0; i < S1.size(); ++i) {
        if (S1[i] != S2[i]) {
            cnt++;
        }
    }

    cout << cnt/2 << endl;
}

Measured memory_bytes: 256
s = int(input())
lst = [s]

for i in range(1,1000001):

    if lst[i-1]%2 == 0:
        lst.append(lst[i-1]//2)
    else:
        lst.append(lst[i-1]*3+1)

    if lst.count(lst[i])==2:
        break

print(i+1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <typeinfo>
#include <cmath>
using namespace std;
#define ll long long 
const ll MOD = 1e9 + 7;

int N;
ll K;

vector<vector<ll>> matmul(vector<vector<ll>> &left, vector<vector<ll>> &right) {
    vector<vector<ll>> res(N, vector<ll>(N));
    for (int i=0; i<N; ++i)
        for (int j=0; j<N; ++j)
            for(int k=0; k<N; ++k)
                res[i][j] = (res[i][j] + left[i][k]*right[k][j]) % MOD;
            
    return res;
}

vector<ll> matmul(vector<vector<ll>> &left, vector<ll> &right) {
    vector<ll> res(N);
    for (int i=0; i<N; ++i)
        for (int j=0; j<N; ++j)
            res[i] = (res[i] + left[i][j]*right[j]) % MOD;
            
    return res;
} 
 
int main()
{
    cin >> N >> K;
    vector<vector<ll>> graph(N, vector<ll>(N));
 
    for (int i=0; i<N; ++i) {
        for (int j=0; j<N; ++j) {
            cin >> graph[i][j];
        }
    }
    vector<vector<ll>> T(N, vector<ll>(N));
    for(int i=0; i<N; ++i)
        T[i][i] = 1;
        
    while (K){
        if (K%2) {
            T = matmul(T, graph);
        }
        graph = matmul(graph, graph);
        K /= 2;
    }
    
    vector<ll> answer(N, 1);
    answer = matmul(T, answer);
    ll res = 0;
    for (int i=0; i<N; ++i)
        res = (res + answer[i]) % MOD;
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

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

    map<long long, long long> T;

    for(long long i = 0; i < m; i++){
        long long a, b;
        cin >> a >> b;

        if(T.find(a) == T.end()){
            T[a] = 1;
        }
        else{
            T[a]++;
        }
        if(T.find(b) == T.end()){
            T[b] = 1;
        }
        else{
            T[b]++;
        }
    }

    map<long long, long long>::iterator it;

    for(it = T.begin(); it != T.end(); it++){
        if(it->second % 2 != 0){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}

Measured memory_bytes: 9008
#include <bits/stdc++.h>
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
int main( void ){
	int n, m, j;
	if (!scanf( "%d%d%d", &n, &m, &j )){
		return -1;
	}
	if (n + m + j >= 22)
		printf( "bust\n" );
	else

		printf( "win\n" );
	return 0;
}


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

map<long long, long long> prime_factor(long long n) {
    map<long long, long long> res;
    for (long long i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

/*
    verified https://onlinejudge.u-aizu.ac.jp/problems/NTL_1_A
*/
int main() {
    int n; cin >> n;
    cout << n << ":";
    auto pf = prime_factor(n);
    for (auto p : pf) {
        for (int i = 0; i < p.second; ++i) {
            cout << " " << p.first;
        }
    }
    cout << endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int n;
  	cin>>n;
    cout<<(n+1)/2<<endl;
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

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

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

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

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    int N, K; cin >> N >> K;
    string S; cin >> S;
    vector<int> listHappy;

    // Right or Left
    int i=1;
    int num=0;
    char pre=S[0];
    while(i<N){
        if(S[i]==pre) {
            num++;
        }else{
            listHappy.push_back(num);
            num=0;
        }
        pre = S[i];
        i++;
    }
    listHappy.push_back(num);

    int ans=0;
    for(auto a: listHappy){
        ans+=a;
    }

    if(listHappy.size() < 2*K){
        ans = S.size()-1;
    }else if(2*K == listHappy.size()){
        ans+=(2*K-1);
    }else{
        ans+=2*K;
    }


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

Measured memory_bytes: 956
L = []
R = []
N, M = map(int, input().split())
for _ in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

if max(L) <= min(R):
    print(min(R) - max(L) + 1)
else:
    print(0)


Measured memory_bytes: 16768
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define vl vector<ll>
#define endl endl;cf
#define be begin()
#define sz size()
#define en end()
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0)
#define forn(i,a,b) for(ll i=1;i<=b;++i)
#define forr(i,a,b) for(ll i=0;i<b;++i)
#define rngx mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define cf cout.flush()
int main()
{
    ios;
    ll n  , k ;
    cin >> n;
    vl v ;
    forn(i , 1 , n)
    {
        ll x;
        cin >>x ;
        v.pb(x);
    }
    vl vv = v;
    sort(all(v));
    unordered_map<ll,ll> mp;
    forr( i , 0 , n )
    {
        mp[i+1] = v[i];
    }
    ll req = n/2 ;
    v  =  vv;
    forr(i , 0 , n){
       if(v[i] > mp[req]){
        cout << mp[req]  <<endl;
       }
       else cout << mp[req+1] <<endl;
    }
}



Measured memory_bytes: 13552
import math

def plot(x,y):
    print(f'{x:.8f} {y:.8f}')

def Koch(n, x1, y1, x2, y2):
    if n == 0:
        plot(x1, y1)
        return
    sx = (2 * x1 + 1 * x2)/3
    sy = (2 * y1 + 1 * y2)/3
    tx = (1 * x1 + 2 * x2)/3
    ty = (1 * y1 + 2 * y2)/3
    ux = (tx - sx) * (1/2) - (ty - sy) * (math.sqrt(3)/2) + sx
    uy = (tx - sx) * (math.sqrt(3)/2) + (ty - sy) * (1/2) + sy
    Koch(n-1, x1,y1, sx,sy)
    Koch(n-1, sx,sy, ux,uy)
    Koch(n-1, ux,uy, tx,ty)
    Koch(n-1, tx,ty, x2,y2)

n = int(input())
Koch(n, 0,0, 100,0)
plot(100,0)


Measured memory_bytes: 5756
n, m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
s.sort(key=lambda x: x[1])
tmp = 0
ans = 0
for si in s:
    if tmp == 0:
        ans += 1
        tmp = si[1]
        continue
    if tmp <= si[0]:
        ans += 1
        tmp = si[1]

print(ans)


Measured memory_bytes: 29084
#include <iostream>

using lli = long long int;

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

int main(void){
    int n, q; scanf("%d%d", &n, &q);
    lli odd = 0, even = 1;
    REP(_, n){
        // 食べない　=> そのまま
        // 食べる =>
        int a; scanf("%d", &a);
        if(a % 2 == 0){ odd <<= 1; even <<= 1; }
        else{
            lli k = odd; odd += even; even += k;
        }
    }
    printf("%lld\n", (q == 0) ? even : odd);
    return 0;
}

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

string S;
int cnt[26];

int main(){
    cin>>S;
    for (int i = 0; i < S.size(); i++)
    {
        char a = S[i];
        int x = a-97;
        cnt[x] = 1;
    }
    
    for (int i = 0; i < 26; i++)
    {
        if(cnt[i] == 0) {
            cout << (char)('a'+i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll k,x; cin >> k >> x;
    for(ll i=x-k+1; i<=k+x-1; i++) cout << i << " ";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  string s; cin>>s;
  string a="abc";
  do{
     if(a==s){
     cout<<"Yes"<<endl;
     return 0;
   }
  }while(next_permutation(a.begin(),a.end()));

  cout<<"No"<<endl;
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	string s;
	cin>>s;
	
	llong ans=0;
	REP(i,1<<(s.size()-1)){
		llong tmp=0;
		int p=0;
		int cnt=1;
		REP(j,s.size()-1){
			if((i>>j)&1){
				tmp+=stoll(s.substr(p,cnt));
				p=j+1;
				cnt=1;
			}else cnt++;
		}
		tmp+=stoll(s.substr(p,cnt));
		
		ans+=tmp;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
def max(a,b); a > b ? a : b; end
S = gets.chomp
dp = Array.new(S.size + 1, 0)
(1 .. S.size).inject(0) do |ld, i|
  dp[i] = (S[i - 1] == '<' ? ld + 1 : 0)
end
(1 .. S.size).inject(0) do |rd, i|
  (S[-i] == '>' ? rd + 1 : 0).tap do |rd_|
    dp[-i - 1] = max(dp[-i - 1], rd_)
  end
end
puts dp.inject(0,&:+)


Measured memory_bytes: 6788
from pprint import pprint as pp

n,y = map(int, input().split())

def func():
  for k10 in range(n+1):
    if k10 * 10000 > y:
      continue
    for k5 in range(n-k10+1):
      k1 = n - k10 - k5
      if (k10 * 10000) + (k5 * 5000) + (k1 * 1000) == y:
        print("{} {} {}".format(k10, k5, k1))
        return
  print("{} {} {}".format(-1, -1, -1))
func()

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

using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

/* [💭] [💡] [🎈] */

using namespace std;

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

    int x;
    cin >> x;
    int c = 1, s = x;
    while (s % 360) {
        c++;
        s += x;
    }
    cout << c;

    return 0;
}

Measured memory_bytes: 3648
s = str(input())
n = len(s)
ans = 'Yes'
for i in range(n):
    if (i+1)%2==1:
        if s[i]=='R' or s[i]=='U' or s[i]=='D':
            continue
        else:
            ans ='No'
            break
    else:
        if s[i]=='L' or s[i]=='U' or s[i]=='D':
            continue
        else:
            ans='No'
            break
print(ans)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// get a integer
		String input = sc.next();
		
		if(distinct_chars(input)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		
	}
	
	
	public static boolean distinct_chars(String inputStr) {
    	int total_chars = 0;    	
    	int[] alphabet = new int[26];
    	
	    for (int i = 0; i < 26; i++) alphabet[i] = 0;
	    
    	for(int i = 0; i < inputStr.length(); i++) {
    		char aux = inputStr.charAt(i);
    		int char_number = (int)aux;
    		//lowercase letters corresponding numbers goes between 97 and 122
    		alphabet[char_number - 97]++;
    	}
    	
    	for (int i = 0; i < 26; i++) {
    		if(alphabet[i]%2 != 0) {
    			return false;
    		}
    	}
    	
    	return true;
    }
}

Measured memory_bytes: 21844
import math
n = int(input())
a = list(map(int, input().split()))

b = sum(a) / n
ceil = math.ceil(b)
floor = math.floor(b)

ans1 = 0
ans2 = 0
for i in range(n):
    ans1 += (a[i] - ceil)**2
for i in range(n):
    ans2 += (a[i] - floor)**2
print(min(ans1, ans2))

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

int main() {
  int A, B, C;
  cin >> A >>B >>C;
  
  bool ans = false;
  for ( int i = 0 ; i < 10000; i++ ){
    if ( A * i % B == C ){
      ans = true;
      break;
    }
  }
  
  if (ans) {
    cout << "YES";
  }
  else {
    cout << "NO";
  }
}
    
  
  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdint>
using namespace std;

int culc_gcd(int a, int b) {
    int u, v;

    if(a < b) {
        u = b;
        v = a;
    }
    else {
        u = a;
        v = b;
    }

    int r;
    do {
        r = u % v;
        u = v;
        v = r;
    } while(r != 0);
    
    return u;
}

int main() {
    int N, X;

    cin >> N >> X;
    int ans;
    for(int i = 0; i < N; i++) {
        int x;
        cin >> x;
        ans = (i == 0) ? abs(X - x) : culc_gcd(ans, abs(X - x));
    }

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int bfs();

int h, w;
int mp[55][55];

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

    cin >> h >> w;
    int black = 0;
    for( int i = 1; i <= h; ++i ) {
        for( int j = 1; j <= w; ++j ) {
            char c;
            cin >> c;
            if( c == '.' ) {
                mp[i][j] = 1;

            } else {
                ++black;

            }
        }
    }
    black += 2;
    int res = bfs();
    if( res == -1 ) cout << res;
    else {
        cout << ( h * w ) - black - res;

    }
    cout << endl;

    return 0;
}

int bfs() {
    queue< pair< P, int > > q;
    q.push( MP( MP( 1, 1 ), 0 ) );

    mp[1][1] = 0;
    while( !q.empty() ) {
        pair< P, int > p = q.front(); q.pop();

        for( int i = 0; i < 4; ++i ) {
            if( p.F.F + dx[i] == h && p.F.S + dy[i] == w ) return p.S;

            if( mp[p.F.F + dx[i]][p.F.S + dy[i]] == 1 ) {
                q.push( MP( MP( p.F.F + dx[i], p.F.S + dy[i] ), p.S + 1 ) );
                mp[p.F.F +dx[i]][p.F.S + dy[i]] = 0;

            }
        }
    }

    return -1;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<double,ll> mp;
double inf =1e9;
#define EPS 1e-10
struct point{
	double x,y;
	void make(){
		cin>>x>>y;
	}
	point(){};
	point(double x,double y):x(x),y(y){};
	point operator + (point &p) { return point(x+p.x,y+p.y)  ; }
	point operator - (point &p) { return point(x-p.x,y-p.y)  ; }
	double norm() { return x*x+y*y;}
	double abs() { return sqrt(norm()) ;}
};

typedef pair<int,point> mmp;

struct line{
	point s,e;
};

double cross(point a,point b){
	return a.x*b.y-a.y*b.x;
}
double dot(point a,point b){
	return a.x*b.x+a.y*b.y;
}

struct circle{
	point p;
	double r;
	void make(){
		p.make();
		cin>>r;
	}
};

double abs(point a){
	return a.abs();
}
double distance(line l,point p){
	point tmp = l.e-l.s;
	if(dot(tmp,p-l.s) < EPS) return abs(p-l.s);
	if(dot(l.s-l.e,p-l.e) < EPS ) return abs(p-l.e);
	return abs(cross(l.e-l.s,p-l.s ) / abs(l.e-l.s) );
}

typedef pair<mp,int> mpp;
vector<mp> daikus(vector<vector<double> > &g,int s){
	vector<mp> cost(g.size(),mp( inf,g.size() ) );
	vector<bool> used(g.size(),false);
	priority_queue<mpp,vector<mpp>,greater<mpp> > q;
	q.push( mpp(mp(0.0,s),g.size())  );
	cost[s] = mp( 0.0,g.size() );
	while(!q.empty()){
		mp now = q.top().first;
		int prev = q.top().second;
		double nowc = now.first;
		int nn = now.second;
		q.pop();
		if(used[nn])continue;
		used[nn] = true;
		cost[nn] = mp(nowc,prev);
		for(int i=0;i<g.size();i++){
			double nextc = g[nn][i];
			if(nextc>50.0){
				continue;
			}
			if(used[i]) continue;
			q.push(mpp(mp(nowc+nextc,i),nn) );
		}
	}
	return cost;
}

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		vector<mmp> a(n);
		map<int,int> hen;
		for(int i=0;i<n;i++){
			cin>>a[i].first;
			a[i].second.make();
			hen[a[i].first] = i;
		}
		vector<vector<double> > g(n,vector<double>(n,inf) );
		for(int i=0;i<n;i++)for(int j=0;j<n;j++) g[i][j] = abs(a[i].second-a[j].second);
		vector<vector<mp> > cost(n);
		for(int i=0;i<n;i++){
			cost[i] = daikus(g,i);
		}
		int m;
		cin>>m;
		/*for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cout<<cost[i][j].first<<' ';
			}
			cout<<endl;
		}
		cout<<endl;

		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cout<<g[i][j]<<' ';
			}
			cout<<endl;
		}
		cout<<endl;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cout<<cost[i][j].second<<' ';
			}
			cout<<endl;
		}
		cout<<endl;
		*/

		for(int i=0;i<m;i++){
			int s,t;
			cin>>s>>t;
			s = hen[s];
			t = hen[t];
			//cout<<"ok"<<s<<' '<<t<<endl;
			vector<int> kei;
			if(cost[s][t].first == inf||cost[s][t].second == n) {
				cout<<"NA"<<endl;
				continue;
			}
			kei.push_back(t);			
			while(t!=s){
		    	//cout<<t<<' '<<cost[s][t].first<<' '<<cost[s][t].second<<endl;
				t = cost[s][t].second;
				kei.push_back(t);
				//cout<<t<<endl;
			}
			//cout<<"ok"<<endl;
			cout<<a[kei[kei.size()-1]].first;
			for(int j=kei.size()-2;j>=0;j--){
				cout<<' '<<a[kei[j]].first;
			}
			cout<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3368
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

int main(){
    INT(n,x,y);
    vector<int> distance(n,0);
    vector<vector<int>> graph(n);
    graph[x-1].push_back(y-1);
    graph[y-1].push_back(x-1);
    for(int i=0;i<n;i++){
        if(i!=0)graph[i].push_back(i-1);
        if(i!=n-1)graph[i].push_back(i+1);
    }
    int a;
    for(int i=0;i<n-1;i++){
        queue<int> next;
        vector<int> subdistance(n,-1);
        next.push(i);
        subdistance[i]=0;
        while(!next.empty()){
            a=next.front();
            next.pop();
            rep(j,graph[a].size()){
                if(subdistance[graph[a][j]]==-1){
                    next.push(graph[a][j]);
                    subdistance[graph[a][j]]=subdistance[a]+1;
                    if(graph[a][j]>i)distance[subdistance[a]+1]++;
                }
            }    
        }
    }
    for(int i=1;i<n;i++){
        out(distance[i]);
    }
}

Measured memory_bytes: 3896
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
#include <deque>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int n, d;
    cin >> n >> d;

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

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) break;

            double sum = 0;

            for (int k = 0; k < d; k++) {
                sum += (x[i][k]- x[j][k])*(x[i][k] - x[j][k]);
            }

            if ((sqrt(sum) - (int)sqrt(sum)) == 0 && sum != 0) {
                cnt ++;
            }
        
        }
    }
    
    cout << cnt << endl;
    


}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N=int(input())
S=list(input())
N=len(S)

turn=0
kuro=0
shiro=0
last=0

ma=0
ans=0
for index,item in enumerate(S):
    if item==".":
        kuro+=1
        last=0
    else:
        shiro+=1
        last+=1
    ma=max((kuro-shiro),ma)
    if ma==(kuro-shiro):
        turn=index
        ans=shiro-kuro

print(min(ans+kuro,shiro-last))#混迷極まる



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

int main() {
	int n;
	cin >> n;
	vector<ll>a(n);
	ll asum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
		asum += a.at(i);
	}
	vector<ll>b(n);
	ll bsum = 0;
	for (int i = 0; i < n; i++) {
		cin >> b.at(i);
		bsum += b.at(i);
	}
	if (asum < bsum) {
		cout << -1 << endl;
		return 0;
	}
	vector<ll>a2b(n);
	for (int i = 0; i < n; i++) a2b.at(i) = a.at(i) - b.at(i);
	sort(a2b.begin(), a2b.end());
	ll minans = 0;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (a2b.at(i) < 0) {
			minans += a2b.at(i);
			ans++;
		}
		else break;
	}
	reverse(a2b.begin(), a2b.end());
	for (int i = 0; i < n; i++) {
		if (minans >= 0)break;
		ans++;
		minans += a2b.at(i);
	}
	cout << ans << endl;
}

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

using namespace std;

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

    int n;
    cin >> n;

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

    int answer = 0;
    for (int i = 0; i < n; ++i) {
        if (a[a[i]] == i) {
            ++answer;
        }
    }

    cout << answer / 2 << endl;

    return 0;
}

Measured memory_bytes: 640
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.container;
import std.array;
import std.math;
import std.range;
import std.typecons;
import std.ascii;

bool check(string s)
{
  int index = 0;
  foreach (c; s) {
    if (c=='(') {
      ++index;
    } else {
      if (index == 0) {
        return false;
      }
      --index;
    }
  }
  return index  == 0;
}

void main()
{
  int n = readln.chomp.to!int;
  string s = readln.chomp;
  string sub, ans;
  int index = 0;
  foreach (c; s) {
    final switch(c) {
      case '(':
        ans ~= sub;
        ans ~= '(';
        sub = "";
        ++index;
        break;
      case ')':
        if (index == 0) {
          sub = sub ~ ")";
          ans = "(" ~ ans;
        } else {
          sub = sub ~ ")";
          --index;
        }
        break;
    }
  }
  //()())))((()(()))(((((
  foreach (i; 0..index) {
    sub ~= ")";
  }
  ans ~= sub;
  assert(ans.check);
  writeln = ans;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
X = list(map(int,input().split()))
ans = abs(X[0])+X[K-1]-X[0]
for i in range(N-K+1):
  A = abs(X[i])+(X[i+K-1]-X[i])
  B = abs(X[N-1-i])+(X[N-1-i]-X[N-K-i])
  if (ans > min(A,B)):
    ans = min(A,B)
print(ans)

Measured memory_bytes: 14384
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, H: "List[int]"):
    print(sum(sorted(H, reverse=True)[K:]))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, H)


if __name__ == '__main__':
    main()


Measured memory_bytes: 30780
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=s.length(),m=0;
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n-1-i])m++;
    }
    cout << m<<endl;
    return 0;
}


Measured memory_bytes: 384
n=int(input())
a=list(input())
b=list(input())
c=list(input())
co=0
for a,b,c in zip(a,b,c):
    if a==b==c:
        co+=0
    elif a==b or a==c or b==c:
        co+=1
    elif a!=b!=c:
        co+=2
print(co)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
ll dp[100000];

ll func(vector<ll>&p,ll ind){
	if(ind>n-1) return 1000000007;
	if(ind==n-1) return 0;

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


	ll left = abs(p[ind+1]-p[ind]) + func(p,ind+1);

	ll right = 1000000007;
	if(ind+2 < n){
		right = abs(p[ind+2]-p[ind]) + func(p,ind+2);
	}

	dp[ind] = min(left,right);
	return dp[ind];

}	

int main(){



ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);

memset(dp,-1,sizeof(dp));

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

cout<<func(p,0)<<"\n";

return 0;
}

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d))
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  string s; cin >> s;
  string t;
  rep(i,3){
    t.pb(s[i]);
  }
  cout << t << endl;
}


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

int main() {
	int match = 0;
	string forecast, real;

	cin >> forecast;
	cin >> real;

	for (int i = 0; i < 3; i++) {
		if (forecast[i] == real[i]) {
			match++;
		}
	}

	cout << match;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

sm = sum(A)

ans = 0
for s in range(len(A)-1):
    #ans += A[s]*sum(A[s+1:])
    sm -= A[s]
    ans += A[s]*sm

print(ans%mod)

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
template<typename T>
inline T read(T&x){
	x=0;int f=0;char ch=getchar();
	while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x=f?-x:x;
}
const int N=3e5+10;
int n,a[N],b[N];
char s[N];
int main(){
	read(n);
	scanf("%s",s+1);
	int len=strlen(s+1);
	for (int i=1;s[i];i++){
		a[i]=a[i-1];
		b[i]=b[i-1];
		if (s[i]=='E') a[i]++;
		else b[i]++;
	}
	int res=4e5+10;
	for (int i=1;s[i];i++){
		res=min(res,b[i-1]+a[len]-a[i]);
	}
	printf("%d\n",res);
	return 0;
}

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

int main() {
  int a, b, c, x, cnt, xp;
  int i, j, k;
  cnt = 0;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> x;

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

  cout << cnt << endl;
}

Measured memory_bytes: 256