akhauriyash/Code-Regression huggingface dataset:
from collections import deque

s = deque(input())
q = int(input())

reverse_flag = -1 # -1なら反転しない

for i in range(q):
    query = list(input().split())
    if query[0] == '1':
        reverse_flag *= -1
    else:
        if query[1] == '1':
            if reverse_flag == -1:
                deque.appendleft(s, query[2])
            else:
                deque.append(s, query[2])
        else:
            if reverse_flag == -1:
                deque.append(s, query[2])
            else:
                deque.appendleft(s, query[2])
                
if reverse_flag == 1:
    s.reverse()
    
print(''.join(s))

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

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}

const int N = 3005;

bool dp[N][N];


int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;

    dp[0][0] = 1;
    for(int i = 0; i <= f; i++) {
        for(int j = 0; j <= f; j++) {
            if(i + 100*a <= f) dp[i + 100*a][j] |= dp[i][j];
            if(i + 100*b <= f) dp[i + 100*b][j] |= dp[i][j];
            if(j + c <= f) dp[i][j+c] |= dp[i][j];
            if(j + d <= f) dp[i][j+d] |= dp[i][j];
        }
    }
    int p = a*100, q = 0;
    for(int i = 0; i <= f; i++) {
        for(int j = 0; j <= f; j++) {
            if(dp[i][j] == 0 or i+j == 0) continue;
            int max_sugar = (i/100) * e;
            if(j > max_sugar) continue;
            if(i+j > f) continue;
//            debug(), dbg(i), dbg(j);
            if(q*(i+j) < j*(p+q)) {
                p = i, q = j;
//                debug(), dbg(p), dbg(q);
            }
        }
    }
    cout << p+q << " " << q << endl;
}





Measured memory_bytes: 12024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define ll long long
#define rep(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main() {
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << "\n";
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	string ans="No"s;
	for(int i=0;i*4<=n;++i){
		for(int j=0;j*7+i*4<=n;++j){
			if(i*4+j*7==n)ans="Yes"s;
		}
	}
	cout<<ans<<"\n"s;
}

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

int main()
{
	string week[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
	int day[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	vector<int> firstDay;
	int a, b;
	int i;

	firstDay.push_back(3);
	for (i = 0; i < 12; i++) {
		firstDay.push_back( (firstDay[i]+day[i])%7 );
	}

	while(cin>>a>>b, a||b) {
		cout<<week[ (firstDay[a-1] + b-1) % 7 ]<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
	int N;
	cin >> N;

	vector<int> t, v;
	inputVector(t, N);
	inputVector(v, N);

	v.push_back(0);
	vector<int> st;
	st.push_back(0);
	{
		int tmp = 0;
		rep(i, N) {
			tmp += t[i];
			st.push_back(tmp);
		}
	}
	rep(i, st.size()) st[i] *= 2;

	int T = 0;
	rep(i, N) T += t[i];
	T *= 2;

	double ret = 0;
	double now = 0;
	int pt = 0;
	REP(i, 1, T) {
		double maxV = v[pt];
		REP(j, pt + 1, N) {
			maxV = min(maxV, v[j] + (st[j] - i) / 2.0);
		}
		if (now < maxV) now += 0.5;
		else if (now > maxV) now -= 0.5;
		ret += now / 2;
		if (pt < N && i == st[pt + 1]) pt++;
	}

	printf("%.5f\n", ret);

    return 0;
}


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



int main (){
    string S;
    cin>>S;
    int Size=S.size();
  	//cout<<Size<<endl;
    reverse(S.begin(), S.end());
    vector<long long> Pi(13);
  	Pi.at(0)=1;
    vector<int> Num13(6);
    vector<char> Num(10);
    Num13={1, 10, 9, 12, 3, 4};
    Num={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    for(int i=0; i<Size; i++){
        if(S.at(i)=='?'){
          	//cout<<'#';//チェック用
          	vector<long long> Num13Sec(13);
           	Num13Sec=Pi;
            for(int j=1; j<10; j++){
                int Move=Num13.at(i%6)*j%13;
            	for(int l=0; l<13; l++){
                	int k=l-Move;
                	if(k<0){
                    	k +=13;
                	}
                Pi.at(l)+=Num13Sec.at(k);
                Pi.at(l)%=1000000007;
                
            }
            }
          /*for(int l=0; l<13; l++){
            	cout<<Pi.at(l)<<" ";
          }*/
        }
        else{
          	//cout<<'%';//チェック用
            int KetaNum;
            for(int j=0; j<10; j++){
                if(S.at(i)==Num.at(j)){
                    KetaNum=j;
                    break;
                }
            }
            int Move=Num13.at(i%6)*KetaNum%13;
            vector<long long> Num13Sec(13);
            Num13Sec=Pi;
            for(int j=0; j<13; j++){
                int k=j-Move;
                if(k<0){
                    k +=13;
                }
                Pi.at(j)=Num13Sec.at(k);
				//cout<<Pi.at(j)<<" ";
            }


        }
      //cout<<endl;
        

    }
  /*for(int i=0; i<13; i++)
  cout<<Pi.at(i)<<" ";
  cout<<endl;*/
  cout<<Pi.at(5);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();

int main()
{
    int n;
    cin>>n;
    vector<int> a(n),c1(100001),c2(100001);
    rep(i,n)
    {
        cin>>a[i];
        if(i % 2 == 0)
        {
            c1[a[i]]++;
        }
        else 
        {
            c2[a[i]]++;
        }
    }

    auto itr1 = max_element(all(c1));
    int idx1 = distance(c1.begin(),itr1);
    auto itr2 = max_element(all(c2));
    int idx2 = distance(c2.begin(),itr2);
    int m1 = *itr1;
    int m2 = *itr2;
    int M1 = m1;
    int M2 = m2;
    int ans = 0;
    if(idx1 == idx2)
    {
        c2.erase(itr2);
        M2 = *max_element(all(c2));
        c1.erase(itr1);
        M1 = *max_element(all(c1));
    }
    ans = n - max(M1+m2,m1+M2); 
    cout<<ans << endl;
    return 0;
}

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

using namespace std;

void chmax(int &a, int b) { a = max(a, b); }

int main()
{
  int N, cost[360] = {};

  cin >> N;
  for(int i = 0; i < N; i++) {
    int m, d, v, s;
    cin >> m >> d >> v >> s;
    d = (m - 1) * 30 + d - 1;
    for(int j = 0; j < v; j++) chmax(cost[(d + j) % 360], s);
    for(int j = 1; j < 360; j++) chmax(cost[(d - j + 360) % 360], s - j);
    for(int j = 1; j < 360; j++) chmax(cost[(d + v + j-1) % 360], s - j);
  }

  cout << *min_element(cost, cost + 360) << endl;
}

Measured memory_bytes: 3112
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int N, K;
    cin >> N >> K;
    vi h(N);
    rep(i, N) cin >> h[i];
    sort(all(h));

    int ans = INT32_MAX;
    rep(i, 0, N - K + 1) {
        ans = min(ans, h[i + K - 1] - h[i]);
    }

    write(ans);
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

template<typename T>
T gcd(T a, T b) {
	if( a < b ) swap(a, b);
	
	T r;
	while( r = a % b ) {
		a = b;
		b = r;
	}
	
	return b;
}

template<typename T>
bool is_prime(T n) {
	
	for(T i = 2; i * i <= n; ++i) {
		if( n % i == 0 ) return false;
	}
	
	return true;
}

template<typename T>
vector<T> prime_factor(T n) {
	vector<T> res;
	for(T i = 2; i * i <= n; ++i) {
		if( n % i == 0 ) {
			while( n % i == 0 ) n /= i;
			res.push_back(i);
		}
	}
	
	if( n > 1 ) res.push_back(n);
	
	return res;
}

int main(void) {
	ll a, b;
	cin >> a >> b;

	ll g = gcd(a, b);
	
	int ans = 1;
	
	if( !is_prime(g) ) {
		vector<ll> div;
		div = prime_factor(g);
		ans += div.size();
	}
	
	else if( g != 1 && is_prime(g) ) ans++;
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right

n,a,b=n1()

if (a+b)%2==0:
    print((b-a)//2)
else:
    print(min(a+(b-a-1)//2,n-b+1+(b-a-1)//2))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
	
    int N; cin >> N;
	vi x(N); rep(i,N) cin >> x[i];

	ll now = INF;
	rep1(i,101) {
		ll tmp = 0;
		rep(j,N) {
			tmp += (x[j] - i) * (x[j] - i);
		}
		chmin(now,tmp);
	}
	cout << now << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

//変数
ll H,W;
vector<int> vec(4);


//解法
void solve() {
	
	SORTS2L(int, vec);

	if (vec[0] == 1 && vec[1] == 4 && vec[2] == 7 && vec[3] == 9) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}


	return;
}

int main() {
	//入力

	//cin >> H>>W;
	rep(i, 4) cin >> vec[i];


	solve();
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll n;
    string s;
    cin >> n >> s;

    vector<ll> l(n,0), r(n,0);
    rep(i, 1, n){
        l[i] = l[i-1];
        if(s[i-1] == 'W') l[i]++;
    }
    for(ll i=n-2; i>=0; i--){
        r[i] = r[i+1];
        if(s[i+1] == 'E') r[i]++;
    }
    ll ans = n;
    rep(i, 0, n){
        ans = min(ans, l[i]+r[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5380
#include <bits/stdc++.h>
using namespace std;
 
#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int n, d;
vector< vector<int> > vec;

bool can(int idx, int idx2){

  int sum = 0;
  for(int i=0;i<d;i++){
    sum += ((vec[idx][i] - vec[idx2][i])*(vec[idx][i] - vec[idx2][i]));
  }

  for(int i=0;i<=sum;i++){
    if(i*i == sum) return true;
  }

  return false;
}

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

  cin >> n >> d;
  for(int i=0;i<n;i++){
    vector<int> aux;
    for(int j=0;j<d;j++){
      int a;
      cin >> a;
      aux.push_back(a);
    }
    vec.push_back(aux);
  }

  int ans = 0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(can(i, j)) ans++;
    }
  }

  cout << ans << endl;
  

  return 0;
}

Measured memory_bytes: 256
MOD = 10**9+7
p= []
rp = []

def g(r,c):
    ans = 0
    if r > c:
        r,c = c,r
    for i in range(r+1):
        ans += f(i+1,c)
        ans %= MOD
    return ans

def f(r,c):
    return (p[r+c] * rp[r] * rp[c]) % MOD

def extgcd(a,b):
    r = [1, 0, a]
    w = [0, 1, b]
    while w[2] != 1:
        q = r[2]//w[2]
        ra = w
        wa = [r[0]-q*w[0], r[1]-q*w[1], r[2]-q*w[2]]
        r = ra
        w = wa
    #[x,y]
    return [w[0], w[1]]

def mod_inv(a,m):
    x = extgcd(a, m)[0]
    return (m+x%m)%m

r1,c1, r2,c2 = map(int,input().split())
p = [0 for _ in range(r2+c2+3)]
rp = [0 for _ in range(max(r2,c2)+2)]

p[0] = 1
p[1] = 1
rp[0] = 1
rp[1] = 1
for i in range(2,c2+r2+3):
    p[i] = (p[i-1] * i) % MOD

for i in range(2,max(r2,c2)+2):
    rp[i] = mod_inv(p[i], MOD)

ans = g(r2,c2) - g(r1-1,c2) - g(r2,c1-1) + g(r1-1,c1-1)
ans %= MOD
print (ans)

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

int main()
{
	std::ios::sync_with_stdio(false);
	
	cin>>n;
	ll a[n+1];
	ll prod=1;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]==0)
		{
			cout<<"0";
			return 0;
		}
	}
	
	for(ll i=1;i<=n;i++)
	{
	  if(a[i]<=1000000000000000000/prod)
	   prod*=a[i];
	  else
	  {
	  	cout<<"-1";
	  	return 0;
	  }
	}
	cout<<prod;
	 
	return 0;
}

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

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

    int N, L;
    cin >> N >> L;
    int S;
    int minabs = 1000;
    for (int i = 1; i <= N; i++) {
        S += L + i - 1;
        if (abs(minabs) > abs(L + i - 1)) minabs = L + i - 1;
    }
    S -= minabs;
    cout << S << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define MAX(c) *max_element((c).begin(), (c).end())
#define MIN(c) *min_element((c).begin(), (c).end())
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const ll MOD = 1e+9 + 7;
// --------------------------------------------------------


const int MAX_N = 1e+2;
const int MAX_W = 1e+5;
VVL dp(MAX_N + 1, VL(MAX_W + 1, 0));

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

    int N, W; cin >> N >> W;
    VL w(N), v(N); REP(i,N) cin >> w[i] >> v[i];

    REP(i, N) {
        REP(j, W + 1) {
            if (j - w[i] >= 0) {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }

    ll ans = MAX(dp[N]);
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 83068
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int a, b, c, ans;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> a >> b >> c;
    int odd = (a % 2) + (b % 2) + (c % 2);
    if (odd == 2) {
        ans++;
        if (a % 2)
            a++;
        else if (b % 2)
            b++;
        else if (c % 2)
            c++;
    } else if (3 - odd == 2) {
        ans++;
        if (a % 2 == 0) a++;
        if (b % 2 == 0) b++;
        if (c % 2 == 0) c++;
    }
    int v = max(a, max(b, c));
    ans += (v - a) / 2 + (v - b) / 2 + (v - c) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define RG register
#define IL inline
#define inf 2147483640
#define LL long long
#define pi acos(-1.0)
#define db double
#define N 100005
using namespace std;
IL int gi()
{
	RG int res=0,w=1;
	RG char ch;
	for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
	if(ch=='-') w=-1,ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) res=10*res+ch-48;
	return res*w;
}
int p[N],n;
int cnt=0,ans=0;
int main()
{
	//freopen("2.in","r",stdin);
	//freopen("2.out","w",stdout);
	n=gi();
	for(RG int i=1;i<=n;++i)
		{
			p[i]=gi();
			if(p[i]==i) cnt+=1;
		}
	if(!cnt) {printf("0\n");return 0;}
	for(RG int i=1;i<=n;++i)
		{
			if(p[i]==i)
				{
					if(p[i+1]==i+1)
						swap(p[i],p[i+1]),ans+=1;
					else swap(p[i],p[i+1]),ans+=1;
				}
		}
	printf("%d\n",ans);
	//fclose(stdin);fclose(stdout);
	return 0;
}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n;
    cin>> n;
    int a[n];


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

    sort ( a, a+n);
    cout << a[n/2]- a[n/2 -1] ;
    nl;


    return 0;
}




Measured memory_bytes: 4104
# -*- coding: utf-8 -*-

n, a, b = map(int, input().split())
ans = 0

for i in range(1,n+1):
    st = str(i)
    stp = 0

    for j in st:
        stp += int(j)

    if a <= stp <= b:
        ans += i

print(ans)

Measured memory_bytes: 3060
use std::collections::HashMap;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    let t: String = read();
    let mut map = HashMap::new();
    for (i, c) in (s.clone() + &s).chars().enumerate() {
        let entry = map.entry(c).or_insert(vec![]);
        entry.push(i);
    }
    let n = s.len();
    let mut ans = 0;
    let mut now = 0;
    for c in t.chars() {
        match map.get(&c) {
            Some(vec) => {
                match vec.binary_search(&(now)) {
                    Ok(idx) => {
                        now = vec[idx] + 1;
                    }
                    Err(idx) => {
                        now = vec[idx] + 1;
                    }
                }
                if now >= n {
                    now -= n;
                    ans += n;
                }
            }
            None => {
                println!("-1");
                return;
            }
        }
    }
    ans += now;
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};

void dump(ll *b,int n){
	for(int i=0;i<n;i++){
		cout << b[i] << " ";
	}
	cout << "\n";
}

bool judge(){

}

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

	int n;
	cin >> n;

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

	sort(a,a+n);
	int m=a[n/2];
	ll ans=0;
	for(int i=0;i<n;i++){
		ans += abs(a[i]-m);
	}
	if(n%2==0 && m!=a[n/2 -1]){
		m=a[n/2-1];
		ll ans2=0;
		for(int i=0;i<n;i++){
			ans2 += abs(a[i]-m);
		}
		ans = min(ans,ans2);
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1024
def getlist():
	return list(map(int, input().split()))

N, K = getlist()

if K == 1:
	print(1)
else:
	ans = 0
	for i in range(1, N + 1):
		c = 0
		x = K / i
		while True:
			if x <= 1:
				break
			else:
				x = x / 2
				c += 1
		ans += (1 / 2) ** c
	print(ans / N)

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

int fact(int n){
    int ret = 1;
    rep(i,n) ret*=(i+1);
    return ret;
}

int main(){
    int n; cin >> n;
    int p[n],q[n];
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    int a[n];
    rep(i,n) a[i] = i+1;
    int cntp = 0, cntq = 0;
    do{
        bool flag = true;
        rep(i,n){
            if(a[i] != p[i]){
                flag = false;
                break;
            }
        }
        if(flag) break;
        cntp++;
    }while(next_permutation(a, a+n));
    rep(i,n) a[i] = i+1;
    do{
        bool flag = true;
        rep(i,n){
            if(a[i] != q[i]){
                flag = false;
                break;
            }
        }
        if(flag) break;
        cntq++;
    }while(next_permutation(a, a+n));
    cout << abs(cntp-cntq) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cstdint>

int main() {
	int k;
	std::cin >> k;

	std::int64_t ans = 0;
	for (int a = 1; a <= k; ++a) {
		for (int b = 1; b <= k; ++b) {
			const int g = std::gcd(a, b);
			for (int c = 1; c <= k; ++c)
				ans += std::gcd(g, c);
		}
	}
	
	std::cout << ans << std::endl;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 A, B, K;
  cin >> A >> B >> K;
  i64 k = std::min(A, K);
  A -= k;
  K -= k;
  k = std::min(B, K);
  B -= k;
  K -= k;
  cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std ; 
#define ll long long int 
#define pb push_back
#define ff first 
#define dobara(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define ss second 
#define S(x) scanf("%d",&x) 
#define SL(x) scanf("%lld",&x)
#define M 1000000007
#define sz(x) (int)x.size()
#define all(a) (a).begin(),(a).end()
#define N 100005 

ll dp[N] , broken[N] , n , m ; 

ll f(int idx){
  if(broken[idx])
    return 0 ;

  if(idx == n)
    return 1LL ; 
  
  if(dp[idx] != -1)
    return dp[idx] ; 
  
  ll res = 0 ; 
  
  res = (f(idx + 1))%M ; 
  
  if(idx + 2 <= n)
    res = (res + f(idx + 2))%M ; 
  
  return dp[idx] = res ; 
}

int main(){
   cin>>n>>m ;
  
   for(int i=1;i<=m;i++){
      int x ;
      cin>>x ; 
      broken[x] = 1; 
   }

   memset(dp , -1 , sizeof(dp) ) ; 
   
   ll ans = f(0) ; 

   cout<<ans<<"\n" ;
}

Measured memory_bytes: 6400
#define LOCAL
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define ll long long
#define sz(x) (int)(x).size()
#define endl '\n'
#define print_case() cout << "Case #" << test_case_number++ << ": "

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

int test_case_number = 1;

void solve(){
    print_case();
}

int32_t main(){
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; ++i) cin >> a[i];
    vec<int> dp(n, INT_MAX);
    dp[0] = 0;

    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j <= i + k && j < n; ++j){
            dp[j] = min(dp[j], abs(a[i] - a[j]) + dp[i]);
            //debug() << imie(dp);
        }
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1792
using System;

namespace VSC
{
    class Program
    {
        static void Main(string[] args)
        {
            String ABC = System.Console.ReadLine();
            String[] str = ABC.Split(" ".ToCharArray());
            var A = int.Parse(str[0]);
            var B = int.Parse(str[1]);
            var C = int.Parse(str[2]);

            if (A < B && A < C && C < B ){
                System.Console.Write ("Yes");
            } else if( B < A && B < C && C < A){
                System.Console.Write ("Yes");
            } else {
            System.Console.Write ("No");
            }
        }
    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	char s[5];
	scanf("%s", s);
	int len = strlen(s);
	int count = 0;
	for (int i = 0; i < len; i++) {
		if (s[i] == '1') {
			count++;
		}
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int a, p;
    scan(a, p);
    auto ans = (3*a + p) / 2;
    writeln(ans);
}



















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

const int N = 1e5 + 5;

string s[2];
int prefix[2][N];

int main(){
	cin>>s[0]>>s[1];
	for(int i = 0; i <= 1; i++){
		for(int j = 0; j < s[i].size(); j++){
			prefix[i][j + 1] = prefix[i][j] + (s[i][j] == 'A' ? 1 : -1);
		}
	}
	int q, l1, r1, l2, r2;
	cin>>q;
	while(q--){
		cin>>l1>>r1>>l2>>r2;
		int tmp1 = (((prefix[0][r1] - prefix[0][l1 - 1]) % 3) + 3) % 3, tmp2 = (((prefix[1][r2] - prefix[1][l2 - 1]) % 3) + 3) % 3;
		if(tmp1 == tmp2)	cout<<"YES\n";
		else cout<<"NO\n";
	}
}

Measured memory_bytes: 1664
import java.util.*
fun readint()=readLine()!!.toInt()
fun readll()=readLine()!!.toLong()
fun readstring()=readLine()!!
fun readlint()=(readLine()!!.split(" ").map{it.toInt()}).toIntArray()
fun readlll()=(readLine()!!.split(" ").map{it.toLong()}).toLongArray()

fun solve() {
    val(a,b) = readlint();
    println(a * b);
}
fun main(args: Array<String>) {
    val t = 1;
    repeat(t) {
        solve();
    }
}

Measured memory_bytes: 36424
n = int(input())
t,a = map(int, input().split())
h = list(map(int, input().split()))

for i in range(n):
    k = float(abs(a - (t - h[i] * 0.006)))
    if i == 0:
        g = k
        p = 0
    else:
        if g > k:
            g = k
            p = i

print(p+1)

Measured memory_bytes: 3060
N=int(input())
S=[input() for i in range(N)]
T=input()
L=1
H=N+1
for i in range(N):
    A=S[i].replace("?","a")
    Z=S[i].replace("?","z")
    if T<A:
        H-=1
    if Z<T:
        L+=1
st=""
for i in range(L,H+1):
    st+=str(i)
    if i==H:
        continue
    st+=" "
print(st)


Measured memory_bytes: 3700
#110
n, m, x, y = map(int, input().split())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))

xmax = max(max(xlist),x)
ymin = min(min(ylist),y)

if(xmax<ymin):
    print("No War")
else:
    print("War")

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

int main() {
  int n;
  cin >> n;
    
   if (n < 10) {
   cout << n;
  }
  
  else if(10 <= n && n < 100) {
    cout << 9;
  }
    
  else if(100 <= n && n < 1000) {
   cout << 9 + n % 100 + 100 * (n / 100 - 1) + 1;
  }
  
  else if(1000 <= n && n < 10000) {
   cout << 909;}
    
  else if(10000 <= n && n < 100000){
   cout << 909 + n % 10000 + 10000 * (n / 10000 - 1) + 1;
  }
  else {
  cout << 90909;
  }
    
    
}

Measured memory_bytes: 256
import bisect

ans = 10**20

N, K = list(map(int, input().split()))
x = [-10**20] + list(map(int, input().split())) + [10**20]

zero = bisect.bisect_left(x, 0)

left = x[:zero] + [0] 
right = [0] + x[zero:]
left.reverse()
l = len(left)
r = len(right)

idxs = [[K-i, i] for i in range(K+1) if K-i < l and i < r]

for l, r in idxs:
    n = abs(left[l]) + right[r] + min(abs(left[l]), right[r])
    ans = min(ans, n)
print(ans)

Measured memory_bytes: 15944
use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|i| i.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<usize>();
    let input = read_vec::<usize>();

    let mut hm = HashMap::new();

    for i in input.iter() {
        *hm.entry(i).or_insert(0) += 1;
    }
    let mut hmc = HashMap::new();
    for i in hm.keys() {
        let val = hm[&*i];
        if val > 1 {
            hmc.insert(i, val * (val-1) / 2);
        } else {
            hmc.insert(i, 0);
        }
    }

    let mut ans = vec![];

    let sum: usize = hmc.values().sum();

    for k in 0..n {

        let mut count = sum;
        let val = hm[&input[k]];
        if val > 1 {
            count -= hmc[&&input[k]];
            if val > 2 {
                count += (val-1) * (val-2) / 2;
            }
        }
        ans.push(count);
    }

    for i in ans {
        println!("{}", i);
    }
    // println!("{:?}", ans);
}

Measured memory_bytes: 24044
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;


void solve(long long N, std::vector<long long> A){
  double ans = 0.0;
  REP(x, N) {
    ans += 1.0 / A.at(x);
  }
    ans = 1.0 / ans;
    printf("%f\n", ans);
}

signed main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, std::move(A));
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    for (int i = k; i < n; i++) {
        if (a[i - k] < a[i]) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    return 0;
}


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

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

			String in = br.readLine();
			char[] ans = in.toCharArray();
			char a = (char) ((char)ans[0]+1);
			System.out.println(a);

		}
	}
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(auto& x:a){
		cin >> x;
	}
	sort(a.begin(), a.end());
	map<int, int> joi;
	for(int i =0; i<n; i++){
		int key = a.at(i);
		if(joi.count(key)){
			joi.erase(key);
		}else{
			joi[key] = 1;
		}
	}
	cout << joi.size() << endl;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a, b; cin >> a >> b;
  if(a <= 0 && b >= 0) {
    cout << "Zero" << endl;
  }
  else if(a > 0) {
    cout << "Positive" << endl;
  }
  else {
    if((b - a) %2 == 1) {
      cout << "Positive" << endl;
    }
    else {
      cout << "Negative" << endl;
    }
  }
}

Measured memory_bytes: 3604
// ITP1_4_D Min, Max and Sum Simple Calculator
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
  
  // 初期値
  long int n, sum = 0;
  cin >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  sort(a.begin(),a.end());
  
  // メインループ
  cout << a.at(0) << " " << a.at(n - 1) << " " << sum << endl;
  return 0;
}


Measured memory_bytes: 3212
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
  input! {
    n: u64,
    x: u64,
    axs: [i64; n],
  }
  println!("{}", solve(n, x, axs));
}

pub fn solve(n: u64, x: u64, mut axs: Vec<i64>) -> String {
  // axsを昇順でソートする
  // (x, a, x-a) -> (x-a1, a2, left-a2)
  // rightが0以下になったら終わり
  let mut rest_x = x as i64;
  let mut counter = 0;
  axs.sort();
  for a in axs.iter() {
    if rest_x < *a {
      break;
    }
    rest_x -= *a;
    counter += 1;
  }

  if counter == axs.len() && rest_x > 0 { counter -= 1; }

  counter.to_string()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define int long long
#define rep(val,cnt) for(int (val)=0;(val)<(cnt);++(val))
#define all(v) (v).begin(),(v).end()
using namespace std;

using ull  = unsigned long long;
using pint = pair<int,int>;
using tint = tuple<int,int,int>;

void Main(void);
signed main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  Main();
}

template<typename T>
struct edge{T to,cost;};

template<typename T>
class Graph{
  public :
  vector<vector<edge<T>>> graph;

  void add(int from,T to,int cost){
    graph[from].emplace_back((edge<T>){to,cost});
  }
  T prim(void){
    using Pi = pair<T,int>;
    T total=0;
    vector<bool> used(graph.size(),false);
    priority_queue<Pi,vector<Pi>,greater<Pi>> que;
    que.emplace(0,0);
    while(!que.empty()){
      auto p=que.top(); que.pop();
      if(used[p.second]) continue;
      used[p.second]=true;
      total+=p.first;
      for(auto &e : graph[p.second]) que.emplace(e.cost,e.to);
    }
    return total;
  }
};

// ---------------------------------------------------------------
// Code from Here
// ---------------------------------------------------------------
void print(pint p){
  cout<<p.first<<" "<<p.second<<" ";
}

void Main(void){
  ull S; cin>>S;
  pint P1,P2,P3;
  P1=pint(0,0),P2=pint(1e9,1);

  // memo : 1e9 * y3 = S + x3
  int div,mod;
  div=S/1000000000,mod=S%1000000000;
  //cout<<div<<" "<<mod<<endl;
  ++div,mod=1000000000-mod;
  P3=pint(mod,div);
  if(S==1e18) P3=pint(0,1000000000);
  print(P1),print(P2),print(P3);
  cout<<endl;
  //cout<<abs(P2.first*P3.second-P2.second*P3.first)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
typedef pii Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

void dijkstra(Graph &g, Array &d, int s, vi &prev)
{
	d.assign(g.size(), Weight(INF,INF));
	prev.assign(g.size(), -1);
	d[s] = Weight(0, 0);
	typedef pair<Weight, int> P;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(d[s], s));
	while (!que.empty())
	{
		Weight dist = que.top().first;
		int v = que.top().second;
		que.pop();
		if (d[v] < dist) continue;
		REP(i, g[v].size())
		{
			Edge e = g[v][i];
			if (d[e.to].first > d[v].first + e.cost.first ||
				(d[e.to].first==d[v].first+e.cost.first&&d[e.to].second-d[prev[e.to]].second>e.cost.second))
			{
				prev[e.to] = e.from;
				d[e.to].first = d[v].first + e.cost.first;
				d[e.to].second = d[v].second + e.cost.second;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

vi buildPath(const vi &prev, int t)
{
	vi path;
	for (int u = t; u >= 0; u = prev[u]) path.push_back(u);
	reverse(path.begin(), path.end());
	return path;
}

int main()
{
	int n, m;
	while (cin >> n >> m, n)
	{
		Graph g(n);
		REP(i, m)
		{
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			a--; b--;
			add_edge(g, a, b, pii(c, d));
			add_edge(g, b, a, pii(c, d));
		}
		Array d;
		vi prev;
		dijkstra(g, d, 0, prev);
		ll ans = 0;
		FOR(i, 1, n) ans += d[i].second - d[prev[i]].second;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4240
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string input;
	cin>>input;
	int cnt=0;
	int k,u,p,c;
	k=u=p=c=0;
	for(int i=0;i<input.size();i++){
		if(input[i]=='K')k++;
		if(input[i]=='U')u++;
		if(input[i]=='P')p++;
		if(input[i]=='C')c++;	
		if(0<k&&0<u&&0<p&&0<c){
			cnt++;
			k--;u--;p--;c--;
		}	
			
	}
	
	
	cout<<cnt<<endl;
}

Measured memory_bytes: 1188
//hail to jwalaji
#include<bits/stdc++.h>
using namespace std;
typedef  int lli;
int main(){
lli n,k;
cin>>n>>k;
vector<lli> h(n),cost(n);
for(lli i=0;i<n;i++){
    cin>>h[i];
}
cost[0]=0;
for(lli i=1;i<n;i++){
        cost[i]=cost[i-1]+abs(h[i]-h[i-1]);
    lli stop=max(0,i-k);
    for(lli j=i-1;j>=stop;--j){
        cost[i]=min(cost[i],cost[j]+abs(h[i]-h[j]));
    }
}
cout<<cost[n-1]<<endl;
return 0;
}


Measured memory_bytes: 3968
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

const int N=1005;

int n,x[N],y[N],d[N],m;
bool in[2];

int main() {
	scanf("%d",&n);
	fo(i,1,n) {
		scanf("%d%d",&x[i],&y[i]);
		in[(x[i]+y[i])&1]=1;
	}
	if (in[0]&&in[1]) {puts("-1");return 0;}
	if (in[0]) d[++m]=1;
	fd(i,30,0) d[++m]=1<<i;
	printf("%d\n",m);
	fo(i,1,m) printf("%d ",d[i]);
	puts("");
	fo(i,1,n) {
		fo(j,1,m)
			if (abs(x[i])>abs(y[i])) {
				if (x[i]>0) x[i]-=d[j],putchar('R');
				else x[i]+=d[j],putchar('L');
			} else {
				if (y[i]>0) y[i]-=d[j],putchar('U');
				else y[i]+=d[j],putchar('D');
			}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,count=0;
  string s;

  cin>>n>>s;

  s[n]='\n';
  for(int i=1;i<=n;i++){
    if(s[i-1]!=s[i]) count++;
  }

  cout<<count<<endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {

	int n;
	cin >> n;

	int f[110][10][5] = { 0 };
	long long int p[110][15] = { 0 };
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 5; j++) {
			for (int k = 0; k < 2; k++) {
				cin >> f[i][j][k];
			}
		}
	}

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

	long long int MAX = 0;

	for (long long int i = 1; i < (1 << 10); i++) {
		int c[110] = { 0 };
		for (int j = 0; j < 10; j++) {
			if ((i & (1 << j)) != 0) {
				int jj = j % 5;
				int kk = j / 5;
				for (int k = 0; k < n; k++) {
					if (f[k][jj][kk] == 1) {
						c[k]++;
					}
				}
			}
		}
		long long int ans = 0;
		for (int j = 0; j < n; j++) {
			ans += p[j][c[j]];
		}
		if (i == 1) {
			MAX = ans;
		}
		else {
			MAX = max(MAX, ans);
		}
	}

	cout << MAX << endl;
	return 0;
}

Measured memory_bytes: 256