akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

bool all_equal(const string &s) {
	set<char> aux(s.begin(), s.end());
	return aux.size() == 1;
}

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

	string s;
	cin >> s;
	
	set<char> all(s.begin(), s.end());

	int ans = 1 << 30;
	for(auto &c : all) {
		string t = s;
		int op = 0;
		while(!all_equal(t)) {
			string new_t = "";
			fori(i, 0, t.size() - 1) {
				if(t[i] == c || t[i + 1] == c) {
					new_t += c;
				}
				else {
					new_t += t[i];
				}
			}
			t = new_t;
			op++;
		}
		ans = min(ans, op);
	}
	cout << ans << '\n';

	return 0;
}



Measured memory_bytes: 256
# abc123_a.py
antena_pos=[int(input()) for _ in range(5)]
k=int(input())
max_dist=antena_pos[-1]-antena_pos[0]

if max_dist <= k:
 print('Yay!')
else:
 print(':(')


"""
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())

l=[a,b,c,d,e]
size=len(l)
for i in range(size):
 for j in range(i,size):
  if i == j:
   continue
  if (l[j]-l[i]) > k:
   print(":(")
   exit()

print("Yay!")
"""


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int count=0;
    if(s.at(0)=='1'){count++;}
    if(s.at(1)=='1'){count++;}
    if(s.at(2)=='1'){count++;}
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
lst = list(map(int, input().split()))
num = lst[0]
res = 0

for i in range(1, n):
  if lst[i] < num:
    res += lst[i - 1] - lst[i]
    lst[i] = lst[i - 1]
  else:
    num = lst[i]
    
print(res)

Measured memory_bytes: 32232
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
 
int main() {
  int N;
  cin >> N ;
  
  vector<int> A(N+1);
  vector<int> B(N);
  
  for(int i = 0; i < N+1; i++){
  	cin >> A.at(i) ;
  }
  for(int i = 0; i < N; i++){
  	cin >> B.at(i) ;
  }
  //入力おわり。
  long mon = 0;
  //勇者Nについて
  for(int i=N-1; i>=0; i--){
    if(A.at(i+1) - B.at(i) <= 0){//先端の町を全部倒せる？
      mon += A.at(i+1);//とりあえず先端の町は全部倒す
      B.at(i) -= A.at(i+1);//勇者パワーを引く
      A.at(i+1)=0;
      
      if(A.at(i)-B.at(i) <= 0){//余力で自分の町も全部倒せる？
      	mon += A.at(i);//全部倒す
     	B.at(i) -= A.at(i);
        A.at(i) = 0;
      }else{//全部は倒せない
        mon += B.at(i);//倒せるだけ倒す
        A.at(i) -= B.at(i);//倒しただけ減る
        B.at(i) = 0;
      }
    }else{//先端の町を倒しきれない
      mon += B.at(i);
      B.at(i)=0;
    }
  }
  cout << mon << endl;
}

Measured memory_bytes: 1024
import math

N, K = input().split()
N = int(N)
K = int(K)
m = N - K
mod = 10**9+7

def factorial_m(N: int, M: int):
	res = 1
	for i in range(2, N+1):
		res *= i
		res %= M
	return res

def nCr(n, r, mod):
	if n == r:
		return 1
	elif r > n:
		return 0
	return (factorial_m(n, mod) * pow((factorial_m(n-r, mod) * factorial_m(r, mod)), mod-2, mod)) % mod

for i in range(1, K+1):
	print(nCr(N-K+1, i, mod) * nCr(K-1, i-1, mod) % mod)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, A, B;
    cin >> N >> A >> B;
    if ((B - A) % 2 == 0) {
       cout << (B - A) / 2 << endl; 
    }
    else {
        cout << min(N - B, A - 1) + 1 + (B - A - 1) / 2 << endl;
    }
    
}


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

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

    // solve
    int ans = 0;
    sort(a.begin(), a.end());
    for (int i = 0; i < N - 1; ++i) {
        ans += a[i + 1] - a[i];
    }

    // output
    cout << ans << endl;

    return 0;
}


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const int MAX_N = 205;

int N, M, R;
ll d[MAX_N][MAX_N];
int RR[10];
const ll INF = 1000000000000;
ll ans, dist;
bool pick[10];
int order[10];

void perm(int idx) {
    if (idx == R) {
        if (dist < ans) ans = dist;
    }
    if (dist > ans) return;
    for (int i = 0; i < R; i++) {
        if (pick[i]) continue;
        pick[i] = true;
        order[idx] = RR[i];
        int dd = 0;
        if (idx > 0) {
            dd = d[order[idx]][order[idx - 1]];
        }
        dist += dd;
        perm(idx + 1);
        pick[i] = false;
        dist -= dd;
    }
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> N >> M >> R;
    REP(i, R) cin >> RR[i];
    REP(i, N + 2) REP(j, N + 2) {
        if (i == j) d[i][j] = 0;
        else d[i][j] = INF;
    }
    int x, y, w;
    REP(i, M) {
        cin >> x >> y >> w;
        d[x][y] = w;
        d[y][x] = w;
    }
    for (int k = 1; k < N + 1; k++) {
        for (int i = 1; i < N + 1; i++) {
            for (int j = 1; j < N + 1; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    ans = LLONG_MAX;
    perm(0);
    cout << ans << endl;

}

Measured memory_bytes: 640
#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
my $c = 0;
for (my $i=1; $i<10; $i++)
{
    for (my $j=1; $j<10; $j++)
    {
        if ($n==$i*$j) {
            $c = 1;
            last;
        }
    }
    if ($c) {
        last;
    }
}

print "Yes\n" if $c==1;
print "No\n" unless $c==1;

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <bitset>
#include <fstream>

#define ll long long
#define scani(x) scanf("%i", &x)
#define scanll(x) scanf("%I64d", &x)
#define scanfl(x) scanf("%f", &x)
#define scanch(x) scanf("%c", &x)
#define scans(x) scanf("%s", x);
#define printi(x) printf("%i", x);
#define printll(x) printf("%I64d", x);
#define printfl(x) printf("%f", x);
#define printch(x) printf("%c", x);
#define prints(x) printf("%s", x);
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define INFI (1 << 29)
#define INFL (1LL << 62)
#define sz(x) int(x.size())
#define fi first
#define se second
#define forn(i, n) for(ll i = 0; i < n; i++)
#define for1(i, n) for(ll i = 1; i <= n; i++)
#define ford(i, n) for(ll i = (n - 1); i >= 0; i--)
#define fori(i, n) for(ll i = n; i >= 1; i--)
#define fore(i, l, r) for(ll i = l; i <= r; i++)
#define get_bit(mask, x) (bool)(mask & (1LL << x))
#define set_bit(mask, x) (mask |= (1LL << x))
#define reset_bit(mask, x) (mask &= ~(1LL << x))
#define toggle_bit(mask, x) (mask ^= (1LL << x))

using namespace std;

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

    ll n, r = 0;

    cin >> n;

    map < string, ll > mapa;
    vector < string > v(n);

    forn(i, n)
    {
        cin >> v[i];

        sort(all(v[i]));

        mapa[v[i]]++;
    }

    for(auto i:mapa)
        if(i.se >= 2)
            r += ((i.se * (i.se - 1)) / 2);

    cout << r << "\n";

    return 0;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,i,j;
    cin>>n;
    vector<bool> used(n,false);
    vector<int> dist(n,99999999);
    vector<vector<pair<int,int>>> v(n);
    for(i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        for(j=0;j<b;j++){
            int to,cost;
            cin>>to>>cost;
            v[i].emplace_back(to,cost);
        }
    }
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
    q.push(make_pair(0,0));
    dist[0]=0;
    while(!q.empty()){
        pair<int,int> e;
        e=q.top();q.pop();
        if(used[e.second]) continue;
        used[e.second]=true;
        dist[e.second]=min(dist[e.second],e.first);
        for(auto p:v[e.second]){
            if(!used[p.first]){
                q.push(make_pair(dist[e.second]+p.second,p.first));
            }
        }
    }
    for(i=0;i<n;i++){
        cout<<i<<' '<<dist[i]<<endl;
    }
}






Measured memory_bytes: 9636
// atcoder/apc001/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n;
  while (cin >> n) {
    vec<lli> a(n);
    vec<lli> b(n);
    cin >> a >> b;

    lli x = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] > b[i]) {
        x += (a[i] - b[i]) * 2;
        b[i] = a[i];
      }
    }

    for (int i = 0; i < n; ++i) {
      if (a[i] != b[i]) {
        lli y = ((b[i] - a[i]) / 2) * 2;
        lli z = min(x, y);
        a[i] += z;
        x -= z;
      }
    }

    if (x) {
      cout << "No" << endl;
      continue;
    }
    bool f = true;
    for (int i = 0; i < n; ++i) {
      f = f && (a[i] <= b[i]);
    }
    cout << (f ? "Yes" : "No") << endl;
  }

  return 0;
}


Measured memory_bytes: 3724
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n, k = input_a
h = input_a

cnt = 0

h.each do |num|
  if num >= k
    cnt += 1
  end
end
puts cnt


Measured memory_bytes: 7940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll N,M,L=1;
  cin>>N;
  M=N;
  while(M>=10){
    M/=10;
    L++;
  }
  ll X=M,ans=M-1;
  while(L-1){
    X=X*10+9;
    ans+=9;
    L--;
  }
  cout<<((N==X)?ans+1:ans)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;


int main(){
    int n;cin >>n;
    map<ll,int> mp;
    rep(i,n){
        ll x;
        cin >> x;
        mp[x]++;
    }
    ll ans = 0;
    for(auto ele : mp){
        if(ele.first==ele.second)continue;
        if(ele.first<ele.second)ans+=ele.second - ele.first;
        else ans += ele.second;
    }
    cout << ans <<endl;
    return 0;

}

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

const int S_SIZE = 10001;
int S[S_SIZE];

bool search(int A[], int n, int key)
{
    // A requires extra space for the sentinel.
    A[n] = key;
    int i = 0;
    while (A[i] != key) {
        ++i;
    }
    return i != n;
}

int main()
{
    int ans = 0;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int s;
        cin >> s;
        S[i] = s;
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int t;
        cin >> t;
        if (search(S, n, t)) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
using namespace std;
#define f(n) for(int i=0;i<n;++i)
#define ll long long

int main() {
	ll n, p, ans, odd = 0, even = 0;
	cin >> n >> p;
	f(n) {
		int t;
		cin >> t;
		if (t % 2 == 0) {
			even++;
		}
		else {
			odd++;
		}
	}
	if (odd < 2) {
		if (p == 1 && odd == 0) {
			ans = 0;
		}
		else {
			ans = 1;
			f(even) {
				ans *= 2;
			}
		}
	}
	else {
		ans = 1;
		f(n - 1) {
			ans *= 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
const int Maxn=10000;
char s[Maxn+5];
int n,k;
char *ans;
bool check(char *a,char *b){
	for(int i=1;i<=n;i++){
		if(a[i]<b[i]){
			return 1;
		}
		if(a[i]>b[i]){
			return 0;
		}
	}
	return 0;
}
int main(){
	scanf("%d%d",&n,&k);
	scanf("%s",s+1);
	while(s[++n]!='\0');
	n--;
	for(int i=1;i<=n;i++){
		s[(n<<1)-i+1]=s[i];
	}
	ans=s;
	for(int i=1;i<=n;i++){
		if(check(s+i-1,ans)){
			ans=s+i-1;
		}
	}
	int len=1;
	while(len<=n&&ans[++len]==ans[1]);
	len--;
	if(k>=15||(len*(1<<(k-1))>=n)){
		for(int i=1;i<=n;i++){
			putchar(ans[1]);
		}
		puts("");
	}
	else{
		int now=n-(len*(1<<(k-1)));
		for(int i=1;i<=(len*(1<<(k-1)));i++){
			putchar(ans[1]);
		}
		for(int i=1;i<=now;i++){
			putchar(ans[i+len]);
		}
		puts("");
	}
	return 0;
}


Measured memory_bytes: 128
K, A, B = map(int, input().split())

unused_turn = K
biscuit = 1

# 換金が割に合わなかったら叩くだけ
if B - A <= 1 or K < A:
    print(1 + K)
    exit()

# お金にできるまで叩く
unused_turn -= A - 1
biscuit += A - 1


# お金をやりくりする
turn = unused_turn // 2
biscuit = biscuit - turn * A + turn * B
unused_turn -= turn * 2

# 最後に叩く
biscuit += unused_turn

print(biscuit)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

template<typename T> struct SegTree_dual{
    using F=function<T(T, T)>;
    int sz=1;
    T et;
    F f, g;
    vector<T> node;

    SegTree_dual(int sz_, T et_, F f_, F g_): et(et_), f(f_), g(g_){
        while(sz<sz_) sz<<=1;
        node.resize(sz<<1, et);
    }

    void update(int l, int r, T x){
        for(l+=sz, r+=sz; l<r; l>>=1, r>>=1){
            if(l&1){
                node[l]=g(node[l], x);
                l++;
            }
            if(r&1){
                --r;
                node[r]=g(node[r], x);
            }
        }
    }

    T query(int i){
        i+=sz;
        T val=node[i];
        i>>=1;
        while(i){
            val=f(val, node[i]);
            i>>=1;
        }
        return val;
    }
};

int n;
lint D, A;
vector<lint> x;
vector<pll> p;

int main(){
    scanf("%d%lld%lld", &n, &D, &A);
    p.resize(n);
    for(auto &i: p){
        scanf("%lld%lld", &i.fi, &i.se);
        x.push_back(i.fi);
    }
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    sort(p.begin(), p.end());

    lint ans = 0;
    SegTree_dual<lint> st(n, 0, plus<>(), plus<>());
    rep(i, n) st.update(i, i+1, p[i].se);
    rep(i, n){
        lint left = st.query(i);
        if(left <= 0) continue;
        int R = upper_bound(x.begin(), x.end(), p[i].fi+D*2)-x.begin();
        lint cnt = (left-1)/A + 1;
        ans += cnt;
        st.update(i, R, -A*cnt);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 9200
s = str(input())
q = int(input())
inv = False
head = ''
tail = ''

for i in range(q):
    a = input()
    if a == '1':
        inv = not inv
        continue
    a = a.split()
    if (a[1] == '1')^inv:
        head = a[2] + head
    else:
        tail += a[2]
s = head + s + tail
if inv:
    print(s[::-1])
else:
    print(s)

Measured memory_bytes: 4512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  if(n<=a)
    cout<<1<<endl;
  else if(a<=b)
    cout<<-1<<endl;
  else{
    n-=a;
    a-=b;
    cout<<(n%a==0?n/a*2+1:(n/a+1)*2+1)<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    bool test = true;
    for (int i = 0; i < s.size(); i++) {
        for (int j = i + 1; j < s.size(); j++) {
            if (s[i] == s[j]) test = false;
        }
    }
    if (test) cout << "yes" << endl;
    else cout << "no" << endl;
}


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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }
template<class T>
inline T upper(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	ll a = m / 2;
	ll left = min(n, a);

	ll right = max(m - left * 2, 0LL);
	cout << left + right / 4 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashSet;
import java.util.Set;

public class Main{
    public static void main(String[] args) {
        Set<String> set = new HashSet<String>();
        try (Scanner sc = new Scanner(System.in)) {
            int n = 1;
            int j = 0;
            n = sc.nextInt();
            String str;
            String value;
            boolean[] ans = new boolean[n];
            int ansi = 0;
            for (int i = 0; i < n; i++) {
                str = sc.next();
                value = sc.next();
                if (str.equals("find")) {
                    if (i == 0) {
                        ans[ansi] = false;
                        ansi++;
                    }else if (set.contains(value)) {
                        ans[ansi] = true;
                        ansi++;
                    } else {
                        ans[ansi] = false;
                        ansi++;
                    }
                }else {
                    set.add(value);
                }
            }
            for (int i = 0; i < ansi; i++) {
                if (ans[i])
                    System.out.println("yes");
                else
                    System.out.println("no");
            }
            sc.close();
            return;
        }
    }
}


Measured memory_bytes: 258396
HEIGHT_BASE = [165, 170, 175, 180, 185, 1000]

distribution = [0, 0, 0, 0, 0, 0]

input_data = [float(input()) for lp in range(int(input()))]

for item in input_data:
    for index, base in enumerate(HEIGHT_BASE):
        if item < base:
            distribution[index] += 1
            break

for index in range(6):
    print(str(index + 1) + ":" + "*" * distribution[index])



Measured memory_bytes: 5612
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<int>())S
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    int n;
    cin >> n;
    vector<string> wi(n);
    for (int i = 0; i < n; i++) {
        cin >> wi[i];
    }  

    Rep(i,1,n){
        // if(wi[i-1][wi[i-1].size()-1] != wi[i][0]){
        if(wi[i-1].back() != wi[i].front()){
            pr("No");
            return 0;
        }

        REP(j, i){
            if(wi[i] == wi[j]){
                pr("No");
                return 0;
            }
        }
    }

    pr("Yes");
    return 0;
}

Measured memory_bytes: 256
"""
https://atcoder.jp/contests/abc150/tasks/abc150_a
"""
import numpy as np


def calc(K: int, X: int) -> int:
    return 500 * K >= X


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")])


def main() -> None:
    K, X = load_input_as_int_array()
    result = calc(K, X)
    print("Yes" if result else "No")


main()


Measured memory_bytes: 12404
<?php
$i = 0;
list($A, $B, $C, $D) = explode(" ", trim(fgets(STDIN)));  // スペース区切りで2つ入力
while ($i <= 100) {
    $C = $C - $B;
    if ($C <= 0) {
        echo 'Yes';
        break;
    }
    $A = $A - $D;
    if ($A <= 0) {
        echo 'No';
        break;
    }
    $i = $i + 1;
}

Measured memory_bytes: 16084
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<lldo>&ar,lldo in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<lldo>&ar,lldo in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,K,X,i,j;cin>>n>>K>>X;
	mineq(n,10000);
	//static llint cp[2505][10005]={0};
	static llint dp[2505][10005]={0};
	static llint ep[2505][10005]={0};
	//左側の残り時間,駅間,の累積WA,dpなら右=左-1,epなら右=左 cpなら片方のみ
	//これを前計算
	ep[0][1]=1;
	for(j=2;j<=n;j++){ep[0][j]=2;}
	for(i=1;i<=X;i++){//dp
		dp[i][1]=1;
		ep[i][1]=1;
		for(j=1;j<=n;j++){
			dp[i][j+1]=(mod+dp[i][j]+ep[i-1][j]-ep[i-1][max(0,j-i-i)])%mod;
		}//駅間
		for(j=1;j<=n;j++){
			ep[i][j+1]=(mod+ep[i][j]+dp[i  ][j]-dp[i  ][max(0,j-i-i)])%mod;
			if(j==i+i+1){ep[i][j+1]++;}
		}//駅間
		/*for(j=1;j<=n+1;j++){cerr<<dp[i][j]<<" ";}
		cerr<<endl;
		for(j=1;j<=n+1;j++){cerr<<ep[i][j]<<" ";}
		cerr<<endl;*/
	}
	llint ans=1,mae;cin>>mae;
	for(i=0;i<K-1;i++){
		int s;cin>>s;
		ans*=(mod+dp[X-i][1+s-mae]-dp[X-i][s-mae]);ans%=mod;
		mae=s;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 391424
#include <iostream>
using namespace std;
int ans[500005],cf[500005],l[500005],r[500005];
const int bl=550;
int main(int argc, char** argv) {
	int n,m,t;
	ios::sync_with_stdio(false);
	cin >> n >> m;
	t=m/bl;
	for(int i=1;i<=n;i++)
		cin >> l[i] >> r[i];
	for(int i=1;i<=n;i++)
	{
		int lst=t;
		for(int j=bl;j>=1;j--)
		{
			int L=(l[i]-1)/j+1,R=r[i]/j;
			L=max(L,lst+1);
			if(R<L) continue;
			++cf[L],--cf[R+1];
			lst=max(lst,R);
		}
	}
	for(int i=1;i<=t;i++)
	{
		int ans=0;
		for(int j=1;j<=n;j++)
			ans+=(l[j]-1)/i!=r[j]/i;
		cout << ans << "\n";
	}
	for(int i=t+1;i<=m;i++)
	{
		cf[i]+=cf[i-1];
		cout << cf[i] << "\n";
	}
	return 0;
}
//dlstxdy

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n, l;
  cin >> n >> l;
  vector<int> v(n);
  for (int i = 0; i < n; i++) v[i] = l + i;
  int mi = INF;
  for (int i = 0; i < n; i++)
    if (abs(mi) > abs(v[i])) mi = v[i];
  cout << accumulate(v.begin(), v.end(), 0) - mi << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;

int main() {
    ll n, p;
    cin >> n >> p;
    if(n == 1) {
        cout << p << endl;
        return 0;
    }
    ll ans = 1;
    for(ll i = 2; i * i <= p; i++) {
        ll m = p;
        ll c = 0;
        while(m % i == 0) {
            m /= i;
            c++;
        }
        if(c >= n)
        ans = max(ans, i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a,b;
	char op;
	while(scanf("%d %c %d", &a, &op, &b), op != '?'){
        
        switch(op){
        case '+':
            printf("%d\n", a + b);
            break;
        
        case '-':
            printf("%d\n", a - b);
            break;
        
        case '*':
            printf("%d\n", a * b);
            break;
        
        case '/':
            printf("%d\n", a / b);
            break;
        }
    }

	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define maxn 200
using namespace std;
char str[maxn];
int main()
{
    scanf("%s",str+1);
    int len=strlen(str+1);
    for(int i=1;i<=len;i++){
        if(i&1){
            if(str[i]!='R'&&str[i]!='U'&&str[i]!='D'){
                puts("No");
                return 0;
            }
        }
        else{
            if(str[i]!='L'&&str[i]!='U'&&str[i]!='D'){
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}

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

using namespace std;

int main(){
    long N, K, Q;
    cin>>N>>K>>Q;
    vector<long> A(Q), P(N, 0);
    for(int i=0; i<Q; ++i){
        cin>>A[i];
        A[i] -= 1;
        P[A[i]]++;
    }

    for(int i=0; i<N; ++i){
        if(K - Q + P[i] > 0){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
long long int q[10000000];
int main()
{
    long long int x,y,a,b,c,i,t=0,f=0,sum=0;
    cin>>x>>y>>a>>b>>c;
    long long int n[a+5],m[b+5],p[c+5];
    for(i=0;i<a;i++)
        cin>>n[i];
    for(i=0;i<b;i++)
        cin>>m[i];
    for(i=0;i<c;i++)
        cin>>p[i];
    sort(n,n+a);
    sort(m,m+b);
    sort(p,p+c);
    for(i=a-1;t<x;i--)
    {
        q[t]=n[i];
        t++;
    }
    for(i=b-1;t-x<y;i--)
    {
        q[t]=m[i];
        t++;
    }
    for(i=0;i<c;i++)
    {
        q[t]=p[i];
        t++;
    }
    sort(q,q+t);

    for(i=t-1;f<x+y;i--)
    {
        sum+=q[i];
        f++;
    }
    cout<<sum<<endl;

    return 0;
}


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

int main(void)
{
    int k;
    cin >> k;
    
    int count[100][10];
    int sum[100];
    int accum[100];
    
    for (int i = 0; i < 10; i++) {
        count[0][i] = 0;
        count[1][i] = 1;
    }
    sum[0] = 0;
    accum[0] = 0;
    sum[1] = 9;
    accum[1] = 9;
    
    int digit;
    for (digit = 2; accum[digit-1] < k; digit++) {
        sum[digit] = 0;
        for(int i = 0; i < 10; i++) {
            int tmp = 0;
            if (i != 0) tmp += count[digit-1][i-1];
            if (i != 9) tmp += count[digit-1][i+1];
            tmp += count[digit-1][i];
            count[digit][i] = tmp;
            if (i != 0) sum[digit] += tmp;
        }
        accum[digit] = accum[digit-1] + sum[digit];
    }
    digit--; // 桁数確定

    int base = accum[digit-1];
    int prev = -1;
    for (int i = digit; i >= 1 && base < k; i--)
        for (int j = 0; j < 10 && base < k; j++) {
            if (i == digit && j == 0) continue;
            if (i < digit && abs(prev-j) >= 2) continue;
            base += count[i][j];
            if (base >= k) {
                cout << j;
                prev = j;
                base -= count[i][j];
                break;
            }
        }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a, b; cin >> a >> b;
  cout << (a-1) * (b-1) << endl;
  return 0;
}

Measured memory_bytes: 3116
_ = input()
s = list(input())
cnt = 0
for i in range(1000):
    a = list(f'{i:03}')
    if a[0] not in s: continue
    s1 = s[s.index(a[0])+1:]
    if a[1] not in s1: continue
    s1 = s1[s1.index(a[1])+1:] 
    if a[2] not in s1: continue
    cnt += 1
print(cnt)

Measured memory_bytes: 9760
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
template <typename CT, typename T> inline void reset_container(CT &c, int sz, T v){c.resize(sz); for(auto &x: c) x=v;}
#define taskname "arc100_b"
int n;
ll a[200001];
ll ans=1e18;
int find_mid(int s, int e){
    ll sum=a[e]-a[s-1];
    int l=s, r=e, m, res=s;
    while(l<=r){
        m=(l+r)/2;
        if((a[m]-a[s-1])*2<=sum){
            res=m;
            l=m+1;
        }
        else r=m-1;
    }
    return res;
}
void check(int i, int j, int k){
    if(i>=j||j>=k||k>=n) return;
    vector <ll> sum;
    sum.pb(a[i]);
    sum.pb(a[j]-a[i]);
    sum.pb(a[k]-a[j]);
    sum.pb(a[n]-a[k]);
    ans=min(ans, *max_element(sum.begin(), sum.end())-*min_element(sum.begin(), sum.end()));
}
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    read(n);
    FOR(i, 1, n) read(a[i]);
    FOR(i, 1, n) a[i]+=a[i-1];
    FFOR(i, 2, n){
        int j=find_mid(1, i);
        int k=find_mid(i+1, n);
        check(j, i, k);
        check(j+1, i, k);
        check(j+1, i, k+1);
        check(j, i, k+1);
    }
    writeln(ans);
}

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

int main(){
  int result=0;
  string s,s1,s2;
  int n,comsize;
  cin >> s;
  comsize=floor(s.size()/2);
  s1=s.substr(0,comsize);
  s2=s.substr(comsize);
  for(int i=0;i<floor(s2.size()/2);i++){
  	char tmp=s2[i];
    s2[i]=s2[s2.size()-1-i];
    s2[s2.size()-1-i]=tmp;
  }
  
  for(int i=0;i<s1.size();i++){
    if(s1[i]==s2[i]) continue;
    result++;
  }
  
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;
#define pi 3.14159265358979

int main()
{
	ll num, target;
	cin >> num >> target;
	vector<pair<ll, ll>> a(num);
	rep(i, num)
	{
		cin >> a[i].first >> a[i].second;
	}
	sort(a.begin(), a.end());
	ll distance = target;

	rep(i, num)
	{
		if (a[i].second < distance)
		{
			distance -= a[i].second;
		}
		else
		{
			cout << a[i].first << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 4764
#include<iostream>
using namespace std;
#include<math.h>

int main() {
  int n, temp;
  cin >> n;
  int res[n];
  for(int i = 0; i < n; i++) {
    res[i] = 0;
  }
  int m = sqrt(n);
  for(int i = 1; i <= m; i++) {
    for(int j = 1; j <= m; j++) {
      for(int k = 1; k <= m; k++) {
        temp = i*i + j*j + k*k + i*j + i*k + j*k - 1;
        if(temp < n) res[temp]++;
      }
    }
  }
  for(int i = 0; i < n; i++) {
    cout << res[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3576
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  int ab[26]={};
  int i;
  while(getline(cin,str)){
    for(i=0;i<str.size();i++){
      if(str[i]>='a'&&str[i]<='z') ab[str[i]-'a']++;
      else if(str[i]>='A'&&str[i]<='Z') ab[str[i]-'A']++;
    }
  //cout << str << endl;
  }
  for(i=0;i<26;i++){
    cout << char('a'+i) << " : " << ab[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3212
#include <iostream>

using namespace std;

template<class T> inline void chmin(T &x, const T &y) {if (x > y) x = y;}

const int  INF = 1e9+7;

int N, W;

long long dp[110000];

int main()
{
  cin >> N >> W;
  
  for (int i = 1; i < 100100; ++i) dp[i] = INF;
  
  while (N--) {
    int w, v; cin >> w >> v;
    for (int i = 100100; i >= 0; --i)
      chmin(dp[i+v], dp[i] + w);
  }
  
  int ans;
  for (int i = 0; i < 100100; ++i)
    if (dp[i] <= W) ans = i;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a<b){
		if(c<d){
			cout << a+c << endl;
		}
		else{
			cout << a+d << endl;
		}
	}
	else{
		if(c<d){
			cout << b+c << endl;
		}
		else{
			cout << b+d << endl;
		}
	} 
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1
#define sosuu 1000000007

int main(){
  int hyp1=0;
  int hyp2=0;
  string S;
  cin >>S;
  rep(i, S.size()){
  if(i%2==0&&S[i]=='0')
    hyp1++;
    
  if(i%2==1&&S[i]=='1')
    hyp1++;
  }
  rep(i, S.size()){
  if(i%2==1&&S[i]=='0')
    hyp2++;
    
  if(i%2==0&&S[i]=='1')
    hyp2++;
  }
  cout << min(hyp1,hyp2) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <queue>
using namespace std;
#define INF 1 << 28

typedef tuple<int, int, pair<int, int>> Node;
typedef pair<int, int> Point;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
int w, h;
int cost_table[4][31][31];
int grid[31][31];
int order_cost[4];

int dijkstra(){
  for(int i=0;i<4;i++){
    for(int j=0;j<h;j++){
      for(int k=0;k<w;k++){
        cost_table[i][j][k] = INF;
      }
    }
  }
  cost_table[1][0][0] = 0;
  priority_queue<Node, vector<Node>, greater<Node>> que;
  que.push(make_tuple(0, 1, make_pair(0,0)));

  while(!que.empty()){
    int cost, dir;
    Point pt;
    Node now = que.top(); que.pop();
    tie(cost, dir, pt) = now;
    int x = pt.first, y = pt.second;
    if(cost_table[dir][y][x] < cost) continue;
    if(x == w - 1 && y == h - 1) return cost;
    for(int i=0; i<4; i++){
      int nd = (dir + i) % 4;
      int nx = x  + dx[nd], ny = y + dy[nd];
      if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
      int ncost = (i == grid[y][x]) ? cost : cost + order_cost[i];
      if(ncost >= cost_table[nd][ny][nx]) continue;
      que.push(make_tuple(ncost, nd, make_pair(nx, ny)));
      cost_table[nd][ny][nx] = ncost;
    }
  }
}

int main(void){
  while(true){
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    for(int i = 0;i<h;i++){
      for(int j = 0;j<w;j++){
        cin >> grid[i][j];
      }
    }
    for(int i = 0;i<4;i++) cin >> order_cost[i];
    cout << dijkstra() << endl;
  }
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
int n,m;
string s[1000];
bool same(int x, int y) {
  return s[x][y]==s[n-x-1][y] && s[x][y]==s[x][n-y-1] && s[x][y]==s[n-x-1][n-y-1];
}

int main() {
  cin >> m >> n;
  for(int i=0; i<n; i++) cin >> s[i];
  int c=0,ans=0;
  for(int i=0; i<n/2+n%2; i++) {
    for(int j=0; j<n/2+n%2; j++) {
      if(!same(i,j)) c++;
    }
  }
  if(!c) ans++;
  m--;
  while(m--) {
    int k,x,y;
    cin >> k;
    while(k--) {
      cin >> x >> y;
      x--,y--;
      bool f=0;
      if(same(x,y)) f=1;
      s[x][y]=(s[x][y]=='1')?'0':'1';
      x=min(x,n-x-1);
      y=min(y,n-y-1);
      if(same(x,y)) c--;
      else if(f) c++;
    }
    if(!c) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

template<typename T>
vector<T> compress(vector<T> A){
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    return A;
}

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){ if(n>0) initialize(n); }
    void initialize(int n){
        par.resize(n);
        sz.assign(n, 1);
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){ return find(x) == find(y); }
    int size(int x){ return sz[find(x)]; }
};

int main(){
    int N, M;
    cin >> N >> M;
    
    // 無限に遠いところの座標値
    int64_t INF = 2e9;
    
    // 座標圧縮前の座標（正負の無限遠を含む）を入れていく。
    vector<int64_t> xs = {-INF, INF}, ys = {-INF, INF};
    auto add = [&](int64_t x, int64_t y){
        xs.push_back(x);
        ys.push_back(y);
    };

    vector<int64_t> A(N), B(N), C(N), D(M), E(M), F(M);
    for(int i=0; i<N; i++){
        cin >> A[i] >> B[i] >> C[i];
        add(A[i], C[i]);
        add(B[i], C[i]);
    }
    for(int i=0; i<M; i++){
        cin >> D[i] >> E[i] >> F[i];
        add(D[i], E[i]);
        add(D[i], F[i]);
    }
    xs = compress(xs);
    ys = compress(ys);

    int xsz = xs.size(), ysz = ys.size();

    // リアル座標値が圧縮座標のどのインデックスに含まれるかを求める
    auto find_x = [&](int a)->int{ return upper_bound(xs.begin(), xs.end(), a) - xs.begin() - 1; };
    auto find_y = [&](int a)->int{ return upper_bound(ys.begin(), ys.end(), a) - ys.begin() - 1; };

    // 圧縮後の座標の、真上に線がある/真左に線がある
    static bitset<3100> above[3100], left[3100];

    // 線を引く
    for(int i=0; i<N; i++){
        A[i] = find_x(A[i]);
        B[i] = find_x(B[i]);
        C[i] = find_y(C[i]);
        for(int x=A[i]; x<B[i]; x++) left[x][C[i]] = 1;
    }
    for(int i=0; i<M; i++){
        D[i] = find_x(D[i]);
        E[i] = find_y(E[i]);
        F[i] = find_y(F[i]);
        for(int y=E[i]; y<F[i]; y++) above[D[i]][y] = 1;
    }

    // UnionFindで扱うために1次元に潰す
    auto encode = [&](int i, int j){ return i*ysz+j; };
    UnionFind uf(xsz*ysz);

    // 線が引いていないところを連結
    for(int i=1; i<xsz; i++) for(int j=0; j<ysz-1; j++){
        if(!above[i][j]) uf.unite(encode(i, j), encode(i-1, j));
        if(!left[i][j]) uf.unite(encode(i, j), encode(i, j-1));
    }

    // 牛と同じ連結成分にある座標について面積を足す。無限遠と連結ならINF
    auto fail = [](){
        cout << "INF" << endl;
        exit(0);
    };
    int cow = encode(find_x(0), find_y(0));
    int64_t ans = 0;
    for(int i=0; i<xsz; i++) for(int j=0; j<ysz; j++) if(uf.same(cow, encode(i, j))){
        if(i==0 || i==xsz-1 || j==0 || j==ysz-1) fail();
        int64_t dx = xs[i+1] - xs[i], dy = ys[j+1] - ys[j];
        ans += dx*dy;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 76476
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]


test=[int(input()) for i in range(D)]
lastday=[0 for j in range(26)]
points=[0 for i in range(D)]

lastday=[lastday[i]+1 for i in range(26)]
lastday[test[0]-1]=0
minus=sum([x*y for (x,y) in zip(c,lastday)])
points[0]=s[0][test[0]-1]-minus


for i in range(1,D):
    lastday=[lastday[i]+1 for i in range(26)]
    lastday[test[i]-1]=0
    minus=sum([x*y for (x,y) in zip(c,lastday)])
    points[i]=points[i-1]+s[i][test[i]-1]-minus


for ps in points:
    print(ps)

Measured memory_bytes: 9248
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int K;
string S;

signed main(){
	cin>>K>>S;
	if((int)S.size()>K){
		cout<<S.substr(0,K)<<"..."<<endl;
	}
	else{
		cout<<S<<endl;
	}
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
bool e[50][50];
bool isc(int n) {
  stack<int> s;
  bool memo[n];
  memset(memo, 0, sizeof(memo));
  memo[0] = 1;
  s.push(0);
  while (!s.empty()) {
    int v = s.top();
    s.pop();
    for (int i = 0; i < n; i++) {
      if (e[v][i]) {
        if (memo[i] == 0) {
          memo[i] = 1;
          s.push(i);
        }
      } else continue;
    }
  }
  for (int i = 0; i < n; i++) if (memo[i] == 0) return 0;
  return 1;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int a[m], b[m];
  for (int i = 0; i < m; i++) cin >> a[i] >> b[i];
  memset(e, 0, sizeof(e));
  for (int i = 0; i < m; i++) e[a[i] - 1][b[i] - 1] = e[b[i] - 1][a[i] - 1] = 1;
  int res = 0;
  for (int i = 0; i < m; i++) {
    e[a[i] - 1][b[i] - 1] = e[b[i] - 1][a[i] - 1] = 0;
    res += !isc(n);
    e[a[i] - 1][b[i] - 1] = e[b[i] - 1][a[i] - 1] = 1;
  }
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 256
n1=input()
nums = list(map(int, input().split()))
n=len(nums)
result = []
for t in range(1,100):
    num1=nums[:t]
    num2=nums[t:]
    s1=sum(num1)
    s2=sum(num2)
    s=s1-s2
    a_s=abs(s)
    result.append(a_s)
print(min(result))

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

int main()
{
	int N, K;
	cin >> N >> K;
	vector<long> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<long>());
	for (int i = 0; i < N; i++) {
	}
	vector<long> b(N - K + 1);
	for (int i = 0; i < N - K + 1; i++) {
		b[i] = a[i] - a[i + K - 1];
	}
	for (int i = 0; i < N; i++) {
	}
	sort(b.begin(), b.end());
	cout << b[0] << endl;
}

Measured memory_bytes: 1792
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), k = in.nextInt();
		int[] dq = new int[n];
		for ( int i = 0; i < n; i++ ) {
			dq[i] = in.nextInt();
		}
		in.close();

		int total = 0;
		for ( int l = 0; l < n; l++ ) {
			for ( int r = 0; r <= n - l; r++ ) {
				int lr = l + r;
				if ( lr > k || lr > n ) break;

				PriorityQueue<Integer> pool = new PriorityQueue<>();
				for ( int i = 0; i < l; i++ )
					pool.add(dq[i]);
				for ( int i = n - 1; n - r <= i; i-- )
					pool.add(dq[i]);

				for ( int i = k - lr; 0 < i; i-- ) {
					if ( !pool.isEmpty() && pool.peek() < 0 ) pool.poll();
					else break;
				}

				int temp = 0;
				for ( Integer i : pool ) temp += i;
				total = Math.max(total, temp);
			}
		}
		System.out.println(total);
	}
}

Measured memory_bytes: 24276
#include <iostream>
#include <string>
using namespace std;
string S;
string A="A";
string C="C";
string a="a";
string z="z";
bool flagF,flagS,flagLS;
int main() {
  flagF=false;
  flagS=true;
  flagLS=true;
  cin>>S;
  if(S.substr(0,1)==A.substr(0,1)){
    for(int i=2;i<S.size()-1;i++){
      if(S.substr(i,1)==C.substr(0,1) && !(flagF)){
        flagF=true;
      }else if(S.substr(i,1)==C.substr(0,1) && flagF){
        flagS=false;
      }else if((S.substr(i,1)<a.substr(0,1)) || (S.substr(i,1)>z.substr(0,1))){
        flagLS=false;
      }
    }
    if((S.substr(1,1)<a.substr(0,1)) || (S.substr(1,1)>z.substr(0,1))){
      flagLS=false;
    }
    if((S.substr(S.size()-1,1)<a.substr(0,1)) || (S.substr(S.size()-1,1)>z.substr(0,1))){
      flagLS=false;
    }
    if(flagF && flagS && flagLS){
      cout<<"AC"<<"\n";
    }else{
      cout<<"WA"<<"\n";
    }
  }else{
    cout<<"WA"<<"\n";
  }
}


Measured memory_bytes: 256