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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  string s;cin>>s;
  vector<ll>a(n-1);
  rep(i,0,n-1)a[i]=abs(s[i+1]-s[i]);
  bool one=false;
  ll ret=1;
  rep(i,0,n-1){
    if(a[i]==1)one=true;
  }
  if(!one){
    ret=2;  
  }
  ll sum=0;
  ll now=1;
  //debug(a,n-1);
  rep(i,0,n-1){
    bool sw=false;
    sw=(i==(n-2&i));
    //if(sw)cout<<i<<endl;
    if(a[i]!=ret)continue;
    ll d=n-2-i;
    
    if(sw){
      sum^=ret;
    }
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 9116
#include<bits/stdc++.h>
#define FIO ios::sync_with_stdio(false)
#define N 100000
#define INF 0x3f3f3f3f
#define LL long long int
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	cout<<x+y/2<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int n,c[30],v[30];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&v[i]);
    for(int i=0;i<n;i++) scanf("%d",&c[i]);
    int ans = 0;
    for(int i=0;i<n;i++){
        if(v[i]>c[i]) ans += (v[i]-c[i]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> d(n);
    for (int i = 0; i < n; ++i) scanf("%d", &d.at(i));
    sort(d.begin(), d.end());
    printf("%d\n", d.at(n / 2) - d.at(n / 2 - 1));
    return 0;
}


Measured memory_bytes: 640
from itertools import accumulate
N = int( input())
A = list( map( int, input().split()))
AA = list(accumulate(A))
ANS = abs( AA[0]*2 - AA[-1])
for i in range(N-1):
    K = abs( AA[i]*2 - AA[-1])
    ANS = min( K, ANS)
print(ANS)

Measured memory_bytes: 24168
A = []
hit = []
for _ in range(3):
    A.append(list(map(int, input().split())))
    hit.append([False]*3)

N=int(input())
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                hit[i][j] = True
                break

for i in range(3):
    if hit[i][0] and hit[i][1] and hit[i][2]:
        print('Yes')
        exit()
    if hit[0][i] and hit[1][i] and hit[2][i]:
        print('Yes')
        exit()
if hit[1][1]:
    if hit[0][0] and hit[2][2] or hit[2][0] and hit[0][2]:
        print('Yes')
        exit()

print('No')


Measured memory_bytes: 62104
/*
Anki:未済
作成日:①2020/03/01
*/

#include <stdio.h>

int main()
{
    int n, p;
    
    scanf( "%d", &n );

    p = n /2;
    if( n % 2 == 0 )  
        printf( "%d", p );
    else
        printf( "%d\n", p + 1 );
    return 0;
}

Measured memory_bytes: 128
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
long double a[1001];
priority_queue<long double, std::vector<long double>, std::greater<long double> >sol;
void solve()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sol.push(a[i]);
	}
	while (sol.size() > 1)
	{
		long double x = sol.top();
		sol.pop();
		long double y = sol.top();
		sol.pop();
		long double ans = (x + y) / (long double)2;
		sol.push(ans);
	}
	cout<<fixed<<setprecision(9) << sol.top();
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
int N, K;
vector<int> L, R;
int main() {
	cin >> N >> K;
	L.resize(K);
	R.resize(K);
	for (int i = 0; i < K; ++ i) {
		cin >> L[i] >> R[i];
	}
	vector<ll> hoge(N);
	hoge[0] = 1;
	hoge[1] = mod-1;
	ll s = 0;
	for (int i = 0; i < N; ++ i) {
		(s += hoge[i]) %= mod;
		for (int j = 0; j < K; ++ j) {
			int x = i + L[j];
			int y = i + R[j] + 1;
			if (x < N) (hoge[x] += s) %= mod;
			if (y < N) (hoge[y] += mod - s) %= mod;
		}
	}
	cout << s << endl;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll N, M;
    cin >> M >> N;

    ll ans = 1;
    ll m = M;
    REP(i, 40)
    {
        if (((N >> i) & 1) == 1)
            ans = (ans * m) % MOD;
        m = (m * m) % MOD;
    }
    cout << ans % MOD << endl;

    return 0;
}


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


/*  
    
*/

void test_case(){
    
    string s; cin >> s;
    if(s.back() == 's')
        s += "es";
    else
        s += "s";
        
    cout << s << endl;
}

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

    int t; t = 1;
    //cin >> t;
    while(t--)
        test_case();
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int gcd(int a, int b)
{
  if (b > a)
  {
    int temp = a;
    a = b;
    b = temp;
  }
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
void p_1()
{
  int N;
  cin >> N;
  int num[N];
  for (int i = 0; i < N; i++)
    cin >> num[i];
  int res = num[0];
  for (int i = 1; i < N; i++)
  {
    if (res == 1)
      break;
    res = gcd(res, num[i]);
  }
  cout << res;
}

void p_2()
{
  int need[10];
  need[1] = 2;
  need[2] = 5;
  need[3] = 5;
  need[4] = 4;
  need[5] = 5;
  need[6] = 6;
  need[7] = 3;
  need[8] = 7;
  need[9] = 6;
  int N, M = 0;
  cin >> N >> M;
  int dp[N + 1];
  for (int i = 1; i < N + 1; i++)
    dp[i] = INT32_MIN;
  dp[0] = 0;
  int pos[M];
  for (int i = 0; i < M; i++)
    cin >> pos[i];
  sort(pos, pos + M);
  for (int i = 1; i < N + 1; i++)
  {
    for (int j = M - 1; j >= 0; j--)
    {
      if (i - need[pos[j]] < 0)
        continue;
      int temp = dp[i - need[pos[j]]] + 1;
      if (dp[i] < temp)
        dp[i] = temp;
    }
  }
  int dig = dp[N];
  string ans = "";
  int match = N;
  for (int i = 0; i < dig; i++)
  {
    for (int j = M - 1; j >= 0; j--)
    {
      if (match - need[pos[j]] < 0)
        continue;
      if (dp[match] == dp[match - need[pos[j]]] + 1)
      {
        ans = ans + to_string(pos[j]);
        match -= need[pos[j]];
        break;
      }
    }
  }
  cout << ans;
}
int main(void)
{
  //p_1();
  p_2();
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//絶対値
long long int change_plus(long long int a) {
	if (a < 0) { return -a; }
	if (a >= 0) { return a; }
}
//大小比較(大)
long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}

main() {
	long long int n, m, k = 0;
	char str[5];
	scanf("%lld%lld",&n,&m);
	if (n+m>=10) { printf("error"); }
	else { printf("%lld",n+m); }
	

}

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

n=int(input())  #数値入力 「N」だけの入力のとき
h=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
cnt=0
L=0
while L != len(h):
    if h[L] != 0:
        for r in range(L+1 ,len(h)):
            if h[r] == 0:
                #do it
                for k in range(L,r):
                    h[k]-=1
                cnt+=1
                break
        else:
            r = len(h)
            for k in range(L,r):
                h[k]-=1
            cnt+=1
    elif h[L] == 0:
        L+=1
print(cnt)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
  int a[10];
  for(int i=0;i<10;i++){
    cin>>a[i];
  }
  sort(a,a+10,greater<int>());
  for(int i=0;i<3;i++){
    cout<<a[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n;
  cin >> n;
  map<string, ll> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    m[s]++;
  }

  cout << "AC x " << m["AC"] << ln; 
  cout << "WA x " << m["WA"] << ln; 
  cout << "TLE x " << m["TLE"] << ln; 
  cout << "RE x " << m["RE"] << ln; 

  return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    string S;
    cin >> S;
    ll cnt=0;
    for (int i = 0; i < S.size(); i++) {
        if(S[i] == 'o') cnt++;
    }
    YES((15-S.size())+cnt >= 8);
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
typedef unsigned long long int ull;
typedef long double ldb;
#define B 1000000007
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repi(i,a,b) for(ll i=b-1;i>=a;i--)
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long int>
#define pb push_back
#define mp make_pair
#define INF 1e18
#define deci(n) fixed << setprecision(n)
#define PI 3.141592653589793238462643
#define ani ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

void pairsort(ll a[], ll b[], ll n) 
{ 
    pair<ll, ll> pairt[n]; 
  
 
    for (ll i = 0; i < n; i++)  
    { 
        pairt[i].first = a[i]; 
        pairt[i].second = b[i]; 
    } 
  
    sort(pairt, pairt + n); 
      
    for (ll i = 0; i < n; i++)  
    { 
        a[i] = pairt[i].first; 
        b[i] = pairt[i].second; 
    } 
}
 
ll extendedGcd(ll a, ll b, ll & x, ll & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = extendedGcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}


  ll binaryToDecimal(string n) 
{ 
    string num = n; 
    ll dec_value = 0; 
    // Initializing base value to 1, i.e 2^0 
    ll base = 1;  
    ll len = num.length(); 
    for (ll i = len - 1; i >= 0; i--) { 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
    return dec_value; 
} 


ll nCr(ll n,ll k){ 
    ll C[n + 1][k + 1]; 
    ll i, j; 
    for (i=0;i<=n;i++){ 
        for(j=0;j<=min(i,k);j++){
            if(j==0||j==i) 
                C[i][j]=1;  
            else
                C[i][j]=(C[i-1][j-1]%B+C[i-1][j]%B)%B; 
        } 
    }
    return C[n][k]%B; 
} 


ll countDivisors(ll n) 
{ 
    ll cnt = 0; 
    for (ll i = 1; i <= sqrt(n); i++) 
    { 
        if (n % i == 0) 
        { 
            // If divisors are equal, 
            // count only one 
            if (n / i == i) 
                cnt++; 
  
            else // Otherwise count both 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
}

ll highestPowerof2(ll n) 
{ 
   ll p = (ll)log2(n); 
    return (ll)pow(2, p);  
} 
bool isPowerOfTwo(int x)
    {   // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
        return (x && !(x & (x - 1)));
    }

void dfs(int p,vector<int> a[],int v[])
{
    if(v[p])
        return ;
    v[p]=1;
    for(int i=0;i<a[p].size();i++)
    {
        if(!v[a[p][i]])
        dfs(a[p][i],a,v);
    }
} 
ll max(ll a, ll b){
  if (a > b)
    return a;
  return b;
}
ll min(ll a, ll b){
  if (a < b)
    return a;
  return b;
}

int main()
{ 
ani;

int t=1;
 // cin>>t;
while(t--)
{
    int n;
    cin>>n;
    int h[n+1];
    rep(i,1,n+1)
    cin>>h[i];

    int dp[n+1];
    rep(i,0,n+1)
    dp[i]=0;

    dp[2]=abs(h[2]-h[1]);
    dp[1]=0;
    dp[3]=min(abs(h[3]-h[1]),abs(h[3]-h[2])+abs(h[2]-h[1]));

    for(int i=4;i<=n;i++)
    {
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<dp[n]<<endl;

















}

return 0;
}

Measured memory_bytes: 1024
{-# LANGUAGE OverloadedStrings #-}
import Prelude hiding (getLine, words)

import Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)

solve :: ByteString -> Int
solve input =
    let [num0, op, num1] = words input
        in (parseOp op) (parseInt num0) (parseInt num1)

parseInt :: ByteString -> Int
parseInt = fst . fromJust . readInt

parseOp :: Num a => ByteString -> (a -> a -> a)
parseOp op = case op of
                  "+" -> (+)
                  "-" -> (-)


main = getLine >>= print . solve

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

int main(void) {
	while (1) {
		int n;
		int mini = INF;
		int a[1001] = {};

		cin >> n;
		if (n == 0) {
			break;
		}
		FOR(i, 0, n - 1) {
			cin >> a[i];
		}
		sort(a, a + n);
		FOR(i, 0, n - 2) {
			if (a[i + 1] - a[i] < mini) {
				mini = a[i + 1] - a[i];
			}
		}
		cout << mini << endl;
	}
}


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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void Main() {
    int n,m;
    cin >> n >> m;
    cout << (n-1)*(m-1) << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n, K;
    cin >> n >> K;
    vector<ll> x(n);
    vector<ll> y(n);
    REP(i,n) cin >> x[i] >> y[i];
    ll ans = LINF*9;
    REP(i,n) REP(j,n) REP(k,n) REP(l,n) {
        if(x[i] >= x[j] || y[k] >= y[l]) continue;
        int cnt = 0;
        REP(m,n) {
            if(x[i] <= x[m] && x[m] <= x[j] && y[k] <= y[m] && y[m] <= y[l]) cnt++;
        }
        if(cnt >= K){
            ll cans = (x[j]-x[i])*(y[l]-y[k]);
            ans = min(ans, cans);
        }
    }
    cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

/*
二分探索です。i 番目が行ける条件を考えます。
まず、i < p なら明らかに OK です。
そうでないとき、まず、全振りして a_{p-1} に勝てなければダメです。
それが大丈夫だとして、残りが始めの p-1 個と右のものだけに振れるなら OK です。
それがダメなら、[p-1,i[ に、忖度しながら振っていきます。
*/

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  lint n, m, v, p;
  std::cin >> n >> m >> v >> p;
  std::vector<lint> a(n); std::cin>>a;
  std::sort(all(a),std::greater<>{});
  debug(m,v,p,a);

  std::vector<lint>b = {0};
  std::partial_sum(all(a),std::back_inserter(b));
  debug(b);
  lint rival = a.at(p-1);
  debug(rival);

  auto check = [&] (lint i) -> bool {
    if (i < p) return true;
    debug("foo");
    lint me = a.at(i);
    if (rival > me + m) return false;
    lint u = n + p - i - 2;
    debug(u,"goo");
    if (v - 1 <= u) return true;
    debug("hoo");
    lint sum = b.at(i) - b.at(p-1);
    lint k = v-1-u;
    debug(sum,k);
    debug(i-p+1,me+m);
    return sum + k * m <= (i - p + 1) * (me + m);
  };
  // debug
  // rep(i,0,n) {
  //   bool b = check(i);
  //   debug(i,b);
  //   std::cerr<<std::endl;
  // }

  lint ok = 0, ng = n;
  while (1 < ng - ok) {
    lint mid = (ng + ok) / 2;
    (check(mid) ? ok : ng) = mid;
  }
  lint ans = ok + 1;
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 998244353;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll three(int N){
    ll tmp = 1;
    rep(i,N){
        tmp *= 3;
        tmp %= mod;
    }
    return tmp;
}


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

    ll sum = 0;
    rep(i,N) sum = (sum+a[i])%mod;

    // dp[i][j] := a[0,i)について,色Xの総和がjになるような場合の数
    vector<vector<ll>> dp(N+1,vector<ll>(sum+1,0));
    dp[0][0] = 1;
    rep(i,N){
        rep(j,sum+1){
            dp[i+1][j] += (2*dp[i][j])%mod;
            dp[i+1][j] %= mod;
            if(j-a[i]>=0){
                dp[i+1][j] += dp[i][j-a[i]];
                dp[i+1][j] %= mod;
            }
        }
    }

    // dup[i][j] := a[0,i)について,色Xの総和がj,色Yの総和がa[0,i)-jの場合の数
    vector<vector<ll>> dp2(N+1,vector<ll>(sum+1,0));
    dp2[0][0] = 1;
    rep(i,N){
        rep(j,sum+1){
            dp2[i+1][j] += dp2[i][j];
            dp2[i+1][j] %= mod;
            if(j-a[i]>=0){
                dp2[i+1][j] += dp2[i][j-a[i]];
                dp2[i+1][j] %= mod;
            }
        }
    }

    ll ans = three(N) % mod;
    ll tmp = 0;
    for(ll i=(sum+1)/2;i<=sum;i++){
        tmp += dp[N][i];
        tmp %= mod;
    }
    tmp = (tmp * 3) % mod;

    ans = (ans - tmp + mod) % mod; 

    if(sum%2 == 0){
        ans += (dp2[N][sum/2] * 3) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  long sumx=0;
  long sumy=0;
  const int mod=1000000007;
  for(int i=0;i<n;i++){
    long x;
    cin >> x;
    sumx=(sumx+x*(-n+2*i+1))%mod;
  }
  for(int i=0;i<m;i++){
    long y;
    cin >> y;
    sumy=(sumy+y*(-m+2*i+1))%mod;
  }
  long ans=sumx*sumy%mod;
  cout << ans;
}




Measured memory_bytes: 256
//============================================================================
// Name        : DPTest.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int N,M,K;
int A[20001]={};
const long long INF=100000000000000;
long long dp[20001]={};
int maxdp[20001][1001]={};
int mindp[20001][1001]={};

int maxD(int n2,int n3){
	int ans2=A[n2+n3];
	if(maxdp[n2][n3]>0)return maxdp[n2][n3];
	if(n3>1)ans2=max(maxD(n2,n3-1),A[n2+n3]);
	maxdp[n2][n3]=ans2;
	return ans2;
}
int minD(int n2,int n3){
	int ans2=A[n2+n3];
	if(mindp[n2][n3]>0)return mindp[n2][n3];
	if(n3>1)ans2=min(minD(n2,n3-1),A[n2+n3]);
	mindp[n2][n3]=ans2;
	return ans2;
}

long long calc(int n1){
	long long ans=INF;
	if(dp[n1]>-1)return dp[n1];
	for(int i=1;i<M+1&&i<n1+1;i++){
		ans=min(ans,calc(n1-i)+(long long)K+(long long)i*(long long)(maxD(n1-i,i)-minD(n1-i,i)));
	}
	dp[n1]=ans;
	return ans;
}
int main() {
	cin>>N>>M>>K;
	for(int i=1;i<N+1;i++)cin>>A[i];
	fill(dp,dp+20001,-1);
	dp[0]=0;
	cout<<calc(N)<<endl;
	return 0;
}

Measured memory_bytes: 160984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;



int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  ll wa;
  if (a[0] > 0) {
    ll ans1 = 0, ans2 = a[0] + 1;
    wa = a[0];
    for (int i = 1; i < n; i++){
      if (wa > 0){
        wa += a[i];
        if (wa < 0) continue;
        else {
          ans1 += wa + 1;
          wa = -1;
        }
      } else {
        wa += a[i];
        if (wa > 0) continue;
        else {
          ans1 += 1 - wa;
          wa = 1;
        }        
      }
    }
    wa = -1;
    for (int i = 1; i < n; i++){
      if (wa > 0){
        wa += a[i];
        if (wa < 0) continue;
        else {
          ans2 += wa + 1;
          wa = -1;
        }
      } else {
        wa += a[i];
        if (wa > 0) continue;
        else {
          ans2 += 1 - wa;
          wa = 1;
        }        
      }
    }
    if (ans1 < ans2) cout << ans1 << endl;  
    else cout << ans2 << endl;
  }
  else if (a[0] < 0) {
    ll ans1 = 0, ans2 = 1 - a[0];
    wa = a[0];
    for (int i = 1; i < n; i++){
      if (wa > 0){
        wa += a[i];
        if (wa < 0) continue;
        else {
          ans1 += wa + 1;
          wa = -1;
        }
      } else {
        wa += a[i];
        if (wa > 0) continue;
        else {
          ans1 += 1 - wa;
          wa = 1;
        }        
      }
    }
    wa = 1;
    for (int i = 1; i < n; i++){
      if (wa > 0){
        wa += a[i];
        if (wa < 0) continue;
        else {
          ans2 += wa + 1;
          wa = -1;
        }
      } else {
        wa += a[i];
        if (wa > 0) continue;
        else {
          ans2 += 1 - wa;
          wa = 1;
        }        
      }
    }
    if (ans1 < ans2) cout << ans1 << endl;  
    else cout << ans2 << endl;
  }
  else {
    ll ans1 = 1, ans2 = 1;
    wa = 1;
    for (int i = 1; i < n; i++){
      if (wa > 0){
        wa += a[i];
        if (wa < 0) continue;
        else {
          ans1 += wa + 1;
          wa = -1;
        }
      } else {
        wa += a[i];
        if (wa > 0) continue;
        else {
          ans1 += 1 - wa;
          wa = 1;
        }        
      }
    }
    wa = -1;
    for (int i = 1; i < n; i++){
      if (wa > 0){
        wa += a[i];
        if (wa < 0) continue;
        else {
          ans2 += wa + 1;
          wa = -1;
        }
      } else {
        wa += a[i];
        if (wa > 0) continue;
        else {
          ans2 += 1 - wa;
          wa = 1;
        }        
      }
    }
    
    if (ans1 < ans2) cout << ans1 << endl;
    else cout << ans2 << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

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

typedef long long ll;

int main(){
	int a, b;
	
	cin >> a >> b;
	
	if (a == 1) a = 14;
	if (b == 1) b = 14;
	
	if (a == b) cout << "Draw" << endl;
	else if (max(a,b) == a) cout << "Alice" << endl;
	else cout << "Bob" << endl;
	
	return 0;
}

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


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    lm = max(L)
    rm = min(R)
    print(max(0,rm-lm+1))

    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 10868
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
using namespace std;
 
int main(){
    
    int N,K;
    char S[10],Ans[10],Ck;

    cin >> N;

    for(int i=0;i<N;i++){
        cin >> S[i];
    }

    cin >> K;
    Ck = S[K-1];

    for(int i=0;i<N;i++){
        if(S[i]!=Ck){
            Ans[i]='*';
        }else{
            Ans[i]=S[i];
        }
    }

    for(int i=0;i<N;i++){
        cout<<Ans[i];
    }

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[51], c[51];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> c[i];
	int ans = 0;
	for (int i = 0; i < n; i++)
		ans += (a[i] > c[i]) ? (a[i] - c[i]) : 0;
	cout << ans;
}

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

// helper function to find minimum cost to reach end
int minCost(int* arr, int n, int k)
{
	int *dp = new int[n];

	// fills dp array with 0
    memset(dp, 0, sizeof(dp));

	for(int i = 1; i < n; i++)
    {
    	int ans = INT_MAX, temp = INT_MAX;
    	for(int j = i - 1; j >= 0 && i - j <= k; j--)
    	{
            temp = dp[j] + abs(arr[i] - arr[j]);
            if(temp < ans)
            	ans = temp;
    	}

        dp[i] = ans;
    }

    return dp[n-1];
}


// function to handle input and output
int main()
{
  int n, k;
  cin >> n >> k;

  int a[n];

  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  
  cout << minCost(a, n, k);

  return 0;
}


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

int main() {
  int N;
  int K;
  cin >> N >>K;
  int x=1;
  for (int i=0; i<N; ++i){
    if(x+K > x*2){
    x +=x;  
    }
    else {
      x +=K;
      }
  }
    cout << x <<endl;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

ll N, A, B, C;
ll hs[100100];

bool can(ll x){
    ll rest = 0;
    for(int i=0;i<N;++i){
        if((hs[i] + B - 1) / B <= x){

        }else{
            rest += (hs[i] - x * B + C - 1) / C;
        }
    }
    return rest <= x;
}

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

    std::cin >> N >> A >> B;
    C = A - B;
    
    for(int i=0;i<N;++i){
        std::cin >> hs[i];
    }
    
    // if minimizing, lb satisfies lb > ub
    // if maximizing, lb satisfies lb < ub
    ll lb = 1001001001001001ll, ub = 0ll;

    while(std::abs(ub - lb) > 1){
        ll mid = (lb + ub) / 2;

        if(can(mid)){
            lb = mid;
        }else{
            ub = mid;
        }
    }

    std::cout << lb << std::endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <set>

int main() {
    int N;
    std::set<std::string> items;
    scanf("%d", &N);
    while(N--){
        std::string item;
        std::cin >> item;
        items.insert(item);
    }
    printf("%d\n", items.size());
    return 0;
}

Measured memory_bytes: 19280
#include <string>
#include <iostream>
using namespace std;
int N, c1, c2, c3, out, ret; string S;
int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		c1 = 0, c2 = 0, c3 = 0, out = 0, ret = 0;
		while (out != 3) {
			cin >> S;
			if (S == "HIT") {
				ret += c3, c3 = c2, c2 = c1, c1 = 1;
			}
			else if (S == "HOMERUN") {
				ret += c1 + c2 + c3 + 1, c1 = 0, c2 = 0, c3 = 0;
			}
			else {
				out++;
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 3172
n, k = map(int, input().split())
mod = 998244353
list_s = []
for _ in range(k):
    l, r = map(int, input().split())
    list_s.append((l, r))
dp = [0] * (n + 1)
sdp = [0] * (n + 1)
dp[1] = 1
sdp[0] = 0
sdp[1] = 1

for i in range(2, n + 1):
    for l, r in list_s:
        dl = max(0, i - r - 1)
        dr = max(0, i - l)
        dp[i] += sdp[dr] - sdp[dl]
        sdp[i] = (sdp[i - 1] + dp[i]) % mod
print(dp[n] % mod)

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

int main() {
  int sum = 0;
  vector<vector<int>> c(3, vector<int>(3));
  rep(i,3) rep(j,3) cin >> c[i][j];

  vector<int> a(3), b(3);
  a[0] = 0;
  rep(i,3) {
    b[i] = c[0][i];
    a[i] = c[i][i] - b[i];
  }

  bool ans = true;
  rep(i,3) rep(j,3) {
    if (c[i][j] != a[i] + b[j]) ans = false;
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3616
from sys import stdin
INF = float("inf")#無限大の設定1
IINF = 10 ** 18#無限大の設定2
MOD = 10 ** 9 + 7#まれに用いるmodを予め設定しておく
a = int(stdin.readline().rstrip())
b = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]
if a!=1 and b!=1:
    print(1)
if a!=2 and b!=2:
    print(2)
if a!=3 and b!=3:
    print(3)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;

int main() {
  vector<int> ABC(3);
  for (int i = 0; i < 3; ++i) {
    cin >> ABC[i];
  }
  sort(ABC.rbegin(), ABC.rend());
  int dif1 = ABC[0] - ABC[1];
  int dif2 = ABC[0] - ABC[2];
  int result = dif1;
  if (dif1 == dif2) {
    ;
  } else if ((dif2 - dif1) % 2 == 0) {
    result += (dif2 - dif1) / 2;
  } else {
    result += (dif2 - dif1) / 2 + 2;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
vector<vector<ll> >d(310,vector<ll>(310,inf));
vector<vector<ll> >exist(310,vector<ll>(310,-1));
void Warshall_Floyd(ll n){
    REP(k,1,n+1){
        REP(i,1,n+1){
            REP(j,1,n+1)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        }
    }
}
int main(){
    ll n,m;cin>>n>>m;
    rep(i,m){
        ll a,b,c;cin>>a>>b>>c;
        d[a][b]=c;
        d[b][a]=c;
        exist[a][b]=c;
        exist[b][a]=c;
    }
    REP(i,1,n+1)d[i][i]=0;
    Warshall_Floyd(n);
    ll cnt=0;
    REP(i,1,n+1){
        REP(j,1,n+1){
            if(exist[i][j]==d[i][j]){
                cnt++;
            }
            //cout<<d[i][j]<<' '<<exist[i][j]<<endl;
        }
    }
    cout<<m-cnt/2<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N;
  cin >> N;
  vector<long> men(5);
  for (int i = 0; i < 5; i++) {
    cin >> men.at(i);
  }
  long minim = men.at(0);
  for (int i = 1; i < 5; i++) {
    if (minim > men.at(i)) {
      minim = men.at(i);
    }
  }
  if (N % minim == 0) {
    cout << N / minim + 4 << endl;
  } else {
    cout << N / minim + 5 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
long long x[30005];
int main() {
	while(1){
		int n,m; scanf("%d%d",&n,&m);
		if(n+m==0) return 0;
		for(int i=1;i<=n;i++){
			long long a; scanf("%lld",&a);
			x[i] = (x[i-1]+a)%m;
		}
		set<long long>s; s.insert(x[n]); ll r = 0;
		for(int i=n-1;i>=0;i--){
			set<long long>::iterator it = s.lower_bound(x[i]);
			if(it != s.begin()){
				it--;
				ll v = ((*it) - x[i]+m)%m;
				r = max(r,v);
			}
			else{
				it = s.end(); it--;
				ll v = ((*it) - x[i]+m)%m;
				r = max(r,v);
			}
			s.insert(x[i]);
		}
		cout << r << endl;
	}
}

Measured memory_bytes: 2616
import java.util.*;
import java.io.*;

class Main{
    public static void main(String args[])throws IOException{
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
          //input
          String[] input = br.readLine().split(" ");
          long N = Long.parseLong(input[0]);
          long A = Long.parseLong(input[1]);
          long B = Long.parseLong(input[2]);

          //for output
          long result = 0;

          //for algorithm
          long dis_A = A - 1;
          long dis_B = N - B;
          long sub = B - A;

          //algorithm
          if((sub % 2) == 0){
            result = sub / 2;
          }else if(sub < 2){
            result = Math.min(dis_A, dis_B) + 1;
          }else{
            if(dis_A == 0 || dis_B == 0){
              result = 0;
            }else{
              if(dis_A < dis_B){
                result = dis_A;
                A = A - dis_A;
                B = B - dis_A;
              }else{
                result = dis_B;
                A = A + dis_B;
                B = B + dis_B;
              }
            }

            if(A > B){
              sub = A - B;
            }else{
              sub = B - A;
            }
            result += sub/2 + 1;
          }
           
          System.out.println(result);

        }

    }
}



Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int wa[4000][3];
    ll ans = 0;
    wa[0][0] = 0;
    wa[0][1] = 0;
    wa[0][2] = 0;

    if (s[0] == 'R')
    {
        wa[0][0]++;
    }
    else if (s[0] == 'G')
    {
        wa[0][1]++;
    }
    else
    {
        wa[0][2]++;
    }
    
    for (int i = 1; i < n;i++){
        for (int j = 0; j < 3;j++){
            wa[i][j] = wa[i-1][j];
        }
        if(s[i] =='R'){
            wa[i][0]++;
        }
        else if(s[i] == 'G'){
            wa[i][1]++;
        }else{
            wa[i][2]++;
        }
    }
    /*
    for (int i = 0; i < n;i++){
        cout << wa[i][0] << endl;
    }
    */
    for (int i = n - 1; i >= 2; i--)
    {
        for (int j = n - 2; j >= 1; j--)
        {
            if(i <= j){
                continue;
            }
            if (s[i] != s[j]  && i > j)
            {
                if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R'))
                { //RG
                    if(j - (i - j) >= 0){
                        if (s[j - (i - j)] == 'B')
                        {
                            ans += wa[j - 1][2] - 1;
                        }
                        else
                        {
                            ans += wa[j - 1][2];
                        }
                    }
                    else
                    {
                            ans += wa[j - 1][2];
                    }
                    }
                    else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R'))
                    { //RB
                        if (j - (i - j) >= 0){
                            if (s[j - (i - j)] == 'G')
                            {
                                ans += wa[j - 1][1] - 1;
                            }
                            else
                            {
                                ans += wa[j - 1][1];
                            }
                        }
                        else
                        {
                            ans += wa[j - 1][1];
                        }
                    }
                    else
                    {
                        //GB
                        if (j - (i - j) >= 0){
                            if (s[j - (i - j)] == 'R')
                            {
                                ans += wa[j - 1][0] - 1;
                            }
                            else
                            {
                                ans += wa[j - 1][0];
                            }
                        }
                        else
                        {
                            ans += wa[j - 1][0];
                        }
                    }
                }
                
            }
        }
    
    cout << ans;
}

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

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

    if ((S[0] == 'a' || S[1] == 'a' || S[2] == 'a')
    && (S[0] == 'b' || S[1] == 'b' || S[2] == 'b')
    && (S[0] == 'c' || S[1] == 'c' || S[2] == 'c')) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import Counter, defaultdict
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


class RollingHash():
    """
    Original code is https://tjkendev.github.io/procon-library/python/string/rolling_hash.html
    """
    class RH():
        def __init__(self, s, base, mod):
            self.base = base
            self.mod = mod
            self.rev = pow(base, mod-2, mod)

            l = len(s)
            self.h = h = [0]*(l+1)
            tmp = 0
            for i in range(l):
                num = s[i]
                tmp = (tmp*base + num) % mod
                h[i+1] = tmp

            self.pw = pw = [1]*(len(s)+1)
            v = 1
            for i in range(l):
                pw[i+1] = v = v * base % mod

        def calc(self, l, r):
            return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod

    @staticmethod
    def gen(a, b, num):
        result = set()
        while 1:
            import random
            import math
            random.seed()
            while 1:
                v = random.randint(a, b)//2*2+1
                if v not in result:
                    break
            for x in range(3, int(math.sqrt(v))+1, 2):
                if v % x == 0:
                    break
            else:
                result.add(v)
                if len(result) == num:
                    break
        return result

    def __init__(self, s, rand=False, num=5):
        if rand:
            bases = RollingHash.gen(2, 10**3, num)
        else:
            assert num <= 10
            bases = [641, 103, 661, 293, 547, 311, 29, 457, 613, 599][:num]

        MOD = 10**9+7
        self.rhs = [self.RH(s, b, MOD) for b in bases]

    def calc(self, l, r):
        return tuple(rh.calc(l, r) for rh in self.rhs)


def slv(N, A, B):
    a = []
    for i in range(N):
        a.append(A[i]^A[i-1])
    b = []
    for i in range(N):
        b.append(B[i]^B[i-1])

    ah = RollingHash(a)
    bh = RollingHash(b)

    ans = []
    for k in range(N):
        if ah.calc(k, N) == bh.calc(0, N-k) and ah.calc(0, k) == bh.calc(N-k, N):
            ans.append('%d %d' % (k, A[k]^B[0]))


    return ans


def main():
    N = read_int()
    A = read_int_n()
    B = read_int_n()
    print(*slv(N, A, B), sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 120744
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;
typedef int64_t i64;

static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

typedef i32 radix_type;

#define RADIX_WIDTH 10
const uint32_t radix_type_max = 30;
const uint32_t radix_type_begin = 0;
const uint32_t radix_width = RADIX_WIDTH;
const uint32_t radix_mask = (1 << RADIX_WIDTH) - 1;
#undef RADIX_WIDTH

static inline uint32_t radix_get_bit (radix_type v, uint32_t shift) {
  return v >> shift & radix_mask;
}

void radix_sort (radix_type *a, uint32_t n) {
  radix_type * const array = (radix_type *) calloc (4 * n, sizeof (radix_type));
  radix_type **bucket = (radix_type **) calloc (1 << radix_width, sizeof (radix_type *));
  uint32_t *len = (uint32_t *) calloc (2 << radix_width, sizeof (uint32_t));
  uint32_t *max_len = len + (1 << radix_width);
  for (uint32_t shift = radix_type_begin; shift < radix_type_max; shift += radix_width) {
    radix_type *p = array;
    memset (len, 0, sizeof (uint32_t) << (radix_width + 1));
    for (uint32_t i = 0; i < n; ++i) {
      uint32_t bit = radix_get_bit (a[i], shift);
      if (len[bit] == max_len[bit]) {
        for (uint32_t j = 0; j < len[bit]; ++j) {
          p[j] = bucket[bit][j];
        }
        max_len[bit] = 2 * max_len[bit] + 1;
        bucket[bit] = p;
        p += max_len[bit];
      }
      bucket[bit][len[bit]++] = a[i];
    }
    for (uint32_t bit = 0, i = 0; bit < (1 << radix_width); ++bit) {
      for (uint32_t j = 0; j < len[bit]; ++j, ++i) {
        a[i] = bucket[bit][j];
      }
    }
  }
  free (array);
  free (bucket);
  free (len);
}

#define ALLOC(size,type) ((type*) calloc ((size), sizeof (type)))

int cmp (const void *a, const void *b) {
  i32 d = *(i32 *)a - *(i32 *)b;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n = read_int();
  i32 *a = ALLOC (3 * n, i32);
  i32 *b = a + n;
  i32 *c = b + n;
  for (i32 i = 0; i < 3 * n; ++i) {
    a[i] = read_int();
  }
  qsort (a, n, sizeof (i32), cmp);
  qsort (b, n, sizeof (i32), cmp);
  qsort (c, n, sizeof (i32), cmp);
  i64 *dp = ALLOC (n, i64);
  for (i32 i = 0, j = 0; i < n && j < n; ++i) {
    for (; j < n && c[j] <= b[i]; ++j);
    dp[i] = n - j;
  }
  for (i32 i = n - 2; i >= 0; --i) {
    dp[i] += dp[i + 1];
  }
  i64 ans = 0;
  for (i32 i = 0, j = 0; i < n && j < n; ++i) {
    for (; j < n && b[j] <= a[i]; ++j);
    ans += dp[j];
  }
  printf ("%" PRIi64 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 2548