akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;
vector< pair<int, char> > a;
vector< pair<int, char> > aa;

bool cl(pair<int, char> l, pair<int, char> r){
  // if( l.first == r.first ) return l.second < r.second;
  return l.first < r.first;
}

int partition(int p, int r){
  int x = a[r].first;
  int i = p-1;
  for(int j=p; j<r; j++){
    if( a[j].first <= x ){
      i++;
      swap(a[i], a[j]);
    }
  }
  swap(a[i+1], a[r]);
  return i + 1;
}

void quickSort(int p, int r){
  if( p < r ){
    int q = partition(p, r);
    quickSort(p, q-1);
    quickSort(q+1, r);
  }
}

void merge(int left, int mid, int right){
  int n1 = mid-left;
  int n2 = right - mid;
  vector< pair<int, char> > l(n1+1);
  vector< pair<int, char> > r(n2+1);

  for(int i=0; i<n1; i++) l[i] = aa[left + i];
  for(int i=0; i<n2; i++) r[i] = aa[mid + i];

  l[n1].first = inf;
  r[n2].first = inf;
  int i = 0, j = 0;
  for(int k=left; k<right; k++){
    if( l[i].first <= r[j].first ){
      aa[k] = l[i];
      i++;
    }else{
      aa[k] = r[j];
      j++;
    }
  }

}
void mergeSort(int left, int right){
  if( left + 1 < right ){
    int mid = (left + right) / 2;
    mergeSort(left, mid);
    mergeSort(mid, right);
    merge(left, mid, right);
  }
}

int main(void) {

  int n;
  cin >> n;
  a.resize(n);
  for(int i=0; i<n; i++) cin >> a[i].second >> a[i].first;

  vector< pair<int, char> > b = a;
  aa = a;
  sort(b.begin(), b.end(), cl);
  quickSort(0, n-1);
  mergeSort(0, n);
  cout << (a == aa ? "Stable" : "Not stable") << endl;
  for(int i=0; i<n; i++) cout << a[i].second << " " << a[i].first << endl;


  return 0;
}

// EOF

Measured memory_bytes: 5960
n = int(input())
A = [int(i) for i in input().split()]
q = int(input())
m = [int(i) for i in input().split()]
memo = []

for i in range(2**n):
  tmp = 0
  for j in range(n):
    if i>>j & 1:
      tmp += A[j]
  memo.append(tmp)
for i in range(q):
  if m[i] in memo:
    print("yes")
  else:
    print("no")


Measured memory_bytes: 43080
#define MYDEBUG
//
#include <bits/stdc++.h>
#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#define dbp4(w,x,y,z) cout<<#w<<","<<#x<<","<<#y<<","<<#z<<": "<<w<<","<<x<<","<<y<<","<<z<<endl
#define ifcin(x) std::ifstream cin(x)
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#define dbp4(w,x,y,z)
#define ifcin(x)
#endif
#define ll long long
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)
#define REP(i, from, to) for(int i=from; i<=to; ++i)
using namespace std;
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last) {
      out << ",";
    }
  }
  out << "]";
  return out;
}
template<typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& v) {
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i] << endl;
  }
  return out;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {
  out << "{" << p.first << "," << p.second << "}";
  return out;
}

int n, q, S[10001], T[500];

bool searchKey(int x) {
  S[n] = x;
  int i = 0;
  while (S[i] != x) {
    i++;
  }
  return i != n;
}

void solve() {
  scanf("%d", &n);
  rep(i,0,n)
  {
    scanf("%d", &S[i]);
  }
  scanf("%d", &q);
  rep(i,0,q)
  {
    scanf("%d", &T[i]);
  }
  int ans = 0;
  rep(i,0,q)
  {
    if (searchKey(T[i])) {
      ans++;
    }
  }
  printf("%d\n", ans);
}
int main() {
  solve();
  return 0;
}



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

int main() {
  long long N;
  cin >> N;
  int count = 0;
  long long M = N;
  long long P = 1;
 
  for (int i = 0; i < 16; i++) {
    if (N / 10 != 0){
      N /= 10;
      count++;
      P *= 10;
    }
    else if (N / 10 == 0){
      break;
    }
  }
  
  if ((M + 1) % P == 0){
    cout << count * 9 + N << endl;
  }
  else {
    cout << count * 9 + N - 1 << endl;
  }
}





Measured memory_bytes: 3608
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input! {
        n: usize,
        m: usize,
        edge: [(usize, usize); m],
    }

    let mut list = vec![vec![]; n+1];
    let mut memo = vec![0; n+1];

    for e in &edge {
        list[e.0].push(e.1);
    }
    
    let mut ans = 0;

    for i in 1..n+1 {
        ans = cmp::max(ans, search(i, &list, &mut memo));
    }
    println!("{}", ans);

}

fn search(pos: usize, list: &Vec<Vec<usize>>, memo: &mut Vec<usize>) ->  usize {

    if memo[pos] != 0 {
        return memo[pos];
    }
    if list[pos].len() == 0 {
        return 0;
    }

    let mut max = 0;

    for i in &list[pos] {
        memo[*i] = search(*i, list, memo);
        max = cmp::max(max, memo[*i]+1);
    }

    max
}



Measured memory_bytes: 14588
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		tmp := nextInt()
		m[tmp]++
	}

	ans := 0
	for k, v := range m {
		if k == v {
			continue
		} else if k > v {
			ans += v
		} else if v > k {
			ans += v - k
		}
	}
	fmt.Println(ans)
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}
func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int h,w,n;
		cin>>h>>w>>n;
		if(h<w)
		swap(h,w);
		cout<<ceil(n/float(h));
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;

int main(){
	int N,K;
	cin>>N>>K;
	if((N-1)%(K-1)==0){
		cout<<(N-1)/(K-1)<<endl;
	}else{
		cout<<((N-1)/(K-1))+1<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  int k, s ;
  cin >> k >> s ;
  int count = 0 ;
  
  REP(i,k+1){
    REP(j,k+1){
      if(0<=s-i-j && s-i-j<=k){
        count++ ;
      }
    }
  }
  
  cout << count <<endl ;

  return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main(){
    int n;
    int a, b;
    cin >> n >> a >> b;
    vector<int> p;
    
    for(int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }
    sort(p.begin(), p.end());
    int cnt[3]={0};

    for(auto i: p){
        if (i <= a){
            cnt[0]++;
        }else if(i <= b){
            cnt[1]++;
        }else{
            cnt[2]++;
        }
    }
    int ans;
    ans = min(cnt[0], cnt[1]);
    ans = min(ans, cnt[2]);
    cout << ans << endl;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

using Pos = array<ll, 2>;

void solve() {
    ll H, W, K;
    cin >> H >> W >> K;
    int cell[801][801];
    Pos start;
    for (ll i = 0; i < H; i++) {
        string s;
        cin >> s;
        for (ll j = 0; j < W; j++) {
            if (s[j] == '#') {
                cell[i][j] = 1;
            }
            else {
                cell[i][j] = 0;
                if (s[j] == 'S') {
                    start = {i, j};
                }
            }
        }
    }

    ll dist[801][801];
    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            dist[i][j] = L_INF;
        }
    }

    constexpr Pos step[] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

    queue<Pos> q;
    q.emplace(start);
    dist[start[0]][start[1]] = 0;
    while (!q.empty()) {
        auto [x, y] = q.front();
        ll d = dist[x][y];
        q.pop();
        if (d + 1 <= K) {
            for (ll i = 0; i < 4; i++) {
                ll xn = x + step[i][0];
                ll yn = y + step[i][1];
                if (!(xn >= 0 && xn < H && yn >= 0 && yn < W)) continue;
                if (cell[xn][yn] == 1) continue;
                if (dist[xn][yn] != L_INF) continue;
                q.push({xn, yn});
                dist[xn][yn] = d + 1;
            }
        }
    }

    ll ans = L_INF;
    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            if (dist[i][j] == L_INF) continue;
            ans = min(ans, (i + K - 1) / K + 1);
            ans = min(ans, (H - 1 - i + K - 1) / K + 1);
            ans = min(ans, (j + K - 1) / K + 1);
            ans = min(ans, (W - 1 - j + K - 1) / K + 1);
        }
    }

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

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 11208
N = int(input())
S = input()

ctr = [0] * 1000
ans = 0
for i in range(1000):
    v1 = i // 100
    v2 = i // 10 - v1 * 10
    v3 = i - v1 * 100 - v2 * 10
    
    p1 = S.find(str(v1))
    if p1 < 0:
        continue
        
    p2 = S[p1+1:].find(str(v2))
    if p2 < 0:
        continue
        
    p3 = S[p1+p2+2:].find(str(v3))
    ans += int(p3 >= 0)
    
print(ans)


Measured memory_bytes: 38768
#include <iostream>
#define ll long long
using namespace std;
int main(void){
    // Your code here!
    ll n,a,b,c;
    cin>>n;
    ll list[n][3];
    cin>>list[0][0]>>list[0][1]>>list[0][2];
    for(ll i=1;i<n;i++){
        cin>>a>>b>>c;
        list[i][0]=max(a+list[i-1][1],a+list[i-1][2]);
        list[i][1]=max(b+list[i-1][0],b+list[i-1][2]);
        list[i][2]=max(c+list[i-1][0],c+list[i-1][1]);
    }
    ll ans;
    ans=max(list[n-1][0],list[n-1][1]);
    ans=max(ans,list[n-1][2]);
    cout<<ans;
}


Measured memory_bytes: 2560
package main

import "fmt"

func main() {
    var n, x, s int

    for {
        fmt.Scanf("%d %d", &n, &x)
        if n == 0 && x == 0 {
            break
        }

        s = 0
        for i:=1; i<=n-2; i++ {
            for j:=i+1; j<=n-1; j++ {
                for k:=j+1; k<=n; k++ {
                    if i + j + k == x {
                        s++
                    }
                }
            }
        }
        fmt.Println(s)
    }

}


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

using namespace std;

#define maxn 1000007
#define ll long long int
#define db(x) cout<<#x<<" ->"<<x<<" "
#define db2(x,y) cout<<#x<<"->"<<x<<", "<<#y<<" -> "<<y<<endl
#define db3(x,y,z) cout<<#x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define prt(x) for(auto it = x.begin(); it!=x.end(); it++) { cout<<*it<<" "; } cout<<endl
#define IN freopen("input.txt","r",stdin)

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
   // IN ;
    int n,k;
    cin>>n>>k;
    k--;
    string str;
    cin>>str;
    str[k] = tolower(str[k]);
    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 sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n, m;
  cin >> n >> m;
  map<int,ll> mp;
  rep(i,n) {
    int a;
    cin >> a;
    mp[-a]++;
  }
  rep(i,m) {
    int b, c;
    cin >> b >> c;
    mp[-c] += b;
  }
  int cnt = 0;
  ll res = 0;
  for (auto e : mp) {
    ll a = -1 * e.first;
    ll d = min((ll)n - cnt, e.second);
    res += a * d;
    cnt += d;
    if (cnt == n) break;
  }
  cout << res << endl;
  return 0;
}

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

long dfs(long h) {
    if (h == 1) {
        return 1;
    } else {
        return dfs(h / 2) * 2 + 1;
    }
}

int main() {
    long H;
    cin >> H;
    
    long sum = dfs(H);

    cout << sum << endl;
    
    return 0;
}

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

int main() {
  int a, b;
  cin >> a;
  cin >> b;
  //cimにに標準入力が入る
 

  int ans = a + b;
  if(ans >= 10) {
    //10以上(10含まれる)の場合の処理
    cout << "error" << endl;
    /*endl=改行
    cout=console.logのようなもの*/
  } else {
    cout << ans << endl;
    //処理
    }
}


Measured memory_bytes: 256
module Main (main) where

import Control.Applicative

main :: IO ()
main = do
  [x,y,z] <- (map read . words) <$> getLine 
  putStrLn $ comp x y z

comp :: Integer -> Integer -> Integer -> String
comp x y z 
  | x < y && y < z = "Yes"
  | otherwise = "No"

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long ll;
int main(){
  ll N;
  cin >> N;
  vector<ll> A(N+1);
  vector<ll> B(N);
  for(ll i = 0;i <= N;i++)cin >> A[i];

  for(ll i = 0;i < N;i++)cin >> B[i];

  ll count = 0;

  for(ll i = 0;i < N;i++){
    ll minl = min(A[i],B[i]);
    count += minl;
    A[i] -= minl;
    B[i] -= minl;

    minl = min(A[i+1],B[i]);
    count += minl;
    A[i+1] -= minl;
    B[i] -= minl;
  }

  cout << count << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define N 210000
int n,cnt;
int a[N],tar[N],ans[N];
vector<int>vec[N];
priority_queue<int,vector<int>,greater<int> >que;
struct Seg_tree
{
	#define ls l,mid,now<<1
	#define rs mid+1,r,now<<1|1
	int v[N];
	int mn[N<<1],pos[N<<1];
	void pushup(int now)
	{
		mn[now]=min(mn[now<<1],mn[now<<1|1]);
		pos[now]=mn[now<<1]<mn[now<<1|1] ? pos[now<<1] : pos[now<<1|1];
	}
	void build(int l,int r,int now)
	{
		if(l==r)
		{
			mn[now]=v[l];pos[now]=l;
			return;
		}
		int mid=(l+r)>>1;
		build(ls);build(rs);
		pushup(now);
	}
	void upd(int &x,int y)
	{x = (!x)||(v[x]>v[y]) ? y : x;}
	int query(int l,int r,int now,int lq,int rq)
	{
		if(lq<=l&&r<=rq)
			return pos[now];
		int mid=(l+r)>>1,ret=0;
		if(mid>=lq)upd(ret,query(ls,lq,rq));
		if(mid<rq) upd(ret,query(rs,lq,rq));
		return ret;
	}
	int query(int l,int r)
	{return query(1,n>>1,1,l,r);}
}tr[2];
int solve(int l,int r)
{
	if(l>r)return 0;
	int t;
	int t1=tr[l&1].query((l+1)>>1,r>>1);t1=(t1<<1)-(l&1);
	int t2=tr[~l&1].query((t1+2)>>1,(r+1)>>1);t2=(t2<<1)-(~l&1);
	tar[a[t1]]=a[t2];
	if(t=solve(l,t1-1))vec[a[t1]].push_back(t);
	if(t=solve(t1+1,t2-1))vec[a[t1]].push_back(t);
	if(t=solve(t2+1,r))vec[a[t1]].push_back(t);
	return a[t1];
}
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		tr[i&1].v[(i+1)>>1]=a[i];
	}
	tr[0].build(1,n>>1,1);
	tr[1].build(1,n>>1,1);
	int t=solve(1,n);
	que.push(t);
	while(!que.empty())
	{
		int t=que.top();que.pop();
		for(int i=0;i<vec[t].size();i++)
			que.push(vec[t][i]);
		ans[++cnt]=t;ans[++cnt]=tar[t];
	}
	for(int i=1;i<=n;i++)
		printf("%d ",ans[i]);
	return 0;
}


Measured memory_bytes: 33536
#include<iostream>
#include<cstring>
using namespace std;
string c;
int main()
{
	int a,b;
	cin>>a>>b>>c;
	int l=c.size();
	for(int i=0;i<l;i++)
	{
		if((!(c[i]>='0'&&c[i]<='9')&&i!=a)||(i==a&&c[i]!='-'))
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	string S, T;
	cin >> S;
	cin >> T;

	int ans = 0;

	for (int i = 0; i < S.length(); i++) {
		if (S[i] != T[i]) {
			ans += 1;
		}
	}

	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 3924
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
using namespace std;
string S;
int main() {
	cin >> S;
	cout << S.substr(0, S.size() - 8) << 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 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 main(int argc, char const *argv[]) {
  int n;cin >> n;
  vector<int> a(n+1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<int> ball(n+1,0);

  for (int i = n; i >= 1;i--){
    int cnt = 0;
    // iの倍数のボールの和
    for (int j = i; j <= n; j += i) {
      if (ball[j] == 1) cnt++;
    }
    if (cnt % 2 != a[i]) ball[i] = 1;
  }
  vector<int> ans;
  for (int i = 1; i <= n; i++) if (ball[i]) ans.pb(i);
  cout << sz(ans) << endl;
  rep(i,sz(ans)) cout << ans[i] << " ";
  return 0;
}

Measured memory_bytes: 3064
/*
Hey there stalker....

█▀▀▄░░░░░░░░░░░▄▀▀█
░█░░░▀▄░▄▄▄▄▄░▄▀░░░█
░░▀▄░░░▀░░░░░▀░░░▄▀
░░░░▌░▄▄░░░▄▄░▐▀▀
░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█
░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█
▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█
█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀
░▀▄░░▀░░▀▀▀░░▀░░░▄█▀
░░░█░░░░░░░░░░░▄▀▄░▀▄
░░░█░░░░░░░░░▄▀█░░█░░█
░░░█░░░░░░░░░░░█▄█░░▄▀
░░░█░░░░░░░░░░░████▀
░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀

Like what you see?
*/
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pii         pair<ll ,ll>
#define vi          vector<ll>
#define present(container, element) (container.find(element) != container.end()) /* For set n maps */
#define cpresent(container, element) (find(all(container),element) != container.end()) /* For vectors */
#define all(a)      (a).begin(),(a).end()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define F           first
#define S           second
#define I           insert
#define sz(x)       (ll)x.size()
#define rep(i,a,b)    for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define trav(a, x) 	for(auto& a : x)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lcase(a) (char)tolower(a)
#define ll long long int
#define lld long double
#define endl "\n"
#define PI 3.14159265358979323844
#define MOD 1000000007
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define mod 1e9 + 7
/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

int main()
{
   IOS

    int TESTS=1;
  //  cin >> TESTS;
    while (TESTS--)
    {
        ll n,sum=0;
        cin>> n;
        vi v(n);
        ll count[100005]={0};
        rep(i,0,n)
        {
            cin >> v[i];
            count[v[i]]++;
            sum+=v[i];
        }

        ll q;
        cin >> q;
        while(q--)
        {
            ll b,c;
            cin >> b>> c;

            sum+=(c-b)*count[b];
            count[c]+=count[b];
            count[b]=0;

            cout<< sum <<endl;

        }
    }
    return 0;
}



Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ios std::ios::sync_with_stdio(false);
int main(){
    ios;
     
     int n;
     while(cin>>n)
     {
        long long  a[n+1];
         int flag1=1;
         for(int i=1;i<=n;i++)
         cin>>a[i];
          for(int i=1;i<=n;i++)
          if( a[i]%2==0 ) {    if ( a[i]%3==0 ||a[i]%5==0   ) continue; else {   flag1=0;break;  }     }
          if(flag1)  {   cout<<"APPROVED"<<endl;    }
          else cout<<"DENIED"<<endl;
     }
    return 0;
}


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

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

template <typename Int>
struct FenwickTree {
  vector<Int> data;
  explicit FenwickTree(int n): data(n, 0) {}
  void add(int i, Int x) { for (; i < (int)data.size(); i |= i+1) data[i] = max(data[i], x); }
  Int sum(int i) const { Int s = 0; for (; i >= 0; i = (i & (i+1)) - 1) s = max(s, data[i]); return s; }
};

long long dp[100001];

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

    int n;
    while (cin >> n) {
        vector<int> weights(n);
        REP(i, n) cin >> weights[i];

        REP(w, n+1) dp[w] = 0;
        dp[weights[0]] = weights[0];

        FenwickTree<long long> ft(n+1);
        ft.add(weights[0], weights[0]);

        FOR(i, 1, n) {
            int w = weights[i];
            long long v = max(dp[w], ft.sum(w-1) + w);
            dp[w] = v;
            ft.add(w, v);
        }

        long long total_weight = 0;
        REP(i, n) total_weight += weights[i];

        cout << total_weight - ft.sum(n) << '\n';
    }
}

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

int main()
{
    long long H;
    cin >> H;
    
    long long ans = 0;
    long long multiply = 1;
    
    while (H > 0) {
        ans += multiply;
        multiply *= 2;
        H /= 2;
    }
    
    cout << ans;

    return 0;
}

Measured memory_bytes: 888
str=gets
n=gets.to_i
(0..n-1).each do |i|
  arr=gets.split
  s,e=arr[1].to_i, arr[2].to_i
  case arr[0]
  when "print" then
    puts str[s..e]
  when "reverse" then
    str[s..e]=str[s..e].reverse
  when "replace" then
    str[s..e]=arr[3]
  end
end

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  int ans = 0;
  rep(i,0,n) {
    int x;
    cin >> x;
    if (x%2==1 and i%2==0) ++ ans;
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3640
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
 
struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n;
LL a[101010];
LL sum[101010], fact[101010];

// a x + b y = gcd(a, b)
LL extgcd(LL a, LL b, LL &x, LL &y) {
    LL g = a; x = 1; y = 0;
    if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
    return g;
}

// mod m ?? a ? ??
LL mod_inverse(LL a, LL m){
    LL x, y;
    extgcd(a, m, x, y);
    return (m + x%m)%m;
}

const LL mod = 1e9 + 7;

int main(){
    fact[0] = 1;
    for(int i = 1;i < 101010;i++)fact[i] = fact[i - 1] * i, fact[i] %= mod;
    cin >> n;
    for(int i = 1;i <= n;i++)cin >> a[i];
    LL ans = 0;
    for(int i = 1;i < n;i++){
        if(i == 1){
            sum[1] = 1;
        }else{
            sum[i] = sum[i - 1] + mod_inverse(i, mod);
        }
        (ans += sum[i] * (a[i + 1] - a[i])) %= mod;
    }
    cout << (ans * fact[n - 1]) % mod << endl;
}


Measured memory_bytes: 2688
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	x, _ := strconv.Atoi(read())
	happ500 := x / 500
	remaining := x % 500
	happ5 := remaining / 5
	fmt.Println(1000*happ500 + 5*happ5)

}


Measured memory_bytes: 640
from operator import mul
from functools import reduce

N, K=map(int, input().split())

def cmb(n, r):
  if(n<r):
    return 0
  r=min(r,n-r)
  if(r==0):
      return 1  
  
  upper=reduce(mul, range(n, n-r, -1))
  under=reduce(mul, range(1,r+1))
    
  return upper // under % INF

INF=10**9+7
for i in range(1,K+1):
  ret = cmb(N-K+1,i)*cmb(K-1,i-1)
  print(ret%INF)
  

Measured memory_bytes: 3944
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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 main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	ll sum=0;
	REP(i,n){
		cin >> a[i];
		sum += a[i];
	}
	
	vector<ll> ans(n,0);
	
	ans[0] = sum;
	for(int i=1; i<=n-2; i+=2){
		ans[0] -= 2*a[i];
	}
	
	for(int i=1; i<n; i++){
		ans[i] = 2*a[i-1]-ans[i-1];
	}
	
	REP(i,n){
		if(i!=0) cout << " ";
		cout << ans[i]; 
	}
	cout << endl;
	
	
	return 0;
}

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

int main() {
    ll n;
    ll ans=1;
    cin >> n;

    for (ll i = 1; i < n+1; i++)
    {
        ans = (ans*i)%1000000007;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define rep(i,n)  for(ll i = 0; i < (n); ++i)
#define red(i,n)  for(ll i = (n)-1; i >= 0; --i)
#define all(a)    begin(a),end(a)
#define pb(a)     push_back(a)
#define yn(a)     cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+7, LINF = 1e18;


int main()
{
    ll n;
    string s;
    cin>>n>>s;

    for(char c:s){
        c+=n;
        if(c>'Z')c-=26;
        cout<<(char)c;
    }
    cout<<endl;
    return 0;
}


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

int main() {
    string str;
    getline(cin, str);
    bool insertSpace = false;
    while (str.find_first_of(" ,.") != string::npos) {
        string::size_type pos = str.find_first_of(" ,.");
        if (3 <= pos && pos <= 6) {
            if (insertSpace) {
                cout << " ";
            } else {
                insertSpace = true;
            }
            cout << str.substr(0, pos);
        }
        str.erase(0, pos + 1);
    }
    cout << str << endl;
}

Measured memory_bytes: 0
n,y=map(int, input().split())

for i in range(n+1):
    for j in range(n+1):
        if 10000*i+5000*j+1000*(n-i-j)==y and n-i-j>=0:
            print(i,j,n-i-j)
            exit()

print('-1 -1 -1')

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

int main()
{
	int a[4], b[4];
	static int ans[100][2];
	int hit, bro, count = 0;
	while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
		hit = 0;
		bro = 0;
		for (int i = 0; i < 4; i++) {
			if (a[i] == b[i])
				hit++;
			else {
				for (int k = 0; k < 4; k++) {
					if (a[i] == b[k])
						bro++;
				}
			}
		}
		ans[count][0] = hit;
		ans[count][1] = bro;
		count++;
	}
	for (int i = 0; i < count; i++) 
		cout << ans[i][0] << " " << ans[i][1] << endl;
}

Measured memory_bytes: 3000
K = int(input())

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

count = 0
for i in range(1,K+1):
    count += i
for i in range(1,K):
    for j in range(i+1,K+1):
        count += gcd(i,j) * 6
for i in range(1,K-1):
    for j in range(i+1,K):
        for k in range(j+1,K+1):
            count += gcd(i,j,k) * 6
print(count)

Measured memory_bytes: 9636
#include <stdio.h>
#include <stdlib.h>

int n, k;

int check(int P, int* w){
	int i = 0;
	int* car = (int*)calloc(k, sizeof(int));
	int j;
	for(j=0;j<k;j++){
		while(car[j]+w[i]<=P){
			car[j] += w[i];
			i++;
			if(i==n) return i;
		}
	}
	free(car);
	return i;
}

int binary_search(int *w){
	long right = 100000*10000;
	long left = 0;
	while(1){
		int middle = (left+right)/2;
		int p1 = check(middle, w);
		if(p1==n){
			if(check(middle-1, w)<n){
				return middle;
			}
			right=middle;
		}
		else{
			left = middle;
		}
	}
}

int main(int argc, char const *argv[])
{
	scanf("%d %d", &n, &k);
	int w[n];
	for(int i=0;i<n;i++)
		scanf("%d", w+i);
	printf("%d\n", binary_search(w));
	return 0;
}



Measured memory_bytes: 4136
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
const ld pi=acos(-1.0);


int main() {
	vector<int>oks(1e7);
	
	for (int i = 0; i < 100; ++i) {
		for (int j = 2; j < 300; ++j) {
			int num=i*i*i+j*(j-1)*(j-2)/6;
			oks[num]=true;
		}
	}
	while (true) {
		int N;cin>>N;
		if(!N)break;
		int ans=-1;
		while (true) {
			if (oks[N]) {
				ans=N;
				break;
			}
			N--;
		}
		cout<<ans<<endl;
	}
	

	return 0;
}


Measured memory_bytes: 41676
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

int main () {
    
    int n, k; cin >> n >> k;
    int a;
    int ist = 0;

    for (int i = 0; i < n; i++) {
        cin >> a;
        if(a == 1) {
            ist = i;
        } 
    } 

    int ans = 1000000000;
    for (int j = 0; j < k; j++) {
        int l = ist - (k-1) + j;
        int r = ist + 1 + j;
        if(l >= 0 && r <= n) {
            int count = 1;
            count += l/(k-1);
            if(l % (k-1) != 0) {
                count += 1;
            } 
            count += (n-r)/(k-1);
            if((n-r) % (k-1) != 0) {
                count += 1;
            }
            ans = min(ans, count);
        } 
    }

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x=max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
#define dame {puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;
#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
//----------------------------------------------------------------
void Main(){
  string s;
  cin>>s;
  int n=s.length();
  int w=0,l=0;
  int g=0,p=0;
  char te = 'g',next = 'p';
  rep(i,n){
    if(s[i]=='g' and te=='p') w++;
    if(s[i]=='p' and te=='g') l++;
    swap(te,next);
  }
  cout<<w-l<<endl;
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String args[]) {
       ///値を取得
       Scanner sc = new Scanner(System.in);
       int N = sc.nextInt();    //参加人数
       int K = sc.nextInt();    ///開始時点の点数
       int Q = sc.nextInt();    //正解数
       
       int[] A = new int[Q];    //参加者の配列
       int[] point = new int[N];    //各参加者の点数の配列
       
       for(int i = 0; i < Q; ++i) {
           A[i] = sc.nextInt(); //各参加者の終了時の点数を取得
           point[A[i]-1]++; //各参加者の点数を格納
       }
       
       for(int j = 0; j < N; ++j) {
             //出力
            if(K - Q + point[j] > 0) {
                System.out.println("Yes");
            } else {
               System.out.println("No");
            }
       }

    }
}


Measured memory_bytes: 60428
#include <iostream>
#include <algorithm>

int main(){
	int w, n, a[30], b[30], result[30];
    std::cin >> w >> n;
    for(int i=0; i<n; i++){
        (std::cin >> a[i]).ignore() >> b[i];
        a[i]--;
        b[i]--;
    }
    for(int i=0; i<w; i++)
        result[i] = i;
    for(int i=0; i<n; i++)
        std::swap(result[a[i]], result[b[i]]);
    for(int i=0; i<w; i++)
        std::cout << result[i] + 1 << std::endl;
	return 0;
}

Measured memory_bytes: 1156
#include<stdio.h>

int main(void)
{
	int x,y,z;
	while(1){
		scanf("%d %d",&x ,&y);
		if(x == 0 && y == 0)break;
		if(x > y){
			z = x;
			x = y;
			y = z;
		}
		printf("%d %d\n",x, y);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main(void){
	char buf[1000], buf2[1000];
	while(scanf("%s%s", buf, buf2) != EOF){
		bool flag = 1;
		for(int i = 0; i < strlen(buf); i++){
			if(buf[i] != buf2[i])flag = 0;
		}
		if(flag)puts("Yes");
		else puts("No");
	}
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

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


template<class T>
bool chmax(T &a, const T &b) { if (a < b) { return b; } return a; }

template<class T>
bool chmin(T &a, const T &b) { if (a > b) { a = b; return a; } return a; }

int main() {
    ll n, x; 
    cin >> n >> x;

    vector<ll> coord(n+1);
    rep(i, n) cin >> coord[i];
    coord[n] = x;

    sort(coord.begin(), coord.end());
    // rep(i, n+1) cout << coord[i] << endl;
    ll d = 0; 
    vector<ll> dist(n);
    rep(i, n) {
        d = abs(coord[i+1]-coord[i]);
        dist[i] = d;
    }
    
    ll ans = dist[0];
    rep(i, n-1) ans = gcd(dist[i+1],ans);
    // rep(i, n) cout << dist[i] << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4764
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main(){
    string s,t;
    cin>>s>>t;
    if(s==t){
        cout<<"Yes"<<endl;return 0;
    }
    int n=s.size();
    string sc(s);
    sc=sc[n-1]+sc.substr(0,n-1);
    while(sc!=s){
        if(sc==t){
            cout<<"Yes"<<endl;return 0;
        }
        sc=sc[n-1]+sc.substr(0,n-1);
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 40005
#define N 100005
using namespace std;
typedef pair<int,int> P;

int par[MAX_N];
int cnt[MAX_N];
int rank[MAX_N];

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

int find(int x){
  if(par[x]==x)return x;
  return par[x]=find(par[x]);
}

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

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

vector<int> W[N],H[N];
bool used[MAX_N];

int main(){
  int n,w,h,x,y,f=0;
  cin>>n>>w>>h;
  init(n);
  for(int i=0;i<n;i++){
    cin>>x>>y;
    x--,y--;
    if(!x||x==w-1||!y||y==h-1)f=1;
    W[x].push_back(i);
    H[y].push_back(i);
  }
  for(int i=0;i<h;i++)
    for(int j=1;j<H[i].size();j++)
      unite(H[i][0],H[i][j]);
  for(int i=0;i<w;i++)
    for(int j=1;j<W[i].size();j++)
      unite(W[i][0],W[i][j]);
  int ans=1,gcnt=0;
  for(int i=0;i<n;i++){
    int pa=find(i);
    if(used[pa])continue;
    used[pa]=true;
    gcnt++;
    ans+=cnt[pa]-1;
  }
  if(gcnt==1)cout<<ans-1<<endl;
  else{
    gcnt--;
    ans+=gcnt*2;
    ans-=f;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 10392
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 1000001; 

// structure to store queries 
struct Query 
{ 
	int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

// driver code 
int main() 
{ 
    int n,q;
    cin>>n>>q;
    int a[n];
    for (int i=0;i<n;i++) cin>>a[i];
	Query queries[q]; 
	int l1,r1;
	for (int i=0;i<q;i++){
	    cin>>l1>>r1;
	    l1--;
	    r1--;
	    queries[i].l=l1;
	    queries[i].r=r1;
	    queries[i].idx=i;
	}
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


Measured memory_bytes: 19288
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	string s, t;
	cin>>s;
	cin>>t;
	int n=s.size();
	bool ok=0;
	for(int i=0; i<n; i++){
		string u=s.substr(i)+s.substr(0, i);
		if(u==t){
			ok=1;
			break;
		}
	}
	if(ok) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	ll n;
	vector<ll>v;
	cin>>n;
	for(ll i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)v.push_back(i+(n/i)-2);
	}
	sort(v.begin(),v.end());
	cout<<v[0]<<endl;
	return 0;
}

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

using namespace std;
int solve (int n)
{
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int x=0;
		int num=i;
		while(num)
		{
			num/=10;
			x++;
		}
		if(x&1)ans++;
	}
	return ans;
}

int main()
{
	int N;
	cin>>N;
	cout<<solve(N);
}


Measured memory_bytes: 256
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 998244353ll
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int dp[N], ans[N];
int32_t main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    int l[k], r[k];
    for(int i=0;i<k;i++)
    cin>>l[i]>>r[i];
    dp[0]=1;
    ans[0]=1;
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<k;j++)
        {
            int m1=i-r[j], m2=i-l[j];
            if(m2>=0)
            ans[i]=(ans[i]+dp[m2])%mod;
            m1--;
            if(m1>=0)
            ans[i]=(ans[i]-dp[m1]+mod)%mod;
        }
        dp[i]=(dp[i-1]+ans[i])%mod;
    }
    cout<<ans[n-1];
}

Measured memory_bytes: 6748
def f(a):
    if a % 4 == 1:
        return 1
    elif a % 4 == 2:
        return a + 1
    elif a % 4 == 3 or a == 0:
        return 0
    else:
        return a


a, b = map(int, input().split())
print(f(b) ^ f(a - 1))
#sample answer.

Measured memory_bytes: 2940