akhauriyash/Code-Regression huggingface dataset:
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define INF 999999999999999997;
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.
	LL N, H, ans = 0;
	cin >> N >> H;
	vector<pair<LL, LL> > ab;
	vector<pair<LL, LL> >c;
	vector<LL> b_only;
	LL b_sum = 0;
	LL a_max = 0;
	FOR(i, 0, N) {
		LL a, b;
		cin >> a >> b;
		b_sum += b;
		a_max = max(a_max, a);
		ab.push_back(MP(a, b));
		b_only.push_back(b);


	}
	sort(b_only.begin(), b_only.end(),greater<LL>());
	FOR(i, 0, b_only.size()) {
		if (b_only[i] > a_max) {
			H -= b_only[i];
			ans++;
			if (H <= 0) {
				break;
			}
		}
		else {
			break;
		}
	}
	if (H > 0) {
		//cout << "nowH = " << H << endl;
		ans += ceil((double)H / a_max);
	}


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

Measured memory_bytes: 3696
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <list>
#include <bitset>
#include <iostream> 
#include <set>
#include <map>
#include <string>
#include <sstream>
#include <climits>
#include <cmath>
#include <stack>
#include <queue>
#include <cfloat>
#include <initializer_list>
#include <iomanip>
#include <functional>
#include <unordered_map>
#include <regex>

using namespace std;

int main(int argc, char *argv[])
{  
  string a, b, c;
  cin >> a >> b >> c;
  cout << string{'A', b[0], 'C'} << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        if(i % 3 == 0){
            cout << " " << i;
        }
        else {
            int temp = i;
            while(temp != 0){
                if (temp % 10 == 3){
                    cout << " " << i;
                    break;
                }
                temp /= 10;
            }
            
        }
        
    }
    cout << endl;
}



Measured memory_bytes: 3116
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define dump(x)  cout << #x << " = " << (x) << endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
ll n;
string p;
string s;
map<string,char> stateO, stateX;
string seed;
bool step(){
    string pre;
    p = "";
    rp(i,n){
        if(i == 0)
            pre = seed;
        else{
            pre = string(1,pre[1]) + string(1,p[p.length()-1]);
            // dump(pre);
        }

        if(s[i] == 'o')
            p += string(1,stateO[pre]);
        else p += string(1,stateX[pre]);
    }
    if(p.substr(n-2,2) == seed)
        return true;
    else return false;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;

    stateO["SS"] = 'S';
    stateO["WS"] = 'W';
    stateO["SW"] = 'W';
    stateO["WW"] = 'S';

    stateX["SW"] = 'S';
    stateX["WW"] = 'W';
    stateX["SS"] = 'W';
    stateX["WS"] = 'S';

    cin >> n;
    cin >> s;
    seed = "SS";
    if(step()) {
        cout << seed[1] <<p.substr(0,n-1);return 0;
    }
    seed = "SW";
    if(step()) {
        cout << seed[1] <<p.substr(0,n-1);return 0;
    }
    seed = "WS";
    if(step()) {
        cout << seed[1] <<p.substr(0,n-1);return 0;
    }
    seed = "WW";
    if(step()) {
        cout << seed[1] <<p.substr(0,n-1);return 0;
    }
    cout << "-1\n";
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main(void){
    while(1){
        int H, W;
        cin >>H >>W;
        if(H == 0 && W == 0) break;
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cout<<"#";
            }
            cout<<endl;
        }cout<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3112
#include <stdio.h>
#include <stdlib.h>

#define abs(a) ((a) < 0 ? - (a) : (a))

int main() {

	int N, Z, W;
	int a[2345];

	scanf("%d %d %d", &N, &Z, &W);

	for (int i = 0; i < N; i++) scanf("%d", &a[i]);

	if (N == 1) printf("%d\n", abs(a[0] - W));
	else if (abs(a[N - 2] - a[N - 1]) > abs(a[N - 1] - W)) printf("%d\n", abs(a[N - 2] - a[N - 1]));
	else printf("%d\n", abs(a[N - 1] - W));

	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define OUT(x) cout<<(x)<<"\n"
#define SZ(x) (int)(x).size()
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)


int main() {
    FASTIO;
    int n;
    cin >> n;

    ll sum = 0;
    vector<ll> s(n);
    rep(i, n) {
        cin >> s[i];
        sum += s[i];
    }

    if(sum % 10 != 0) {
        OUT(sum);
        return 0;
    }

    sort(ALL(s));
    rep(i, n) {
        sum -= s[i];
        if(sum % 10 != 0) {
            OUT(sum);
            return 0;
        }
        sum += s[i];
    }

    OUT(0);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
#include<regex>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

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



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<map>
#include<tuple>
using namespace std;
#define INF 1100000000000
#define MAX 1100000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

int dp[110000];
vector<int> V[110000];


int f(int x){
    if(dp[x]>0) return dp[x];
    int ans=0;
    for(int i=0;i<(int)V[x].size();i++){
        int next=V[x][i];
        //cout<<next<<endl;
        ans=max(ans,f(next)+1);
    }
    dp[x]=ans;
    //cout<<x<<" "<<dp[x]<<endl;

    return dp[x];
}

int main(){
    int N,M;
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int x,y;
        cin>>x>>y;
        V[x].push_back(y);
    }
    //f(1);
    //return 0;
    int ans=0;
    for(int i=1;i<=N;i++){
        ans=max(ans,f(i));
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int a = 0;
		int min = 0, max = 0;
		long sum = 0;

		for(int i = 0; i < n; i++) {
			a = sc.nextInt();
			if(i == 0) {
				min = a;
				max = a;
			}

			min = Math.min(min, a);
			max = Math.max(max, a);
			sum += a;
		}
		System.out.println(min + " " + max + " " + sum);

	}

}


Measured memory_bytes: 42568
#include	<iostream>
#include	<string>
#include	<algorithm>

using namespace std;

int main()
{
	string		str;
	int			ComCnt;

	cin >> str;
	cin >> ComCnt;

	string		Command;
	int			a, b;
	string		PreStr;
	string		SubStr;
	string		PostStr;

	for (int i = 0; i < ComCnt; i++)
	{
		cin >> Command;
		if (Command == "print")
		{
			cin >> a >> b;
			cout << str.substr(a, b - a + 1) << endl;
		}
		else if (Command == "reverse")
		{
			cin >> a >> b;
			PreStr = str.substr(0, a);
			SubStr = str.substr(a, b - a + 1);
			reverse(begin(SubStr), end(SubStr));
			PostStr = str.substr(b + 1);
			str = PreStr + SubStr + PostStr;
		}
		else if (Command == "replace")
		{
			cin >> a >> b >> SubStr;
			PreStr = str.substr(0, a);
			PostStr = str.substr(b + 1);
			str = PreStr + SubStr + PostStr;
		}
	}

	return 0;
}

Measured memory_bytes: 3192
n = int(input())
INF = float('inf')
L = [1]
for x in (6, 9):
    i = 1
    while x ** (i + 1) < 10 ** 6:
        L.append(x ** i)
        i += 1
L.sort(reverse=True)
dp = [INF] * (n + 1)
dp[0] = 0
for m in L:
    for i in range(n+1):
        if dp[i] != INF:
            if i + m <= n:
                dp[i+m] = min(dp[i] + 1, dp[i+m])
print(dp[-1])


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

using namespace std;

int n, m, mod = 1e9 + 7;
int mat[1000][1000];
bool v[1000][1000] = {};

bool check(int i, int j) {
    if (i == n || j == m)
        return 0;
    return mat[i][j] != -1;
}

int Mod(int x) {
    if (x >= mod)
        x -= mod;
    return x;
}

int solve(int i, int j) {
    if (i == n - 1 && j == m - 1)
        return 1;

    int r = 0;
    if (v[i][j])
        r = mat[i][j];
    else {
        if (check(i + 1, j))
            r = Mod(r + solve(i + 1, j));
        if (check(i, j + 1))
            r = Mod(r + solve(i, j + 1));
    }
    r = Mod(r);
    mat[i][j] = r;
    v[i][j] = 1;
    return r;
}

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

    cin >> n >> m;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            char c;
            cin >> c;
            c == '#' ? mat[i][j] = -1 : mat[i][j] = 0;
        }
    cout << solve(0, 0) << "\n";
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n, c;
    cin >> n >> c;
    vector<VI> dis(c, VI(c)), col(3, VI(c, 0));
    FOR(i, 0, c)cin >> dis[i];
    FOR(i, 0, n)FOR(j, 0, n) {
        int in;
        cin >> in;
        col[(i + j + 2) % 3][--in]++;
    }

    int ans = INF;
    FOR(A, 0, c)FOR(B, 0, c)FOR(C, 0, c) {
        if (A == B || B == C || C == A)continue;
        VI s = { A,B,C };
        int sum = 0;
        FOR(i, 0, 3) {
            int M_sum = 0;
            FOR(k, 0, c)M_sum += dis[k][s[i]] * col[i][k];
            sum += M_sum;
        }
        chmin(ans, sum);
    }
    
    cout << ans << "\n";

}

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

int main(){

 string S;
 cin >> S;
 
 string output ="";

 for(int i = 0; i < S.size(); i++){
   if(S.at(i) == '0'){
     output += '0';
   }
   else if(S.at(i) == '1'){
     output += '1';
   }
   else if(S.at(i) == 'B'){
     if(output == ""){
       continue;
     }
     else{
       output.pop_back();
       
     }
   }
 }
 cout << output << endl;
}

Measured memory_bytes: 256
s = input()
ans = ['KIHBR','KIHBRA','KIHBAR','KIHBARA',
       'KIHABR','KIHABRA','KIHABAR','KIHABARA',
       'AKIHBR','AKIHBRA','AKIHBAR','AKIHBARA',
       'AKIHABR','AKIHABRA','AKIHABAR','AKIHABARA']
for i in ans:
    if i == s:
        print('YES')
        exit()

print('NO')

Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string s; cin >> s;
	ll K; cin >> K;
	ll ans = 0;
	ll cnt = 1;
	rep(i, 0, s.size()) {
		if (i == s.size() - 1)ans += cnt / 2;
		else if (s[i] == s[i+1]) {
			cnt++;
		}
		else {
			ans += cnt / 2;
			cnt = 1;
		}
	}
	if (cnt == s.size()) {
		ans = (cnt * K) / 2;
	}
	else {
		ans *= K;
		if (s[0] == s[s.size() - 1]) {
			cnt = 0;
			rep(i, 0, s.size()) {
				if (s[i] == s[0])++cnt;
				else break;
			}
			ll x = 0;
			rREP(i, 0, s.size()) {
				if (s[s.size() - 1] == s[i])++x;
				else break;
			}
			if (cnt / 2 + x / 2 < (cnt + x) / 2) {
				ans += K - 1;
			}
		}
	}
	cout << ans << "\n";


	return 0;
}


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

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

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

    int N;
    cin >> N;

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

    int ans = sum;
    int t = 0;
    for (int i=0; i<N; ++i) {
        t += W[i];
        ans = min(ans, abs((sum-t)-t));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a; int b;
  int ab;
  int i;
  while((scanf("%d %d",&a,&b))!=EOF){
    ab=a+b;

    for(i=1;;i++){
      ab/=10;
      if(ab==0) break;
    }
    printf("%d\n",i);
  }
  return 0;
}



Measured memory_bytes: 2048
import collections
n = int(input())
s = [input() for _ in range(n)]

chrs = [collections.Counter(s_) for s_ in s]

result = ''

for al in 'abcdefghijklmnopqrstuvwxyz':
    if all([al in chrs_ for chrs_ in chrs]):
        result += min([chrs_[al] for chrs_ in chrs])*al
print(result)

Measured memory_bytes: 3436
#include <iostream>
#include <string>
#include <string.h>
using namespace std;

int n, m, p, a = 0, t = 0;
int w[100001];
bool f[100001];
string s;

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

    memset(f, 0, sizeof(f));
    memset(w, 0, sizeof(w));

    for (int i = 0; i < m; i++) {
        cin >> p >> s;
        
        if (!f[p]) {
            if (s == "AC") {
                a++;
                f[p] = 1;
                t += w[p];
            }
            else if (s == "WA")
                w[p]++;
        }
    }

    cout << a << " " << t << endl;

    return 0;
}


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



void solve(){
    
    int n; cin >> n;
    int a[n];
    for(int& u : a){ cin >> u; }
    long long ans = 0;
    int maxHeight = -1;
    for(int i = 0; i < n; i++){
        maxHeight = max(maxHeight, a[i]);
        ans += maxHeight - a[i];
    }
    cout << ans << '\n';
    
}


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

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

    int t = 1;
    // cin >> t;


    for(int i = 1; i <= t; i++){
        // cout << "Case #" << i << ": ";

        solve();

    }
    return 0;
}

Measured memory_bytes: 4372
#include <cctype>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	string w, t;
	cin >> w;
	for(auto &c : w) c = tolower(c);

	int count = 0;
	while(cin >> t && t != "END_OF_TEXT") {
		string t0;
		for(auto &c : t) 
			if(isalpha(c))
				t0.push_back(tolower(c));
		count += (w == t0);
	}
	cout << count << endl;

	return 0;
}



Measured memory_bytes: 3184
#include<iostream>
#include<map>
using namespace std;
map<int,int> f;
int n;
int a[200005];
long long tot;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        f[i-a[i]]++;
    }
    for(int i=1;i<=n;i++)
    {
        tot+=f[i+a[i]];
    }
    cout<<tot;
    return 0;
}

Measured memory_bytes: 20856
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n;
vi a;

int main()
{
    cin >> n;
    a.resize(n);
    rep(i, n) cin >> a[i];

    int alice = 0;
    int bob = 0;

    sort(all(a), greater<int>());

    rep(i, n){
        if(i % 2 == 0) alice += a[i];
        else bob += a[i];
    }
    cout << alice - bob << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = sorted(list(int(input()) for _ in range(n)))
    B = deque([])
    for i in range(n // 2):
        if i % 2 == 0:
            B.appendleft(A[i])
            B.append(A[-(i + 1)])
        else:
            B.append(A[i])
            B.appendleft(A[-(i + 1)])

    if n % 2 != 0:
        if abs(B[0] - A[n // 2]) < abs(B[-1] - A[n // 2]):
            B.append(A[n // 2])
        else:
            B.appendleft(A[n // 2])

    res = 0
    for i in range(1, n):
        res += abs(B[i] - B[i - 1])

    print(res)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 55384
/**
 * author: moririn_cocoa       
**/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

int main(void) {
  
  int A;
  int B;
  int C;
  
  cin >> A;
  cin >> B;
  cin >> C;
  
  if ( A == B && B != C ) {
    
    cout << "Yes" << endl;
  }
  
  else if ( A == C && B != C ) {
    
    cout << "Yes" << endl;
  }
  
  else if ( B == C && C != A ) {
    
    cout << "Yes" << endl;
  }
  
  else {
    
    cout << "No" << endl;
  }

return 0;
}

Measured memory_bytes: 3636
import numpy as np
c = np.zeros((10, 10))
n = int(input())
for i in range(1, n+1):
  s = str(i)
  c[int(s[0]), int(s[-1])] += 1
ans = 0
for i in range(10):
  for j in range(10):
    ans += c[i, j] * c[j, i]
print(int(ans))

Measured memory_bytes: 12468
N,A,B,C = map(int, input().split())
L = []
for _ in range(N):
    L.append(int(input()))

lst = []

min_mp = 100000000

def check_mp(lst):

        global a,b,c
        global L

        len_A=0
        len_B=0
        len_C=0

        cnt_A=0
        cnt_B=0
        cnt_C=0

        for i in range(len(lst)):
                if lst[i] == "a":
                        cnt_A += 1
                        len_A += L[i]
                if lst[i] == "b":
                        cnt_B += 1
                        len_B += L[i]
                if lst[i] == "c":
                        cnt_C += 1
                        len_C += L[i]

        if cnt_A==0 or cnt_B==0 or cnt_C==0:
                return 10000000000




        difA = abs(len_A - A)
        difB = abs(len_B - B)
        difC = abs(len_C - C)

        diff = difA+difB+difC

        synth_mp = 10 * (cnt_A+cnt_B+cnt_C - 3)

        return diff + synth_mp


def nxt():
        global N
        global lst
        global min_mp

        if len(lst) == N:
                mp = check_mp(lst)

                if mp < min_mp:
                        min_mp = mp
                return

        lst.append("a")
        nxt()
        lst.pop(-1)

        lst.append("b")
        nxt()
        lst.pop(-1)

        lst.append("c")
        nxt()
        lst.pop(-1)

        lst.append("N")
        nxt()
        lst.pop(-1)

        return


nxt()

print(min_mp)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  ll x;
  cin >> x;
  ll ans = 2*(x/11);
  if (x%11 != 0) ans += (x%11<=6 ? 1 : 2);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

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




using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	cout << (a * 3 + b) / 2 << endl;

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);

  sort(vec.begin(), vec.end());

  int ans = 0;
  
  for (int i = 0; i < N - 1; i++) ans += vec.at(i);

  cout << ans + vec.at(N - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

int main(){
  int n,ans;
  bool a;

  while(1){
    scanf("%d",&n);
    if(n == 0) break;

    FOR(i,n+1,n*2+1){
      a = true;
      for (int j = 2; j*j <= i; j++) {
        if(i%j == 0) a = false;
      }
      if(a) ans++;
    }

    printf("%d\n",ans);
    ans = 0;
  }



  return 0;
}


Measured memory_bytes: 3168
#!/usr/bin/env python3

import math

h,w = list(map(int,input().split(" ")))

c = []

for i in range(h):
    l = list(input())
    c.append(l)

for i in range(h):
    for j in range(w):
        flg = 0
        if c[i][j] == "#":
            if j != 0:
                if c[i][j-1] == "#":
                    flg = 1
            if j != w-1:
                if c[i][j+1] == "#":
                    flg = 1
            if i != 0:
                if c[i-1][j] == "#":
                    flg = 1
            if i != h-1:
                if c[i+1][j] == "#":
                    flg = 1
            if flg == 0:
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int q;
    cin >> s >> q;
    deque<char> dq;
    int flip = 0;
    for (int i = 0; i < s.size(); i++) dq.push_back(s[i]);
    for (int i = 0; i < q; i++){
        int t;
        cin >> t;
        if (t == 1){
            flip ^= 1;
        }
        else{
            int f;
            char c;
            cin >> f >> c;
            if ((f==1) ^ flip) dq.push_front(c);
            else dq.push_back(c);
        }
    }
    if (flip){
        reverse(dq.begin(),dq.end());
    }
    for (int i = 0; i < dq.size(); i++){
        cout << dq[i];
    }
}


Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;

namespace Project
{
	class MainClass
	{
		public static int n;
		public static int[] b;
		public static void Main(string[] args)
		{
			n = int.Parse(Console.ReadLine());
			int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
			CountingSort(a);
			var sb = new System.Text.StringBuilder();
			for (int i = 0; i < n; i++)
			{
				sb.Append(b[i]);
				if (i != n - 1)
					sb.Append(" ");
			}
			Console.WriteLine(sb);
		}

		public static void CountingSort(int[] a, int k = 10000)
		{
			b = new int[n];
			int[] c = new int[k + 1];
			for (int j = 0; j < n; j++)
			{
				c[a[j]]++;
			}
			for (int i = 1; i < k + 1; i++)
			{
				c[i] += c[i - 1];
			}
			for (int j = n - 1; j >= 0; j--)
			{
				b[c[a[j]] - 1] = a[j];
				c[a[j]]--;
			}
		}
	}
}

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

int main()
{
    int n, m, wa = 0, ac = 0;
    cin >> n >> m;
    vector<bool> is_ac(n, false);
    vector<int> p_wa(n);
    rep(i, m) {
        int p;
        string r;
        cin >> p >> r;
        if (r == "AC") {
            is_ac[p-1] = true;
        }
        if (r == "WA" && is_ac[p-1] == false) {
            p_wa[p-1]++;
        }
    }
    rep(i, n) {
        if (is_ac[i] == true) {
            ac++;
            wa += p_wa[i];
        }
    }
    printf("%d %d\n", ac, wa);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
    #include <algorithm>
    #include <string>
    #include <cmath>
    #include <ctype.h>
    #include <map>
    #include <vector>
    #define REP(i,n) for(int i=0;i<(int)n;i++)
    #define REP1(j,n) for(int j=0;j<(int)n;j++)
    #define REPD(i,n) for(int i=n;i>=0;i--)
    #define REPD1(j,n) for(int j=n;j=>0;j--)
    #define REPS(i,n) for(int i=1;i<=(int)n;i++)
    #define REPS1(j,n) for(int j=1;j<=(int)n;j++)
    #define rep(i,a,n) for(int i=a;i<=(int)n;i++)
    #define SZ(x) ((int)(x).size())	//size() unsigned -> int
    #define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())
     
    using namespace std;
    typedef long long ll;
     
    int main(void) {
    	int n,m;
    	cin >> n>>m;
    	int k[31], a[31][31];
    	REP(i, n) {
    		cin >> k[i];
    		REP1(j, k[i]) {
    			cin >> a[i][j];
    		}
    	}
    	int t[35] = { 0 };
    	REP(i, n) {
    		REP1(j, k[i]) {
    			t[a[i][j]]++;
    		}
    	}
    	int c = 0;
    	for (int i = 0; i <= m;i++) {
    		if (t[i] == n) c++;
    	}
    	cout << c << endl;
    	return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	int N, M;
	cin >> N >> M;
	int sum = 1900 * M + 100 * (N - M);
	cout << sum * (1 << M) << "\n";

	return 0;
}

Measured memory_bytes: 256
n,i,j,v,c[10],r;
main(){
	for(;scanf("%d",&n),n;){
		memset(c,0,sizeof(c));
		for(i=0;i<n;i++){
			r=0;
			for(j=0;j<n;j++){
				scanf("%d",&v);
				c[j]+=v;
				r+=v;
				printf("%5d",v);
			}
			printf("%5d\n",r);
		}
		r=0;
		for(j=0;j<n;j++){
			r+=c[j];
			printf("%5d",c[j]);
		}
		printf("%5d\n",r);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t

string getcode(string s){
    string ret = "";
    
    ret = ret + s[0];
    
    for(int i = 1 ; i < s.size() ; i++ ){
        char c = s[i-1];
        if( c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' ){
            ret = ret + s[i];
        }
    }
    
    return ret;
}

void solve(){
    int n;
    cin >>n;
    string s[64];
    int max_len = 0;
    
    if(n==0)exit(0);
    
    for(int i = 0 ; i < n ; i++ ){
        string temp;
        cin >> temp;
        s[i] = getcode(temp);
        max_len = max(max_len,(int)s[i].size());
        //cout << s[i] << endl;
    }
    
    for(int len = 1 ; len <= 64 ; len++ ){
        map<string,bool> lut;
        bool flag = true;
        for(int i = 0 ; i <  n && flag ; i++ ){
            string temp;
            
            if( s[i].size() < len ){
                temp = s[i];
            }else{
                temp = s[i].substr(0,len);
            }
            
            if( lut.find(temp) != lut.end() ){
                flag = false;
            }else{
                lut[temp] = true;
            }
        }
        
        if( flag ){
            cout << len << endl;
            return;
        }
    }
    
    cout << -1 << endl;
}

int main(void){
    while(true)solve();
    return 0;
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define int long long
int MAXN = 1e6 + 1;
vector<int>spf;
int gcd(int a, int b){
	if(b == 0) return a;
	return gcd(b, a%b);
}
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  spf[i] = i;
    for (int i=4; i<MAXN; i+=2) spf[i] = 2;
    for (int i=3; i*i<MAXN; i++) {
        if (spf[i] == i) {
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
void test_case(){
	spf.resize(MAXN + 1);
	sieve();
	
	int n; cin>>n;
	vector<int>a(n), b(n);
	for(int i=0;i<n;i++) {
		cin>>a[i];
		b[i] = a[i];
	}
	
	bool ans = 1;
	set<int>st;
	for(int i=0;i<n;i++){
		set<int>new_set;
		while(a[i] != 1){
			int factor = spf[a[i]];
			a[i] = a[i] / factor;
			new_set.insert(factor);
		}
		
		for(int x : new_set){
			if(st.count(x)){
				ans = 0;
				break;
			}
			else{
				st.insert(x);
			}
		}
		if(!ans){
			break;
		}
	}
	if(ans){
		cout<<"pairwise coprime"<<endl;
		return ;
	}
	a.clear();
	a = b;
	int g = a[0];
	for(int i=1;i<n;i++){
		g = gcd(a[i], g);
		if(g == 1){
			cout<<"setwise coprime"<<endl;
			return ;
		}
	}
	cout<<"not coprime"<<endl;
}
		
 
signed main(){
	IOS;
	int t=1, i=1; 
	//cin>>t;
	while(t--){
		//cout<<"Case #"<<i<<": ";
		test_case();
		i++;
	}
}


Measured memory_bytes: 26584
#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++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

VVL G;

ll dfs(ll from, ll now){
    map<ll,ll> rec;
    for(auto e : G[now]){
        if(e == from) continue;
        rec[dfs(now, e) + 1]++;
    }
    ll mx = 0;
    for(auto r : rec){
        if(mx < r.first) mx = r.first + r.second - 1;
        else mx += r.second;
    }
    return mx;
}

int main(){
    ll N;
    cin >> N;
    G.resize(N+1);
    rep(i, 2, N+1){
        ll a;
        cin >> a;
        G[i].push_back(a);
        G[a].push_back(i);
    }
    cout << dfs(-1, 1) << endl;
    return 0;
}

Measured memory_bytes: 19712
<?php
$s = trim(fgets(STDIN));
$t = trim(fgets(STDIN));

for($i = 0; $i <= strlen($s) - strlen($t); $i++){
    $flag = true;
    for($j = 0; $j < strlen($t); $j++){
        if($s[$i+$j] == $t[$j] || $s[$i+$j] == "?"){
            //ok
        }else{
            $flag = false;
        }
    }
    if($flag){
        $str = "";
        for($j = 0; $j < strlen($s); $j++){
            if($j >= $i && $j < $i + strlen($t)){
                $str.= $t[$j-$i];
            }else{
                if($s[$j] == "?"){
                    $str.= "a";
                }else{
                    $str.= $s[$j];
                }
            }
        }
        $ret[] = $str;
    }
}
if(isset($ret)){
    sort($ret);
    echo $ret[0];
}else{
    echo "UNRESTORABLE";
}

Measured memory_bytes: 4856
n=int(input())
H=list(map(int,input().split()))

cnt=0
maxcnt=0
for i in range(n-1):
  if H[i]>=H[i+1]:
    cnt+=1
  else:
    if cnt>maxcnt:
      maxcnt=cnt
    cnt=0
  if cnt>maxcnt:
    maxcnt=cnt
print(maxcnt)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
#define int long long

int N;
vector<int> G[1010];
vector<int> X(1010);
static bool dp[1010][5050];

pair<int, int> rec(int n, int pre) {
  vector<pair<int, int>> e;
  for (auto x : G[n]) {
    if (x != pre) {
      e.push_back(rec(x, n));
    }
  }

  int sum = 0;
  memset(dp, false, sizeof(dp));
  dp[0][0] = true;

  for (int i = 0; i < e.size(); i++) {
    int l = e[i].first, r = e[i].second;
    sum += l + r;
    for (int j = 0; j <= X[n]; j++) {
      if (!dp[i][j]) continue;
      if (j + l <= X[n]) dp[i + 1][j + l] = true;
      if (j + r <= X[n]) dp[i + 1][j + r] = true;
    }
  }

  int M = 1e18;
  for (int i = X[n]; i >= 0; i--) {
    if (dp[e.size()][i]) {
      M = i;
      break;
    }
  }

  if (M == 1e18) {
    cout << "IMPOSSIBLE" << endl;
    exit(0);
  }

  return make_pair(X[n], sum - M);
}

signed main() {
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int p;
    cin >> p;
    p--;
    G[i + 1].push_back(p);
    G[p].push_back(i + 1);
  }
  for (int i = 0; i < N; i++) cin >> X[i];

  rec(0, -1);

  cout << "POSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 5376
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")
}
#[allow(dead_code)]
struct Main {
    n: usize,
    k: usize,
    f_graph: Vec<Vec<usize>>,
    labels: Vec<Option<usize>>,
    label_cnts: Vec<usize>,
    b_pairs: Vec<Option<(usize, usize)>>,
    visited: Vec<bool>,
}
#[allow(dead_code)]
impl Main {
    fn dfs(&mut self, i: usize, label: usize) {
        self.visited[i] = true;
        self.labels[i] = Some(label);
        self.label_cnts[label] += 1;
        for &new_i in self.f_graph[i].clone().iter() {
            if !self.visited[new_i] {
                self.dfs(new_i, label);
            }
        }
    }
    fn invoke(&mut self) {
        for i in 0..self.n {
            if !self.visited[i] {
                self.label_cnts.push(0);
                let label_i = self.label_cnts.len() - 1;
                self.dfs(i, label_i);
            }
        }
        let mut b_cnts: Vec<usize> = vec![0; self.n];
        for &b_pair in self.b_pairs.iter() {
            let a = b_pair.unwrap().0;
            let b = b_pair.unwrap().1;
            if self.labels[a] == self.labels[b] {
                b_cnts[a] += 1;
                b_cnts[b] += 1;
            }
        }
        for i in 0..self.n {
            let label = self.labels[i].unwrap();
            let res = self.label_cnts[label] - 1 - self.f_graph[i].len() - b_cnts[i];
            println!("{}", res);
        }
    }
}
fn main() {
    let n: usize = read();
    let m: usize = read();
    let k: usize = read();
    let mut f_graph: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..m {
        let a: usize = read::<usize>() - 1;
        let b: usize = read::<usize>() - 1;
        f_graph[a].push(b);
        f_graph[b].push(a);
    }
    let mut b_pairs: Vec<Option<(usize, usize)>> = vec![None; k];
    for i in 0..k {
        let a: usize = read::<usize>() - 1;
        let b: usize = read::<usize>() - 1;
        b_pairs[i] = Some((a, b));
    }
    Main {
        n: n,
        k: k,
        f_graph: f_graph,
        b_pairs: b_pairs,
        labels: vec![None; n],
        label_cnts: vec![],
        visited: vec![false; n],
    }.invoke();
}

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

int main(){
  int i,ki[1000001],all[1000001],n[200],a;
  for(i=0;;i++){
    n[i]=i*(i+1)*(i+2)/6;
    if(n[i]>1000000)break;
  }
  for(int j=0;j<=1000000;j++){
    ki[j]=j;
    all[j]=j;
  }
  for(int j=2 ; j<i ; j++){
    for(int k=n[j];k<=1000000;k++){
      all[k]=min(all[k],all[k-n[j]]+1);
      if(n[j]%2==1){
      ki [k]=min(ki [k],ki[k-n[j]]+1);
      }
    }
  }
  while(1){
    cin>>a;
    if(a==0)break;
    cout<<all[a]<<" "<<ki[a]<<endl;
  }

  return 0;
}

Measured memory_bytes: 10808
n,q = map(int,input().split())
s = list(input())
p = [tuple(map(str,input().split())) for i in range(q)]

#s[x]が左へ抜けるか O(q)
def judge_left(x):
    for i in range(q):
        if p[i][0] == s[x]:
            if p[i][1] == 'L':
                x -= 1
            else:
                x += 1
        if x == -1:
            return True
        if x == n:
            return False
    return False

#s[x]が右へ抜けるか O(q)
def judge_right(x):
    for i in range(q):
        if p[i][0] == s[x]:
            if p[i][1] == 'L':
                x -= 1
            else:
                x += 1
        if x == -1:
            return False
        if x == n:
            return True
    return False

#どこまで左で抜けるか
ok = -1
ng = n
while ng-ok > 1:
    mid = (ng+ok)//2
    if judge_left(mid):
        ok = mid
    else:
        ng = mid
left = ok+1

#どこまで右で抜けるか
ok = n
ng = -1
while ok-ng >1:
    mid = (ok+ng)//2
    if judge_right(mid):
        ok = mid
    else:
        ng = mid
right = n-ok

print(max(n-left-right,0))

Measured memory_bytes: 103496
/* ☻ ☻ ☻ ☻ ☻ ☻ ☻ ☻ ☻ ☻ ☻ ☻ ☻ */
/* ☻ Name : Souvik Mahato  ☻ */
/* ☻ Nick : WIZARDO        ☻ */
/* ☻ Institution : IIEST   ☻ */
/* ☻ ☻ ☻ ☻ ☻ ☻ ☻ ☻ ☻ ☻ ☻ ☻ ☻ */

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define in(v) (v).begin(),(v).end()
#define rin(v) (v).rbegin(),(v).rend()
#define inf 1e9+7



int solvius()
{
    int n,k;
    cin>>n>>k;
    vector<int> h(n),cost(n,inf);
    for(int &x : h)
        cin>>x;
    cost[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+k;j++)
            cost[j]=min(cost[j],cost[i]+abs(h[j]-h[i]));
    }
    cout<<cost[n-1];
    return 0;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);    
	ll t=1;
   // cin>>t;
	while(t--)
		solvius();
    return 0;
}

Measured memory_bytes: 3948
LI = lambda: list(map(int, input().split()))

N = int(input())
V = LI()
C = LI()


def main():
    ans = 0
    for v, c in zip(V, C):
        if v > c:
            ans += v - c
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
  int a,b;
  cin >> a>>b;
  int ans;
  if(a-1>=b)
    ans = 2*a-1;
  else if(a==b)
    ans = a+b;
  else
    ans = 2*b-1;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    int n,a[10000],min,max,sum;
    long long int sum_ll;
    min=1000000;
    max=(-1000000);
    
    sum_ll=0;
    scanf("%d",&n);
    for (int i=0;i<=n-1;i++){
        scanf("%d",&a[i]);
            if (min>a[i]){
                min=a[i];
            }
            if (max<a[i]){
                max=a[i];
            }
            sum_ll+=a[i];
    }
    printf("%d %d %lld\n",min,max,sum_ll);
    return 0;
}


Measured memory_bytes: 3240
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        if(n % 2 == 1)
        	System.out.println(n / 2 + 1);
        else
        	System.out.println(n / 2);
    }

}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    ll a,b,x; cin >> a >> b >> x;
    ll bb = b/x + 1;
    ll aa = (a==0?0:(a-1)/x + 1);
   
    cout <<  bb-aa << endl;

    return 0;
}

Measured memory_bytes: 3568
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int N, M;
    ArrayList<Integer>[] lists;

    private void solve() {
        N = nextInt();
        M = nextInt();
        lists = new ArrayList[N];
        for(int i = 0;i < N;i++) {
            lists[i] = new ArrayList<>();
        }
        for(int i = 0;i < M;i++) {
            int k = nextInt();
            for(int j = 0;j < k;j++) {
                int n = nextInt() - 1;
                lists[n].add(i);
            }
        }

        int[] P = new int[M];
        for(int i = 0;i < M;i++) {
            P[i] = nextInt();
        }

        int ans = 0;
        for(int i = 0;i < 1 << N;i++) {
            int[] cnt = new int[M];
            for(int j = 0;j < N;j++) {
                int k = (i >> j) & 1;
                if (k == 1) {
                    for(int sw : lists[j]) {
                        cnt[sw]++;
                    }
                }
            }

            boolean ok = true;
            for(int j = 0;j < M;j++) {
                if (cnt[j] % 2 != P[j]) {
                    ok = false;
                }
            }

            if (ok) {
                ans++;
            }
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23252
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int N, a[100005];

int main() {
	cin >> N;
	for_(i,0,N) cin >> a[i];
	
	int xor_sum = 0;
	for_(i,0,N) xor_sum ^= a[i];
	
	Vec< bool > use(N, false);
	
	int ans = 0;
	for_rev(b,30,0) {
		if (xor_sum >> b & 1) {
			int k = -1;
			for_(i,0,N) {
				if (use[i]) continue;
				if ((a[i] & ((1 << (b+1)) - 1)) == (1 << b)) {
					k = i;
					break;
				}
			}
			
			if (k == -1) {
				puts("-1");
				return 0;
			}
			
			xor_sum ^= a[k];
			a[k]--;
			xor_sum ^= a[k];
			use[k] = true;
			++ans;
		}
	}
		
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 640