akhauriyash/Code-Regression huggingface dataset:
n, m, x, y = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()

for i in range(x+1, y+1):
	if(i <= a[-1]):
		continue
	if(i > b[0]):
		continue
	print ("No War")
	exit()
print ("War")

Measured memory_bytes: 3064
def c_atcodeer_and_election_report(N, R):
    t, a = 1, 1  # 高橋, 青木の票数
    for x, y in R:
        # t<=nx ∧ a<=ny を満たす最小のnを求める
        n = max(t // x, a // y)
        if t > n * x or a > n * y:
            n += 1
        t = n * x
        a = n * y
    return t + a

N = int(input())
R = [[int(i) for i in input().split()] for j in range(N)]
print(c_atcodeer_and_election_report(N, R))

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

int k,s;
int cnt=0;

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

	cin>>k>>s;
	REP(i,k+1) {
		REP(j,k+1) {
			if(i+j>s) continue;
			if(s-(i+j)<=k) cnt++;
		}
	}
	cout<<cnt<<endl;

	return 0;
}


Measured memory_bytes: 256
/****************### With The name of ALLAH, most Gracious, most Compassionate ###****************/

/**============================================================================**\
|   Author      : Md Jubayer Hossen Jame
|   Study       : CSE, BRUR
|   Today       : 03 September, 2k20
|   Source      : AtCoder Online Judge
|   Problem link: https://atcoder.jp/contests/abc177/tasks/abc177_b
|   Algorithm   :
|
\**============================================================================**/

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

#define FI                    freopen("input.txt", "r", stdin)
#define FO                    freopen("output.txt", "w", stdout)
#define FasterIO              ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

typedef long long             ll;
typedef unsigned long long    ull;
typedef unsigned int          ui;

#define mem(x,y)              memset(x,y,sizeof(x));
#define pii                   pair<int,int>
#define mk                    make_pair
#define ff                    first
#define ss                    second
#define pb                    push_back
#define ppb                   pop_back
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
#define for0(i, n)            for (int i = 0; i < (int)(n); ++i)
#define endl                  '\n'

const double PI = acos(-1.0);

#define gcd(a,b)              __gcd(a,b)
#define lcm(a,b)              (a*(b/gcd(a,b)))

///Direction Array
// 4 Direction - DOWN, UP, RIGHT, LEFT
int dx4[]= {+1, -1, +0, +0};
int dy4[]= {+0, +0, +1, -1};
#define isValid(a, b, R, C)   (0 <= a && a < R) && (0 <= b && b < C)
int dx8[]= {+0, +0, +1, -1, -1, +1, -1, +1};
int dy8[]= {-1, +1, +0, +0, +1, +1, -1, -1};

///Knight Moves
int dr[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int dc[] = {-2, -2, -1, 1, 2, 2, 1, -1};
/**************************************************************************************************/

void test_case()
{
    string s, sub;
    cin >> s >> sub;

    int chang = INT_MAX;
    for(int i = 0, j, match, k; i < s.size(); ++i)
    {
        for(j = 0, k = i, match = 0; j < sub.size() and k < s.size() ; ++j, ++k)
        {
            if( s[k] != sub[j] ) match++;
        }
        if(j == sub.size())chang = min( chang, match);
    }
    cout << chang << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    //FI;
    //FO;
#endif // ONLINE_JUDGE
    //FasterIO

    int T = 1;
    //cin >> T;
    for(int tc = 1; tc <= T; ++tc)
    {
        //cout << "Case #" << tc << ":" << endl;
        test_case();
    }
    return 0;
}


Measured memory_bytes: 3600
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)
INF = 10**18
t = int(input())
for _ in range(t):
    n, a, b, c, d = map(int, input().split())
    memo = defaultdict(lambda: INF)

    def dfs(n, cost):

        if memo[n] <= cost:
            return 0

        memo[n] = cost
        if n == 0:
            return 0

        dfs(0, cost+n*d)

        r = n % 2
        dfs((n-r)//2, cost+a+r*d)
        if r != 0:
            dfs((n+(2-r))//2, cost+a+(2-r)*d)

        r = n % 3
        dfs((n-r)//3, cost+b+r*d)
        if r != 0:
            dfs((n+(3-r))//3, cost+b+(3-r)*d)

        r = n % 5
        dfs((n-r)//5, cost+c+r*d)
        if r != 0:
            dfs((n+(5-r))//5, cost+c+(5-r)*d)
            
    dfs(n, 0)
    print(memo[0])


Measured memory_bytes: 133588
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

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

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

    vector<int> x(n), y(n), h(n);
    rep(i, n){
        cin >> x[i] >> y[i] >> h[i];
    }

    int a = x[0];
    int b = y[0];
    int c = h[0];
    rep(i, n){
        if(h[i] > 0){
            a = x[i];
            b = y[i];
            c = h[i];
        }
    }

    rep(i, 101){
        rep(j, 101){
            bool ok = true;
            int ch = c + abs(i - a) + abs(j - b);

            for(int k = 0; k < n; k++){
                int nh = max(ch - abs(i - x[k]) - abs(j - y[k]), 0LL);

                if(nh != h[k]){
                    ok = false;
                    break;
                }
            }

            if(ok){
                cout << i << " " << j << " " << ch << endl;
                return 0;
            }
        }
    }

    return 0;
}


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

int main() {
    int N,M,C;
    cin>>N>>M>>C;
    vector<int> dataB(M);
    vector<vector<int>>data(N,vector<int>(M));
    for(int i=0;i<M;i++) {
        cin >> dataB.at(i);
}
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin >>data.at(i).at(j);
        }
    }
     int ans =0;
    for(int i=0;i<N;i++){
        int count =C;
        for(int j=0;j<M;j++){
            count +=data.at(i).at(j)*dataB.at(j);
        }
        if(count>0) ans++;
    }
    cout << ans <<endl;
}


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

using namespace std;

int N, K;
vector<int> h;
vector<int> dp_table;

void dp() {
	dp_table[0] = 0;
	dp_table[1] = abs(h[1] - h[0]);
	for (int i = 2; i < N; i++) {
		int min_cost = 9999999*100;
		for (int step = 1; (step <= K && i-step >= 0); step++) {
			int _tmp = dp_table[i - step] + abs(h[i-step] - h[i]);
			if (_tmp < min_cost) {
				min_cost = _tmp;
			}
		}
		dp_table[i] = min_cost;
	}
}

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

	for (int i = 0; i < N; i++) {
		int _;
		cin >> _;
		h.push_back(_);
		dp_table.push_back(-1);
	}

	dp();

	std::cout << dp_table[N-1] << endl;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    int k, t;
    cin >> k >> t;
    int mx = -1;
    rep(i, t) {
        int a;
        cin >> a;
        chmax(mx, a);
    }
    cout << max(0, mx + mx - 1 - k) << endl;

    return 0;
}

Measured memory_bytes: 256
while True:
    n , x = map(int,input().split(' '))
    if n + x == 0:
        break
    cnt = 0
    for a in range(1 , n - 1):
        for b in range(a + 1 , n):
            if a + b >= x:
                break
            for c in range(b + 1 , n + 1):
                if a + b + c == x:
                    cnt += 1
                    break
    print(cnt)


Measured memory_bytes: 5592
//		HYSO SERIOUS? WHY SO SERIOUS                            RIOUS? WHY SO SERIOUS? WHYSO SERIO
//		 ERIOUS? WHY SO SERIOUS ? WHY                          WHY SO SERIOUS? WHY SOSERIOUSWHYS
//		       OSERIOUS? WHY SO SERIOU         SERIOUS        ERIOUS? WHY SO SERIOUS? WHYS
//		          WHY SO SERIOUS? WHY SOSERIOUS? WHYSOSERIOUS? WHY SO SERIOUS?WHY SO SE
//		           ERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SOSERIO
//		           WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WH
//		            SERIOUS?WHYSO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHYSO SE
//		              ?WHYSOSERIOUS?WHY SO SERIOUS? WHY SO SERIOUS?WHYSO SERIOUS?
//		                           OSERIOUS? WHY SO SERIOUS?WHYSOSER
//		                                 HYSOSERIOUS?WHYSOSERI
//		                                     SOSERIOUS?W
//		                                         SER
//		                                          W


#include 	<ext/pb_ds/assoc_container.hpp> 
#include 	<ext/pb_ds/tree_policy.hpp> 
#include 	<iostream>
#include 	<queue>
#include 	<tuple>
#include 	<vector>
#include	<bits/stdc++.h>
#include	<algorithm>
#include 	<cmath>
#include 	<map>
#include 	<string>
#include 	<iomanip> 
#include 	<ctype.h>
#define 	ll  long long int
#define		read(a) long long int a; cin>>a;
#define 	readstr(s) string s; cin>>s;
#define 	readc(c) char c; cin>>c;
#define 	readarr(a,l) long long int a[l]={0}; for(ll i=0;i<l;i++) cin>>a[i];
#define 	loop(i,a,b) for(ll i=a;i<b;i++)
#define 	rloop(i,a,b) for(ll i=a;i>b;i--)
#define 	loopchar() for(char c='a';c<='z';c++)
#define 	printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define		printv(v) for (int i: v) cout << i << " "; cout << endl;
#define 	loopitr(vec) for(auto itr=vec.begin();itr!=vec.end();itr++)
#define 	ff first
#define 	ss second
#define 	readmtrx(i,j,a,b) ll arr[a][b]={0};for(ll i=0;i<a;i++)for(ll j=0;j<b;j++) cin>>arr[i][j];
#define 	all(a) a.begin(), a.end()
#define 	yes cout <<"YES"<<endl;
#define 	no cout <<"NO"<<endl;
#define 	sc(x) cout << (#x) << " is " << (x) << endl;
#define 	fast ios_base::sync_with_stdio(false);cin.tie(0);
#define 	pb(p) push_back(p)
#define 	mp make_pair
#define 	fsort(vec) sort(vec.begin(),vec.end())
#define 	rsort(vec) sort(vec.begin(),vec.end(),compare)
#define 	Endl endl
#define 	ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define 	roundoff std::cout << std::setprecision(15)
#define 	inf 9223372036854775807
#define 	infn -9223372036854775807
#define 	pi 3.14159265358979323846
const 		int mod = 1e9+7; 
#define 	REVERSE(vec) reverse(vec.begin(),vec.end())
using 		namespace __gnu_pbds; 
using 		namespace std;

ll gcd (ll a, ll b) { return b ? gcd (b, a % b) : a; }
ll lcm (ll a, ll b) { return a / gcd(a, b) * b; }

//code start from here 

int main() {
	fast;
	read(a)
	set<string>st;
	loop(j,0,a){
		readstr(s)
		st.insert(s);		
	}
	cout<<st.size()<<endl;
	return 0;
}

//ends here 

Measured memory_bytes: 19216
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let x: i64 = read();
    let a: i64 = read();
    let b: i64 = read();

    println!("{}", (x - a) % b);
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

typedef long long ll;

ll mini(ll a, ll b)
{
    if (a < b)
        return a;
    return b;
}

int main()
{
    ios_base::sync_with_stdio(0);
    ll a, b, c, d;
    ll x;
    cin >> a >> b >> c >> d >> x;
    a *= 4;
    b *= 2;
    ll A = mini(a, mini(b, c));
    ll B = d;
    ll odp1 = 0;
    odp1 += x / 2 * B;
    if (x % 2 == 1)
        odp1 += A;
    ll odp2 = 0;
    odp2 = x * A;
    cout << mini(odp1, odp2);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int a[101][101];

int main(){
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];

    int c = 1;
    int cnt = 0;
    rep(y, h){
        if(y%2 == 0){
            for(int x=0; x<w; x++){
                a[y][x] = c;
                cnt++;
                if(cnt == v[c-1]){
                    cnt = 0;
                    c++;
                }
            }
        }        
        else {
            for(int x=w-1; x>=0; x--){
                a[y][x] = c;
                cnt++;
                if(cnt == v[c-1]){
                    cnt = 0;
                    c++;
                }
            }
        }
    }

    rep(i, h){
        rep(j, w) cout << a[i][j] << " ";
        cout << endl;
    }
}

Measured memory_bytes: 384
# 1 "l.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "l.cpp"
# 1 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 1
       
# 12 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp"
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/bits/stdc++.h" 1
 #include <bits/stdc++.h>
# 13 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/ext/pb_ds/assoc_container.hpp" 1
 #include <ext/pb_ds/assoc_container.hpp>
# 14 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2
# 1 "/home/tysm/dev/cpplib/bin/../stdlib/ext/pb_ds/tree_policy.hpp" 1
 #include <ext/pb_ds/tree_policy.hpp>
# 15 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp" 2







using namespace std;
using namespace __gnu_pbds;

using ii = pair<long long, long long>;
using vi = vector<long long>;
using vd = vector<long double>;
using vb = vector<bool>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvd = vector<vd>;
using vvb = vector<vb>;
using vvii = vector<vii>;
# 50 "/home/tysm/dev/cpplib/bin/../include/cpplib/stdinc.hpp"
inline long long mod(const long long n, const long long m = ((long long)1e9+7)){
    return (n%m + m)%m;
}

/**
 * Euclidean GCD.
 *
 * Time Complexity: O(log(min(a, b))).
 * Space Complexity: O(log(min(a, b))).
 */
long long gcd(const long long a, const long long b){
    if(a < 0 or b < 0)
        return gcd(abs(a), abs(b));
    if(a == 0)
        return b;
    return gcd(b%a, a);
}

/**
 * Euclidean derivated LCM.
 *
 * Time Complexity: O(log(min(a, b))).
 * Space Complexity: O(log(min(a, b))).
 */
long long lcm(const long long a, const long long b){
    // same as a*b/gcd(a, b) but avoiding overflow.
    return a/gcd(a, b)*b;
}
# 2 "l.cpp" 2

long long dp[2][(long long)3e3][(long long)3e3];
bool dp_aux[2][(long long)3e3][(long long)3e3];
vi arr;

long long solve(long long i, long long j, long long cur){
    if(j < i)
        return 0;
    if(dp_aux[cur][i][j])
        return dp[cur][i][j];
    dp_aux[cur][i][j] = true;
    if(cur == 0){
        return dp[cur][i][j] = max(
            arr[i] + solve(i+1, j, 1),
            arr[j] + solve(i, j-1, 1)
        );
    }
    else{
        return dp[cur][i][j] = min(
            - arr[i] + solve(i+1, j, 0),
            - arr[j] + solve(i, j-1, 0)
        );
    }
}

int32_t main(){
    (ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL));
    long long n;
    cin >> n;
    arr.resize(n);
    for(long long &i:arr)
        cin >> i;
    cout << solve(0, n-1, 0) << "\n";
    return 0;
}


Measured memory_bytes: 158208
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1e9+7;
using namespace std;

int main(){
    string s; cin >> s;
    int a=0, z=s.length()-1;
    for(; a < s.length(); ++a) if(s[a] == 'A') break;
    for(; z > 0; --z) if(s[z] == 'Z') break;
    cout << z-a+1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void){
    int n,sum=0,ave1,ave2,st1=0,st2=0;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;++i){
        scanf("%d",&a[i]);
    }
    for(int k=0;k<n;++k){
        sum += a[k];
    }
    ave1 = sum/n;
    ave2 = ave1 + 1;
    for(int j=0;j<n;++j){
        st1 += (a[j]-ave1)*(a[j]-ave1);
    }
    for(int l=0;l<n;++l){
        st2 += (a[l]-ave2)*(a[l]-ave2);
    }
    if(st1 < st2){
        printf("%d",st1);
    }else{
        printf("%d",st2);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<vector<UL>> E(N);
		rep(i, N - 1) {
			UL a, b; cin >> a >> b; a--; b--;
			E[a].push_back(b);
			E[b].push_back(a);
		}
		vector<UL> F(N); rep(i, N) F[i] = E[i].size();
		//cout << "F = ";
		//rep(i, N) cout << F[i] << " "; cout << endl;
		vector<UL> A(N);
		queue<UL> Q; rep(i, N) if (F[i] == 1) Q.push(i);
		while (Q.size()) {
			UL p = Q.front(); Q.pop();
			if (A[p]) continue;
			UL nx = 0;
			for (UL e : E[p]) if (!A[e]) nx = e;
			//cout << "B = " << p << ", A = " << nx << endl;
			A[nx] = 1;
			for (UL e : E[nx]) {
				if (e == p) continue;
				if (A[e]) continue;
				F[e]--;
				//cout << "F[" << e << "] = " << F[e] << endl;
				if (F[e] == 0) { cout << "First" << endl; return; }
				if (F[e] == 1) { Q.push(e); }
			}
		}
		cout << "Second" << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 6912
#include <iostream>
#include <string>
using namespace std;
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; }
const long long INF = 1LL<<60;

// 入力
string s, t;

// DPテーブル
int dp[3100][3100] = {0}; // 初期値も初期条件も 0

int main() {
    cin >> s >> t;

    // DPループ
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 0; j < t.size(); ++j) {
            if (s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }
// 復元
    string res = "";
    int i = (int)s.size(), j = (int)t.size();
    while (i > 0 && j > 0)
    {
        // (i-1, j) -> (i, j) と更新されていた場合
        if (dp[i][j] == dp[i-1][j]) {
            --i; // DP の遷移を遡る
        }

        // (i, j-1) -> (i, j) と更新されていた場合
        else if (dp[i][j] == dp[i][j-1]) {
            --j; // DP の遷移を遡る
        }

        // (i-1, j-1) -> (i, j) と更新されていた場合
        else {
            res = s[i-1] + res; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
            --i, --j; // DP の遷移を遡る
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 37120
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

n,m,v,p=LI()
a=LI()
b=sorted(a)[::-1]

def check(k):
    tot=m*v
    if k<=p-1:
        return True
    if b[p-1]>b[k]+m:
        return False
    tot-=m*p
    mx=b[k]+m
    for i in range(p-1,n):
        if i==k:
            continue
        tot-=min(max(0,mx-b[i]),m)

    if tot<=0:
        return True
    else:
        return False
        
l,r=0,n

while r-l>1:
    mid=(l+r)//2
    if check(mid):
        l=mid
    else:
        r=mid

ok=b[l]
ans=sum([1 if i>=ok else 0 for i in b])
print(ans)


Measured memory_bytes: 63084
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>

using namespace std;

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

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

const int Maxn = (int) 1e5 + 10;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int dp[Maxn];

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

    int n, m;
    cin >> n >> m;
    dp[0] = 1;
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        dp[x] = -1;
    }

    for (int i = 0; i < n; ++i) {
        if (dp[i + 1] == -1) dp[i + 1] = 0;
        else {
            dp[i + 1] = dp[i];
            if (i - 1 >= 0) (dp[i + 1] += dp[i - 1]) %= MOD;
        }
    }

    cout << dp[n] << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
ll gcd(ll a, ll b){
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}
int main(){
    int k, tmp; sc(k);
    int ans = 0;
    for (int i = 1; i <= k; i++){
        for (int j = 1; j <= k; j++){
            for (int l = 1; l <= k; l++){
                tmp = gcd(i, j);
                ans += gcd(tmp, l);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3760
#include<stdio.h>
int main(void)
{
	int n,a,b,A,B,i;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		A=0; B=0;
		for(i=0;i<n;i++){
			scanf("%d %d",&a,&b);
			if(a==b){
				A+=a; B+=b;
			}	
			else if(a>b) A+=a+b;
			else if(b>a) B+=a+b;
		}
		printf("%d %d\n",A,B);
	}
	return 0;
}	

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

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let ks = readn::<usize>(" ");
    let k = ks[0];
    let s = ks[1];

    let upper = std::cmp::min(k, s);
    let mut ans = 0;
    for x in 0..(upper+1) {
        for y in 0..(std::cmp::min(k, s - x)+1) {
            if x + y + k >= s {
                ans += 1;
            }
        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
int a[200005],n,b[200005];
int main(){
	n=read();
	for (int i=1;i<=n;++i) a[i]=read();
	int cur=1;bool flag=1;
	for (int i=n;i;--i){
		b[cur]=a[i];
		if (flag) cur=n-cur+1;
		else cur=n-cur+2;
		flag^=1;
	}
	for (int i=1;i<=n;++i) printf ("%d ",b[i]);
	return 0;
}


Measured memory_bytes: 3712
import sys
from itertools import permutations

input = sys.stdin.readline


def main():
    N, C = map(int, input().split())
    D = [None] * C
    for i in range(C):
        D[i] = tuple(map(int, input().split()))
    A = [None] * N
    for i in range(N):
        A[i] = tuple(map(int, input().split()))

    R = [[0] * C for _ in range(3)]
    for i in range(N):
        for j in range(N):
            R[(i + j + 2) % 3][A[i][j] - 1] += 1

    cost = [[0] * C for _ in range(3)]
    for r in range(3):
        for Y in range(C):
            tmp = 0
            for X, num in enumerate(R[r]):
                tmp += D[X][Y] * num
            cost[r][Y] = tmp

    ans = float("inf")
    for c0, c1, c2 in permutations(range(C), r=3):
        ans = min(ans, cost[0][c0] + cost[1][c1] + cost[2][c2])

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 11276
n = gets.to_i
a_and_bs = []
n.times do
  a_and_bs.push(gets.split.map(&:to_i))
end

a_and_bs.sort_by! { |a_and_b| a_and_b[1] }

dp = 0
a_and_bs.each do |a_and_b|
  dp += a_and_b[0]
  if dp > a_and_b[1]
    puts 'No'
    exit
  end
end

puts 'Yes'


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

Measured memory_bytes: 3116
def main():
    n, adj = getInputs()
    sequence = getTopologicalSort(n, adj)

    distance = [-1] * n
    longest = -1

    for v in sequence:
        if len(adj[v]) == 0:
            distance[v] = 0
        else:
            for dest in adj[v]:
                distance[v] = max(distance[v], 1 + distance[dest])
                longest = max(longest, distance[v])

    print(longest)

def getTopologicalSort(n, adj):
    state = [0] * n
    toVisit = list(range(n))

    topologicalSort = []
    order = []

    while len(toVisit) > 0:
        curr = toVisit.pop()

        if state[curr] == 0:
            order.append(curr)
            state[curr] = 1

            foundNewDest = False
            for dest in adj[curr]:
                if state[dest] == 0:
                    toVisit.append(dest)
                    foundNewDest = True

            if not foundNewDest:
                while True:
                    v = order[-1]

                    allProcessed = True
                    for dest in adj[v]:
                        if state[dest] == 0:
                            allProcessed = False
                            break

                    if allProcessed:
                        state[v] = 2
                        topologicalSort.append(order.pop())

                    if len(order) == 0 or not allProcessed:
                        break

    return topologicalSort

def getInputs():
    n, m = map(lambda x: int(x), input().split())

    adj = []
    for i in range(n):
        adj.append([])

    for i in range(m):
        a, b = map(lambda x: int(x), input().split())
        adj[a - 1].append(b - 1)

    return n, adj

main()


Measured memory_bytes: 97508
my ($k,$a,$b) = get.words>>.Int;
say do if $b - $a > 2 {
  if $k >= $a - 1 {
    $k -= $a - 1;
    my $med = ($k div 2) * ($b - $a);
    my $last = $k - ($k div 2) * 2;
    $a + $med + $last;
  } else {
    $k + 1;
  }
} else {
  $k + 1;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }

int main(){
    ll a,b;
    cin >> a >> b;
    a--;
    if(a < 0) a = 0;
    else if(a%4 == 1) a = 1;
    else if(a%4 == 2) a++;
    else if(a%4 == 3) a = 0;

    if(b%4 == 1) b = 1;
    else if(b%4 == 2) b++;
    else if(b%4 == 3) b = 0;
    
    cout << (b^a) << endl;

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL H, W; cin >> H >> W;
		rep(y, H)rep(x, W) {
			string S; cin >> S;
			if (S == "snuke") {
				cout << (char)('A' + x) << (y + 1) << endl;
				return;
			}
		}
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


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

using namespace std;
#define ll long long
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1e9 + 7;
typedef pair<int,int> P;


const int MAX = 10000;

int main (){
    vector<vector<char> > maze(51,vector<char>(51));
    vector<vector<int> > d(51,vector<int>(51));
    int dx[4] = {0,1,0,-1};
    int dy[4] = {1,0,-1,0};
    int ans = 0;
    int h,w;
    cin >> h >> w;
    REPS(i,h){
        REPS(j,w){
            cin >> maze.at(i).at(j);
            d.at(i).at(j) = MAX;
            if(maze.at(i).at(j) == '.') ans++;
        }
    }
    queue<P> que;
    que.push(P(1,1));
    d.at(1).at(1) = 0;

    while(que.size()){

        P p = que.front();
        que.pop();

        REP(i,4){
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if(nx > 0 && nx <= w && ny > 0 && ny <= h && maze.at(ny).at(nx) == '.' && d.at(ny).at(nx) == MAX){
                que.push(P(nx,ny));
                d.at(ny).at(nx) = d.at(p.second).at(p.first) + 1;
            }




        }


    }
  	if(d.at(h).at(w) == MAX) cout << -1 << endl;
  else{
    ans = ans - d.at(h).at(w) -1;
    cout << ans << endl;
  }


    return 0;
}

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

const int MAXN = 100010;

long long max3(long long _n1, long long _n2, long long _n3) {
	return max(_n1, max(_n2, _n3));
}

int n;
long long K;
long long a[MAXN];
int main() {
	cin>>n>>K;
	for (int i=0; i<n; i++)
		cin>>a[i];

	//dp[bit][0] : free choose 0/1 on the next step.(loose at this bit)
	//dp[bit][1] : put a number matched k[bit].(full load)
	long long dp[42][2];
	// memset(dp, 0, sizeof(dp));
	for (int bit=41; bit>=0; bit--)
		dp[bit][1]=0, dp[bit][0] = (1ll<<63);
	for (int bit=40; bit>=0; bit--) {
		long long mask = (1ll<<bit);
		// if (mask > K)
		// 	continue;
		long long have1 = 0, have0 = 0;
		for (int i=0; i<n; i++) {
			if ( (a[i]&mask) != 0)
				have1++;
			else
				have0++;
		}
		// cout<<"bit["<<bit<<"] h0="<<have0<<" h1="<<have1<<endl;
		// cout<<"\tdp[max]="<<dp[bit][1]<<"  dp[free]="<<dp[bit][0]<<endl;
		if (K&mask) { //full load
			dp[bit][1] = dp[bit+1][1] + mask*have0; //choose 1
			dp[bit][0] = max3(dp[bit+1][0] + mask*have1, //choose 0
							  dp[bit+1][0] + mask*have0, //choose 1
							  dp[bit+1][1] + mask*have1); //choose 0
		}else { // maybe have limit
			dp[bit][1] = dp[bit+1][1] + mask*have1; //choose 0
			if (mask <= K)
			dp[bit][0] = max(dp[bit+1][0] + mask*have1, //choose 0
							 dp[bit+1][0]+mask*have0); //choose 1
		}
		// cout<<"\tdp[max]="<<dp[bit][1]<<"  dp[free]="<<dp[bit][0]<<endl;
	}
	cout<<max(dp[0][0], dp[0][1])<<endl;
	return 0;
}

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

int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> p(A), q(B), r(C);
    for (int i = 0; i < A; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < B; i++) {
        cin >> q[i];
    }
    for (int i = 0; i < C; i++) {
        cin >> r[i];
    }
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    sort(q.begin(), q.end());
    reverse(q.begin(), q.end());
    sort(r.begin(), r.end());
    reverse(r.begin(), r.end());

    priority_queue<int, vector<int>, greater<int>> quep;
    priority_queue<int, vector<int>, greater<int>> queq;
    for (int i = 0; i < X; i++) {
        quep.push(p[i]);
    }
    for (int i = 0; i < Y; i++) {
        queq.push(q[i]);
    }

    for (int i = 0; i < C; i++) {
        int red = quep.top();
        int green = queq.top();
        if (r[i] > red && r[i] < green) {
            quep.pop();
            quep.push(r[i]);
        } else if (r[i] < red && r[i] > green) {
            queq.pop();
            queq.push(r[i]);
        } else if (r[i] > red && r[i] > green) {
            if (r[i] - red > r[i] - green) {
                quep.pop();
                quep.push(r[i]);
            } else {
                queq.pop();
                queq.push(r[i]);
            }
        }
    }

    ll ans = 0;
    while (!quep.empty()) {
        ans += quep.top();
        quep.pop();
    }
    while (!queq.empty()) {
        ans += queq.top();
        queq.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 2552
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=5e2+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int dp[MAXn][MAXn],d[MAXn][MAXn];
int main(){
  IOS();
  int n,m,q;
  cin>>n>>m>>q;
  REP(i,m){
    int l,r;
    cin>>l>>r;
    d[l][r]++;
  }
  REP(i,501) dp[i][0] = d[i][0];
  for(int i=500;i>=0;i--)REP1(j,501)
    dp[i][j] = d[i][j]+dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1];
  while(q--){
    int l,r;
    cin>>l>>r;
    cout<<dp[l][r]<<endl;
  }
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
#define yn(f) cout<<(f?"yes":"no")<<endl
#define Yn(f) cout<<(f?"Yes":"No")<<endl
#define YN(f) cout<<(f?"YES":"NO")<<endl
#define COUT(x) cout<<(x)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  string s; cin>>s; int n=0; rep(i,3) n+=TF(s[i]=='1'); COUT(n);
}













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

int main() {
    int N;
    cin >> N;
    int x = N % 10;

    if(x == 2 ||x == 4 ||x == 5 ||x == 7 ||x == 9) cout << "hon" << endl;
    else if(x == 0 ||x == 1 ||x == 6 ||x == 8) cout << "pon" << endl;
    else if(x == 3) cout << "bon" << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, k;
    cin >> n >> k;
    deque<int> dq;
    rep(i,n){
        int v;
        cin >> v;
        dq.push_back(v);
    }

    int lim = k;
    int ans = 0;
    while(k){
        int ope = k, cnt = lim-k;
        priority_queue<int, vector<int>, greater<int>> pq;
        deque<int> dq_tmp = dq;
        int sum = 0;
        rep(i, ope){
            if (dq_tmp.empty()) break;
            int v = dq_tmp.front(); dq_tmp.pop_front();
            sum += v;
            pq.push(v);
            ans = max(ans, sum);
        }
        for(int i = 0; i < cnt; i++){
            int sum_tmp = sum;
            priority_queue<int, vector<int>, greater<int>> pq_tmp = pq;
            deque<int> dq_tmp_tmp = dq_tmp;
            for(int j = 0; j < i; j++){
                if (dq_tmp_tmp.empty()) break;
                int v = dq_tmp_tmp.back(); dq_tmp_tmp.pop_back();
                pq_tmp.push(v);
                sum_tmp += v;
                ans = max(ans, sum_tmp);
            }
            for(int j = i; j < cnt; j++){
                if (pq_tmp.empty() || pq_tmp.top() > 0) break;
                int v = pq_tmp.top(); pq_tmp.pop();
                sum_tmp += v * -1;
                ans = max(ans, sum_tmp);
            }
        }
        k--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll a, b, c ,d;
  cin >> a >> b >> c >> d;
  string ans="No";
  if(abs(a-c)<=d){
    ans="Yes";
  }else if(abs(a-b)<=d and abs(b-c)<=d){
    ans = "Yes";
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// #define debug(a) cout << "["; rep(i,a.size()) cout << a[i] << ", "; cout<<"]"<< endl;

const ll mod = 1000000007;

int main() {
    int l, r, d; cin >> l >> r >> d;
    cout << r / d - (l - 1) / d << endl;
    return 0;
}

Measured memory_bytes: 3596
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int[] a = new int[4];
		for(int i = 0 ; i < 4 ; i++) a[i] = Integer.parseInt(sc.next());
		sc.close();
		if((Math.abs(a[0] - a[1]) <= a[3] && Math.abs(a[1] - a[2]) <= a[3]) || Math.abs(a[0] - a[2]) <= a[3]) ou.println("Yes");
		else ou.println("No");
		ou.flush();
	}
}

Measured memory_bytes: 35440
fn main() {
    let mut line: String = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let digits = line.trim().chars().collect::<Vec<_>>();

    let ans = sum(&digits, 0);
    println!("{}", ans);
}

fn sum(d: &[char], p: u64) -> u64 {
    if d.len() == 0 {
        return p;
    }
    let mut total = 0;
    for i in 1..d.len()+1 {
        let pp = to_num(&d[0..i]);
        total += sum(&d[i..], pp + p);
    }
    total
}

fn to_num(d :&[char]) -> u64 {
    d.iter().rev().enumerate().fold(0, |acc, (i, n)| {
        acc + n.to_digit(10).unwrap() as u64 * 10u64.pow(i as u32)
    })
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map.Entry;

public class Main {

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

			String S[] = new String[3];

			int N = Integer.parseInt(br.readLine());

			for (int i = 0; i < 3; i++) {
				S[i] = br.readLine().trim();
			}

			int op = 0;

			for (int i = 0; i < N; i++) {
				HashMap<Character, int[]> cnt = new HashMap<Character, int[]>();

				for (int j = 0; j < 3; j++) {
					if (i < S[j].length()) {
						int[] e = cnt.get(S[j].charAt(i));
						if (e == null) {
							e = new int[1];
							e[0] = 1;
							cnt.put(S[j].charAt(i), e);
						} else {
							e[0]++;
						}
					}
				}

				int mx = 0;
				char mxc = 0;
				for (Entry<Character, int[]> e : cnt.entrySet()) {
					if (e.getValue()[0] > mx) {
						mx = e.getValue()[0];
						mxc = e.getKey();
					}
				}

				if (mx > 0) {
					for (int j = 0; j < 3; j++) {
						if (i >= S[j].length()) {
							op++;
						} else if (S[j].charAt(i) != mxc) {
							op++;
						}
					}
				}
			}
			
			System.out.println(op);
		} catch (Exception exp) {
			exp.printStackTrace();
		}
	}
}


Measured memory_bytes: 23124
n = int(input())
MOD = int(1e9 + 7)

a, b, c = 1, 1, 1

for i in range(n):
    a *= 10;
    b *= 9;
    c *= 8;
    a %= MOD;
    b %= MOD;
    c %= MOD;
    
print((a - 2 * b + c) % MOD);

Measured memory_bytes: 8900
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x,n,p;
    cin>>x>>n;
    vector<bool> v(501);
    fr(i,n){
        cin>>p;
        v[p+200]=true;
    }
    fr(i,150){
        if(!v[x+200-i]) return cout<<x-i<<'\n',0;
        if(!v[x+200+i]) return cout<<x+i<<'\n',0;
    }
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
  string ans = (S[2] == S[3] && S[4] == S[5]) ? YES : NO;
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int MAX=1e5+10;
const ll INF=1e18;
const double PI=acos(-1);


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

    int n,m,x;
    cin >> n >> m >> x;
    vector<int> b(n+1);
    rep(i,m) {
        int a;
        cin >> a;
        b[a]=1;
    }
    rep(i,n) b[i+1]+=b[i];
    
    cout << min(b[x],b[n]-b[x]) << endl;

    return 0;   
}

Measured memory_bytes: 3656
N, X = map(int, input().split())
a = list(map(int, input().split()))
ans = 0

if X == min(a):
  print(1)
elif X == sum(a):
  print(len(a))
else:
  while X > 0 and N > 0:
    X -= min(a)
    N -= 1
    a.remove(min(a))
    ans += 1
  print(ans - 1)

Measured memory_bytes: 3064