akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <tuple>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

using T = tuple<ll,ll>;
using Graph = vector<vector<T>>;

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

    ll x;
    cin >> x;

    ll s(100);
    for (ll i=0; ; i++)
    {
        if (s>=x)
        {
            cout << i << endl;
            return 0;
        }

        s += s / 100;
        //cout << gain << ' ' << s << endl;
    }

    return 0;
}


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

int n,m;
vector<int> G[100001];
vector<int> mdfG[100001];
bool useless[100001];
int cutted[100001];
bool used[100001];
vector<int> route;
int cmp[100001];
int all=0;
int ans=0;

set<deque<int> > se;

void dfs(int v,int p){
	used[v]=true;
	route.push_back(v);
	for(int i=0;i<mdfG[v].size();i++){
		int next=mdfG[v][i];
		if(p!=next){
			if(!used[next]){
				dfs(next,v);
			}else{
				deque<int> tmp;
				int si=route.size()-1;
				while(route[si]!=next){
					tmp.push_back(route[si]);
					si--;
				}
				tmp.push_back(next);
				int best=next;
				for(int j=0;j<tmp.size();j++){
					best=min(best,tmp[j]);
				}
				while(best!=tmp[0]){
					int tp=tmp.front();
					tmp.pop_front();
					tmp.push_back(tp);
				}
				se.insert(tmp);
			}
		}
	}
	used[v]=false;
	route.pop_back();
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	if(m==n-1){
		printf("0\n");
	}else if(m==n){
		printf("1\n");
	}else{
		queue<int> que;
		memset(cmp,-1,sizeof(cmp));
		for(int i=0;i<n;i++){
			if(G[i].size()==1){
				que.push(i);
				useless[i]=true;
			}
		}
		while(que.size()){
			int v=que.front();
			que.pop();
			for(int i=0;i<G[v].size();i++){
				int next=G[v][i];
				cutted[next]++;
				if(!useless[next] && G[next].size()==cutted[next]+1){
					useless[next]=true;
					que.push(next);
				}
			}
		}
		for(int i=0;i<n;i++){
			if(G[i].size()-cutted[i]>=3){
				cmp[i]=all++;
				for(int j=0;j<G[i].size();j++){
					int next=G[i][j];
					if(useless[next])continue;
					if(G[next].size()-cutted[next]<=2){
						if(cmp[next]==-1){
							cmp[next]=all++;
							que.push(next);
						}
					}
				}
			}
		}
		if(que.size()==0){
			for(int i=0;i<n;i++){
				if(!useless[i]){
					que.push(i);
					cmp[i]=0;
					all++;
					break;
				}
			}
		}
		while(que.size()){
			int v=que.front();
			que.pop();
			for(int i=0;i<G[v].size();i++){
				if(cmp[G[v][i]]==-1 && !useless[G[v][i]]){
					cmp[G[v][i]]=cmp[v];
					que.push(G[v][i]);
				}
			}
		}
		for(int i=0;i<n;i++){
			if(useless[i])continue;
			for(int j=0;j<G[i].size();j++){
				if(cmp[i]!=cmp[G[i][j]] && !useless[G[i][j]])mdfG[cmp[i]].push_back(cmp[G[i][j]]);
			}
		}
		for(int i=0;i<all;i++){
			sort(mdfG[i].begin(),mdfG[i].end());
			mdfG[i].erase(unique(mdfG[i].begin(),mdfG[i].end()),mdfG[i].end());
		}
		dfs(0,-1);
		printf("%d\n",se.size()/2);
	}
	return 0;
}

Measured memory_bytes: 71156
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.util.Map.Entry;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		String s = sc.next();
		StringBuilder ans = new StringBuilder();
		for(int i = 0; i < s.length(); i++){
			if(s.charAt(i) == 'B'){
				if(ans.length() != 0) ans.delete(ans.length()-1, ans.length());
			}else ans.append(s.charAt(i));
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22996
n, k = map(int, input().split())

ans = 0
for i in range(k + 1, n + 1):
    ans += (n // i) * (i - k)
    if k == 0:
        m = n % i
    else:
        m = n % i - k + 1
    ans = max(ans, ans + m)

print(ans)

Measured memory_bytes: 9192
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (n,m) = scan "%d %d" Tuple2.make
let ls = scan_list ~sep:' ' Int.of_string

let () =
  let total = List.sum ls in
  let ms = List.sort Int.compare ls |> List.drop (n - m) in
  if ListL.exists ms ~f:((>=) ((pred total)/(4*m))) then
    Printf.printf "No\n"
  else Printf.printf "Yes\n"


Measured memory_bytes: 5380
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
int n;
LL a[55], k;
int main() {
	//freopen("atcoderd.in", "r", stdin);
	//freopen("atcoderd.out", "w", stdout);
	scanf("%lld", &k);
	n = 50;
	LL tmp = k / n;
	for(int i = 1; i <= n; i++)a[i] = n - 1;
	for(int i = 1; i <= n; i++){
		a[i] += tmp * n;
		for(int j = 1; j <= n; j++){
			if(j != i)a[j] -= tmp;
		}
	}
	for(int i = 1; i <= k % n; i++) {
		a[i] += n;
		for(int j = 1; j <= n; j++) {
			if(j != i)a[j]--;
		}
	}
	LL Min = a[1];
	for(int i = 2; i <= n; i++){
		if(Min > a[i])Min = a[i];
	}
	if(Min < 0)for(int i = 1; i <= n; i++)a[i] += abs(Min);
	printf("%d\n", n);
	for(int i = 1; i <= n - 1; i++){
		printf("%lld ", a[i]);
	}
	printf("%lld\n", a[n]);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 0

for  i in range(N):
    tmp = 0
    if A[i] >= B[i]:
        A[i] -= B[i]
        ans += B[i]
    else:
        ans += A[i]
        tmp = B[i] - A[i]
        A[i] = 0
        if A[i+1] >= tmp:
            A[i+1] -= tmp
            ans += tmp
        else:
            ans += A[i+1]
            A[i+1] = 0
            
print(ans)    

Measured memory_bytes: 97280
#include<stdio.h>
int main()
{
  int n,l,t[201],i,sum=0,c=0,sum1=0,small;
  scanf("%d%d",&n,&l);
  for(i=0;i<n;i++)
  {
    t[i]=l+(i+1)-1;
   // System.out.print(t[i]+" ");
    sum1=sum1+t[i];
  }
  for(i=0;i<n-1;i++)
  {
    if(t[i]==0)
    {
      c++; break;
    }
  }
  
  if(c==0)
  {
    if(sum1>=0)
    {
    small=t[0];
     for(i=1;i<n-1;i++)
     {
      if(t[i]<small)
      {
        small=t[i];
      }
     }
    }
    else
    {
      small=t[0];
      for(i=1;i<n;i++)
     {
      if(t[i]>small)
      {
        small=t[i];
      }
     }
    }
    for(i=0;i<n;i++)
    {
      sum=sum+t[i];
    }
//    System.out.println(small);
    sum=sum-small;
  }
  
  else
  {
    for(i=0;i<n;i++)
    {
      sum=sum+t[i];
    }
  }
  
  printf("%d",sum);
    
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include <string>
#include <algorithm>

using namespace std;
typedef long long ll;


int main(){
    int n;
    int count = 0;
    string str;
    cin >> n;
    cin >> str;

    for (int i = 0; i < n; i++) {
        if (str[i] == 'A') {
            if (str[i + 1] == 'B') {
                if (str[i + 2] == 'C') {
                    count++;
                }
            }
        }
    }
    cout << count << endl;

    return 0;
}

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

#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9, MOD = INF + 7;
 
/////////////////////////////////////////////////////////////////////
 
const int N = 3e5 + 5, LOG = 20;

int FACT[N], INV[N];

int Power(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1LL * a * a % MOD) if (b & 1) res = 1LL * res * a % MOD;
	return res;
}
int C(int n, int k) { return k > n ? 0 : 1LL * INV[k] * INV[n - k] % MOD * FACT[n] % MOD; }
int P(int n, int m) { return C(n + m - 2, n - 1); }

int main() {
 
	sync;

	int h, w, a, b; cin >> h >> w >> a >> b;
	FACT[0] = 1;
	for (int i = 1; i < N; i++) FACT[i] = 1LL * FACT[i - 1] * i % MOD;
	INV[N - 1] = Power(FACT[N - 1], MOD - 2);
	for (int i = N - 2; i >= 0; i--) INV[i] = 1LL * INV[i + 1] * (i + 1) % MOD;
	int ans = 0;
	for (int i = 1; i <= h - a; i++) ans = (ans + 1LL * P(b, i) * P(w - b, h - i + 1) % MOD) % MOD;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
static const int INF = 10000000;
using ll = long long;

int main(){
	int N, A;
	cin >> N;
	vector<vector<P>> s(N, vector<P>());
	for(int i = 0; i < N; ++i){
		int A;
		cin >> A;
		for(int j = 0; j < A; ++j){
			int x, y;
			cin >> x >> y;
			x--;
			s[i].push_back(make_pair(x, y));
		}
	}
	
	int ans = 0;
	for(int i = 0; i < (1 << N); ++i){
		bool success = true;
		for(int j = 0; j < N; ++j){
            if(1 != ((i >> j) & 1)) continue;
			for(auto itr : s[j]){
				if (((i >> itr.first) & 1) != itr.second){
					success = false;
					break;
				}
			}
		}
		if(success){
            int tmp = 0;
            for(int j = 0; j < N; ++j){
              tmp += (i >> j) & 1;
	        }
			ans = max(ans, tmp);
		}
	}
	
    cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define chmax(x,y) x = max(x, y)
#define chmin(x,y) x = min(x, y)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 998244353;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<ll> sum(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(all(a));
    rep(i, n) {
        if(i == 0) sum[i] = (ll) a[i];
        else sum[i] = sum[i - 1] + (ll) a[i];
    }
    for(int i = n - 1; i >= 0; i--) {
        if(sum[i-1] * 2 < a[i]) {
            cout << n - i << endl;
            return 0;
        }
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 4564
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    String S;
    private void solve() {
        S = next();

        int ans = 753;
        for(int i = 0;i <= S.length() - 3;i++) {
            String substr = S.substring(i, i + 3);
            int a = Integer.parseInt(substr);

            if (Math.abs(753 - a) < ans) {
                ans = Math.abs(753 - a);
            }
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22612
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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 main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  a.push_back(0);
  a.push_back(1e9+1);
  sort(a.begin(), a.end());
  int l = 0, r = n+1;
  while (r-l > 1) {
    int mid = (l+r)/2;
    vector<bool> dp(k);
    dp[0] = true;
    int mx = 0;
    rep(i, n+2) {
      if (i == mid)
        continue;
      for (int j = k-1; j >=0; j--) {
        if (dp[j] && j+a[i] < k) {
          dp[j+a[i]] = true;
          chmax (mx, j+a[i]);
        }
      }
    }
    if (mx+a[mid] >= k)
      r = mid;
    else
      l = mid;
  }
  cout << l << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
static const int MAX_N = 100;
static const int MAX_V = 100;
static const int INF = 1 << 30;

int N, W;
int v[MAX_N], w[MAX_N];
int dp[MAX_N + 1][MAX_N * MAX_V + 1];

void solve(){
	fill(dp[0], dp[0] + MAX_N * MAX_V + 1, INF);
	dp[0][0] = 0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= MAX_N * MAX_V; j++){
			if(j < v[i]){
				dp[i + 1][j] = dp[i][j];
			}else{
				dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
			}
		}
	}
	int res = 0;
	for(int i = 0; i <= MAX_N * MAX_V; i++) if(dp[N][i] <= W) res = i;
	printf("%d\n", res);
}

int main(){
	scanf("%d %d", &N, &W);
	for(int i = 0; i < N; i++) scanf("%d %d", &v[i], &w[i]);
	solve();
	return 0;
}

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

int n,k,m;

int ans(){

  queue<int> Q;
  
  for(int i=m+1 ; i <= n ; i++)Q.push(i);
  for(int i=1 ; i < m ; i++)Q.push(i);
  
  while(Q.size() != 1){
    int temp;
    for(int i=0 ; i < k-1 ; i++){
      temp=Q.front();
      Q.pop();
      Q.push(temp);
    }
    Q.pop();
  }
  
  return Q.front();
  
}
int main(){
  
  while(1){
    
    cin >>n>>k>>m;
    if(n==0 && k==0 && m==0)break;
    
    cout <<ans()<<endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 1268
#include<stdio.h>
int main()
{
	int a[200],i=0,num,count=0;
	scanf("%d",&num);
	for(i=0; i<num; i++)
		scanf("%d",&a[i]);
	while(1){
		for(i=0; i<num; i++){
			if(a[i] % 2 == 0)
				a[i] = a[i]/2;
			else{
				printf("%d",count);
				return 0;
				}
			}
		count++;
		}
}

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

int main(){
    int A,B;
    cin >> A >> B;
    for(int i = 1; i <= 1000; i++){
        int a = i * 0.08;
        int b = i * 0.10;
        if(a == A && b == B){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

long XOR(long a, long b){
  long bit_a[40],bit_b[40],bit_xor[40];
  for (int i = 0; i < 40; i++) {
    bit_a[i] = 0;
    bit_b[i] = 0;
  }
  bit_a[0] = a;
  bit_b[0] = b;
  for (int i = 1; i < 40; i++) {
    bit_a[i] += bit_a[i-1]/2;
    bit_a[i-1] %= 2;
    bit_b[i] += bit_b[i-1]/2;
    bit_b[i-1] %= 2;
  }
  for (int i = 0; i < 40; i++) {
    if (bit_a[i] == bit_b[i]) {
      bit_xor[i] = 0;
    } else {
      bit_xor[i] = 1;
    }
  }
  for (int i = 38; i >= 0; i--) {
    bit_xor[i] += bit_xor[i+1]*2;
  }
  return bit_xor[0];
}

int main(void) {

  long a,b;
  scanf("%ld %ld", &a, &b);
  if (a == b) {
    printf("%ld\n", a);
    return 0;
  }
  if (a%2 == 0) {
    if ((b-a+1)%4 == 0) {
      printf("0\n");
    } else if ((b-a+1)%4 == 1) {
      printf("%ld\n", b);
    } else if ((b-a+1)%4 == 2) {
      printf("1\n");
    } else {
      printf("%ld\n", XOR(1,b));
    }
  } else {
    if ((b-a)%4 == 0) {
      printf("%ld\n", a);
    } else if ((b-a)%4 == 1) {
      printf("%ld\n", XOR(a,b));
    } else if ((b-a)%4 == 2) {
      printf("%ld\n", XOR(a,1));
    } else {
      printf("%ld\n", XOR(a,XOR(1,b)));
    }
  }

  return 0;
}

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

int main() {
  ll n;
  cin >> n;
  ll ans=0;
  for(ll i=1;i<=n;i++) {
    ll temp=i;
    ll count=1;
    while(temp/10) {
      temp/=10;
      count++;
    }
    if(count%2) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

using ll=long long;
#define max_sum 1000000000000000000

int main(){

  int n;
  cin >> n;

  ll a;
  ll sum=1;

  bool flag = 0;

  for(int i=0;i<n;i++){
    cin >> a;
    if(a==0){
      cout << 0 << endl;
      return 0;
    }
    if(flag==1 || max_sum/sum<a){
      flag=1;
    }else{
      sum*=a;
    }
  }

  if(flag==1) cout << -1 << endl;
  else cout << sum << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[200],sum=0,good=-1,mi=11451419;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
		a[i] *= n;
	}
	for(int i=0;i<n;i++){
		if(mi > abs(a[i]-sum) ){
			mi = abs(a[i]-sum);
			good = i;
		}
	}
	cout<<good<<endl;
	return 0;
}

Measured memory_bytes: 256
/*                          The four Truths of Life

                                    CKMKB
                                    PKMKB

                                    CKMKC
                                    PKMKC
*/


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define ye cout<<"YES";
#define no cout<<"NO";
#define ln cout<<"\n";
// cout<<"Case #"<<ts<<": “;
//priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;


using namespace std;

ll mod(ll x, ll m) {
	return (x % m + m) % m;
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t = 1, r, n, a, d, c, b, x, y, sum, cnt, i, j, k, m, l, q, maxx, minn, temp, ans, flag, g, ts;
	ll mod = 1000000007;
	char ch, chh;
	double dans;
	string str, ttr;

	//cin >> t;


	for (ts = 1; ts <= t; ts++)
	{
		flag = 0; sum = 0; cnt = 0; ans = 0; k = 0; maxx = 0; minn = 0; a = 0; b = 0; temp = 0;

		cin >> n;
		ll arr[n]; for (i = 0; i < n; i++) {cin >> arr[i];}

		temp = arr[0];

		for (i = 1; i < n; i++)
		{
			temp = (temp ^ arr[i]);
		}

		for (i = 0; i < n; i++)
		{
			x = (arr[i] ^ temp);
			cout << x << " ";
		}




		ln
	}
	return 0;
}


Measured memory_bytes: 5116
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int n;
    string s;
    cin >> n >> s;
    bool res = false;
    if(s.size() % 2 == 0){
        res = true;
        for(int i=0; i<n/2; i++){
            if(s.at(i) != s.at(n/2 + i)){
                res = false;
                break;
            }
        }
    }
    if(res){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

int K, A, B;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> K >> A >> B;
	for (int i = A; i <= B; ++i)
	{
		if ((i % K) == 0) { cout << "OK"; return 0; }
	}
	cout << "NG";
}

Measured memory_bytes: 3604
n=int(input())
s=input()
r,g,b=0,0,0
for i in range(n):
    if s[i]=="R":
        r+=1
    elif s[i]=="G":
        g+=1
    else:
        b+=1
chohuku=0
double=0
for i in range(1,n-1):
    for j in range(1,min(i+1,n-i)):
        chohuku+=1
        k=j+i
        l=i-j
        if s[i]!=s[k] and s[i]!=s[l] and s[l]!=s[k]:
            double+=1
ans=r*g*b-double
print(ans)

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

int dp[501][2][4][10][501],n,m,sum;
string s,t;

int dfs(int idx,bool tight=true,int zig=3,int pre=0,int mod=0){
  if(idx==s.size())return (!mod)&&(zig<3);
  int &res=dp[idx][tight][zig][pre][mod];
  if(~res)return res;
  res=0;
  int x=s[idx]-'0';
  int r=(tight?x:9);
  for(int i=0;i<=r;i++){
    if(zig<3&&pre==i)continue;
    if(zig==0&&pre>=i)continue;
    if(zig==1&&pre<=i)continue;
    res+=dfs(idx+1,tight&&i==r,zig<2?zig^1:zig==2?pre<i:i?2:3,i,(mod*10+i)%m);
    res%=10000;
  }
  return res;
}


main(){
  memset(dp,-1,sizeof(dp));
  cin>>s>>t>>m;
  int A=dfs(0);
  memset(dp,-1,sizeof(dp));
  swap(s,t);
  int B=dfs(0);
  r(i,t.size())sum+=(sum*10+(t[i]-'0'))%m;
  cout<<(B-A+10000+!sum)%10000<<endl;
}


Measured memory_bytes: 81704
using System;

namespace CF2016qB
{
    class A
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string k = "CODEFESTIVAL2016";
            int count = 0;

            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != k[i]) count++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
const int Maxn = 4010;
int sta[Maxn], tp;
int a[Maxn];
int n, A, B;
int main() {
	int i, j, k;
	cin >> A >> B; n = A+B;
	if(A <= B){ printf("Impossible\n"); return 0; }
	for(i = 0; i < n; i++){
		if(tp == 0){ sta[++tp] = i; continue; }
		cout << "? " << sta[tp] << " " << i << endl;
		char s;
		cin >> s;
		if(s == 'N') tp--;
		else sta[++tp] = i;
	}
	a[sta[tp]] = 1;
	for(i = 0; i < n; i++){
		if(i == sta[tp]) continue;
		cout << "? " << sta[tp] << " " << i << endl;
		char s;
		cin >> s;
		if(s == 'Y') a[i] = 1;
	}
	cout << "! ";
	for(i = 0; i < n; i++) cout << a[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 724
// In The Name Of God
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define sqr(A) ((A) * (A))
#define X first
#define Y second
#define MP make_pair
#define bsz  __builtin_popcount
#define all(A) A.begin(), A.end()
using namespace std;
using namespace __gnu_pbds;
template < typename T >
using ordered_set = tree < T , null_type , less < T > , rb_tree_tag , tree_order_statistics_node_update >;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int PR = 727;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 1e5 + 20;
int h[N], n, dp[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> h[i];
	dp[n - 2] = abs(h[n - 2] - h[n - 1]);
	for (int i = n - 3; i >= 0; i--)
		dp[i] = min(dp[i + 1] + abs(h[i] - h[i + 1]), dp[i + 2] + abs(h[i] - h[i + 2]));
	cout << dp[0] << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define f(i,j,k)=for(int i=j;i<=k;i++)  
#define f2(i,j,k)=for(int i=j;i>=k;i--)  
int main(){
    long long n;
    cin>>n;
    cout<<8-(n-400)/200<<endl;
    return 0;
}


Measured memory_bytes: 3636
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		int a[] = fs.nextIntArray(n);
		for(int i=0;i<n;i++) {
			int now = a[i];
			if(now % 2 != 0)continue;
			if(now % 3 == 0)continue;
			if(now % 5 == 0)continue;
			System.out.println("DENIED");
			return;
		}
		System.out.println("APPROVED");
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 22228
#include<stdio.h>
int main(void)
{
    int a,b,c,d;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&d);
    if(a*b >= c*d){
        printf("%d",a*b);
    }
    else{
        printf("%d",c*d);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    printf("%.10f\n%d\n",1.*a*b/2,(c*2==a && d*2==b));
    return 0;
}


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

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


int main() {
	vector<string>a;
	int b;
	string s;
	cin >> b;
	rep(i, b) {
		cin >> s;
		a.push_back(s);
	}
	cout << "AC x " << count(a.begin(), a.end(), "AC")<<endl;
	cout << "WA x " << count(a.begin(), a.end(), "WA") << endl;
	cout << "TLE x " << count(a.begin(), a.end(), "TLE") << endl;
	cout << "RE x " << count(a.begin(), a.end(), "RE") << endl;
	return 0;
}

Measured memory_bytes: 7464
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i,n) cout << s[i] << t[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 3528
/**
 * @author karayuu
 */

fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(" ").map { it.toInt() }
    var amount = 0

    val list = mutableListOf<Int>()

    (1..n).forEach { list.add(readLine()!!.toInt()) }

    list.sort()

    val remaining = x - (list.sum())
    amount += n

    amount += (remaining / list.first())

    println(amount)
}

Measured memory_bytes: 36200
#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)


#define MAX_V 110

struct edge{int to,cap,rev;};

vector<edge> G[MAX_V];  //??°???????????????
int level[MAX_V];       //?§??????????????????¢
int iter[MAX_V];        //???????????§????????????

// from??????to?????????????????????cap???????????°?????????????????????
void add_edge(int from,int to,int cap){
	G[from].push_back(  (edge){ to  ,cap,(int)G[to  ].size()   }  );
	G[to  ].push_back(  (edge){ from,0  ,(int)G[from].size()-1 }  );
}

// s????????????????????¢???BFS??§?¨??????????
void bfs(int s){
	rep(i,MAX_V)level[i]=-1;
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();que.pop();
		
		rep(i,G[v].size()){
			edge &e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}

//?¢?????????????DFS??§??¢???
int dfs(int v,int t,int f){
	if(v==t)return f;
	for(int &i=iter[v];i<G[v].size();i++){
		edge &e=G[v][i];
		if(e.cap>0&&level[v]<level[e.to]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

// s??????t???????????§???????±???????
int max_flow(int s,int t){
	if(s==t)return INF;
	int flow=0;
	for(;;){
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,INF))>0){
			flow+=f;
		}
	}
}

void isUsedDfs(int s,int t,bool used[MAX_V]){
	if(s==t)return ;
	for(auto &e:G[s]){
		if(!used[e.to]&&e.cap>0){
			used[e.to]=true;
			isUsedDfs(e.to,t,used);
		}
	}
}


int main(){
	int k,n,m;
	cin>>k>>n>>m;
	int s = 1+k+n;
	int t = 0;
	int v = s+1;
	
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		add_edge(a,b,c);
		add_edge(b,a,c);
	}
	
	rep(i,k)add_edge(s,i+1,INF);
	
	int res = max_flow(s,t);
	vector<edge> Greg[MAX_V];
	rep(i,v)Greg[i] = G[i];
	
	
	bool used[MAX_V]={};
	used[s]=true;
	isUsedDfs(s,t,used);
	
	int ans = 0;
	vector<int> sflow(v,-1),tflow(v,-1);
	rep(i,v){
		for(auto e:Greg[i]){
			if(used[i]&&!used[e.to]){
				rep(i,v)G[i] = Greg[i];
				if(sflow[i]==-1) sflow[i] = max_flow(s,i);
				if(tflow[e.to]==-1)tflow[e.to] = max_flow(e.to,t);
				ans = max( ans , res + min(sflow[i],tflow[e.to]) );
			}
		}
	}
	if(ans>=INF)cout<<"overfuro"<<endl;
	else cout<<ans<<endl;
	
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii  = pair<int,int>;
const int INF=1001001001;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    int n,m;
    cin >> n>>m;
    priority_queue<int> PQ;
    int t;
    rep(i, n)
    {
        cin >> t;
        PQ.push(t);
    }
    rep(i,m){
        t = PQ.top();
        t /= 2;
        PQ.pop();
        PQ.push(t);
    }
    ll ans = 0;
    rep(i, n)
    {
        int t=PQ.top();
        ans += t;
        PQ.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 892
#include<iostream>
using namespace std;
int main(){
  int num[5]={5,7,5,7,7},n,cnt=0,step,size,ie,f=0;
  string s[40];
  cin >> n;
  while(n!=0){
    cnt=0;
    step=0;
    for(int i=0;i<n;i++){
      cin >> s[i];
    }
    for(int i=0;i<n;i++){
      f=0;
      ie=0;
      for(int j=0;j<5;j++){
        size=0;
        while(num[j]>size){
        size += s[i+ie].length();
          ie++;
        }
        if(num[j]!=size){
          f=1;
          break;
        }
      }
    if(f==0){
      cout << i+1<<endl;
      break;
    }
  }
  cin >> n;
}
}



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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

ll ans[10001];

void solve(long long N) {
  FOR(x, 1, 110) {
    FOR(y, 1, 110) {
      FOR(z, 1, 110) {
        ll n = x * x + y * y + z * z + x * y + y * z + z * x;
        if (n < 10001) {
          ans[n]++;
        }
      }
    }
  }
  FOR(i, 1, N + 1) {
    cout << ans[i] << '\n';
  }
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}

Measured memory_bytes: 3724
#include<stdio.h>

int A[1000000],n;

int binarySearch(int);

int main()
{
  int i,q,k,sum=0;

  scanf("%d",&n);
  
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }

  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&k);
      if(binarySearch(k))sum++;
    }
  printf("%d\n",sum);

  return 0;
}


int binarySearch(int key)
{
  int left=0;
  int right=n;
  int mid;
  while(left<right)
    {
      mid=(left+right)/2;
      if(key==A[mid]) return 1;
      if(key>A[mid]) left=mid+1;
      else if(key<A[mid]) right=mid;
    }

  return 0;
}



Measured memory_bytes: 2132
N = int(input())
s = input()
t = input()
for i in range(N):
    s_matubi = s[i:]
    t_matubi = t[:N - i]
    if s_matubi == t_matubi:
        print(2 * N - len(s_matubi))
        break
else:
    print(2 * N)


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

using namespace std;

int main(void) {
    int a, b, A = 0, B = 0;
    for (int i = 0; i< 4; i++) {
        cin >> a;
        A += a;
    }
    for (int i = 0; i< 4; i++) {
        cin >> b;
        B += b;
    }

    cout << max(A, B) << endl;

    return 0;
}


Measured memory_bytes: 3068
#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define LC(a) (a<<1)
#define RC(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
#define fin(name)  freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define FOR(i,start,end) for(int i=start;i<=end;i++)  
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
const int N=1e3+5;

int a[N];

int main(){
    int n,ma=1,mi=1;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]<a[mi]) mi=i;
        if(a[i]>a[ma]) ma=i;
    }
	cout<<2*n-1<<endl;
    if(abs(a[ma])>=abs(a[mi])){
        for(int i=1;i<=n;i++){
            cout<<ma<<" "<<i<<endl;
        }
        for(int i=1;i<n;i++){
            cout<<i<<" "<<i+1<<endl;
        }
    }
    else{
        for(int i=1;i<=n;i++){
            cout<<mi<<" "<<i<<endl;
        }
        for(int i=n;i>1;i--){
            cout<<i<<" "<<i-1<<endl;
        }
    }
	return 0;
}

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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n, o;
    vector<int> v;
    cin >> n;
    while(n--){
    	int w;
    	cin >> w;
    	v.push_back(w);
    }
    for (int i = 1; i < v.size(); ++i){
    	int a = 0, b = 0;
    	for (int j = 0; j < i; ++j)
    		a += v[j];

    	for (int j = i; j < v.size(); ++j)
    		b += v[j];

    	if(i == 1)
    		o = abs(a-b);
    	else
    		o = abs(a-b) < o ? abs(a-b) : o;
    }
    cout << o << endl;
}

Measured memory_bytes: 256
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, M = rl()
H = rl()
import collections
edges = collections.defaultdict(list)
for i in range(M):
	a, b = rl()
	a = a-1
	b = b-1
	edges[a].append(b)
	edges[b].append(a)

ans = 0
visited = {}
for n in range(N):
	if n in visited: continue
	if n not in edges:
		ans += 1
		continue
	good = True
	for next_node in edges[n]:
		if H[n] <= H[next_node]:
			good = False
	if good:
		ans += 1
		for next_node in edges[n]:
			visited[next_node] = 1
	visited[n] = 1
print(ans)

Measured memory_bytes: 107028
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

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

def combination(m,n):
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def main():
    n, k = [int(x) for x in stdin.readline().rstrip().split()]
    a_1 = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    a_2 = [0] + [0] * (n-1)
    a_3 = []
    now = 1
    while True:
        now = a_1[now-1]
        a_3.append(now)
        if a_2[now-1]:
            break
        else:
            a_2[now-1] = 1
    start = a_3.index(a_3[-1])
    a_4 = a_3[:start]
    a_5 = a_3[start:-1]
    if k <= len(a_4):
        print(a_4[k-1])
    else:
        amari = k - len(a_4)
        # print(a_1,a_2,a_3,a_4,a_5)
        print(a_5[(amari%len(a_5))-1])

main()

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

using namespace std;

int main()
{
	int N, K, Q;
	cin >> N >> K >> Q;
	int a[N];
	int x;
	for(int i=0;i<N;i++)
	{
		a[i] = 0;
	}
	int p = Q;
	while(p--)
	{
		cin >> x;
		a[x-1] += 1;
		
	}
	for(int i=0;i<N;i++)
	{
		if((Q - a[i]) < K)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{   
    string n;
    cin >> n;
    int ans = 0;
    for(int i = 0;i < n.size();i++)
    {
        if(n[i] == '2')
        {
            ans++;
        }
    }
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
bool ok(string s)
{
	rep(i,s.size()/2)
		if(s[i]!=s[s.size()-i-1])return 0;
	return 1;
}
using namespace std;
int h,w,k;
int pre[20][1010];
int main(){
	cin>>h>>w>>k;
	rep(i,h){
		string s;
		cin>>s;
		pre[i][0]=0;
		forn(j,1,w){
			pre[i][j]=pre[i][j-1]+(int)(s[j-1]=='1');
		}
	}
	int ans=1e9+7;
	rep(i,1<<(h-1)){
		int last=0;
		vpii v;
		rep(j,h){
			if(j==h-1||(i&(1<<j))){
				v.pb(m_p(last,j));
				last=j+1;
			}
		}
		int cnt=0;
		rep(j,h)if(i&(1<<j))cnt++;
		int n=v.size();
		last=0;
		forn(j,1,w){
			int res[20]={0};
			rep(ii,n){
				forn(jj,v[ii].X,v[ii].Y){
					res[ii]+=(pre[jj][j]-pre[jj][j-1]);
				}
			}
			bool flag=0;
			rep(ii,n){
				if(res[ii]>k){ 
					cnt=1e9+7;
					flag=1;
					break;
				}
			}
			if(flag)break;
			int res1[20]={0};
			rep(ii,n){
				forn(jj,v[ii].X,v[ii].Y){
					res1[ii]+=(pre[jj][j]-pre[jj][last]);
				}
			}
			bool flag1=0;
			rep(ii,n){
				if(res1[ii]>k){
					flag1=1;
					break;
				}
			}
			if(flag1){
				cnt++;
				last=j-1;
			}
		}
	//	cout<<cnt<<endl;
		ans=min(cnt,ans);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
from fractions import gcd
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
  
def check_disjoint(i, div_list):
  flag = True
  for d in div_list:
    if gcd(i, d)!=1:
      flag = False
      break
  if flag:
    div_list.append(i)
  return div_list
      

a, b = map(int, input().split())
s = make_divisors(gcd(a, b))
if len(s) == 1:
  print(1)
else:
  div_list = [s[1]]
  inputs = s[2:]
  for i in inputs:
    div_list = check_disjoint(i, div_list)
  print(len(div_list)+1)

Measured memory_bytes: 5344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define REP(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)((x).size()))

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e15+10;
const ll mod = 1e9+7;
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; }
#define print(x) cerr << #x << " is " << x << endl;

#define MAX_V 5000 //(1e5 + 2)
#define INF 1000000  //1e6

ll dp[2005][2005];

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<P> B;
    rep(i, N){
        cin >> A[i];
        B.push_back(make_pair(A[i], i));
    }
    sort(ALL(B), greater<P>());
    
    rep(n, N){
        int i = B[n].second;
        ll v = B[n].first;
        //cout << i << " " << v << endl;
        rep(k, n + 1){
            if (k <= i)
                chmax(dp[k + 1][n - k],  dp[k][n - k] + v * abs(k - i));
            int ii = N - 1 - (n - k);
            if (i <= ii)
                chmax(dp[k][n - k + 1], dp[k][n - k] + v * abs(ii - i));
            //cout << v << " " << dp[k][n - k] + v * abs(k - i) << " dp [" << k << "][" << n - k + 1 << "] " << dp[k][n - k] + v * abs(ii - i) << endl;
            
        }
        //if (n == 1)exit(1);
    }
    ll ans = 0;
    rep(k, N + 1){
        //cout << "dp[ " << k << " " << N - k << " " << dp[k][N - k] << endl;
        chmax(ans, dp[k][N - k]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 26320