akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(N: int, d: "List[int]"):
    sorted_d = sorted(d)
    abc_max = sorted_d[N // 2 - 1]
    arc_min = sorted_d[N // 2]
    print(arc_min - abc_max)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 15220
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
	using u64 = std::int_fast64_t;
public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
#pragma endregion

int coin_map[500][500];
vector<string> cmds;
int main() {
	cin >> H >> W;
	rep(i, H) {
		rep(j, W) {
			cin >> coin_map[i][j];
		}
	}
	for (int y = 0; y < H; y++) {
		if (y % 2 == 0) {
			for (int x = 0; x < W - 1; x++) {
				if (coin_map[y][x] % 2 == 1) {
					coin_map[y][x]--;
					coin_map[y][x + 1]++;
					cmds.push_back((to_string(y + 1) + " " + to_string(x + 1) + " " + to_string(y + 1) + " " + to_string(x + 2)));
				}
			}
			if (coin_map[y][W - 1] % 2 == 1) {
				if (y != H - 1) {
					coin_map[y][W - 1]--;
					coin_map[y + 1][W - 1]++;
					cmds.push_back((to_string(y + 1) + " " + to_string(W) + " " + to_string(y + 2) + " " + to_string(W)));
				}
			}
		}
		else {
			for (int x = W - 1; x > 0; x--) {
				if (coin_map[y][x] % 2 == 1) {
					coin_map[y][x]--;
					coin_map[y][x - 1]++;
					cmds.push_back((to_string(y + 1) + " " + to_string(x + 1) + " " + to_string(y + 1) + " " + to_string(x)));
				}
			}
			if (coin_map[y][0] % 2 == 1) {
				if (y != H - 1) {
					coin_map[y][0]--;
					coin_map[y + 1][0]++;
					cmds.push_back((to_string(y + 1) + " " + to_string(1) + " " + to_string(y + 2) + " " + to_string(1)));
				}
			}
		}
	}
	cout << cmds.size() << endl;
	rep(i, cmds.size()) {
		cout << cmds[i] << endl;
	}
}



Measured memory_bytes: 11892
dic = ["", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan",
       "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"]
while True:
  m, n = map(int, input().split())
  if m == 0:
    break
  x = m ** n
  ind = 0
  ans = ""
  while x:
    if x % 10000:
      ans = str(x % 10000) + dic[ind] + ans
    x //= 10000
    ind += 1
  print(ans)


Measured memory_bytes: 5596
import scala.io.StdIn._

object Main extends App {
  val a = readInt()
  val b = readInt()
  val c = readInt()
  val x = readInt()

  var count = 0
  for (i <- 0 to a; j <- 0 to b; k <- 0 to c) {
    if (i * 500 + j * 100 + k * 50 == x) count += 1
  }

  println(count)
}


Measured memory_bytes: 26876
N, W = map(int, input().split())
items = sorted([list(map(int, input().split())) for i in range(N)])

# dp1[i][j] := 商品0 ~ i が対象
dp = [[0] * (W + 1) for i in range(N + 1)]

# dpテーブルを埋める
for i in range(N):
    wi, vi = items[i]
    for j in range(W + 1):
        if j + wi <= W:
            dp[i + 1][j + wi] = max(dp[i + 1][j + wi], dp[i][j] + vi)
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])


ans = 0
for i, (wi, vi) in enumerate(items):
    for j in range(W):
        ans = max(ans, dp[i][j] + vi)

print(ans)


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

using namespace std;
map<int,int> frequency; 

bool divisibleSieve[(int)1e6+1];

int f() {
    memset(divisibleSieve, true, sizeof(divisibleSieve));
    auto last = frequency.rbegin();
    for(auto& x:frequency){
        if(!divisibleSieve[x.first]) continue;
        for(int i = 2*x.first; i <= last->first; i += x.first){
            divisibleSieve[i] = false;
        }
    }
    int ans = 0;
    for(auto& x:frequency){
        if(divisibleSieve[x.first] && x.second == 1){
            ans++;
        }
    }
    return ans;
}

int main(){
    int n; cin >> n;
    int aux;
    for(int i = 0; i < n; ++i){
        cin >> aux;
        frequency[aux]++;
    } 
    cout << f();
    return 0;
}

Measured memory_bytes: 13884
a=int(input())
s=input()
ans=s.count("R")*s.count("G")*s.count("B")
for i in range(a):
  for j in range(i+1,(a+i+1)//2):
    if s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
      ans-=1
print(ans)


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,m,n) for(int i=m;i<(n);i++)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> pii;

double ans;
int N,M,K;

void dfs(int t,int res){
	if(t==N){
		if(res<=K)ans+=1;
		else ans +=res-K;
	}
	else{
		FOR(j,1,M+1){
			dfs(t+1,res+j);
		}
	}
}

void solve(){
	ans = 0;
	cin>>N>>M>>K;
	if(N==0)exit(0);
	dfs(0,0);
	REP(_,N){
		ans/=M;
	}
	printf("%.10lf\n",ans);
}

signed main() {
	while (true) {
		solve();
	}
}


Measured memory_bytes: 3212
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val restaurants = (1..n).map {id-> readLine()!!.split(" ").let { Restaurant(id, it[0], it[1].toInt()) } }.sorted()
    restaurants.forEach { println(it.id)}
}

class Restaurant(val id:Int, val city:String, val score:Int):Comparable<Restaurant> {
    override fun compareTo(other: Restaurant): Int {
        if(city == other.city) {
            return score.compareTo(other.score) * -1
        }
        return city.compareTo(other.city)
    }
}


Measured memory_bytes: 40508
#include <algorithm>  //min, max, sort, unique, fill
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>  //pair, swap,
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<ll>;

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

static const ll kIntMax = numeric_limits<ll>::infinity();
static const double kFloatMax = numeric_limits<double>::infinity();

vector<ll> vi;

int main() {
  string s;
  cin >> s;
  ll y = 0;
  y = 700 +
      100 * count_if(s.begin(), s.end(), [](char ss) { return ss == 'o'; });
  cout << y << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<string> v;
string s;
int n,m;
int fa[100005];
int find(int x){
	if(x==fa[x]) return x;
	else return fa[x]=find(fa[x]);
} 
void uni(int x,int y){
	int f1=find(x),f2=find(y);
	if(f1!=f2) fa[f1]=f2;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		fa[i]=i;
	}
	for(int i=1,x,y;i<=m;i++){
		cin>>x>>y;
		uni(x,y);
	}
	int ans=0;
	for(int i=1;i<=n;i++) {
		if(fa[i]==i) ans++;
	}
	cout<<ans-1;
} 

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

int main(){
	int H,W;
	while(true){
		cin >> H >> W;
		if(H == 0 && W == 0)
			return 0;
		for(int i = 0; i < H ; i++){
			for(int i = 0; i < W ; i++){
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

ull l[51] = {1}, p[51] = {1};  // l-0 버거의 길이 1, 패티 수 1

ull solution(ull n, ull x) {
    if (n == 1) {
        int base[6] = {0, 0, 1, 2, 3, 3};
        return base[x];
    } else {
        ull mid = l[n] / 2 + 1;  // 길이는 항상 홀수이다
        if (x < mid) {
            return solution(n - 1, x - 1);
        } else if (x == mid) {
            return p[n - 1] + 1;
        } else if (x > mid) {
            if (x == l[n]) {
                return 2 * p[n - 1] + 1;
            } else {
                return p[n - 1] + 1 + solution(n - 1, x - 1 - l[n - 1] - 1);
            }
        }
    }
    return -1;
}

int main() {
    ull n, x;
    cin >> n >> x;
    
    for (int i = 1; i <= 50; i++) {
        l[i] = 3 + 2 * l[i - 1];
        p[i] = 1 + 2 * p[i - 1];
    }
    
    cout << solution(n, x) << '\n';
    
    return 0;
}


Measured memory_bytes: 256
/*If the frog is currently on Stone 
i,
jump to Stone 
i
+
1
 or Stone 
i
+
2
. Here, a cost of 
|
h
i
−
h
j
|
 is incurred, where 
j
 is the stone to land on. */
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
# define PI  3.14159265358979323846
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
int main() 
{
	
 	ll n;cin>>n;
 	ll a[n];
 	for (int i = 0; i < n; ++i)
 	{
 		cin>>a[i];
 	}
 	ll dp[n]={0};
 	dp[0]=0;
 	dp[1]=abs(a[1]-a[0]);
 	for (int i = 2; i < n; ++i)
 	{
 		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
 	}
 	cout<<dp[n-1];

 	
 	return 0;
 }

Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int N, K; cin >> N >> K;
    int res = 0;
  
    rep(i, 0, N) {
      int x; cin >> x;
      res += min(x, K-x)*2;
    }
  
    cout << res << endl;
}


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

#define rep(i,n) for(ll i=0;i<(n);i++)
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<ll>>;
template<typename T=ll,typename U=ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}

const ll INF = (ll)1e9;
ll dh[4]{0,1,0,-1};
ll dw[4]{1,0,-1,0};

int main(){
    ll H,W;
    cin >> H >> W;
    auto d = v<v<ll>>(H,v<ll>(W,INF));
    auto que = queue<p<>>();
    rep(i,H)
        rep(j,W){
    		char a;  	
            cin >>a;
            if(a=='#'){
                que.push(make_pair(i,j));
                d[i][j]=0;
            }
        }
    
    while(!que.empty()){
        auto u = que.front(); que.pop();
        int h = u.first;
        int w = u.second; 
        rep(i,4){
            int nh = h+dh[i];
            int nw = w+dw[i];
            if(0<=nh&&nh<H&&0<=nw&&nw<W&&d[nh][nw]==INF){
                d[nh][nw]=d[h][w]+1;
                que.push(make_pair(nh,nw)); 
            }
        }
    }
    
    ll ans =0;
    rep(i,H)
        rep(j,W) chmax(ans,d[i][j]);
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 24500
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  int N=s.length();
  int t=N;
  for (int i=0; i<N-1; i++) {
    if (s[i+1]!=s[i]) {
      t=min(t,max(i+1,N-i-1));
    }
  }
  printf("%d\n",t);
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)(n),(int)(n))
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
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;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[1000010];
  ll dp[1000010][2];
  
  scanf("%s",s);
  dp[0][0]=0;
  dp[0][1]=1;
  n = strlen(s);
  for(i=1;i<=n;i++){
    j = (ll)(s[i-1]-'0');
    dp[i][0]+=min(dp[i-1][0]+j,dp[i-1][1]+10-j);
    dp[i][1]+=min(dp[i-1][0]+j+1,dp[i-1][1]+9-j);
  }
  printf("%lld",dp[n][0]);
  return 0;
}



Measured memory_bytes: 16768
#include <bits/stdc++.h>
 
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
 
const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;
 
int main()
{
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if (s < t)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int n,m,dp[105][105];char s[105][105];
int main()
{
    scanf("%d%d",&n,&m);
    rep(i,1,n) scanf("%s",s[i]+1);
    dp[1][1] = (s[1][1] == '#');
    rep(i,1,n) rep(j,1,m)
    if(i != 1 || j != 1){
        dp[i][j] = inf;
        char cur = s[i][j];
        if(i > 1) {
            char prev = s[i-1][j];
            if(prev == cur) chmin(dp[i][j], dp[i-1][j]);
            else chmin(dp[i][j], dp[i-1][j] + (cur == '#'));
        }
        if(j > 1) {
            char prev = s[i][j-1];
            if(prev == cur) chmin(dp[i][j], dp[i][j-1]);
            else chmin(dp[i][j], dp[i][j-1] + (cur == '#'));
        }
    }
    printf("%d\n",dp[n][m]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s, t;
int main() {
	int n, i;
	cin>>n>>s>>t;
	for(i=0; i<n; i++) if(s.substr(i,n-i)==t.substr(0,n-i)) break;
	cout<<n+i;
}

Measured memory_bytes: 256
if __name__== '__main__':
  s = input()
  if s[0] == 'A' and s[1] == 'A' and s[2] == 'A':
        	print('No')
  elif s[0] == 'B' and s[1] == 'B' and s[2] == 'B':
      		print('No')
  else:
        	print('Yes')
      


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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define in insert
#define mp(a, b) make_pair(a, b)
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define INF INT_MAX
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
	string s, t;
	cin>>s>>t;
	if(t.size()<=s.size())
		cout<<"No"<<endl;
	else if(t.substr(0, s.size())==s)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	// cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VI A(N);
  rep(i,N) cin>>A[i];
  bitset<4004004> bs(1);
  rep(i,N) bs=bs|(bs<<A[i]);
  int sum=0;
  rep(i,N) sum+=A[i];
  rep(i,4004004){
    if(i>=(sum+1)/2 and bs[i]){
      cout<<i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
#define gg(u) for(int &i=cur[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=5e5+5,M=1e6+5,inf=0x3f3f3f3f;
inline int min(R int x,R int y){return x<y?x:y;}
struct eg{int v,nx,w;}e[M];int head[N],tot=1;
inline void add(R int u,R int v,R int w){
    e[++tot]={v,head[u],w},head[u]=tot;
    e[++tot]={u,head[v],0},head[v]=tot;
}
int dep[N],cur[N],S,T,n;
bool bfs(){
    memset(dep,-1,(T+1)<<2);
    memcpy(cur,head,(T+1)<<2);
    static int q[N];
    int h=1,t=0,u;q[++t]=S,dep[S]=0;
    while(h<=t){
        u=q[h++];
        go(u)if(e[i].w&&dep[v]<0)q[++t]=v,dep[v]=dep[u]+1;
    }
    return ~dep[T];
}
int dfs(int u,int lim){
    if(u==T||!lim)return lim;
    int fl=0,f;
    gg(u)if(dep[v]==dep[u]+1&&(f=dfs(v,min(lim,e[i].w)))){
        fl+=f,lim-=f,e[i].w-=f,e[i^1].w+=f;
        if(!lim)break;
    }
    if(!fl)dep[u]=-1;
    return fl;
}
inline int dinic(){R int res=0;while(bfs())res+=dfs(S,inf);return res;}
int p[N],q[N],blp[N],blq[N],s0[N],s1[N],sum,cnt;
int main(){
//  freopen("testdata.in","r",stdin);
    scanf("%d",&n);
    fp(i,1,n)scanf("%d",&p[i]),++p[i];
    fp(i,1,n)scanf("%d",&q[i]),++q[i];
    fp(i,1,n)if(!blp[i]){
        ++cnt;
        for(R int j=i;!blp[j];j=p[j])blp[j]=cnt;
    }
    fp(i,1,n)if(!blq[i]){
        ++cnt;
        for(R int j=i;!blq[j];j=q[j])blq[j]=cnt;
    }
    S=0,T=cnt+1;
    fp(i,1,n)sum+=p[i]!=q[i];
    fp(i,1,n){
        if(p[i]==q[i]){
            if(p[i]==i)continue;sum+=2;
            add(S,blp[i],1),add(blq[i],T,1),add(blp[i],blq[i],2);
        }else{
            if(p[i]==i)add(S,blq[i],1);
            else if(q[i]==i)add(blp[i],T,1);
            else add(blp[i],blq[i],1);
        }
    }
    printf("%d\n",sum-dinic());
    return 0;
}

Measured memory_bytes: 24832
#include <stdio.h>
#define change(x, y) {int t = x; x = y; y = t;}

int main(int argc, const char * argv[])
{

    int mou;
    int big[3];
    int i;
    
    for (i = 0; i < 10; i++) {
        scanf("%d", &mou);
        if (i == 0) big[i] = mou;
        else if (i == 1) big[i] = mou;
        else if (i == 2){
            big[i] = mou;
            if (big[0] < big[1]) change(big[0], big[1]);
            if (big[1] < big[2]) change(big[1], big[2]);
            if (big[0] < big[1]) change(big[0], big[1]);
        }
        else{
            if (big[0] < mou){
                big[2] = big[1];
                big[1] = big[0];
                big[0] = mou;
            }
            else if (big[1] < mou){
                big[2] = big[1];
                big[1] = mou;
            }
            else if (big[2] < mou) big[2] = mou;
        }
    }
    for (i = 0; i < 3; i++) {
        printf("%d\n", big[i]);
    }
    return 0;
}

Measured memory_bytes: 600
// A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;
int main()
{
    double t, x;

    cin >> t >> x;

    cout << t / x << endl;
    return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー


Measured memory_bytes: 3740
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

#ifdef LOCAL  //デバッグ出力
#define dout cout
#define debug() if (true)
#else
#define dout \
  if (false) cout
#define debug() if (false)
#endif

using namespace std;
int main() {
  string a;
  cin >> a;
  if (a == "SUN") {
    cout << 7;
  } else if (a == "MON") {
    cout << 6;
  } else if (a == "TUE") {
    cout << 5;
  } else if (a == "WED") {
    cout << 4;
  } else if (a == "THU") {
    cout << 3;
  } else if (a == "FRI") {
    cout << 2;
  } else if (a == "SAT") {
    cout << 1;
  }

  return 0;
}

Measured memory_bytes: 256
//encoding:utf-8
#include<iostream> //c++
#include<time.h> //時間にかんして
#include<stack> //スタックに関して　最新のデータから捨てる
#include<queue> //キューに関して　最古のデータから捨てる
#include<math.h>
#include<vector>
#include<algorithm> //sort とかにいる
#include<string>
#include <unordered_set>//c++11に必要

#define ll long long
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<int>can(M);
  for(int i=0;i<M;i++){
    cin>>can[i];
  }
  sort(can.rbegin(),can.rend());
  // vector<int> sticks{0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

  vector<int> sticks{0,2,5,5,4,5,6,3,7,6};


  vector<int>dp(N+1);
  for(int i=1;i<N+1;i++){
    dp[i]=-1;
  }
  dp[0]=0;
  for(int i=1;i<N+1;i++){
    for (auto x:can){
      if(i>=sticks[x]){
        dp[i] = max(dp[i],dp[i-sticks[x]]+1);
      }
    }
  }


  // 一回何桁まで行けるかをｄｐでといた後に復元する
  // 最大桁までいけたパターンから後ろ向きに調べて行く
  int remain = N;
  while(remain>0){
    for(auto x:can){
      if(dp[remain-sticks[x]]==dp[remain]-1){
        if(dp[remain-sticks[x]]>0 || remain-sticks[x]==0){
          remain -= sticks[x];
          cout<<x;
          break;
        }
      }
    }
  }
  // while (remain > 0) {
  //   // cout<<remain<<endl;
  //     for (auto x:can) {
  //         if (dp[remain - sticks[x]] == dp[remain] - 1)
  //             if (dp[remain - sticks[x]] > 0 || remain - sticks[x] == 0) {
  //                 remain -= sticks[x];
  //                 cout << x;
  //                 break;
  //             }
  //     }
  // }

  cout<<endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <vl> graph;

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << " " << (a + b > n ? a + b - n : 0);
	return 0;
}

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

int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int flag = 1;
    for (int i = 0; i < n; i++)
    {
        if (s[i] != t[i])
        {
            flag = 0;
            break;
        }
    }
    if (flag == 0)
        cout << "No\n";
    else
        cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 3624
n, m = map(int, input().split())

l = [0 for _ in range(m)]
r = [0 for _ in range(m)]
for i in range(m):
    l[i], r[i] = map(int, input().split())

lmax = max(l)
rmin = min(r)
print(max(rmin-lmax+1, 0))

Measured memory_bytes: 10996
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, X);
    OUT(1000 * (X / 500) + 5 * ((X % 500) / 5));
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int n, K; cin >> n >> K;
  vll xys;
  rep(i,n) {
    ll x, y; cin >> x >> y;
    xys.pb(mp(x, y));
  }
  ll ans = INFL;
  rep(i,n) {
    ll x1 = xys[i].ff;
    rep(j,n) {
      ll x2 = xys[j].ff;
      rep(k,n) {
        ll y1 = xys[k].ss;
        rep(l,n) {
          ll y2 = xys[l].ss;
          if (x1 >= x2 || y1 >= y2) continue;
          int cnt = 0;
          rep(m,n) {
            ll x = xys[m].ff, y = xys[m].ss;
            if (x1 <= x && x <= x2 && y1 <= y && y <= y2) {
              cnt++;
            }
          }
          ll area = (x2-x1) * (y2-y1);
          if (cnt >= K) {
            ans = min(ans, area);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
#define ll long long
const long long mod = 1e9 + 7;

int main() {
	string s;
	set<ll> a;
	cin >> s;

	for (int i = 0; i < 4; i++) {
		a.insert((ll)s[i]);
	}
	if (a.size() == 2)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
/*

    * * * *      *       *     * * *        * *      * * * *    * * * *
    *       *    *     *       *     *    *     *   *          *
    *       *    *   *         *     *   *       *  *          *
    * * * *      * *           * * *     *       *    * * *      * * *
    *      *     *   *         *     *   *       *          *          *
    *       *    *     *       *     *    *     *           *          *
    *        *   *       *     * * *        * *     * * * *    * * * *

*/

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int               long long
#define ff                first
#define ss                second
#define md                1000000007
#define md1               998244353
#define inf               9000000000000000000
#define minf              -1000000000000000
#define pb                push_back
#define ppb               pop_back
#define in                insert
#define mkp               make_pair
#define mpll              map<ll,ll>
#define len(p)            (ll)p.size()
#define pll               pair<ll,ll>
#define all(v)            v.begin(),v.end()
#define mem(a,t)          memset(a,t,sizeof(a))
#define endl              "\n"
#define ar                array
#define vl                vector<ll>
#define vvl               vector<vl>
#define lb                lower_bound
#define ub                upper_bound
#define be()              begin()
#define en()              end()
#define vpll              vector<pair<ll,ll>>
#define f(i,yha,wha)      for(ll i=yha;i<wha;i++)
#define rf(i,wha,yha)     for(ll i=wha;i>=yha;i--)
#define f0(n)             for(ll i=0;i<n;i++)
#define f1(n)             for(ll i=1;i<=n;i++)
#define fg(i,yha,wha,gap) for(ll i=yha;i<wha;i+=gap)

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


void solve()
{
    ll h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    ll ans = (h2 - h1) * 60 + m2 - m1;

    cout << ans - k << endl;




}

int32_t main()
{
    flash();
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n, r;
  cin >> n >> r;
  int ans = r;
  if(n < 10) ans += 100 * (10 - n);
  cout << ans << endl;
  return 0;
}

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

int main() {
  int t, n, count = 0;
  double x, y;
  cin>>t>>n;
  while (t--) {
    cin>>x>>y;
    int val = (int)ceil(sqrt(x*x + y*y));
    if (val <= n)
      count++;
  }
  cout<<count<<'\n';
}


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

vector<int> Zalgorithm(const string &s){
    int n=s.size();
    vector<int> z(n);
    z[0]=n;
    int i=1,j=0;
    while(i<n){
        while(i+j<n&&s[j]==s[i+j]) ++j;
        z[i]=j;
        if (j==0){++i; continue;}
        int k=1;
        while(i+k<n&&k+z[k]<j) z[i+k]=z[k],++k;
        i+=k,j-=k;
    }
    return z;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int bit=0,n=S.size();
    for (auto c:S) bit|=1<<(c-'a');
    if (__builtin_popcount(bit)==1){
        cout << n << '\n' << 1 << '\n';
        return 0;
    }
    vector<int> check(n+1,1);
    int ok=1;
    for (int _=0;_<2;++_){
        vector<int> Z=Zalgorithm(S);
        for (int i=1;i<n;++i){
            if (n%i==0&&Z[i]==n-i) ok=0;
            for (int j=i;j<=Z[i];j+=i){
                check[(!_?i+j:n-(i+j))]=0;
            }
        }
        reverse(S.begin(),S.end());
    }
    int ans=0;
    for (int i=1;i<n;++i) ans+=check[i];
    if (ok) cout << 1 << '\n' << 1 << '\n';
    else cout << 2 << '\n' << ans << '\n';
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define DEBUG true
#define $(x) {if (DEBUG) {cout << #x << " = " << (x) << endl;}}


int main() {
    LL a, b, x;
    cin >> a >> b >> x;
    LL ans = (b / x) - (a / x) + 1;
    if (a % x != 0) ans--;
    cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

  int main(){
    int n;
    string s;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    sort(v.begin(),v.end());
    cout << v[(n/2)] -v[(n/2)-1] << endl;

    
    return 0;
  }


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int h, w, k; cin >> h >> w >> k;
	char c[h][w]; rep(i,h)rep(j,w) cin >> c[i][j];
	int ans = 0;
	for(int ym = 0; ym < (1 << h); ++ym) {
		for(int xm = 0; xm < (1 << w); ++xm) {
			int cnt = 0;
			for(int y = 0; y < h; ++y) {
				if(ym >> y & 1) continue;
				for(int x = 0; x < w; ++x) {
					if(xm >> x & 1) continue;
					if(c[y][x] == '#') ++cnt;
				}
			}
			if(cnt == k) {
				++ans;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <utility>
#include <math.h>
using namespace std;

int main() {
    long long a, b, r = 0;
    cin >> a >> b;
    for (long long i = b; i <= a + 1; i++) {
        r += i * (a - i + 1) + 1;
        r %= 1000000007;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 3636
//#pragma GCC optimize(3)
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set> 
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define inf 200009
#define infm 800009
#define INF (int)1e9
#define mod 1000000007LL
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;
int n,maxX,K;

struct edge{
	int tset,tadd;
	int minv,maxv;
}t[inf*4];
int val[inf];

void ST_set(int u,int x){
	t[u].tset=x;
	t[u].maxv=t[u].minv=x;
	t[u].tadd=0;
	return;
}

void ST_add(int u,int x){
	t[u].tadd+=x;
	t[u].maxv+=x;
	t[u].minv+=x;
	return;
}

void ST_pushdown(int u){
	int ls=u*2,rs=u*2+1;
	if (t[u].tset!=-1){
		ST_set(ls,t[u].tset);
		ST_set(rs,t[u].tset);
		t[u].tset=-1;
	}
	if (t[u].tadd){
		ST_add(ls,t[u].tadd);
		ST_add(rs,t[u].tadd);
		t[u].tadd=0;
	}
	return;
}

void ST_pushup(int u){
	t[u].minv=t[u*2].minv;
	t[u].maxv=t[u*2+1].maxv;
	return;
}

void ST_build(int u,int l,int r){
	t[u].tadd=0;
	t[u].tset=-1;
	if (l==r){
		t[u].maxv=t[u].minv=val[l];
		return;
	}
	int mid=(l+r)/2;
	ST_build(u*2,l,mid);
	ST_build(u*2+1,mid+1,r);
	ST_pushup(u);
	return;
}

void ST_modify(int u,int l,int r,int x){
	if (x==0){
		return;
	}
	if (t[u].minv+x>=maxX){
		ST_set(u,maxX);
		return;
	}
	if (t[u].maxv+x<=0){
		ST_set(u,0);
		return;
	}
	if (t[u].minv+x>=0 && t[u].maxv+x<=maxX){
		ST_add(u,x);
		return;
	}
	ST_pushdown(u);
	int mid=(l+r)/2;
	ST_modify(u*2,l,mid,x);
	ST_modify(u*2+1,mid+1,r,x);
	ST_pushup(u);
	return;
}

int ST_query(int u,int l,int r,int k){
	if (l==r){
		return t[u].maxv;
	}
	ST_pushdown(u);
	int mid=(l+r)/2;
	if (k<=mid){
		return ST_query(u*2,l,mid,k);
	}
	else{
		return ST_query(u*2+1,mid+1,r,k);
	}
	ST_pushup(u);
	return 0;
}


struct data{
    int t,a,id;
}a[inf];
int R[inf],rnk[inf];

bool cmp1(data _1,data _2){
	return _1.a<_2.a;
}

bool cmp2(data _1,data _2){
	return _1.t<_2.t;
}

int main(){
    rd(maxX) rd(K)
    for (int i=1;i<=K;i++){
        rd(R[i])
    }
    rd(n)
    for (int i=1;i<=n;i++){
        rd(a[i].t) rd(a[i].a)
        a[i].id=i;
    }
    R[++K]=a[n].t+1;
    sort(a+1,a+n+1,cmp1);
    for (int i=1;i<=n;i++){
    	val[i]=a[i].a;
    	rnk[a[i].id]=i;
	}
    sort(a+1,a+n+1,cmp2);
    ST_build(1,1,n);
    int f=-1,pos=0;
    for (int i=1;i<=K;i++){
    	while (pos<n && a[pos+1].t<R[i]){
    		pos++;
    		int ans=ST_query(1,1,n,rnk[pos]);
    		ans+=f*(a[pos].t-R[i-1]);
    		ans=max(0,ans);
    		ans=min(maxX,ans);
    		printf("%d\n",ans);
		}
		ST_modify(1,1,n,(R[i]-R[i-1])*f);
		f=-f;
	}
	return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;
struct Edge { int from, to; long long cost; };
using Graph = vector<vector<Edge>>;

struct Combination {
    vector<long long> fac, inv, finv;
    long long md = 0;
    Combination(int n, long long m): fac(n + 1), inv(n + 1), finv(n + 1) {
        md = m;
        fac[0] = fac[1] = 1;
        inv[1] = 1;
        finv[0] = finv[1] = 1;
        for(int i = 2; i <= n; i++) {
            fac[i] = fac[i - 1] * i % md;
            inv[i] = md - inv[md % i] * (md / i) % md;
            finv[i] = finv[i - 1] * inv[i] % md;
        }
    }
    long long P(int n, int r) {
        if(r < 0 || n < r) return 0;
        return fac[n] * finv[n - r] % md;
    }
    long long C(int n, int r) {
        if(r < 0 || n < r) return 0;
        return fac[n] * (finv[r] * finv[n - r] % md) % md;
    }
    long long H(int n, int r) {
        if(r < 0 || n < r) return 0;
        return (r == 0 ? 1 : C(n + r - 1, r));
    }
};

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

    int n,k;
    cin>>n>>k;
    Combination c(2020,MOD);
    cout<<c.C(k,n)<<endl;
}


Measured memory_bytes: 3256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int D,T,S,ANS=0 ;
    cin>>D>>S>>T;
    ANS=S*T;
    if(ANS>=D){
        cout<< "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint(), L = getint(), T = getint();
	vector<int> A, V;
	int X0;
	char W0;
	X0 = getint();
	W0 = *ci++;
	ci++;
	if (W0 == '1') V.pb((X0 + T) % L);
	else V.pb((X0 - (T % L) + L) % L);

	rep(i, N - 1) {
		int x = getint();
		int w = getcha();
		getcha();
		if (w != W0) A.pb(x);

		if (w == '1') V.pb((x + T) % L);
		else V.pb((x - (T % L) + L) % L);
	}

	int aite = A.size();

	int kaisuu = 0;
	kaisuu += (T / L) * 2 * aite;
	T = T % L;
	rep(i, aite) {
		int tmp = A[i];
		if (W0 == '1') {
			if (X0 >= tmp) tmp += L;
			while (X0 + T > tmp - T) {
				kaisuu++;
				tmp += L;
			}
		}
		else {
			if (X0 <= tmp) tmp -= L;
			while (X0 - T <= tmp + T) {
				kaisuu++;
				tmp -= L;
			}
		}
	}
	kaisuu %= N;
	
	sort(V.begin(), V.end());

	if (W0 == '1') {
		int doko = (X0 + T) % L;
		int itr = lower_bound(V.begin(), V.end(), doko) - V.begin();

		int kotae[100100];
		int kari = N + kaisuu - itr;
		for (int i : V) {
			kotae[kari % N] = i;
			kari++;
		}
		rep(i, N) putint(kotae[i]);
	}
	else {
		int doko = (X0 - (T % L) + L) % L;
		int itr = lower_bound(V.begin(), V.end(), doko) - V.begin();

		int kotae[100100];
		int kari = N + N - kaisuu - itr;
		for (int i : V) {
			kotae[kari % N] = i;
			kari++;
		}
		rep(i, N) putint(kotae[i]);
	}
	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 3576
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array


def num_string_to_array(num_string):
    return array.array("B", map(int, num_string))


def num_array_to_string(num_array):
    return "".join(map(str, num_array))


def solve(n, x, d):
    answer = x[:]
    rest_distance = d
    for i in range(n):
        if rest_distance <= 0:
            return answer
        elif answer[i] == 0:
            answer[i] = 1
            rest_distance -= 1
    for j in range(n)[::-1]:
        if rest_distance <= 0:
            return answer
        elif answer[j] == 1 and answer[j] == x[j]:
            answer[j] = 0
            rest_distance -= 1
    return answer


def main():
    n = int(input())
    x = num_string_to_array(input())
    d = int(input())
    answer = num_array_to_string(solve(n, x[:], d))
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 7880
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

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

  std::string s,t;
  cin>>s>>t;

  std::vector<int64_t> char_pos[30];
  for(int i=0;i<s.size();i++){
    char_pos[s[i]-'a'].push_back(i);
  }

  for(auto c:t){
    if(char_pos[c-'a'].size()==0){
      cout<<-1<<endl;
      return 0;
    }
  }

  int64_t result=0;
  int64_t pos=0;

  for(auto c:t){
    auto itr=std::lower_bound(char_pos[c-'a'].begin(),char_pos[c-'a'].end(),pos);
    if(itr==char_pos[c-'a'].end()){
      result+=s.size()-pos;
      pos=char_pos[c-'a'].front()+1;
      result+=pos;
    }else{
      result+=*itr-pos+1;
      pos=*itr+1;

    }
  }

  cout<<result<<endl;




  return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

signed main(){
  int sta,fin;
  cin>>sta>>fin;
  int n;
  cin>>n;
  bool ok[1005];
  for(int i=0; i<=1000; i++) ok[i]=true;
  
  for(int i=0; i<n; i++){
    int s,f;
    cin>>s>>f;
    for(int j=s; j<=f; j++){
      ok[j]=false;
    }
  }
  
  if(fin-sta==1){
    if(ok[fin]==false&&ok[sta]==false) cout<<1<<en;
    else cout<<0<<en;
    RE;
  }
  int ans=0;
  for(int i=sta+1; i<fin; i++){
    if(ok[i]==false) ans=1;
  }
  cout<<ans<<en;
}




Measured memory_bytes: 3084
// B - Cut and Count
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; string S; cin>>N>>S;
	int maxi = 0;
	rp(sep, 1, N){
		vector<int> abc('z'-'a'+1);
		rp(i, 0, sep) rp(j, sep, N)
			if(S[i]==S[j]){ abc[S[i]-'a']++; break; }
		int count = 0; for(int c:abc) if(c) count++;
		maxi = max(maxi, count);
	}
	cout<< maxi <<endl;
}

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

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

const double EPS = 1e-10;

typedef struct union_find_tree {
	vector<int> data;
	map<int, int> parent;
	map<int, int> rank;

	//constructor
	union_find_tree(vector<int> data_) {
		data = data_;
		
		for (int i=0; i<(int)data.size(); i++) {
			parent[data[i]] = data[i];
			rank[data[i]] = 1;
		}
	}

	//Find root
	int root (int x) {
		return parent[x] == x ? x : parent[x] = root(parent[x]);
	}

	//check if the two emements are in the same tree
	bool is_same(int x, int y) {
		return root(x) == root(y);
	}	
	
	//Unite two trees
	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		
		if (x == y) return;

		if (rank[x] < rank[y])
			parent[x] = y;
		else {
			parent[y] = x;
			if (rank[x] == rank[y]) rank[x]++; 
		}
		return;
	}
} uft;

int n, q;

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

  vector<int> data(n);
  for (i=0; i<n; i++) data[i] = i;
  uft u(data);

  for (i=0; i<q; i++) {
    int c, x, y;
    scanf("%d%d%d ", &c, &x, &y);
    if (c==0)
      u.unite(x, y);
    else {
      printf("%d\n", (u.is_same(x,y)) ? 1 : 0);  
    }
  }

	return 0;
}

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

using namespace std;

int main(){
  int A, B;
  cin >> A >> B;
  
  int p = -1;
  for(int i = 1; i <= 1000; i++){
    if((int)(i * 1.08) == A + i && (int)(i * 1.1) == B + i){
      p = i;
      break;
    }
  }
  
  cout << p << endl;
  
  return 0;
}

Measured memory_bytes: 256