akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<iostream>
#include<queue>
#include<climits>
using namespace std;
static const int INF = INT_MAX / 3;
struct edge{
  int from,to,cap,rev;
};
struct ledge{
  int to,cap;
};
using node = int;
using graph = vector<vector<edge>>;
int dfs(int f,int v,int t,graph &g,vector<int> &level){
  if (v == t){
    return f;
  } 
  for(auto &e: g[v]){
    if(e.cap > 0 and
       level[e.to] > level[v]){
      int d = dfs(min(f,e.cap), e.to, t, g, level);
      if(d > 0){
        e.cap -= d;
        g[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int bfs(int s,int t,graph &g){
  using node = int;
  queue<node> q;
  vector<int> level(g.size(),-1);
  q.push(s);
  level[s] = 0;
  while(not q.empty()){
    auto v = q.front();q.pop();
    for(auto &e: g[v]){
      if(level[e.to] >= 0
         or e.cap <= 0) continue;
      q.push(e.to);
      level[e.to] = level[v] + 1;
    }
  }
  int d = 0,dd;
  while((dd = dfs(INF,s,t,g,level)) != 0){
    d += dd;
  }
  return d;
}

int max_flow(int s,int t,graph &g){
  int f = 0;
  while(true){
    int df = bfs(s,t,g);
    if (df == 0) break;
    f += df;
  }
  return f;
}

int main(){
  int v,e;
  cin >> v >> e;
  graph g(v);
  for(int i = 0; i < e;i++){
    int u,v,c;
    cin >> u >> v >> c;
    g[u].push_back({u,v,c,(int)g[v].size()});
    g[v].push_back({v,u,0,(int)g[u].size() - 1});
  }
  cout << max_flow(0,v-1,g) << endl;
}

Measured memory_bytes: 3140
#import sys
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a=[0]
b=[0]
for i in range(N):
    a.append(a[i]+A[i])
for j in range(M):
    b.append(b[j]+B[j])
ans = 0
l = M
for k in range(N+1):
    if a[k] > K:
        break
    while b[l] > K - a[k]:
        l -= 1
    ans = max(ans,k+l)
print(ans)


Measured memory_bytes: 47608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;cin>>a;
    cout<<(a+a*a+a*a*a)<<endl;
}

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

using namespace std;

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

#define int ll

const ll mod = 1e9 + 7;


main(){
	double a,b,h,m;
	double t1 = 2.0*M_PI/60.0;
	double t2 = 2.0*M_PI/(60.0*12);

	cin >> a >> b >> h >> m;

	double t = t1*m - t2*(60*h+m);


	double ans = sqrt(a*a + b*b - 2*cos(t)*a*b);

	printf("%.10f\n",ans);

	return 0;
}


Measured memory_bytes: 4184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<int> c = a, d = b;
    sort(c.begin(), c.end());
    sort(d.begin(), d.end());
    if (n & 1) {
        cout << d[n / 2] - c[n / 2] + 1 << '\n';
    } else {
        int s = d[n / 2] + d[n / 2 - 1];
        int t = c[n / 2] + c[n / 2 - 1];
        cout << s - t + 1 << '\n';
    }
    return 0;
}


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

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

    vector<int> scores(N);
    for (int& x : scores)
        cin >> x;

    int grade = accumulate(begin(scores), end(scores), 0);

    if (grade % 10 == 0)
    {
        sort(begin(scores), end(scores));

        bool removed = false;
        for (int i = 0; i < N; i++)
            if (scores[i] % 10 != 0)
            {
                grade -= scores[i];
                removed = true;
                break;
            }

        if (!removed)
            grade = 0;
    }

    cout << grade << endl;
}


Measured memory_bytes: 256
#include <iostream>

#define MAX_H 1003
#define MAX_W 1003
#define MAX_N (int)1e6

using namespace std;

int cave[MAX_H][MAX_W];
bool isPrime[MAX_N];

void cave_setting() {
    fill_n((int *)cave, MAX_H * MAX_W, -1);
    int y = MAX_H/2+1, x = MAX_W/2+1;
    int dy = 1, dx = 1, count = 1;
    cave[y][x] = 1;
    for (int i = 2; i < MAX_N;) {
        // right
        while (dx <= count) {
            cave[y][x+dx] = i;
            i++; dx++;
        }
        x+=dx-1; dx = 1;
        // up
        while (dy <= count) {
            cave[y-dy][x] = i;
            i++; dy++;
        }
        y-=dy-1; dy = 1;
        count++;
        // left
        while (dx <= count) {
            cave[y][x-dx] = i;
            i++; dx++;
        }
        x-=dx-1; dx = 1;
        // under
        while (dy <= count) {
            cave[y+dy][x] = i;
            i++; dy++;
        }
        y+=dy-1; dy = 1;
        count++;
    }
}

int main() {
    // isPrime table setting
    fill_n((bool *)isPrime, MAX_N, true); isPrime[0] = false; isPrime[1] = false;
    for (int i = 2; i < MAX_N; i++) {
        for (int j = i + i; j < MAX_N; j = j + i) {
            isPrime[j] = false;
        }
    }

    cave_setting();

    // input
    int m, n;
    while (cin >> m >> n, m|n) {
        int sx, sy;
        // search first node
        for (int j = 0; j < MAX_H; j++) {
            for (int i = 0; i < MAX_W; i++) {
                if (cave[j][i] == n) {
                    sx = i; sy = j;
                }
            }
        }
        // search
        int now[MAX_W];
        int search[MAX_W];
        int lastPrime[MAX_H][MAX_W];
        fill_n((int *)now, MAX_W, -1);
        fill_n((int *)search, MAX_W, -1);
        fill_n((int *)lastPrime, MAX_H * MAX_W, 0);
        now[sx] = isPrime[cave[sy][sx]];
        int last = 0;
        int max = 0;
        if (now[sx]) last = lastPrime[sy][sx] = cave[sy][sx];

        for (int j = sy; j < MAX_H-1; j++) {
            for (int i = 0; i < MAX_W; i++) {
                if (now[i] >= 0 && cave[j][i] <= m) {
                    for (int d = -1; d <= 1; d++) {
                        if (i + d >= 0 && i + d < MAX_W && cave[j+1][i+d] <= m && now[i]+isPrime[cave[j+1][i+d]] > search[i+d]) {
                            search[i+d] = now[i] + isPrime[cave[j+1][i+d]];
                            if (isPrime[cave[j+1][i+d]]) lastPrime[j+1][i+d] = cave[j+1][i+d];
                            else lastPrime[j+1][i+d] = lastPrime[j][i];
                        }
                    }
                }
            }
            for (int i = 0; i < MAX_W; i++) {
                if (search[i] != -1) now[i] = search[i];
                if (now[i] > max) {
                    max = now[i];
                    if (lastPrime[j+1][i] > 0) last = lastPrime[j+1][i];
                } else if (now[i] == max && lastPrime[j+1][i] > last) {
                    last = lastPrime[j+1][i];
                }
            }
        }
        cout << max << " " << last << endl;
    }
    return 0;
}

Measured memory_bytes: 10000
#include<iostream>

using namespace std;

int main(){
    unsigned long long  h, w;
    cin >> h >> w;
        if(h == 1 || w == 1){
            cout << 1 << endl;
        }else{
        if(w%2){
            if(h%2){
                cout << (w/2+1)*(h/2 + 1) + (w/2)*(h/2) << endl;
            }else{
                cout << (w/2+1)*(h/2) + (w/2)*(h/2) << endl;
            }
        }else{
            cout << (w/2 * h) << endl;
        }
    }

}

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

int main() {
	int n, x = 0;
	string s;
	cin >> n >> s;

	int ans = x;
	for (auto c : s) {
		x += c == 'I' ? 1 : -1;
		ans = max(ans, x);
	}

	cout << ans << "\n";
	
	return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val x = readLine.toInt
  
  def check(n:Int): Int = {
    val sqrt = math.sqrt(n).toInt
    val notPrime = (2 +: (3 to sqrt).filter(_ % 2 == 1)).exists(n % _ == 0)
    if (n == 2) n
    else if (notPrime) check(n+1)
    else n
  }
  
  println(check(x))
}

Measured memory_bytes: 25424
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
const int inf = 1012345678;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n,m,c; cin >> n >> m >> c;
    int b[m]; rep(i,m) cin >> b[i];
    int a[n][m]; rep(i,n) rep(j,m) cin >> a[i][j];
    
    int ans = 0;
    rep(i,n){
        int tmp = 0;
        rep(j,m) tmp += a[i][j]*b[j];
        tmp += c;
        if(tmp>0) ans++;
    }

    cout << ans << ln;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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



int N, M;
vector<P> v;

int main () {
  cin >> N >> M;
  Rep(i, M) {
    int a, b;
    cin >> a >> b;
    v.emplace_back(a, b);
  }

  sort(All(v), [](P& x, P& y){ 
    if (x.second == y.second) {
      return x.first < y.first;
    } else {
      return x.second < y.second; 
    }
  });

  int tmp = 0;
  int ans = 0;
  Rep(i, v.size()) {
    //cout << v[i].first <<v[i].second << tmp << "\n";

    if (v[i].first >= tmp) {
      ans++;
      tmp = v[i].second;
    }
  }

  cout << ans << "\n";

}

Measured memory_bytes: 3444
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979
#define MAXI 7500000

//.size()はunsigned int　0-1をするとオーバーフローする
 
using namespace std;
typedef long long int ll;
typedef pair< long long int , long long int> P;

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

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

struct edge{long long int to;
long long int cost;};

 
int main(void){

	int n,w[101];
	int front,back;
	int mini=INF;

	cin>>n;
	FOR(i,1,n){
		cin>>w[i];
	}

	FOR(i,1,n-1){
		front=0;
		back=0;
		FOR(j,1,i){
			front+=w[j];
		}
		FOR(j,i+1,n){
			back+=w[j];
		}
		mini=min(mini,abs(front-back));
	}

	cout<<mini<<endl;

}



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

int main (void){
    int a, b;
    int cnt = 0;
    cin >> a >> b;
    if(a == b){
        cout << a << endl;
    }else if(a < b){
        cout << a << endl;
    }else{
        cout << a - 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>

int bubbleSort(int n, int A[])
{
    int count = 0;
    int i, j;
    for (i = 0; i < n; i++) {
        for (j = n-1; j > 0; j--) {
            if (A[j-1] > A[j]) {
                int tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                count++;
            }
        }
    }
    return count;
}

int main()
{
    int i;
    int N;
    int A[100];
    scanf("%d", &N);
    for (i = 0; i < N ;i++) {
        scanf("%d", &A[i]);
    }
    
    int count = bubbleSort(N, A);
    for (i = 0; i < N ;i++) {
        if (i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n%d\n", count);
        
    return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b) {
    ll r;
    while(b) {
        r = b;
        b = a % b;
        a = r;
    }
    return a;
}
int n;
set<ll> num;
int main() {
    scanf("%d",&n);
    for(int i=0,pos;i<=n;i++)
        scanf("%d",&pos),
        num.insert(1ll*pos);
    ll las=0,ans;
    for(set<ll>::iterator it=num.begin();it!=num.end();it++){
        ll val=*it;
        if(!las) {las=val;continue;}
        if(las==*num.begin()) ans=val-las;
        else ans=GCD(ans,val-las);
        las=val;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define MOD 1000000007
const ll INF = 1e18;
template <class T>
void show(vector<T> v) {
  for (int i = 0; i < v.size(); i++) {
    cerr << v[i] << " ";
  }
  cerr << endl;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int m, n, q;
vector<int> a, b, c, d;
int ans;

// Aの末尾にM以下の数を追加していく
void dfs(vector<int> A) {
  if (sz(A) == n + 1) {
    int now = 0;
    rep(i, q) {
      if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
    }
    chmax(ans, now);
    return;
  }
  // Aの末尾に直前の数を基準に追加していく 入れられるのはm以下まで
  // そのためにdfsの最初にはvector<int>(1,1)をいれている
  //1-indexにもなるしちょうど都合がいい
  A.pb(A.back());
  while (A.back() <= m) {
    dfs(A);
    //末尾を+1して次の状態へ
    A.back()++;
  }
}

int main(int argc, char const* argv[]) {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  dfs(vector<int>(1, 1));
  cout << ans << endl;
  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n;
  	cin >> n;
  	vi p(n);
  	vi check(n,0);
  	
  	rep(i,n) {
      	cin >> p[i];
    	if(p[i] == i+1) check[i]=1;
    }
  	
  	int ans = 0;
  	
  	rep(i,n){
    	if(check[i]==1){
        	ans++;
          	i++;
        }
    }
  	
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m,q;
int a[51],b[51],c[51],d[51];
int num[11];
int ans;

void dfs(int v,int cn){
	if(v==n){
		int cnt=0;
		for(int j=0;j<q;j++){
			if(num[b[j]]-num[a[j]]==c[j]){
				cnt+=d[j];
			}
		}
		ans=max(ans,cnt);
		return;
	}
	for(int i=cn;i<=m;i++){
		num[v]=i;
		dfs(v+1,i);
	}
}

int main(void){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=0;i<q;i++){
		scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
		a[i]--;
		b[i]--;
	}
	num[0]=1;
	dfs(1,1);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3760
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end


a,b=gi

puts a <= b ? a : a-1


Measured memory_bytes: 2428
// #include <boost/multiprecision/cpp_int.hpp>
// using boost::multiprecision::cpp_int;
#include <bits/stdc++.h>
using namespace std;
// ¯\_(ツ)_/¯
#define f first
#define s second
#define p push
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define foi(i, a, n) for (i = (a); i < (n); ++i)
#define foii(i, a, n) for (i = (a); i <= (n); ++i)
#define fod(i, a, n) for (i = (a); i > (n); --i)
#define fodd(i, a, n) for (i = (a); i >= (n); --i)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define endl " \n"
#define newl cout<<"\n"
#define MAXN 100005
#define MOD 1000000007LL
#define EPS 1e-13
#define INFI 1000000000             // 10^9
#define INFLL 1000000000000000000ll //10^18
// ¯\_(ツ)_/¯
//#define l long int
//#define d double
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vll>
#define vvld vector<vector<ld>>

//vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of 10 rows and 20 columns, with value 500.
#define mii map<int, int>
#define mll map<long long, long long>
#define pii pair<int, int>
#define pll pair<long long, long long>

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

ll tc, n, m, k;
// ll ans = 0, c = 0;
// ll i, j;
// ll a, b;
// ll x, y;

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

    ll w;
    cin>>n>>w;
    vll weight(n, 0), price(n, 0);
    rep(i, 0, n) {
        cin>>weight[i];
        cin>>price[i];
    }
    vvll dp(n+1, vll(w+1, 0));
    rep(i, 1, n+1) {
        rep(j, 1, w+1) {
            if(j >= weight[i-1]) {
                dp[i][j] = max(dp[i-1][j], price[i-1] + dp[i-1][j-weight[i-1]]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
//    rep(i, 1, n+1)
//    rep(j, 1, w+1)
//    cout<<dp[i][j]<<endl[j==w];

    cout<<dp[n][w];


    return 0;
}

/*
2
4
0 1 0 1
5
0 0 1 0 0
*/

Measured memory_bytes: 80256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<int> B(N);
    vector<int> A(N);
    REP(i,N) cin>>A[i];
    int now = 0;
    REP(i,N) now ^= A[0]^A[i];
    B[0] = now^A[0];
    rep(i,1,N) B[i] = A[0]^A[i]^B[0];
    REP(i,N) cout<<B[i]<<" \n"[i+1==N];
}


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

int main(void){
    long n;
    cin >> n;
    vector<long> a(n), b(n);
    long sum=0;
    bool diff = false;
    long index=-1;
    long b_min=LONG_MAX;
    for(long i=0; i<n; i++){
        cin >> a[i] >> b[i];
        sum += a[i];
        if(a[i]!=b[i]){
            diff=true;
        }
        if(a[i]>b[i]){
            if(b[i]<b_min){
                b_min=b[i];
                index=i;
            }
        }
    }
    if(diff){
        cout << sum - b[index] << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 512
import copy
H, W, K = map(int, input().split())
map_info = [list(input()) for i in range(H)]
bits = H + W
count_total = 0
ans = 0

#行全パターン
for row in range(2 ** H):
    #列全パターン
    for column in range(2 ** W):
        map_updated = copy.deepcopy(map_info)
        count = 0
        #ある行パターンの中で何ビットずらすか
        for bit_row in range(H):
            count = 0
            # 行パターンをbit_rowビットだけずらして1なら赤く塗る
            if (row >> bit_row) & 1:
                map_updated[bit_row] = ['*' for i in map_updated[bit_row]]
        #ある列パターンの中で何ビットずらすか
        for bit_column in range(W):
            count = 0
            # 列パターンをbit_columnビットだけずらして1なら赤く塗る
            if (column >> bit_column) & 1:
                for j in range(H):
                    map_updated[j][bit_column] = '*'
        #黒マスカウント
        for i in range(H):
            count += map_updated[i].count('#')
        if count == K:
            ans += 1
print(ans)


Measured memory_bytes: 9264
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;


int main(){
    string s,ans;
    cin >> s;
    itrfor(itr,s){
        if(*itr == 'B'){
            if( ans.length() >=1) ans.erase( ans.end() -1);
        }
        else if( *itr == '0') ans += '0';
        else ans += '1';
    }
    cout << ans << endl;
}

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

int main() {
    int n, k;
    cin >> n >> k;

    double ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i >= k) {
            ans += (double)1;
            continue;
        }
        ans += (double)1 / pow(2,ceil(log2((double)k / i)));
    }
    ans /= (double)n;
    printf("%.10f", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
int n,i,j,k,s,aa[200005],vis[200005];
int main()
{
	scanf("%d",&n);
	rep(i,n)
	{
		scanf("%d",&aa[i]);
	}
	sort(aa+1,aa+n+1);
	for (k=1073741824;k>=2;k/=2)
	{
		i=1;j=n;
		while (i<j)
		{
			while (vis[i]) i++;
			while (vis[j]) j--;
			if (i>=j) break;
			if (aa[i]+aa[j]==k)
			{
				vis[i]=vis[j]=1;
				s++;
				i++;
				j--;
				continue;
			}
			if (aa[i]+aa[j]<k) i++;
			else if (aa[i]+aa[j]>k) j--;
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 1792
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial;

void main(){
    writeln(totalSum(readln.chomp));
}

long totalSum(string str){
    long total=0;
    foreach(i,s;str){
        auto num=[s].to!long;
        auto headPattern=2^^i;
        foreach(k;0..str.length-i){
            auto tailLength=str.length-i-1-k;
            auto tailPattern=tailLength==0?1:2^^(tailLength-1);
            total+=num*10^^k*headPattern*tailPattern;
        }
    }
    return total;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
 
int main(){
    int N;
    cin >> N;
    int ans = 0;
    int N_digits = 1+floor(log10(N));
    for (int i=1; i<=N; i++){
        // if (i<500){
        //     cout << i << " " << ans << endl;
        // }
        int digits = 1+floor(log10(i));
        int first = i/pow(10, digits-1);
        int last = i%10;
        if (last==0) continue;
        for (int j=1; j<N_digits; j++){
            //cout << "HERE" << endl;
            if (j==1) {
                if (first==last && first <= N){
                    ans++;
                }
            } else {
                //cout << "HERE" << endl;
                ans += pow(10, j-2);
            }
        }
        int min_pos;
        if (N_digits>1){
            min_pos = last*pow(10, N_digits-1) + first;
        } else {
            min_pos = first;
        }
        // if (i<500){
        //     cout << "i:" << i << " minpos" << min_pos << endl;
        // }
        ans += max(min(ceil(pow(10, N_digits-2)), ceil((N - min_pos + 1.)/10.)), 0.);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math

def calcPow(X):
    num = int(math.sqrt(X))
    Max = 0

    if(X <= 3):
        return X

    for i in range(2,num+1):
        for j in range(2,X):
            if(pow(i,j) > X):
                if(pow(i,j-1) > Max):
                    Max = pow(i,j-1)
                    break
                break

    return Max


if __name__ == '__main__':
    X = int(input())

    print(calcPow(X))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<vector<vector<int>>> dp(182, vector<vector<int>>(5, vector<int>(1 << 15, 0)));
  for (int i = 0; i <= 4; i++){
    dp[0][i][0] = 1;
  }
  for (int i = 0; i < 181; i++){
    for (int j = 0; j <= 4; j++){
      for (int k = 0; k < (1 << 15); k++){
        for (int l = 0; l <= 4; l++){
          if (j + l <= 4 && k + (i + 1) * (i + 1) * l < (1 << 15)){
            dp[i + 1][j + l][k + (i + 1) * (i + 1) * l] += dp[i][j][k];
          }
        }
      }
    }
  }
  while (1){
    int N;
    cin >> N;
    if (N == 0){
      break;
    }
    cout << dp[181][4][N] << endl;
  }
}


Measured memory_bytes: 123636
INF = 1000000
n = int(input())
t = [[int(i) for i in input().split()] for j in range(n)]
dp = [[-INF for i in range(3)] for j in range(n)]
for j in range(3):
    dp[0][j] = t[0][j]
a = [0, 1, 2]

for i in range(1, n):
    for j in range(3):
        k = list(set(a).difference(set([j])))
        dp[i][j] = max(dp[i - 1][k[0]], dp[i - 1][k[1]]) + t[i][j]

print(max(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]))


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

#define pb push_back
#define ll long long int
#define mpi map<int, int>
#define vi vector<int>
#define si set<int>
#define pii pair<int, int>
#define vpi vector<pii>
#define vs vector<string>
#define pri priority_queue<int>
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define For(i, n) for (int i = 0; i < n; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, x, y) for (int i = x; i <= y; i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

double tick()
{
    static clock_t oldt, newt = clock();
    double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
    oldt = newt;
    return diff;
}

int main()
{
    int n, k, d;
    cin >> n >> k;
    //ll ar[n];
    si s;
    For(i, k)
    {
        cin >> d;
        int x;
        For(i, d)
        {
            cin >> x;
            s.insert(x);
        }
    }
    cout << n - s.size() << endl;

    cerr << "execution time is: " << tick() << "\n";
}


Measured memory_bytes: 3728
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const LL mo=924844033;
const int N=2000;
int n,k;
LL f[N+10],g[N+10][N+10][2],h[N+10],fac[N+10];
int main() {
    scanf("%d%d",&n,&k);
    f[0]=1;
    for (int i=1;i<=k*2;i++) {
        g[0][0][0]=1;
        g[0][0][1]=0;
        int maxp=0;
        for (int j=i,p=1;j<=n;j+=k*2,p++) {
            maxp=max(maxp,p);
            for (int kx=0;kx<=p;kx++)
                g[p][kx][0]=g[p][kx][1]=0;
        }
        for (int j=i,p=1;j<=n;j+=k*2,p++)
            for (int kx=0;kx<p;kx++) {
                LL nowx=g[p-1][kx][0];
                if (j+k<=n) g[p][kx+1][1]=(g[p][kx+1][1]+nowx)%mo;
                if (j-k>0) g[p][kx+1][0]=(g[p][kx+1][0]+nowx)%mo;
                g[p][kx][0]=(g[p][kx][0]+nowx)%mo;
                nowx=g[p-1][kx][1];
                if (j+k<=n) g[p][kx+1][1]=(g[p][kx+1][1]+nowx)%mo;
                g[p][kx][0]=(g[p][kx][0]+nowx)%mo;
            }
        for (int j=0;j<=n;j++) h[j]=0;
        for (int j=0;j<=maxp;j++) {
            LL nowx=(g[maxp][j][0]+g[maxp][j][1])%mo;
            for (int kx=0;kx+j<=n;kx++)
                h[kx+j]=(h[kx+j]+f[kx]*nowx)%mo;
        }
        for (int j=0;j<=n;j++) f[j]=h[j];
    }
    fac[0]=1;
    for (int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mo;
    LL ans=0;
    for (int j=0;j<=n;j++) {
        if (j%2==0) ans=(ans+fac[n-j]*f[j]);
        else ans=(ans-fac[n-j]*f[j])%mo;
    }
    ans=(ans%mo+mo)%mo;
    printf("%lld\n",ans);
    return 0;
}


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





int main() 
{
	long long n;
	cin >> n;
	long long s = (long long)sqrt(n);
	long long i = 0;
	long long j = 0;
	for (i = s; i > 1; i--)
	{
		if(n % i == 0)
		{
			j = n / i;
			break;
		}
	}
	if (i == 1)
		j = n;
	string str = to_string(j);
	cout << str.size();
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static String solve(String x) {
        String rev = "";
        for (int i = 2; i >= 0; i--){
            rev += x.charAt(i);
        }
        return (x.equals(rev) ? "Yes": "No");
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = in.next();
        System.out.println(solve(s));
    }
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	VI v(m), p(m);
	rep(i, m){
		int k, s;
		cin >>k;
		rep(j, k){
			cin >>s; v[i] |= (1<<(s-1));
		}
	}
	rep(i, m) cin >>p[i];
	
	ll ans =0;
	rep(msk, 1<<n){
		bool ok =true;
		rep(j, m){
			int z = __builtin_popcount(msk & v[j]);
			if(p[j] != z%2) ok= false;
		}
		if(ok) ans++;
	}

	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
bool prime(int n){
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0)return false;
    }
    return n!=1;
}
int gcd(int x,int y){
    if(x<y)swap(x,y);
    if(y==0)return x;
    return (y,x%y);
}
int lcm(int x,int y){
    return x*y/gcd(x,y);
}
int kai(int n){
    if(n==0)return 1;
    return kai(n-1)*n;
}
int mod_pow(int x,int y,int mod){
    int res=1;
    while(y>0){
        if(y&1){
            res=res*x%mod;
        }
        x=x*x%mod;
        y>>=1;
    }
    return res;
}
int a,b,ans=1,ma;
map<int,int>mp;
int solve(int n){
    for(int i=2;i<=sqrt(n);i++){
        if(!prime(i))continue;
        while(n%i==0){
            mp[i]++;
            n/=i;
        }
        ans*=pow(i,mp[i]/a);
    }
    if(n!=1)mp[n]=1;
    ans*=pow(n,mp[n]/a);
    return ans;
}
signed main(){
    cin>>a>>b;
    cout<<solve(b)<<endl;
}

Measured memory_bytes: 2432
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private int N;
    private int W;
    private int[] w;
    private int[] v;

    private Map<String, Long> memo = new HashMap<>();

    private void solve(Scanner sc) {
        N = sc.nextInt();
        W = sc.nextInt();
        w = new int[N];
        v = new int[N];
        for (int i = 0; i < N; ++i) {
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }

        _out.println(calc(0, 0));
    }
    private long calc(int d, long weight) {
        String key = d + ":" + weight;
        if (d >= N) {
            return 0;
        }
        if (memo.containsKey(key)) {
            return memo.get(key);
        }

        long v1 = 0;
        if (weight + w[d] <= W) {
            v1 = calc(d + 1, weight + w[d]) + v[d];
        }
        long v2 = calc(d + 1, weight);
        long vr = Math.max(v1, v2);
        memo.put(key, vr);
        return vr;
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

int main() {
	int sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;
	int dx=tx-sx, dy=ty-sy;
	cout<<string(dy,'U')<<string(dx,'R');
	cout<<string(dy,'D')<<string(dx,'L');
	cout<<'L'<<string(dy+1,'U')<<string(dx+1,'R')<<'D';
	cout<<'R'<<string(dy+1,'D')<<string(dx+1,'L')<<'U';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define tam 100347
#define offset 50000
using namespace std;
typedef long long  ll;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
const ll INF=1e11;
ll dp[51][tam];
ll val[500];
ll n;

ll go(ll pos,ll suma)
{
    if (pos==n)
    {
        if (suma==offset)
            return 1;
        return 0;
    }
    if (dp[pos][suma]!=-1)
        return dp[pos][suma];
    ll tot=go(pos+1,suma+val[pos]);
    tot+=go(pos+1,suma);
    //cout<<tot<<" "<<pos<<endl;
    return dp[pos][suma]=tot;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    ll a;
    cin>>n>>a;
    forr(i,0,n)
    {
        cin>>val[i];
        val[i]-=a;
        //cout<<val[i]<<" ";
    }
    //cout<<endl;
    memset(dp,-1,sizeof dp);
    cout<<go(0,offset)-1<<endl;
}


Measured memory_bytes: 40192
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <chrono>
#include <utility>
#include <string>
#include <cmath>

#define rep(i, n, m) for(int i = (n); (i) < (m); (i)++)
#define len(arr) sizeof(arr) / sizeof(*arr)

using namespace std;

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

    long double x, y;
    cin >> x >> y;
    long long int ans = log2(y / x) + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll r, g, b, k; cin >> r >> g >> b >> k;
  rep(i, k)
  {
    if(r >= g) g *= 2;
    else b *= 2;
  }
  if(r < g&&g < b) fin("Yes");
  fin("No");
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(4); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
# input
a = input()
num = [int(a) for a in input().split()]
# Odd or Even
counter = 0
while True:
    b = list(map(lambda x: x % 2, num))
    if sum(b) == 0:
        num = list(map(lambda x: x/2, num))
        counter += 1
    else:
        print(counter)
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

int keta(int x,int base = 10){
	int ret = 0;
	while(x){
		x /= base;
		ret++;
	}
	return ret;
}

signed main(){
	int n,k;
	cin >> n >> k;
	cout << keta(n,k) << endl;
}

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

int main()
{
	vector<int> a(3);
	cin >> a.at(0) >> a.at(1) >> a.at(2);

	sort(a.begin(), a.end());
	cout << a.at(2) - a.at(1) + a.at(1) - a.at(0) << endl;
}

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

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

  int x, y, z;
  cin >> x >> y >> z;

  printf("%d %d %d\n", z, x, y);

  return (0);
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MXX = 1e6 + 5;


int main ()
{
    string s; cin>>s;
    string str = "";
    for(int i = 0; i<s.size(); i++)
    {
        if(s[i] == '0')
        {
            str+='0';
        }
        else if(s[i] == '1')
        {
            str+='1';
        }
        else
        {
            int x = str.size();
           if(str.size()>=1) str.erase(x-1, 1);
        }
    }
    cout<<str<<endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector <long> time(n), dead(n);
    rep(i,n) cin >> time[i] >> dead[i];

    vector <pair <long,long> > set(n);
    rep(i,n) set[i].first = dead[i], set[i].second = time[i];

    sort(all(set));

    long sum=0;
    bool ok=true;

    for(int i=0; i<n; i++){
        sum += set[i].second;
        if(sum > set[i].first){
            ok=false;
            break;
        }
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define MOD 998244353

struct BIT {
	std::vector<int> data;
	int n;
	BIT(int n) {
		this->n = n;
		data.resize(n + 1);
	}
	void add(int i, int val) {
		for (i++; i <= n; i += i & -i) data[i] += val;
	}
	int sum(int i) {
		int res = 0;
		for (; i; i -= i & -i) res += data[i];
		return res;
	}
};

char buf[5000000];
char *p = buf;
int ri() {
	int r = 0, s = 0;
	for (;;) {
		if (*p == '-') {
			s = 1;
			break;
		}
		if (*p <= '9' && *p >= '0') {
			r = *p - '0';
			break;
		}
		p++;
	}
	p++;
	for (;;) {
		if (*p < '0' || *p > '9') break;
		r = r * 10 + *p - '0';
		p++;
	}
	p++;
	if (s) r = -r;
	return r;
}

void radix_sort(std::pair<int, int> *x, int n) {
	int c[256] = { 0 };
	std::pair<int, int> *r0 = (std::pair<int, int> *) malloc(sizeof(std::pair<int, int>) * n);
	assert(r0);
	for (int i = 0; i < n; i++) c[x[i].first & 0xFF]++;
	for (int i = 1; i < 256; i++) c[i] += c[i - 1];
	for (int i = n - 1; i >= 0; i--) r0[--c[x[i].first & 0xFF]] = x[i];
	memset(c, 0, sizeof(c));
	for (int i = 0; i < n; i++) c[r0[i].first >> 8 & 0xFF]++;
	for (int i = 1; i < 256; i++) c[i] += c[i - 1];
	for (int i = n - 1; i >= 0; i--) x[--c[r0[i].first >> 8 & 0xFF]] = r0[i];
	memset(c, 0, sizeof(c));
	for (int i = 0; i < n; i++) c[x[i].first >> 16 & 0xFF]++;
	for (int i = 1; i < 256; i++) c[i] += c[i - 1];
	for (int i = n - 1; i >= 0; i--) r0[--c[x[i].first >> 16 & 0xFF]] = x[i];
	memset(c, 0, sizeof(c));
	for (int i = 0; i < n; i++) c[r0[i].first >> 24 & 0xFF]++;
	for (int i = 1; i < 256; i++) c[i] += c[i - 1];
	for (int i = n - 1; i >= 0; i--) x[--c[r0[i].first >> 24 & 0xFF]] = r0[i];
	for (int i = 1; i < n; i++) assert(x[i].first >= x[i - 1].first);
	free(r0);
}

int main() {
	fread(buf, 1, 5000000, stdin);
	int n = ri();
	std::pair<int, int> a[n];
	for (int i = 0; i < n; i++) {
		int x = ri() + 1000000000;
		int y = ri() + 1000000000;
		a[i] = {y, x};
	}
	
	int b2[n + 3];
	b2[0] = 1;
	for (int i = 1; i <= n + 2; i++) {
		b2[i] = b2[i - 1] + b2[i - 1];
		if (b2[i] >= MOD) b2[i] -= MOD;
	}
	
	radix_sort(a, n);
	for (int i = 0; i < n; i++) a[i] = {a[i].second, i};
	radix_sort(a, n);
	
	BIT tree(n);
	int64_t res = 0;
	for (int i = 0; i < n; i++) {
		int v = tree.sum(a[i].second);
		res += b2[v];
		res += b2[i - v];
		res += b2[a[i].second - v];
		res += b2[n - a[i].second - 1 - i + v];
		
		tree.add(a[i].second, 1);
	}
	res += (int64_t) (b2[n] - 1) * n;
	res -= b2[n + 2] - 4;
	std::cout << res % MOD << std::endl;
	return 0;
}


Measured memory_bytes: 8292
use std::collections::BTreeSet;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: i32 = read();
    let mut kuku = BTreeSet::new();

    for i in 1..10 {
        for j in 1..10 {
            kuku.insert(i * j);
        }
    }

    let ans = if kuku.iter().find(|&&x| x == n).is_some() {
        "Yes"
    } else {
        "No"
    };

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
import scala.annotation.tailrec
object Main extends App {
  import scala.io.StdIn._


  val n = readInt
  val a = Array.tabulate(n){_ ⇒ readLine.trim.toInt}
  println(
    math.max(calMaxDecrease(a), calMaxIncrease(a))
  )
  def calMaxIncrease(a: Array[Int]): Int = {
    @tailrec
    def sub(a: Array[Int], pos: Int = 0, prev: Int = -1, length: Int = 0, maxLength: Int = 0): Int = {
      if (a.length == pos) math.max(length, maxLength)
      else if (a(pos) > prev) sub(a, pos + 1, a(pos), length + 1, maxLength)
      else if (a(pos) == prev) sub(a, pos + 1, prev, length, maxLength)
      else sub(a, pos, -1, 0, math.max(length, maxLength))
    }
    sub(a)
  }
  def calMaxDecrease(a: Array[Int]): Int = {
    @tailrec
    def sub(a: Array[Int], pos: Int = 0, prev: Int = Int.MaxValue, length: Int = 0, maxLength: Int = 0): Int = {
      if (a.length == pos) math.max(length, maxLength)
      else if (a(pos) < prev) sub(a, pos + 1, a(pos), length + 1, maxLength)
      else if (a(pos) == prev) sub(a, pos + 1, prev, length, maxLength)
      else sub(a, pos, Int.MaxValue, 0, math.max(length, maxLength))
    }
    sub(a)
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}


Measured memory_bytes: 59652
#include <iostream>

const int MAX = 100000;
const int NIL = -1;

struct Node {
  int parent;
  int left;
  int right;
};

Node T[MAX];
int D[MAX];
int C[MAX];
int n;

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

  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
    D[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    int id, k;
    std::cin >> id >> k;
    for (int j = 0; j < k; ++j) {
      std::cin >> C[j];
      T[C[j]].parent = id;
      if (j == 0) T[id].left = C[j];
      else T[C[j-1]].right = C[j];
    }
  }

  for (int i = 0; i < n; ++i) {
    int id = i;
    while (T[id].parent != NIL) {
      ++D[i];
      id = T[id].parent;
    }
  }

  for (int i = 0; i < n; ++i) {
    int id = i;
    int child = T[id].left;
    std::cout << "node " << id << ": ";
    std::cout << "parent = " << T[id].parent << ", ";
    std::cout << "depth = " << D[id] << ", ";
    if (T[id].parent == NIL) std::cout << "root, ";
    else if (child == NIL) std::cout << "leaf, ";
    else std::cout << "internal node, ";
    std::cout << "[";
    int j = 0;
    while (child != NIL) {
      if (j) std::cout << ", ";
      std::cout << child;
      child = T[child].right;
      ++j;
    }
    std::cout << "]\n";
  }

  return 0;
}



Measured memory_bytes: 5052
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=500500;
char s[N];
int dep[N];
int n;
int dfs(int x){
	if(dep[x]!=-1){
		return dep[x];
	}
	dep[x]=0;
	if(x-1>=0&&s[x-1]=='<'){
		dep[x]=max(dep[x],dfs(x-1)+1);
	}
	if(x<n&&s[x]=='>'){
		dep[x]=max(dep[x],dfs(x+1)+1);
	}
	return dep[x];
}
int main(){
	memset(dep,-1,sizeof(dep));
	scanf("%s",s);
	n=strlen(s);
	LL sum=0;
	for(int i=0;i<=n;i++){
		sum+=dfs(i);
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 18304
a,b,c,x,y = map(int, input().split())
ab = a*x + b*y
if min(x,y) == x:
    abc = c*x*2 + (y-x) * b
else:
    abc = c*y*2 + (x-y) * a
all_c = max(x,y) * c * 2
print(min(ab, abc, all_c))

Measured memory_bytes: 9148