akhauriyash/Code-Regression huggingface dataset:
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for i in range(0,a+1):
  for j in range(0,b+1):
    for k in range(0,c+1):
      y = i*500 + j*100 + k*50
      if x == y:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    ll ans = 1;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    rep(i, n){
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, n){
        if(log10((ld)ans)+log10((ld)a[i])>18){
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
        if(ans > (ll)1000000000000000000 || ans < 0){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4004
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int N, K;
  std::cin >> N >> K;
  std::string S;
  std::cin >> S;

  // Output
  S[K - 1] = std::tolower(S[K - 1]);

  std::cout << S << std::endl;

  return 0;
}


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

using namespace std;


const int N = 100100;
#define ll long long
#define fr(i,a,n) for (int i=a;i<n;i++)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vipb(v) int x;cin>>x;v.pb(x);
#define vllpb(v) ll x;cin>>x;v.pb(x);
#define in(x) cin>>x;
#define in2(x,y) cin >> x >> y;
#define in3(x,y,z) cin>>x>>y>>z;
#define in4(a,x,y,z) cin>>a>>x>>y>>z;
#define in5(a,b,x,y,z) cin>>a>>b>>x>>y>>z;


typedef vector<int> VI;
typedef vector<ll> VL;


string s;
ll n, m, k;

int main() {
	cin >> n >> m;
	if (n < 10)
		cout << m + (100 * (10 - n)) << endl;
	else
		cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;

const int MOD=1000000007;

int a[100010];
int main(){
	LL a,b,n;
	cin>>a>>b>>n;
	if(n<=b-1)cout<<(a*n)/b<<"\n";
	else cout<<(a*(b-1)/b)<<"\n";
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
int main()
{
    std::string s;
    std::cin >> s;

    if((s>= "a")&&(s<="z")){
        std::cout << "a" << std::endl;
    }

    else if((s>= "A")&&(s<="Z")){
        std::cout << "A" << std::endl;
    }
}

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

struct vicinity { long long From, To, Cost; };

long long N;
vector<vector<long long> > G;
vector<vicinity> V;
vector<long long> X;
vector<long long> Y;

long long DFS(long long P, long long Q) {
	long long RET = 0;
	for (long long NP : G[P]) {
		if (NP == Q) continue;
		RET += DFS(NP, P);
	}
	return X[P] = RET + 1;
}

int main() {
	cin >> N;
	G.resize(N);
	V.resize(N);
	X.resize(N);
	for (int i = 0; i < N - 1; i++) {
		cin >> V[i].From >> V[i].To >> V[i].Cost;
		V[i].From--, V[i].To--;
		G[V[i].From].push_back(V[i].To);
		G[V[i].To].push_back(V[i].From);
	}
	DFS(0, -1);
	long long COUNT = 0;
	bool check = false;
	for (int i = 0; i < N - 1; i++) {
		long long M = min(X[V[i].From], X[V[i].To]);
		COUNT += min(M, N - M) * 2 * V[i].Cost;
		if (M * 2 == N) check = true, COUNT -= V[i].Cost;
	}
	if (check) {
		cout << COUNT << endl;
		return 0;
	}
	else {
		Y.resize(N);
		for (int i = 0; i < N; i++) {
			long long MAX = 0;
			for (int j : G[i]) {
				if (X[j] < X[i]) MAX = max(MAX, X[j]);
				else MAX = max(MAX, N - X[i]);
			}
			Y[i] = MAX;
		}
		long long Center;
		for (int i = 0; i < N - 1; i++) {
			if (Y[i] * 2 <= N) Center = i;
		}
		long long MIN = 1000000000;
		for (int i = 0; i < N - 1; i++) {
			if (V[i].From == Center || V[i].To == Center) MIN = min(MIN, V[i].Cost);
		}
		cout << COUNT - MIN << endl;
	}
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}

ll BinarySearch(ll ng, ll ok, function<bool(ll)> judge){
    while(abs(ok - ng) > 1){
        ll mid = (ok + ng) / 2;
        if(judge(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

signed main(){
    ll n, m, v, p;
    cin >> n >> m >> v >> p;

    vector<int> score(n);
    for(auto&& i : score) cin >> i;

    sort(rall(score));

    auto fn = [&](ll x){
        ll vote = m * v;
        ll s = x + m;

        REP(i, n){
            if(i < p - 1){
                vote -= m;
                continue;
            }
            if(score[i] > s){
                return false;
            }
            ll d = s - score[i];
            vote -= min(d, m);
        }

        return vote <= 0;
    };

    ll bound = BinarySearch(-1, score[0], fn);

    int ans = 0;
    REP(i, n){
        if(score[i] >= bound) ans++;
        else break;
    }

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


Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
using namespace std;
int n, m;
int main(){
    int i, j, k;
    cin >> n >> m;
    int maxn = -2147483647;
    int a = n + m;
    if(a > maxn)maxn = a;
    int b = n - m;
    if(b > maxn)maxn = b;
    int c = n * m;
    if(c > maxn)maxn = c;
    cout << maxn << endl;
    return 0;
}

Measured memory_bytes: 256
n, a, b = (int(i) for i in input().split()) 
sum = 0

for num in range(1, n + 1):
  sum_num = 0
  for c_num in str(num):
    sum_num += int(c_num)
  if sum_num >= a and sum_num <= b:
    sum += num
    
print(sum)

Measured memory_bytes: 3060
n,k,q = gets.split(" ").map(&:to_i)
array = []
array_player = Array.new(n, 0)
q.times do |i|
  array << gets.to_i
end

array.each do |num|
  array_player[num - 1] += 1
end

array_player.each do |num|
  puts (k + num - q) > 0 ? "Yes" : "No"
end

Measured memory_bytes: 6068
import java.io.PrintWriter

fun main(args: Array<String>) {
    val pw = PrintWriter(System.out)

    val n = readInputLine().toLong()

    val divisor1 = mutableSetOf<Long>()

    for (i in LongRange(1L, n - 1L)) {
        if (i * i > n - 1L) {
            break
        }
        if ((n - 1L) % i == 0L) {
            divisor1.add(i)
            divisor1.add((n - 1L) / i)
        }
    }

    val divisor2 = mutableSetOf<Long>()
    divisor2.add(n)

    for (i in LongRange(2L, n)) {
        if (i * i > n) {
            break
        }
        if (n % i == 0L) {
            divisor2.add(i)
            divisor2.add(n / i)
        }
    }

    var ans = divisor1.count() - 1

    for (d in divisor2) {
        var tmp = n
        while (tmp % d == 0L) {
            tmp /= d
        }
        if (tmp % d == 1L) {
            ans++
        }
    }

    pw.println(ans)

    pw.flush()
}

fun readInputLine(): String {
    return readLine()!!
}


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

int main(){
    priority_queue<int> PQ;
    int N, M; cin >> N >> M;
    vector<pair<int, int>> pairs(N);
    for(int i = 0; i < N; i++) cin >> pairs[i].first >> pairs[i].second;

    sort(pairs.begin(), pairs.end());
    int index = 0;
    ll res = 0;

    for(int i = 1; i <= M; i++){
        for(int j = index; j < N; j++){
            if(pairs[j].first > i) break;
            PQ.push(pairs[j].second);
            index++;
        }
        if(!PQ.empty()){
            res += PQ.top();
            PQ.pop();
        }
    }
    cout << res << endl;
}

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

int main(){
  string a,b;
  cin >> a >> b;
  if(a.size()>b.size()) cout << "GREATER" << endl;
  else if(a.size()<b.size()) cout << "LESS" << endl;
  else{
    rep(i,a.size()){
      if(a.at(i)==b.at(i)){}
      else if(a.at(i)<b.at(i)) {cout << "LESS" << endl;return 0;}
      else {cout << "GREATER" << endl;return 0;}
    }
    cout << "EQUAL" << endl;
  }

	return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())

from fractions import Fraction

probability = Fraction(1, N)
probability_total = 0

for i in range(N):
    count = 0
    point = i + 1
    while K > point:
        count += 1
        point = point * 2
    probability_total = probability_total + probability * Fraction(1, 2) ** count

print(float(probability_total))

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

int main() {
    int n;
    cin >> n;
    pair<pair<string,int>,int> p[n];

    rep(i,n){
        string str;
        int point;
        cin >> str >>point;
        p[i]= make_pair(make_pair(str,-point),i+1);
    }

    std::sort(p,p+n);
    rep(i,n){
        cout << p[i].second <<endl;
    }
}

Measured memory_bytes: 3616
N,M = map(int, input().split())
def usage():
    
    fct = factorize(M)
    lis = []
    for t in fct:
      lis.append(t[1])
    ans = 1
    for nums in lis:
      ans = (ans*cmb(N+nums-1,N-1,10**9+7))%(10**9+7)
    print(ans)
    
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, 10*N ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
usage()

Measured memory_bytes: 122048
#include<cstdio>

int dp[200000];
int h[200000];

int abs(int x) {
    return x < 0 ? -x : x;
}

int main(void) {
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0; i<n; i++)
        scanf("%d",&h[i]);

    for(int i=0; i<n; i++)
        dp[i] = 1e9;

    dp[0] = 0;
    for(int i=0; i<n; i++)
        for(int j=1; j<=k && i+j<n; j++)
            if(dp[i+j] > dp[i] + abs(h[i+j]-h[i]))
                dp[i+j] = dp[i] + abs(h[i+j] - h[i]);

    printf("%d\n", dp[n-1]);
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int c=1;
    char ch=s[0];
    string d="";
    d+=s[0];
    for(int i=1;i<s.size();i++)
    {
        if(s[i]==ch)
            c++;
        else
        {
            c=1;
            ch=s[i];
            d+=s[i];
        }
    }
   int q=d.size();
   cout<<q<<"\n";
    return 0;
}


Measured memory_bytes: 3748
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "ctime"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	string s;
	cin >> s;
	long long int box = 0;
	long long int ans = 0;
	for (auto i : s) {
		if (i == 'B')box++;
		else ans += box;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 720
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 1e5 + 5;

int n, k;
int arr[N];

int main()
{
  cin >> n >> k;
  for(int i = 0 ; i < n ; i++) {
    cin >> arr[i];
  }
  vector<int> dp(n + 1);
  dp[0] = 0;
  for(int i = 1; i < n; i++) {
    dp[i] = 2e9;
    for(int j = i - 1; j >= max(0, i - k); j--)
      dp[i] = min(dp[i], abs(arr[i] - arr[j]) + dp[j]);
  }
  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
  int N,X;
  cin >> N >> X;
  int m[102];
  for(int i = 0;i < N;++i) cin >> m[i];
  int B = m[0];
  for(int i = 0;i < N;++i) {
    X =X - m[i];
    if(B > m[i]) B = m[i];
    }
  int res = 0;
  while(X >= B){
    X -= B;
    ++res;
  }
  cout << res + N << endl;
}

Measured memory_bytes: 256
def main():
    while True:
        N, M = map(int, input().split())
        if not N:
            return
        order = [int(input()) for _ in range(N)]
        draw = [int(input()) for _ in range(M)]
        p = 0
        ans = 0
        for i in range(M):
            p += draw[i]
            if p >= N - 1:
                ans = i + 1
                break
            p += order[p]
            if p >= N - 1:
                ans = i + 1
                break

        print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    vector<vector<int>> a;
    vector<vector<bool>> check;

    vector<int> tmp(3);
    vector<bool> tmpc(3, false);
    rep(i, 3){
        rep(j, 3){
            int num;
            cin >> num;
            tmp[j] = num;
        }
        a.push_back(tmp);
        check.push_back(tmpc);
    }

    int n;
    cin >> n;

    rep(i, n){
        int b;
        cin >> b;
        rep(j, 3){
            rep(k, 3){
                if(!check[j][k]&&a[j][k]==b){
                    check[j][k] = true;
                }
            }
        }
    }

    string ans = "No";

    rep(i, 3){
        if(check[i][0]&&check[i][1]&&check[i][2]){
            ans = "Yes";
        }
    }

    rep(i, 3) {
      if (check[0][i] && check[1][i] && check[2][i]) {
        ans = "Yes";
      }
    }

    if (check[0][2] && check[1][1] && check[2][0]) {
      ans = "Yes";
    }

    if (check[0][0] && check[1][1] && check[2][2]) {
      ans = "Yes";
    }

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

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <utility>
#include <algorithm>
#include <ctime>
#include <cstdarg>
#include <sstream>
#include <functional>
using namespace std;

int const MAX_N = 100 * 1002;

vector<int> e[MAX_N], e_back[MAX_N];
int in_deg[MAX_N], ans[MAX_N], nnew[MAX_N];

int calced[MAX_N], max_dist[MAX_N];
int dfs(int v) {
	if (calced[v])
		return max_dist[v];
	for (int i = 0; i < (int)e_back[v].size(); i++)
		max_dist[v] = max(max_dist[v], dfs(e_back[v][i]) + 1);
	calced[v] = 1;
	return max_dist[v];
}

void dfs_rec(int v, int dst) {
	nnew[v] = 1;
	for (int i=0; i<(int) e[v].size(); i++)
		if (!nnew[e[v][i]])
			if (max_dist[e[v][i]] == dst + 1) {
				ans[e[v][i]] = v;
				dfs_rec(e[v][i], dst + 1);
			}
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n - 1 + m; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		e[a].push_back(b);
		in_deg[b]++;
		e_back[b].push_back(a);
	}

	int root = 0;
	for (int i=0; i<n; i++)
		if (in_deg[i] <= 0) {
			root = i;
			break;
		}

	for (int i = 0; i < n; i++) ans[i] = -1, max_dist[i] = 0;

	for (int i=0; i<n; i++)
		if (!calced[i])
			dfs(i);
	dfs_rec(root, 0);

	for (int i = 0; i < n; i++) ans[i]++;
	for (int i = 0; i < n; i++) printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 16896
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

S = S()
ans = 0

for i in range(1<<(len(S)-1)):
    tmp_ans = 0

    for j in range(len(S)-1):
        if (i & 1):
            tmp_ans *= 10
            tmp_ans += int(S[j])
            ans += tmp_ans
            tmp_ans = 0
        else:
            tmp_ans *= 10
            tmp_ans += int(S[j])
       
        i >>= 1
    
    if (not tmp_ans):
        ans += int(S[-1])
    else:
        tmp_ans *= 10
        tmp_ans += int(S[-1])
        ans += tmp_ans

print(ans)


Measured memory_bytes: 40048
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  string s;
  cin>>a>>b>>s;
  if(s[a]!='-') return 0*puts("No");
  for(int i=0;i<a+b+1;i++){
    if(i==a) continue;
    if(!isdigit(s[i])) return 0*puts("No");
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) ((x+mo_num)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define P pair<int,int>
#define SET set<int>
#define mp map<int,int>
#define mk make_tuple
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
using namespace std;
const int INF=LLONG_MAX/2;
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//up down left right
const int maxn=1e6+1e5;
const int mo_num=1e9+7;
int n,m,t,a[maxn],b[maxn],ans;

main()
{
    IOS
    cin>>n;
    string k;
    cin>>k;
    int len=k.length();
    if(len<=n)out(k)
    else {
        fun(i)cout << k[i - 1];
        cout<<"...";
    }
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9+1;
const ll LINF = 1e18+1;
const long double PI = acos(-1.0);

#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#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--)
 
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SORT(v) sort(ALL(v));
#define RSORT(v) sort(RALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;
 
#define HOGE COUT("HOGE")
 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
 
template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}
template<typename T> T lcm(T a,T b){return a*b/gcd(a, b);}


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
int main() {
    IN(int, n);
    VIN(int, b, n-1);
    vi a(n,INF);
    REP(i, n-1){
        chmin(a[i], b[i]);
        chmin(a[i+1], b[i]);
    }
    int sum = 0;
    REP(i, n){
        sum += a[i];
    }
    COUT(sum);
}


Measured memory_bytes: 3636
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W = LI()
    a = [SS() for _ in range(H)]

    white_columun = set()
    for c in range(W):
        cnt = 0
        for r in range(H):
            if a[r][c] == '.':
                cnt += 1
        if cnt == H:
            white_columun.add(c)

    for i in a:
        if i.count('.') < W:
            ans = []
            for j in range(W):
                if not j in white_columun:
                    ans.append(i[j])
            print(''.join(ans))

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10144
/*
How to lambda
  ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound
  1 2 2 2 3 3
    ^lb   ^ub */
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)

#define DumpArray(cont,from,to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

using namespace std;
typedef long long ll;
typedef long double ld;
int N,Q;
string S;
string T[2*1000*100+10],D[2*1000*100+10];
bool fallFromLeft(int s) {
    if (s==-1)return true;
    if (s==N)return false;
    int cpos=s;
    REP(i,Q)
        if (T[i][0]==S[cpos]) {
            if (D[i][0] == 'L') {
                if (--cpos < 0)return true;
            }else{
                if (++cpos >= N) return false;
            }
        }
    return false;
}
bool fallFromRight(int s) {
    if (s==-1)return false;
    if (s==N)return true;
    int cpos=s;
    REP(i,Q)
        if (T[i][0]==S[cpos]) {
            if (D[i][0] == 'L') {
                if (--cpos < 0)return false;
            }else{
                if (++cpos >= N) return true;
            }
        }
    return false;
}
int main() {
    cin >> N >> Q >> S;
    REP(i,Q)
        cin >> T[i] >> D[i];
    int l=-1,r=N;
    int ans=0;
    while(r-l>1) {
        int m=l+(r-l)/2;
        if (fallFromLeft(m))
            l=m;
        else
            r=m;
    }
    ans+=l+1;
    l=-1,r=N;
    while(r-l>1) {
        int m=l+(r-l)/2;
        if (fallFromRight(m))
            r=m;
        else
            l=m;
    }
    ans+=N-r;
    cout << N-min(ans, N) << endl;

    return 0;
}


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

int main(){
    double d,t,s;
    cin >> d >> t >> s;
    double time_taken = d/s;
    if(time_taken<=t){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3740
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

string seq;
map<string, int> w;
int cur;

int num() {
    int ret = 0;

    while(cur < seq.size() && isdigit(seq[cur])) {
      ret = 10 * ret + seq[cur++] - '0';
    }

    return ret;
}

int atm() {
    string a = seq.substr(cur, 1);

    cur++;

    while(cur < seq.size() and islower(seq[cur])) {
      a.push_back(seq[cur++]);
    }

    auto it = w.find(a);

    if(it == w.end()) {
      return -1;
    } else {
      return it->second;
    }
}

int mol() {
    if(cur == seq.size()) {
      return 0;
    }

    int ret = 0;

    if(seq[cur] == ')') {
      return 0;
    }

    if(seq[cur] == '(') {
        cur++;
        ret = mol();
        cur++;

        if(ret < 0) {
          return ret;
        }

        ret *= num();
        int d = mol();

        if(d < 0) {
          return d;
        } else {
          return ret + d;
        }
    }

    ret = atm();

    if(ret < 0) {
      return ret;
    }

    ret *= max(1, num());
    int d = mol();

    if(d < 0) {
      return d;
    } else {
      return ret + d;
    }
}

int main() {
  for(string s; cin >> s && s != "END_OF_FIRST_PART"; ){
    int d;
    cin >> d;
    w[s] = d;
  }

  for(; cin >> seq && seq != "0"; ) {
    cur = 0;
    int ans = mol();
    if(ans < 0) {
      cout << "UNKNOWN" << endl;
    } else {
      cout << ans << endl;
    }
  }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int res = 0;
  for (int i = 0; i < N; ++i) {
    int h; cin >> h;
    if (h >= K) ++res;
    
  }
  cout << res << endl;
}

Measured memory_bytes: 3580
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var HW = ReadLine().Split().Select(int.Parse).ToArray();
        int H = HW[0], W = HW[1];
        int N = int.Parse(ReadLine());
        var a = ReadLine().Split().Select(int.Parse).ToArray();
        var map = new int[H, W];
        int index = 0;
        bool muki = false;
        for (int i = 0; i < H; i++)
        {
            if (muki)
            {
                for (int j = 0; j < W; j++)
                {
                    if (a[index] <= 0)
                    {
                        j--;
                        index++;
                        continue;
                    }
                    else
                    {
                        map[i, j] = index + 1;
                        a[index]--;
                    }
                }
            }
            else
            {
                for (int j = W - 1; j >= 0; j--)
                {
                    if (a[index] <= 0)
                    {
                        j++;
                        index++;
                        continue;
                    }
                    else
                    {
                        map[i, j] = index + 1;
                        a[index]--;
                    }
                }
            }
            muki = !muki;
        }
        for (int i = 0; i < H; i++)
        {
            var line = new int[W];
            for (int j = 0; j < W; j++)
            {
                line[j] = map[i, j];
            }
            WriteLine(string.Join(" ",line));
        }
    }
}


Measured memory_bytes: 29676
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class BNiceShopping {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int A, B, M;
        cin >> A >> B >> M;
        vector<int> a(A), b(B), x(M), y(M), c(M);
        REP(i, A) cin >> a[i];
        REP(i, B) cin >> b[i];
        REP(i, M) {
            cin >> x[i] >> y[i] >> c[i];
            x[i]--, y[i]--;
        }

        int ma = INF;
        int mb = INF;
        REP(i, A) {
            ma = min(ma, a[i]);
        }
        REP(i, B) {
            mb = min(mb, b[i]);
        }
        int res = ma + mb;
        REP(i, M) {
            res = min(res, a[x[i]] + b[y[i]] - c[i]);
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BNiceShopping solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 4224
// Written By NewbieChd
#include <cstdio>
#include <cctype>
#include <vector>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 3007;
vector<int> g[maxN];
int w[maxN];
bool dfs(int x) {
    for (auto y : g[x])
        if (w[y] < w[x] && !dfs(y))
            return 1;
    return 0;
}

int main() {
    int n = read(), i, x, y;
    for (i = 1; i <= n; ++i)
        w[i] = read();
    for (i = 1; i < n; ++i)
        x = read(), y = read(), g[x].push_back(y), g[y].push_back(x);
    for (i = 1; i <= n; ++i)
        if (dfs(i))
            printf("%d ", i);
    return 0;
}


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

using namespace std;
const int maxn = 305;
int n, m, l;
long long path[maxn][maxn];
int ans[maxn][maxn];
long long inf = 100000000000000000;
int main()
{
    scanf("%d%d%d", &n,&m, &l);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)
            path[i][j] = inf+7;
    }
    for(int i=1;i<=m;i++)
    {
        int x, y, v;
        scanf("%d%d%d",&x,&y, &v);
        path[x][y] = path[y][x] = v;
    }
    for(int i=1;i<=n;i++)
        path[i][i] = 0;
    for(int k=1;k<=n;k++){
        for(int j=1;j<=n;j++){
            for(int i=1;i<=n;i++){
                path[i][j] = min(path[i][k] + path[k][j], path[i][j]);
                if(path[i][j]<0) while(1);
            }
        }
    }
//    for(int i=1;i<=n;i++){
//        for(int j=1;j<=n;j++){
//            printf("%d %d %lld\n",i, j, path[i][j]);
//        }
//    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            ans[i][j] = (path[i][j] <=l?1:1e9);
        }
    }
    for(int k=1;k<=n;k++){
        for(int j=1;j<=n;j++){
            for(int i=1;i<=n;i++){
                ans[i][j] = min(ans[i][j], ans[i][k] + ans[k][j]);
                if(ans[i][j]<0) while(1);
            }
        }
    }
    int q;
    scanf("%d",&q);
    while(q--){
        int x, y;
        scanf("%d%d", &x, &y);
        printf("%d\n", ans[x][y]<=n*2?ans[x][y] - 1:-1);
    }
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define  rep(i,n) for(li i = 0; i < (n); ++i)
#define  red(i,n) for(li i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;


int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(a*n,b)<<endl;

    return 0;
}



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

struct node_t {
    node_t *child[2];
    int val;
};

string::iterator state;
bool consume(char c) {
    if(*state != c) return false;
    ++state;
    return true;
}

node_t *parse() {
    node_t *ret = new node_t();
    assert(consume('('));
    if(consume(')')) {
        ret->child[0] = nullptr;
    } else {
        ret->child[0] = parse();
        assert(consume(')'));
    }

    assert(consume('['));
    while(isdigit(*state)) {
        ret->val *= 10;
        ret->val += *state - '0';
        ++state;
    }
    assert(consume(']'));
    
    assert(consume('('));
    if(consume(')')) {
        ret->child[1] = nullptr;
    } else {
        ret->child[1] = parse();
        assert(consume(')'));
    }

    return ret;
}

node_t *merge(node_t *a, node_t *b) {
    node_t *ret = new node_t;
    if(a == nullptr || b == nullptr) {
        ret = nullptr;
    } else {
        ret->val = a->val + b->val;
        ret->child[0] = merge(a->child[0], b->child[0]);
        ret->child[1] = merge(a->child[1], b->child[1]);
    }
    return ret;
}

void print(node_t *m) {
    if(m == nullptr) return;

    cout << '(';
    print(m->child[0]);
    cout << ')';

    cout << '[' << m->val << ']';

    cout << '(';
    print(m->child[1]);
    cout << ')';
}

int main() {
    string A, B; cin >> A >> B;

    state = begin(A);
    node_t *a = parse();
    state = begin(B);
    node_t *b = parse();

    node_t *m = merge(a, b);
    print(m); cout << endl;
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
long double N, d1, x, ans;
int main() {
	cin >> N >> d1 >> x;
	for(int i = N; i >= 1; i--) {
		long double s = d1 * 2 * N + N * (2 * N - 1) * x;
		ans += s / 2 / N;
		s = s - (4 * d1 + 4 * N * x - 2 * x)  / 2 / N;
		d1 = ((2 * N - 2) * d1 + d1 + 2 * x + 3 * d1 + 3 * x) / 2 / N;
		N--;
		x = (s - 2 * N * d1) / N / (2 * N - 1);
	//	if(i > 990) printf("%.10lf\n", (double)x);
	}
	printf("%.15lf", (double)ans);
	return 0;
}
/*
1
2 21
*/

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
const ll mod = 1e9+7;

int n;
ll a[maxn];
ll ans;
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

  cin>>n;
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }
  for (int j=0; j<=60; j++) {
    vector<ll> v(2);
    for (int i=0; i<n; i++) {
      v[a[i]>>j&1]++;
    }

    ans += (1LL<<j)%mod*v[0]%mod*v[1]%mod;
    ans %= mod;
  }
  ans %= mod;
  ans += mod;
  ans %= mod;

  cout<<ans<<endl;

  return 0;
}
// don't forget to read in the input :^)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;

int main () {
    double r, g; cin >> r >> g;
    cout <<  2 * g - r << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {

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

		String str = br.readLine();

		if (str.equals("ABC")) {
			System.out.println("ARC");
		} else {
			System.out.println("ABC");
		}

	}
}


Measured memory_bytes: 32336
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int f(int x){
  if(x%2) return x%4 == 1;
  return x + (x%4 == 2);
}

void solve(){

  int a, b;
  cin >> a>> b;
  cout << (f(a-1) ^ f(b)) fin;
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef vector<int>VI;
int n;
VI a;
int work(VI a,int d){
	if(d<0)return 0;
	int i=0,j=a.size()-1,ans=0;
	VI b;
	for(;i<j;++i){
		for(;i<j-1 && a[i]+a[j]>(1<<d);--j);
		if(a[i]+a[j]==(1<<d))++ans,a[i]=a[j--]=-1;
	}
	for(int x:a)if(x!=-1)b.push_back(x);
	ans+=work(b,d-1);return ans;
}
int main(){
	scanf("%d",&n);a.resize(n);for(int&x:a)scanf("%d",&x);
	sort(a.begin(),a.end());
	printf("%d\n",work(a,30));
	return 0;
}

Measured memory_bytes: 50548
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll A[100010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N, greater<ll>());
	ll ans = 0;
	bool ok = false;
	for (int i = 0; i < N - 1; i++) {
		if (A[i] == A[i + 1]) {
			if (ans == 0) ans = A[i];
			else {
				ans *= A[i];
				ok = true;
				break;
			}
			i++;
		}
	}
	if (ok) cout << ans << endl;
	else cout << 0 << endl;
}

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

using namespace std;

unsigned long f(unsigned long x)
{
	int r = x % 4;
	if (r == 0)
	{
		return x;
	}
	if (r == 1)
	{
		return 1;
	}
	if (r == 2)
	{
		return x ^ 1;
	}
	if (r == 3)
	{
		return 0;
	}
}

void solve()
{
	unsigned long a, b;
	cin >> a >> b;
	if (a) a--;
	cout << (f(a)^f(b)) << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, long long M, std::vector<long long> x, std::vector<long long> y)
{
    vector<ll> cnt(N, 1);
    vector<bool> contains(N, false);
    contains[0] = true;

    for (int i = 0; i < M; i++)
    {

        cnt[x[i] - 1]--;
        cnt[y[i] - 1]++;
        if (contains[x[i] - 1])
        {
            contains[y[i] - 1] = true;

            if (cnt[x[i] - 1] == 0)
            {
                contains[x[i] - 1] = false;
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        if(contains[i])ans++;
    }
    
    cout << ans << endl;
}

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


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    int n;
    cin >> n;
    string c;
    cin >> c;

    int left = 0;
    int right = n - 1;
    int cnt = 0;
    while (true) {
        for (; left < n; left++) {
            if (c[left] == 'W') {
                break;
            }
        }
        for (; right >= 0; right--) {
            if (c[right] == 'R') {
                break;
            }
        }

        if (left >= n || right < 0 || right <= left) {
            break;
        }

        swap(c[left], c[right]);
        cnt++;
    }
    put(cnt);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 3720
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n = inp()
a = inpl()
all_num = 0
for i in a:
    all_num ^= i
ans = []
for i in a:
    ans.append(all_num ^ i)
print(*ans)


Measured memory_bytes: 106748
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

//vector//
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

typedef pair<int,int> P;  //q(p.first,p.second)

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

    if(s*t >= d){
        cout << "Yes";
    } else {
        cout << "No";
    }
}

Measured memory_bytes: 3608