akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int par[100010];
int rnk[100010];
int p[100010];

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        rnk[i]=0;
    }
}

int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(rnk[x]<rnk[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(rnk[x]==rnk[y])rnk[x]++;
    }
}

bool same(int x,int y){
    return find(x)==find(y);
}

int main(){
    int N,M;
    cin>>N>>M;
    for(int i=1;i<=N;i++){
        cin>>p[i];
    }
    init(N+1);
    for(int i=0;i<M;i++){
        int x,y;
        cin>>x>>y;
        unite(x,y);
    }
    int ans=0;
    for(int i=1;i<=N;i++){
        if(same(p[i],i))ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

const int N = (int)1e5 + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e13;
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int n, w;
ll a[N], b[N], dp[103][N];
int main ()
{
    scanf ("%d %d", &n, &w);
    for (int i = 1; i <= n; ++i)
    {
        scanf ("%lld %lld", a + i, b + i);
    }
    dp[1][a[1]] = b[1];
    for (int i = 2; i <= n; ++i)
    {
        for (int j = 0; j <= w; ++j)
        {
            dp[i][j] = max(dp[i - 1][j], dp[i][j]);
            if (j - a[i] >= 0)
            {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i]] + b[i]);
            }
        }
    }
    ll ans = 0;
    for (int j = 0; j <= w; ++j) ans = max(ans, dp[n][j]);
    printf ("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 80640
#include <bits/stdc++.h>
//#define fisier 1
using namespace std;
typedef long long ll;
const double dancila = 3.14159265359;
bool compara(int a, int b){
	if (a < b) return false;
	return true;
}
int main(){
	#ifdef fisier
        ifstream cin("input.in");
        ofstream cout("output.out");
    #endif	
		
	ios_base::sync_with_stdio();
	cin.tie(0);
	
	long long n, k;
	cin >> n >> k;
	n %= k;
	if (n <= abs(n-k)){
	}else {
		n = abs(n-k);
	}
	cout << n;
}


Measured memory_bytes: 3596
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
 
        Scanner scanner = new Scanner(System.in);
 
        int vacation = scanner.nextInt();
        int homeworkNumber = scanner.nextInt();
        int studyDay = 0;
 
        for (int i = 0; i < homeworkNumber; i++) {
            studyDay += scanner.nextInt();
        }
 
        int playable;
      
        playable = vacation - studyDay;
 
        if (playable >= 0) {
            
            System.out.println(playable);
        } else {
            System.out.println("-1");
        }
 
        scanner.close();
 
    }
 
}

Measured memory_bytes: 46020
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a+b<10)
	{
		cout<<a+b;
	 } 
	 else
	 {
	 	cout<<"error";
	 }
	return 0;
 } 


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
const int mod = 1e9+7;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
ll n;
typedef pair<int,int> pa;
map<pa,int> mp;
inline int add(int a,int b){a+=b;if(a>=mod) a-=mod;return a;}
inline int DFS(ll a,ll b){
	if(b<0) return 0;
	if(b==0) return 1;
	if(mp.count(mk(a,b))) return mp[mk(a,b)];
	int res=0;
	res=add(res,DFS(a>>1,b>>1));
	res=add(res,DFS((a-1)>>1,(b-1)>>1));
	if(b>=2) res=add(res,DFS(a>>1,(b-2)>>1));
	return mp[mk(a,b)]=res;
}
int main()
{
	cin>>n;
	cout<<DFS(n,n);
	return 0;
}

Measured memory_bytes: 256
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; cin>>___T; for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6+10;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9+7;
void add(int &a,int b) {a+=b; if(a>=mod) a-=mod;}
void dec(int &a,int b) {a-=b; if(a<0) a+=mod;}
int main()
{
    ll n;
    ll ans = 0;
    cin >> n;
    for(int i = 1; i <= n; i++)
    if(i % 3 != 0 && i % 5 != 0)
    ans+=i;
    cout << ans << endl;
    
}

Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main(void){
    
    int len_num, len;
    int max, sum;
    int len_array[] = {};
    
    cin >> len_num;
    
    max = 0;
    sum = 0;
    
    for (int i = 0; i < len_num; i++){
        
        cin >> len;
        
        sum += len;
        
        if (len > max) max = len;
        
    }
    
    sum = sum - max;
    
    if (sum > max) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <math.h>
#include <cmath>
#include <limits>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#define INF 1000000000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long int ll;
using namespace std;

int main() {

	int a; cin >> a;
	if (a % 2 == 0) { cout << a / 2 << endl; }
	else { cout << a / 2 + 1 << endl; }

	return 0;
}

Measured memory_bytes: 256
# N,M = map(int, input().split())
a = [0] * 5
a[0] = int(input())
a[1] = int(input())
a[2] = int(input())
a[3] = int(input())
a[4] = int(input())
k = int(input())


ok = True
for i in range(4):
    if a[i+1] - a[i] > k :
        ok = False
        break
if  a[4] - a[0] > k:
    print(":(")
else:
    print("Yay!")


Measured memory_bytes: 3064
#include <stdio.h>
int main(void){
  char ox;
  int price=700;
  scanf("%c",&ox);
  if(ox=='o')price+=100;
  scanf("%c",&ox);
  if(ox=='o')price+=100;
  scanf("%c",&ox);
  if(ox=='o')price+=100;
  printf("%d",price);
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        // 入力
        Scanner sc = new Scanner(System.in);
        long[] x = new long[5];
        long n = sc.nextLong();
        if (n==9) System.out.println(0);
        x[0] = sc.nextLong();
        x[1] = sc.nextLong();
        x[2] = sc.nextLong();
        x[3] = sc.nextLong();
        x[4] = sc.nextLong();
        long count = 0;

        Arrays.sort(x);
        if (n % x[0] == 0) {
            count = n / x[0];
        } else {
            count = n / x[0] + 1;
        }
        count += 4;

        System.out.println(count);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define N 2010
typedef long long ll;
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
using namespace std;
const int P = 1e9 + 7;
inline ll quickpow(ll x, int k) {
	ll res = 1;
	while (k) {
		if (k & 1)	res = res * x % P;
		x = x * x % P;
		k >>= 1;
	}
	return res;
}
int n, m;
ll X;
struct Edge{
	int u, v, w;
}E[N];
bool cmp(const Edge &a, const Edge &b) {
	return a.w < b.w;
}
int cnt, Cnt;
int fa[N];
int find(int cur) {
	return fa[cur] == cur ? cur : fa[cur] = find(fa[cur]);
}
inline ll calc(int id) {
	ll res = E[id].w;
	for (int i = 1; i <= n; ++i)	fa[i] = i;
	fa[E[id].u] = E[id].v;
	for (int i = 1, ct = 0; i <= m && ct < n - 1; ++i) if (i != id) {
		int u = E[i].u, v = E[i].v, w = E[i].w;
		u = find(u), v = find(v);
		if (u == v)	continue;
		fa[u] = v; res += w; ++ct;
	}
	return res;
}
int main() {
	read(n), read(m), read(X);
	for (int i = 1; i <= m; ++i) {
		int u, v, w; read(u), read(v), read(w);
		E[i] = (Edge){u, v, w};
	}
	sort(E + 1, E + 1 + m, cmp);
	ll mn = calc(0);
	if (mn > X) {
		puts("0");
		return 0;
	}
	for (int i = 1; i <= m; ++i) {
		ll tmp = calc(i);
		if (tmp > X)	++Cnt;
		else if (tmp == X)	++cnt;
	}
	if (mn == X) {
		printf("%lld\n", ((quickpow(2, cnt) - 2) * quickpow(2, Cnt) % P + P) % P);
		return 0;
	}
	ll ans = 2ll * (quickpow(2, cnt) - 1) * quickpow(2, Cnt) % P;
	printf("%lld\n", (ans % P + P) % P);
	return 0;
}


Measured memory_bytes: 3272
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

class Main {
	
	static class InsertionSort {
		public void insertionsort (InputReader ir) {
			
			int n = ir.nextInt();
			int array[] = new int[n];
			StringBuilder sb = new StringBuilder ();
			
			//配列入力
			for (int i = 0; i < n; i++ ) {
				array[i] = ir.nextInt();
				
				if (i != 0) sb.append(" ");
				sb.append(array[i]);
			}
			
			System.out.println(sb);
			sb.setLength(0);
		
			//挿入ソート
			for (int i = 1; i < n; i++) {
				int v = array[i];
				int j = i - 1;
				
				while ( j >= 0 && array[j] > v) {
					array[j + 1] = array[j];
					j--;
				}
				array[j + 1] = v;
				
				for (int k = 0; k < n; k++ ) {
					if (k != 0) sb.append(" ");
					sb.append(array[k]);
				}
				System.out.println(sb);
				sb.setLength(0);
			}
			
			
		}
	}
	
	static class InputReader {
		BufferedReader br;
		StringTokenizer st;
		
		public String nextString() {
			
			 while (!st.hasMoreTokens()) {
	                try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                }
	            }
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(nextString());
		}
					
		public InputReader (InputStream inputStream) {
			br = new BufferedReader (new InputStreamReader (inputStream));
			st = new StringTokenizer ("");
		}
		
	}
	
	public static void main (String[] args) {
		InputStream inputStream = System.in;
		InputReader in = new InputReader (inputStream);
		InsertionSort obj = new InsertionSort ();
		obj.insertionsort (in);
	}
	
}



Measured memory_bytes: 26416
<?php

    $N = intval(trim(fgets(STDIN)));
    
    $A_array = array_map('intval',explode(" ",trim(fgets(STDIN))));
    
    sort($A_array);
    
    // var_dump($A_array);
    
    //配列の前後の値が同じかどうか調べていく200000なので全探査可能
    for($i=0;$i<$N-1;$i++){
        if($A_array[$i] == $A_array[$i+1]){
            echo "NO\n";
            exit;
        }
    }
    echo "YES\n";
    
?>

Measured memory_bytes: 38096
#include <bits/stdc++.h>
#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 OUT(s) cout << s << "\n";
using namespace std;

string S,T;
// https://atcoder.jp/contests/abc167
void Main()
{
    if (1<=S.length() && 10>=S.length() && S == T.substr(0, (T.length()-1))) {
        OUT("Yes");
    } else {
        OUT("No");
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    cin >> S >> T;
    Main();
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define vec vector
#define ref(a) &(a)

typedef long long ll;

using namespace std;

int k, s;

int solve() {
  int ans = 0;
  rep(x, k+1) rep(y, k+1) {
    int z = s - x - y;
    if (z < 0) break;
    if (z <= k) ans++;
  }
  return ans;
}

int main() {
  cin >> k >> s;
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]

# エントリーポイント
def main():
    A, B = input(int, int)

    cur, c = 1, 0
    while cur < B:
        cur = cur - 1 + A
        c += 1
        if B <= cur:
            break
    print(c)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


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

using namespace std;

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

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

long long int gcd(long long int a,long long int b){
	while(b){
		a%=b;
		swap(a,b);
	}
	return a;
}

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

	cin>>L>>R;
	K=gcd(L,R);
	int ans=1;
	for(long long int i=2;i*i<=K;i++){
		if(K%i)continue;
		ans++;
		while(K%i==0)K/=i;
	}
	if(K>1)ans++;
	cout<<ans<<endl;
	return 0;
}

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

int n,arr[13],sum=0;

void recur(int curr,int product){
    if(curr<n){
        for(int i=-1 ; i <= 1 ;i++){
            recur(curr+1,product*(arr[curr]+i) );
        }
    }
    else {
        if(product%2==0){
            sum+=1;
        }
    }
}


int main(){
    scanf("%d",&n);
    for(int i= 0 ; i < n ; i++){
        scanf("%d",&arr[i]);
    }
    recur(0,1);
    printf("%d",sum);

}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] t = new int[10];
    int[] s = new int[10];

    for(int i=0;i<10;i++){
      t[i] = sc.nextInt();
    }
    for(int i=0;i<10;i++){
      s[i] = sc.nextInt();
    }

    Arrays.sort(t);
    Arrays.sort(s);

    System.out.println((t[9] + t[8] + t[7]) + " " + (s[9] + s[8] + s[7]));
  }
}

Measured memory_bytes: 12000
n,k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

dp = [False]*(k+1)


for i,x in enumerate(dp):
    if not x:        
        for ai in a:
            if i+ai <= k:dp[i+ai] = True
    

if dp[k]:print('First')
else : print('Second')

Measured memory_bytes: 3828
#include<stdio.h>

int main(void)
{
    int a, b, k;

    scanf("%d%d%d", &a, &b ,&k);

    for (int i = a; b >= i; i++) {
        if ((a+k > i) || (b-k) < i) {
            printf("%d\n", i);
        }
    }
}

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

int gcd(int x,int y){
  if(x%y==0) return y;
  else{
    int z=x%y;
    return gcd(y,z);
  }
}

int main()
{
  int a,b;
  int g;
  long int l;
  while(cin >> a >> b){
  
    if(a>b) g=gcd(a,b);
    else if(a<b) g=gcd(b,a);
    else g=a;

    l=(long int)a*b/g;
    cout << g << " " << l << endl;
  }

  return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int num = 0;
  for (int i=0; i<N-2; i++) {
    if (S.at(i)=='A'&&S.at(i+1)=='B'&&S.at(i+2)=='C') num++;
  }
  cout << num << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
energy = sorted([tuple(map(int,input().split())) for _ in range(n)])
ret = 0
ind = 0
while(m):
  a,b = energy[ind]
  if b > m:
    ret += a * m
    m = 0
  else:
    ret += a * b
    m -= b
  ind += 1
print(ret)

Measured memory_bytes: 17756
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#define int long long int

//O(n*k)
signed main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	int n, k;
	std::cin >> n >> k;
	std::vector<int> h;
	for (int j = 0; j < n; j++)
	{
		int m;
		std::cin >> m;
		h.push_back(m);
	}

	std::vector<int> dp;
	dp.push_back(0);
	for (int j = 1; j < n; j++)
	{
		int m = dp[j - 1] + std::abs(h[j - 1] - h[j]);
		int c = 0;
		for (int i = j - 1; i >=std::max(j-k, c); i--)
		{
			m = std::min(m, dp[i] + std::abs(h[j] - h[i]));
		}
		dp.push_back(m);
	}
	std::cout << dp[n - 1];
	return 0;

}


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

using namespace std;

int main()
{
    int n,i,p=0;
    string s;
    cin>>n>>s;
    if(n%2==0)
    {
        for(i=0; i<n/2; i++)
            if(s[i]!=s[n/2+i])
            {
                p=1;
                break;
            }
        if(p==0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    else
        cout <<"No"<< endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

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

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	int a[3],b[3];
	rep(i,3) std::cin >> a[i];
	rep(i,3) std::cin >> b[i];
	int m;
	{
		std::vector<int> dp(n+1);
		std::iota(all(dp),0);
		rep(i,3) {
			rep(j,n) {
				if(j+a[i]>n) continue;
				dp[j+a[i]]=std::max(dp[j+a[i]],dp[j]+b[i]);
			}
		}
		m=dp[n];
	}
	std::vector<int> dp(m+1);
	std::iota(all(dp),0);
	rep(i,3) {
		rep(j,m) {
			if(j+b[i]>m) continue;
			dp[j+b[i]]=std::max(dp[j+b[i]],dp[j]+a[i]);
		}
	}
	print(dp[m]);

	return 0;
}


Measured memory_bytes: 195584
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_cnt = 0
b_cnt = 0
for i in range(n):
    if a[i] > b[i]:
        b_cnt += (a[i] - b[i])
    elif a[i] < b[i]:
        k  = (b[i] - a[i])
        if k % 2 == 0:
            a_cnt += k//2
        else:
            b_cnt += 1
            a_cnt += (k+1)//2
if a_cnt >= b_cnt:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 4596
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
	int n,a,b;
	cin>>n>>a>>b;
	vector<int> v(n);
	rep(i,n)cin>>v[i];
	
	int ans = 0;
	
	rep(i,n){
		if(v[i]>=b || v[i]<a)ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
//int a[200005], b[200005];
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    int v = 1<<28;
    int ans = 0;
    for ( int v = (1<<28); v; v>>=1) {
        // 上位bitから順に判定
        rep(i, n) a[i] &= (v * 2 - 1);
        rep(i, n) b[i] &= (v * 2 - 1);
//        sort(a, a+n); sort(b, b+n);
        sort(a.begin(), a.end()); sort(b.begin(), b.end());
        int t = 0;
        for ( int i = n - 1, j = 0, k = 0, l = 0; i >= 0; i-- ) {
            while( j < n && a[i]+b[j] < v) j++;
            while( k < n && a[i]+b[k] < 2 * v) k++;
            while( l < n && a[i]+b[l] < 3 * v) l++;
            t += k + ( n - j - l);
            t &= 1;
        }
        if (t) ans |= v;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
/*“Dengan menyebut nama Allah yang Maha Pengasih lagi Maha Penyayang”*/
/*“In the name of Allah, Most Gracious, Most Merciful”*/
/*Link Problem : */
/*Author : Althafa Dhia Syauqi */
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef uint64_t uint64;
typedef int64_t  int64;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_n(i,n) for(int i=1;i<=(n);i++)
#define endl '\n'
#define mod 1e9+7
#define pb push_back
using namespace std;
void optimization()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
uint64 a,b;
int main()
{
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	gunakan saat OJ membutuhkan file eksternal */
	optimization();
   	cin >> a>>b;
  	if((a+b)-2*((a+b)/2)==0)
      cout << (a+b)/2<<endl;
  	else
      cout << "IMPOSSIBLE"<<endl;
    return 0;
}


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

#define sz(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
////////////////////
int const N = 10;

string s[N];
int h, w;
int was[N][N];
int cn = 0;

void dfs(int y, int x){
	if(was[y][x]) return;
	was[y][x] = 1;
	if(x + 1 < w && s[y][x+1] == '#') dfs(y, x+1);
	if(y + 1 < h && s[y+1][x] == '#') dfs(y+1, x);
}

void solve(){
	cin >> h >> w;
	rep(i, 0, h) cin >> s[i];
	cn = h - 1 + w - 1 + 1;
	rep(i, 0, h) rep(j, 0, w) if(s[i][j] == '#') --cn;
	dfs(0, 0);
	
	
	if(cn == 0 && was[h-1][w-1]) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}

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

	solve();

	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

string replaceOtherStr(std::string &replacedStr, std::string from, std::string to) {
    const unsigned int pos = replacedStr.find(from);
    const int len = from.length();
 
    if (pos == std::string::npos || from.empty()) {
        return replacedStr;
    }
 
    return replacedStr.replace(pos, len, to);
}

string replaceAll(std::string &replacedStr, std::string from, std::string to) {
    unsigned int pos = replacedStr.find(from);
    int toLen = to.length();
 
    if (from.empty()) {
        return replacedStr;
    }
 
    while ((pos = replacedStr.find(from, pos)) != std::string::npos) {
        replacedStr.replace(pos, from.length(), to);
        pos += toLen;
    }
    return replacedStr;
}

int main()
{
    cout << fixed << setprecision(15);
    string s;
    cin >> s;

    // cout << s << endl;

    // string s = "a, b, c";     // 置換対象の文字列
    string target = "BC";     // 検索文字列
    string replacement = "D"; // 置換文字列

    if (!target.empty()) {
        string::size_type pos = 0;
        while ((pos = s.find(target, pos)) != std::string::npos) {
            s.replace(pos, target.length(), replacement);
            pos += replacement.length();
        }
    }

    ll N = s.length();
    ll acount = 0;
    ll ans = 0;
    REP(i, N){
        if(s[i] == 'A'){
            acount++;
        }
        else if(s[i] == 'D'){
            ans += acount;
        }
        else{
            acount = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3748
#include<stdio.h>
#include<string.h>

int main(){
	int n, m;
	int i, j, k, t;
	int ans = 0;
	scanf("%d %d", &n, &m);
	for(i = 0; i <= n; i++)
		for(j = 0; j <= n; j++){
			t = m - i - j;
				if(t >= 0 && t <= n) ans++;
		}
	printf("%d\n", ans);
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li a, b, n;

int main() {
    cin >> a >> b >> n;
    if (b > n) {
        cout << (a * n) / b << endl;
        return 0;
    }
    n = b - 1;
    cout << (a * n) / b << endl;

    return 0;
}

Measured memory_bytes: 3636
H,W = map(int,input().split())
c = [list(map(int,input().split())) for _ in [0]*10]
A = [list(map(int,input().split())) for _ in [0]*H]

n = [0]*10
for row in A:
    for a in row:
        if a != -1:
            n[a] += 1
n[1] = 0

def get_cost(n,tmp_cost = None):
    if cost[n] != None:
        return cost[n]
    if tmp_cost == None:
        tmp_cost = c[n][1]
    ret = tmp_cost
    for i in range(10):
        if i == n:
            continue
        if c[n][i] < tmp_cost:
            ret = min(ret,get_cost(i,tmp_cost-c[n][i])+c[n][i])
    if ret < tmp_cost:
        cost[n] = ret
    return ret

cost = [None]*10
cost[1] = 0
ans = 0
for i,ni in enumerate(n):
    if ni > 0:
        ans += ni * get_cost(i)
print(ans)

Measured memory_bytes: 3444
# 写経

n = int(input())
lst_F = [list(map(int, input().split())) for _ in range(n)]
lst_P = [list(map(int, input().split())) for _ in range(n)]


ans = -float("INF")
for b in range(1, 2**10):
    tmp = 0
    for i in range(n):
        c = 0
        for k in range(10):
            if b&(1<<k) and lst_F[i][k]:
                c += 1
        tmp += lst_P[i][c]
    ans = max(tmp, ans)


print(ans)

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

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

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    // ostr << p.first << ", " << p.second;
    ostr << "(" << p.first << ", " << p.second << ")";
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll v(n); v[i]=x;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll v(m,vll(n)); v[i][j]=x;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll v(n); v[i]=make_pair(x,y); v[i].first/second;
// v.front() : v[0]
// v.back()  : v[v.size()-1]

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF ((ll)1e+12)
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<=(b); i++)
#define FORR(i,a,b) for(ll i=(b); i>=(a); i--)
#define fix(x) cout << fixed << setprecision(x)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()

template<typename T> T sum(vector<T>& v){return accumulate(all(v), (T)0);}
template<typename T> inline void sort(vector<T>& v){sort(all(v));}
template<typename T> inline void rsort(vector<T>& v){sort(all(v), greater<T>());}
template<typename T> inline void chmin(T& a, T b){if(a>b) a=b;}
template<typename T> inline void chmax(T& a, T b){if(a<b) a=b;}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    FOR(i,a,b){
        if(i%n==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;
void KthSubstring() {
	string s;
	int K;
	cin >> s;
	cin >> K;
	set<string> arr;
	for (size_t i = 'a'; i <= 'z'; i++)
	{
		for (size_t j = 0; j < s.size(); j++)
		{
			if (s[j] == i) {
				string t;
				t += s[j];
				arr.insert(t);
				for (size_t k = 1; k < K; k++)
				{
					if (j + k < s.size()) {
						t += s[j + k];
						arr.insert(t);
					}
				}
			}
		}
		if (arr.size() >= K) {
			int ind = 1;
			for (set<string>::iterator p = arr.begin(); ind <= K ; p++)
			{
				if (ind == K) {
					cout << *p;
				}
				ind++;
			}
			break;
		}
	}

}
int main() {
	KthSubstring();
	return 0;
}


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

using namespace std;

void input(vector<int> &v, int n)
{
	int temp;
	v.resize(n + 1);
	v[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> temp;
		v[i] = v[i - 1] + temp;
	}
}

void dcount(vector<int> &v, unordered_map<int, int> &m)
{
	int d;
	for (auto i = v.begin(); i != v.end(); i++)
	{
		for (auto j = i + 1; j != v.end(); j++)
		{
			d = *j - *i;
			auto res = m.find(d);
			if (res == m.end()) m[d] = 1;
			else res->second++;
		}
	}
}

int main(void)
{
	int N, M;
	while (1)
	{
		cin >> N >> M;
		if (!N) break;
		vector<int> y, x;
		unordered_map<int, int> dy, dx;
		input(y, N);
		input(x, M);
		dcount(y, dy);
		dcount(x, dx);
		int ans = 0;
		for (auto i = dy.begin(); i != dy.end(); i++)
		{
			auto j = dx.find(i->first);
			if (j == dx.end()) continue;
			ans += i->second * j->second;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 30032
#include<bits/stdc++.h>
using namespace std;
int n,k,l[15],r[15],m=998244353,dp[200005],sum[200005];
int main(){
  cin>>n>>k;
  for(int i=1;i<=k;i++) cin>>l[i]>>r[i];
  dp[1]=1;
  sum[1]=1;
  for(int i=2;i<=n;i++){
    for(int j=1;j<=k;j++){
      if(i-l[j]<=0) continue;
      int x=(sum[i-l[j]]-sum[i-min(r[j],i-1)-1]+m)%m;
      dp[i]=(dp[i]+x)%m;
    }
    sum[i]=(sum[i-1]%m+dp[i]%m)%m;
  }
  cout<<dp[n];
  return 0;
}

Measured memory_bytes: 5160
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
char get(int x){
    if(x<10) return x+'0';
    else if(x<36) return x-10+'a';
    else return x-36+'A';
}
int main(){
        string s;
        LL k;
        cin>>k>>s;
        LL x=s.length();
        if(x<=k){
            cout<<s<<endl;
        }
        else if(x>k){
            string ans=s.substr (0,k);
            ans=ans + "...";
            cout<<ans<<endl;
        }
       return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int d[30][30], cnt[3][30];

int main(){
	int n, c;
	cin >> n >> c;
	for(int i=0; i<c; i++){
		for(int j=0; j<c; j++){
			cin >> d[i][j];
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			int x;
			cin >> x;
			cnt[(i+j)%3][x-1]++;
		}
	}

	ll ans=LLONG_MAX;
	int color[3];
	for(color[0]=0; color[0]<c; color[0]++){
		for(color[1]=0; color[1]<c; color[1]++){
			for(color[2]=0; color[2]<c; color[2]++){
				if(color[0]==color[1] || color[1]==color[2] || color[2]==color[0]) continue;

				ll tmp=0;
				for(int l=0; l<3; l++){
					for(int m=0; m<c; m++){
						if(color[l]==m) continue;
						tmp+=d[m][color[l]]*cnt[l][m];
					}
				}
				ans=min(ans, tmp);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb push_back
typedef long long ll; 
int pre[25][200005]; 
int main()
{
	// freopen("ARC098-D.in", "r", stdin); 
	int n; 
	scanf("%d", &n); 
	ll ans = 0; 
	for (int i = 1; i <= n; i++)
	{
		int x; 
		scanf("%d", &x); 
		for (int j = 0; j < 25; j++)
			pre[j][i] = (i ? pre[j][i - 1] : 0) + (x >> j & 1); 
		int mx = 0; 
		for (int j = 0; j < 25; j++)
		{
			int k = std::lower_bound(pre[j], pre[j] + i + 1, pre[j][i] - 1) - pre[j]; 
			mx = std::max(mx, k); 
		}
		// printf("%d %d\n", i, mx);
		ans += i - mx; 
	}
	printf("%lld\n", ans);
	return 0; 
}


Measured memory_bytes: 19712
// C - GCD on Blackboard
#include <bits/stdc++.h>
using namespace std;

int gcd(int a, int b){return b? gcd(b, a%b): a;}

int main(){
	int N; cin>>N;
	vector<int> A(N), L(N), R(N);

	for(int n=0; n<N; ++n) cin>>A[n];

	for(int l=0; l<=N-2; ++l){
		int r = N - l - 2;
		L[l+1] = gcd(L[l], A[l]);
		R[r] = gcd(R[r+1], A[r+1]);
	}

	int maxi = 0;
	for(int n=0; n<N; ++n) maxi = max(maxi, gcd(L[n], R[n]));
	cout<< maxi <<endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>

using namespace std;

#define INF 999999999

bool pr[200000];

void erato(){
	pr[0] = false;
	pr[1] = false;
	pr[2] = true;
	for(int i=3;i<200000;i++){
		pr[i] = true;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				pr[i] = false;
				continue;
			}
		}
	}
}

int main(){
	int i, j, n, p, now;
	erato();
	while(1){
		cin >> n >> p;
		if(n==-1) break;
		now = n*2+2;
		i=0;
		while(1){
			for(j=n+1;now-j>=j;j++){
				if(pr[j]&&pr[now-j]){
					//cout << j << " " << now-j << endl;
					i++;
				}
			}
			if(i>=p)break;
			now++;
		}
		cout << now << endl;
	}
	return 0;
}

Measured memory_bytes: 1360
#include <cstdlib>
#include <iostream>
typedef long long LL;

LL max(LL a, LL b, LL c) {
  return std::max(a, std::max(b, c));
}

int main() {
  int n; std::cin >> n;
  LL score_a = 0, score_b = 0, score_c = 0;
  for (int i = 0; i < n; ++i) {
    LL a, b, c; std::cin >> a >> b >> c;
    LL tmp_a = score_a, tmp_b = score_b, tmp_c = score_c;

    score_a = std::max(tmp_b, tmp_c) + a;
    score_b = std::max(tmp_c, tmp_a) + b;
    score_c = std::max(tmp_a, tmp_b) + c;

//    std::cout << score_a << ", " << score_b << ", " << score_c << std::endl;
  }

  std::cout << max(score_a, score_b, score_c) << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,p[ohara];
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n)cin>>p[i];
    sort(p,p+n);
    rep(i,n){
        if(i==n-1)ans+=p[i]/2;
        else ans+=p[i];
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let (n, k): (usize, usize);
    input!(n, k);
    let mut a = input_vector::<usize>();
    a.sort_by(|a, b| b.cmp(&a));
    let mut ans = n;
    let mut t = 0;
    for i in 0..a.len() {
        if t + a[i] < k {
            t += a[i];
        } else {
            ans = std::cmp::min(ans, n - i - 1);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
num = int(input())
cnt = 1
s = []
while cnt <= num:
  x = cnt
  if x % 3 == 0:
    s.append(cnt)
    x = 0
  while x > 0:
    if x % 10 == 3:
      s.append(cnt)
      break
    x = x // 10
  cnt += 1
s = ' '.join(str(i) for i in s)
s = ' ' + s
print(s)


Measured memory_bytes: 6108
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 2000
 
bool flag;
int n,k,u,v,ans;
int cnt[MAXN+3];
vector<int>G[MAXN+3];
 
int Dfs(int u,int fa,int d) {
    if(d>k) return 1;
    int ret=0; cnt[u]=1;
    for(int i=0;i<G[u].size();i++) {
        int v=G[u][i];
        if(v==fa)
            continue;
        ret+=Dfs(v,u,d+1);
        cnt[u]+=cnt[v];
    }
    return ret;
}
int main() {
    scanf("%d %d",&n,&k);
    if(k%2==0)
        flag=true;
    else flag=false;
    k/=2;
    for(int i=1;i<n;i++) {
        scanf("%d %d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for(int i=1;i<=n;i++) {
        memset(cnt,0,sizeof(cnt));
        int tot=0; cnt[i]=1;
        for(int j=0;j<G[i].size();j++) {
            tot=max(tot,Dfs(G[i][j],i,1));
            cnt[i]+=cnt[G[i][j]];
        }
        if(flag) tot=0;
        tot+=cnt[i];
        ans=max(ans,tot);
    }
    printf("%d\n",n-ans);
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
int dp[500000][4];
int calc(vector<int> &a){
    int n = a.size();
    rep(i,n+1){
        rep(j,4){
            dp[i][j] = -inf;
        }
    }
    dp[0][0] = 0;
    for(int i=0;i<n-1;i++){
        chmax(dp[i+1][0],dp[i][0]);
        chmax(dp[i+1][0],dp[i][1]);
        chmax(dp[i+1][0],dp[i][2]);
        chmax(dp[i+1][0],dp[i][3]);
        
        if(a[i+1]!=1){
            chmax(dp[i+1][1],dp[i][0] + a[i+1]-1);
            chmax(dp[i+1][1],dp[i][1] + a[i+1]-1);
            chmax(dp[i+1][1],dp[i][3] + a[i+1]-1);
        }
        chmax(dp[i+1][2],dp[i][0] + a[i+1]);
        chmax(dp[i+1][2],dp[i][1] + a[i+1]);
        chmax(dp[i+1][2],dp[i][3] + a[i+1]);
        if(a[i+1]!=1){
            chmax(dp[i+1][3],dp[i][0] + a[i]);
            chmax(dp[i+1][3],dp[i][1] + 1);
            chmax(dp[i+1][3],dp[i][3] + a[i]-1);
        }else{
            chmax(dp[i+1][2],dp[i][0] + a[i]);
            chmax(dp[i+1][2],dp[i][1] + 1);
            chmax(dp[i+1][2],dp[i][3] + a[i]-1);    
        }
    }
    int mx = 0;
    for(int i=0;i<4;i++){
        chmax(mx,dp[n-1][i]);
    }
    return mx;
}

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<vector<int> > a;
    vector<int>tmp;
    int c = 0;
    bool flag = 1;
    rep(i,n){
        if(s[i]=='1'){
            c++;
            flag = 0;
        }else{
            if(flag){
                if(tmp.size()!=0){
                    a.push_back(tmp);
                    tmp.clear();
                    tmp.shrink_to_fit();
                }
            }else{
                tmp.push_back(c);
                flag = 1;
                c = 0;
            }
        }
    }
    if(c!=0){
        tmp.push_back(c);
    }
    if(tmp.size()!=0){
        a.push_back(tmp);
    }
    int res = 0;
    for(auto s:a){
        // for(auto x:s){
        //     cerr << x << " ";
        // }
        // cerr << endl;
        res += calc(s);
        // cerr << res << endl;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// 約数の列挙O(√n)
vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i=1LL;i*i<=n;i++){
        if(n%i==0){
            res.push_back(i);
            if(i!=n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main(){
    ll n;
    cin>>n;
    vector<ll> v=divisor(n);

    ll ans=0;
    for(int i=0;i<v.size();i++){
        ll m=v[i]-1;
        if(m<=0) continue;
        if(n/m == n%m) ans+=m;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	int a,b; cin >> a >> b;
	if(a>b) cout << a-1 << endl;
	else cout << a << endl;
}

Measured memory_bytes: 256
n = int(input())
lst = []
for _ in range(n):
    a,b = map(int,input().split())
    lst.append((a,b,a+b))
lst.sort(key=lambda x:x[2], reverse=True)
x,y = 0,0
for i in range(n):
    if i%2==0:
        x += lst[i][0]
    else:
        y += lst[i][1]
print(x - y)

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

int main() {
	ll n;
	int k;
	cin >> n >> k;
	int ans = 0;
	while (n >=1) {
		n /= k;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256