akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>

bool update(int*m, const std::vector<int>& max);

int main(int argc, char* argv[]){
  int n;
  std::ios::sync_with_stdio(false);

  std::int64_t* a;
  std::cin >> n;
  std::cin.ignore();
  a = new std::int64_t[n];
 
  for(int i = 0; i < n; i++){
    std::cin>> a[i];
  }

  std::vector<std::int64_t> pow2;
  std::int64_t p = 2;
  while(p < 1000000000){
    pow2.push_back(p);
    p *= 2;
  }

  int c = 0;
  for (int i = 0; i < n; i++){
    int c_i = 0;
    for (int j = 0; j < pow2.size(); j++){
      if ((a[i] % pow2[j]) == 0){
        c_i = j + 1;
      } else {
        break;
      }
    }
    c += c_i;
  }
  std::cout << c;
  delete [] a;
  return 0;  
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
//unionfind
struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  rep(i,n-k){
    if(a.at(i+k)>a.at(i))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

Measured memory_bytes: 3956
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n = ini()
a = inl()
b = inl()
for i in range(1, n):
    a[i] += a[i-1]
for i in range(n-2, -1, -1):
    b[i] += b[i+1]
ans = 0
for i in range(n):
    ans = max(ans, a[i] + b[i])
print(ans)

Measured memory_bytes: 9128
#include<stdio.h>

int main(){
  long int x = 0;
	double A, B, N;
	scanf("%lf %lf %lf", &A, &B, &N);
	if(N >= B - 1){
      x = A * ((B - 1) / B);
		printf("%ld", x);
	}
	else{
      x = A * (N / B);
		printf("%ld", x);
	}

	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

	cout << (n % 500 <= a ? "Yes" : "No") << endl;
}


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

using namespace std;

int main()
{
   string S,T;
   cin >> S >> T;
   int count=0;

   for(int i= 0; i<3;++i)
   {
      if(S[i]==T[i]) count++;
   }

   cout << count << endl;
}


Measured memory_bytes: 256
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  string s;
  cin >> s;
  int i,ans=(1<<29);
  for(i=0;i<s.size()-2;i++){
    int a=s[i]-'0',b=s[i+1]-'0',c=s[i+2]-'0';
    ans=min(ans,abs(753-(100*a+10*b+c)));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3560
N,H=map(int,input().split())
L=[list(map(int,input().split())) for _ in range(N)]
A=max(a for a,_ in L)
B=sorted(b for _,b in L if b>A)
M=len(B)
while B and H>0:
    H-=B.pop()
print(M-len(B)+max(-1,H-1)//A+1)

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S; cin >> S;
    string ans;
    if (S == "A"){ans = "T";}
    else if (S == "T"){ans = "A";}
    else if (S == "C"){ans = "G";}
    else if (S == "G"){ans = "C";}
    cout << ans << endl;
}

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


Measured memory_bytes: 3580
{-# LANGUAGE BangPatterns, MultiWayIf #-}
import Control.Applicative((<$>))
import Control.Monad
-- import Data.Map ((!))
-- import qualified Data.Map as M
import Data.IntMap ((!))
import qualified Data.IntMap as M
import qualified Data.List as L
import Data.Maybe (catMaybes)
-- import Debug.Trace
-- import qualified Data.Char as C
-- import qualified Data.IntSet as I
-- import Text.Regex.Posix ((=~))
--------------------------------------------
readInt    = read :: String -> Int
getInt     = readInt <$> getLine
getIntList = map readInt . words <$> getLine
int2bin 0 =  []
int2bin n =  n `mod` 2 : int2bin (n `div` 2)
----------------------------------------------

data Pos = Pos { x :: Int, y :: Int }

mkMap [] _ m = m
mkMap (xs:xss) j m = mkMap xss (j+1) (_mkMap xs 1 j m)
  where
    _mkMap [] _ _ m = m
    _mkMap (a:as) i j m = _mkMap as (i+1) j $ (a, Pos i j):m

sub (Pos x y) (Pos x' y') = abs (x-x') + abs (y-y')

mkTable x to d m cach
  | x == to+1 = cach
  | x <= d    = mkTable (x+1) to d m $ M.insert x 0 cach
  | otherwise =
      let
        !d_pre   = cach ! (x-d)
        !pos_pre = m ! (x-d)
        !pos     = m ! x
        !cost    = d_pre + sub pos_pre pos
      in
        mkTable (x+1) to d m $ M.insert x cost cach

main :: IO ()
main = do
  [h, w, d] <- getIntList
  tmp <- replicateM h getIntList
  q   <- getInt
  lrs <- replicateM q getIntList
  let m = M.fromList $ mkMap tmp 1 []
      table = mkTable 1 (h*w) d m M.empty
  forM_ lrs $ \[l, r] -> do
    print $ table ! r - table ! l


Measured memory_bytes: 140156
program main
	implicit none
	character(20) :: S
	integer :: i, ans, left
	integer, allocatable :: x(:)
	read(*, *) S
	allocate(x(1:len_trim(S) + 1))
	do i = 1, len_trim(S)
		if(S(i:i) == 'A' .OR. S(i:i) == 'C' .OR. S(i:i) == 'G' .OR. S(i:i) == 'T') then
			x(i) = 1
		else
			x(i) = 0
		end if
	end do
	x(len_trim(S)+1) = 0
	
	ans = 0
	do i = 1, len_trim(S)
		if(x(i) == 1) then
			left = i
			do while(x(left+1) == 1)
				left = left + 1
			end do
			ans = max(ans, left - i + 1)
		end if
	end do
	write(*, *) ans
end program main

Measured memory_bytes: 256
n, k = gets.split.map!(&:to_i)
a    = gets.split.map!(&:to_i).unshift(0)

x = 1
a1 = 1
a2 = a[a1]
while a1 != a2
  x += 1
  a1 = a[a1]
  a2 = a[a[a2]]
end

y = 0
a1 = 1
a2 = a2
while a1 != a2
  y += 1
  a1 = a[a1]
  a2 = a[a[a2]]
end

k = (k - y) % x + y if k >= y

puts k.times.inject(1) { |ai, *| a[ai] }


Measured memory_bytes: 27200
#include <cstdio>
#define mod (ll)1e9+7
using namespace std;
typedef long long ll;
int n;
ll ans;
int main() {
	scanf("%d",&n);
	ans=1;
	for (int i=1;i<=n;i++) {
		ans*=i;
		ans%=mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
// Don't place your source in a package
import java.util.*;
import java.lang.*;
import java.io.*;

// Please name your class Main
class Main {
	public static void main (String[] args) throws java.lang.Exception {
	    Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String str = in.next();
		
		int s = str.length();
		
		int ans = 300000;
		
		int e = 0;
		
		for(int i=0;i<s;i++){
		   if( str.charAt(i)=='E' ) e++;
		}
		
		int w = 0 ;
		
		for(int i=0;i<s;i++){
		    
		    if( str.charAt(i)=='E' ) e--;
		    
		    ans = Math.min(ans,w+e);
		    
		    
		    if( str.charAt(i)=='W' ) w++;
		}
	
		System.out.print(ans);
	}
}

Measured memory_bytes: 29020
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
const ll INF = 1LL<<60;




int main()
{
    int X,N;
    cin >> X >> N;
    vector<int> p(N);
    bool ok = false;
    rep(i,N){
        cin >> p[i];
        if(X == p[i]) ok = true;
    }

    int ans = 0;
    int sub = X;
    int temp = X;
    rep2(i,-1,102){
        bool ck = false;
        rep(j,N){
            if(p[j] == i){
                ck = true;
            }
        }
        if(!ck) temp = fabs(X - i);
        if(temp < sub) ans = i;
        sub = temp;
    }

    if(!ok) ans = X;
    cout << ans << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
struct custom_hash 
{
    static unsigned long long splitmix64(unsigned long long x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(unsigned long long x) const 
    {
        static const unsigned long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
mt19937 random_generator(chrono::steady_clock::now().time_since_epoch().count());

int a, b, c, d; 
void read()
{
	cin >> a >> b >> c >> d; 
}

void solve()
{
	for (int i = 1; ; i++)
	{
		if (i % 2 == 1)
		{
			c -= b; 
			if (c <= 0)
			
			{
				cout << "Yes" << endl;
			
			return;
		} 
		}
		
		else 
	    {
			a -= d; 
			if (a <= 0)
			{
				cout << "No" << endl;
			return;
		} 
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	read();
	solve();
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,flag;
    cin>>n;
    int a[n],i,j=0;
    for(i=0; i<n; i++)
        cin>>a[i];
    sort(a,a+n);
    while(a[n-2]!=0)
    {
        flag=0;
        for(i=0; i<n; i++)
        {
            if(a[i]==0)
                i++;

            else
            {
                flag=1;
                for(j=i+1; j<n; j++)
                {
                    a[j]=a[j]%a[i];
                }
            }
            if(flag==1)
                break;
        }

        sort(a,a+n);

    }
    cout<<a[n-1]<<endl;

    return 0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  bool b = true;
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while (true) {
    C -= B;
    if (C <= 0) {break;}
    A -= D;
    if (A <= 0) {
      b = false;
      break;
    }
  }
  if (b) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}

Measured memory_bytes: 3620
#include<stdio.h>

int n,C[50];

int solve(int s,int y){
  if(y==0) return 1;
  if(s>=n) return 0;
  int res=solve(s+1,y) || solve(s+1,y-C[s]);
  return res;
}

int main(){
  int a,b,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&C[i]);
  }
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&b);
    if(solve(0,b)) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}



Measured memory_bytes: 2100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;
	static boolean bElapsed = false;

	void solve() {
		int[] ia = readNums();
		int n = ia[0];
		int m = ia[1];
		long ans = 0;
		if (n == 1 && m == 1)
			ans = 1;
		else if (n == 1)
			ans = m - 2;
		else if (m == 1)
			ans = n - 2;
		else
			ans = (long)(n - 2) * (m - 2);
		pln(ans);
	}

	int abs(int a) {
		return (a >= 0) ? a : -a;
	}

	int max(int a, int b) {
		return (a > b) ? a : b;
	}

	int min(int a, int b) {
		return (a < b) ? a : b;
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++) {
			nums[i] = pint(flds[i]);
		}
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	static BufferedReader _in;
	static PrintWriter _out;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.err.println((end - start) + "ms");
		}
	}
}


Measured memory_bytes: 21204
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

lint p=1000*1000*1000+7;
lint pro[100002];

lint pow_mod(lint a,lint b,lint p){
if(b==0)return 1;
  if(b%2==0){
    lint d=pow_mod(a,b/2,p);
    return (d*d)%p;
  }else{
    return (a*pow_mod(a,b-1,p))%p;
  }
}

//x / a mod p=x * inv_mod(a,p) 
lint inv_mod(lint a,lint p){
  return pow_mod(a,p-2,p);//(a^(p-2))mod p
}

lint comb_mod(lint n,lint k,lint p){
  if(n<k)return 0;
  return pro[n]*inv_mod((pro[k]*pro[n-k])%p,p)%p;
}

int main(){
  pro[0]=1;
  FOR(i,1,100002)pro[i]=(pro[i-1]*i)%p;
  int n;
  cin>>n;
  int l,r;
  int an[n+1];
  REP(i,n+1)an[i]=-1;
  REP(i,n+1){
    int a;
    cin>>a;
    if(an[a-1]>=0){
      l=an[a-1];
      r=i;
      break;
    }
    an[a-1]=i;
  }
  // cerr<<l<<r<<endl;
  REP(i,n+1){
    lint ans=comb_mod(n+1,i+1,p)-comb_mod(l+(n-r),i,p);
    ans%=p;
    if(ans<0)ans+=p;
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 2432
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (A, B) = Read2Longs();
            if (CanEat(A, B))
            {
                return "Yay!";
            }
            else
            {
                return ":(";
            }
        }
        public static bool CanEat(long a, long b)
        {
            if (a + b < 1 && a + b > 16)
            {
                return false;
            }
            if(a >= 9 || b >= 9)
            {
                return false;
            }
            return true;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 28108
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string.h>
using namespace std;
typedef long long ll;

int main() {
    string s, ans; cin >> s;
    for (int i = 0; i < s.size(); i++) ans += 'x';
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18


int a[200005], b[200005];
int n, ans;

int main()
{
	//入力
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", a + i);
	for (int i = 0; i < n; i++) scanf("%d", b + i);

	//上位bitから走査
	for (int v = (1 << 28); v; v >>= 1)
	{
		//vまで全部1がたったbitをつくり,各a,bとアンドを取ることで
		//a,bのvより上位のビットだけを消す

		//vを上位から走査しているので、今必要ない分に絞って消せるので
		//上書きしてもかまわない
		for (int i = 0; i < n; i++) a[i] &= (v * 2 - 1);
		for (int i = 0; i < n; i++) b[i] &= (v * 2 - 1);

		//二部探索するためのソート
		sort(a, a + n); sort(b, b + n);

		int t = 0;

		for (int i = n - 1, j = 0, k = 0, l = 0; i >= 0; i--)
		{
			//vを超える最小の添字がj
			//v以上で2*vを超える最小の添字がk
			while (j < n && a[i] + b[j] < v) j++;
			while (k < n && a[i] + b[k] < 2 * v) k++;

			//3*vを超える最小の添字がl
			while (l < n && a[i] + b[l] < 3 * v) l++;

			//vビット目に立ってるビットが偶数か奇数か計算する
			t += k - j + n - l;
			t &= 1;
		}
		if (t) ans |= v;
	}
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int n;
	scanf("%d",&n);
	int tot = (n + 1001) / 1000;
	int bil = tot * 1000;
	bil -= n;
	bil %=1000;
	printf("%d\n",bil);
	
	return 0;
};

Measured memory_bytes: 3752
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const llong MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
template<class T>
int dp2csv(const vector<vector<T>> & dp, const string fname);
int range_check(int val, int min, int max) {
	if (val < min) {
		return -1;
	}
	if (val > max) {
		return -1;
	}
	return val;
}
template<class T,class T1>
bool array_find(const T& array, const T1& dst) {
	auto result = find(array.first(), array.end(), dst);
	if (result == array.end()) {
		return false;
	}
	else {
		return true;
	}
}
int main() {
	int k, x;
	cin >> k >> x;
	if (k * 500 >= x) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}
template<class T>
int dp2csv(const vector<vector<T>> & dp, const string fname) {
	ofstream ofs(fname);
	if (ofs.fail()) { cerr << "cannot open file. :" + fname << endl; return -1; }
	for (auto dp_row : dp) {
		for (auto dp_cell : dp_row) {
			ofs << dp_cell << ",";
		}
		ofs << endl;
	}
	ofs.close();
	return 0;
}


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

bool adj[8][8];

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		adj[u][v] = true;
		adj[v][u] = true;
	}

	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		p[i] = i;
	}
	int ans = 0;
	do {
		if (p[0] != 0) continue;
		bool ok = true;
		for (int i = 0; i < n - 1; i++) {
			if (!adj[p[i]][p[i + 1]]) {
				ok = false;
			}
		}
		if (ok) {
			ans++;
		}
	} while (next_permutation(p.begin(), p.end()));
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;




int main(){
    
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if (k <= a){
        cout << k;
    }
    else{
        if (k <= a+b){
            cout << a;
        }
        else{
            
            cout << a - ((k-a)-b);
        }
    }
}










Measured memory_bytes: 3624
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 305;
const int mo = 1e+9+7;

int f[N][N][N];
int n,m;
int ad[N][N][N];

int add(int x,int y){return x+y>=mo?x+y-mo:x+y;}

int main(){
	n=get();m=get();
	fo(t,1,m){
		int l=get(),r=get(),x=get();
		if (x==1){
			fo(i,l,r)ad[r][i][0]++,ad[r][i][r+1]--;
			fo(i,0,r)ad[r][i][l]++,ad[r][i][r+1]--;
			fo(i,l,r)ad[i][r][0]++,ad[i][r][r+1]--;
			fo(i,0,r)ad[i][r][l]++,ad[i][r][r+1]--;
			fo(i,0,r)
				fo(j,0,r)
				if (i>=l||j>=l)ad[i][j][r]++,ad[i][j][r+1]--;
		}
		if (x==2){
			fo(i,0,l-1)ad[r][i][0]++,ad[r][i][l]--;
			fo(i,0,l-1)ad[i][r][0]++,ad[i][r][l]--;
			fo(i,0,l-1)fo(j,0,l-1)ad[i][j][r]++,ad[i][j][r+1]--;
			fo(i,l,r)ad[r][i][l]++,ad[r][i][r+1]--;
			fo(i,l,r)ad[i][r][l]++,ad[i][r][r+1]--;
			fo(i,l,r)fo(j,l,r)ad[i][j][r]++,ad[i][j][r+1]--;
		}
		if (x==3){
			fo(i,0,r)ad[r][i][0]++,ad[r][i][l]--;
			fo(i,0,l-1)ad[r][i][l]++,ad[r][i][r+1]--;
			fo(i,0,r)ad[i][r][0]++,ad[i][r][l]--;
			fo(i,0,l-1)ad[i][r][l]++,ad[i][r][r+1]--;
			fo(i,0,r)
				fo(j,0,r)
				if (i<l||j<l)ad[i][j][r]++,ad[i][j][r+1]--;
		}
	}
	f[0][0][0]=1;
	fo(i,0,n)
		fo(j,0,n)
			fo(k,0,n){
				if (k)ad[i][j][k]+=ad[i][j][k-1];
				if (ad[i][j][k])f[i][j][k]=0;
				else{
					int w=max(i,max(j,k));
					f[w+1][j][k]=add(f[w+1][j][k],f[i][j][k]);
					f[i][w+1][k]=add(f[i][w+1][k],f[i][j][k]);
					f[i][j][w+1]=add(f[i][j][w+1],f[i][j][k]);
				}
			}
	int ans=0;
	fo(i,0,n)fo(j,0,n)ans=add(ans,f[i][j][n]);
	fo(i,0,n)fo(k,0,n)ans=add(ans,f[i][n][k]);
	fo(j,0,n)fo(k,0,n)ans=add(ans,f[n][j][k]);
	printf("%d\n",ans);
	return 0;
}

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

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

int main(){
  int n; cin >> n;
  set<int> st;

  rep(i,n){
    int a; cin >> a;
    st.insert(a);
  }
  if((n - st.size()) % 2 == 0) cout << st.size();
  else cout << st.size() - 1;
  cout << endl;
}

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

class UnionFind{
    public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> parent;

    //-1で初期化。最初はすべてバラバラ
    UnionFind(int N){
        parent = vector<int>(N,-1);
    }

    //Aがどのグループに属しているか(Aの根)を調べる
    int root(int A){
        if(parent[A] < 0) return A;
        return parent[A]=root(parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A){
        return -parent[root(A)];
    }

    //AとBをくっつける
    bool unite(int A, int B) {
    //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        //既にくっついているからくっつけない
        if(A == B) return false; 

        //大きいほう(A)に小さいほう(B)をくっつける
        //大小が逆ならひっくり返す
        if(size(A) < size(B)) swap(A,B);

        //Aのサイズを更新する
        parent[A] += parent[B];
        //Bの親をAに変更する
        parent[B] = A;

        return true;
    }

    //AとBが同じグループならtrueを返す
    bool same(int A, int B){
        return root(A)==root(B);
    } 
};

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

    int n,r;
    cin>>n>>r;
    int p[n];
    UnionFind uni(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
        p[i]--;
        uni.unite(p[i],i);
    }

    map<int,int> mp;
    for(int i=0;i<n;i++){
        if(uni.root(i)==i) mp[uni.size(i)]++;
    }
    int dp[r+1];
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    for(auto i:mp){
        for(int j=0;j<=r;j++){
            if(dp[j]>=0){
                dp[j]=i.second;
            }
            else if(j<i.first || dp[j-i.first]<=0){
                dp[j]=-1;
            }
            else dp[j]=dp[j-i.first]-1;
        }
    }
    if(dp[r]>=0){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;

    

}



Measured memory_bytes: 6492
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll cnt;
int main() {
    string s, t;
    cin >> s >> t;
    REP(i,s.size()){
        if (s[i] != t[i]) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3912
#include<stdio.h>
int main(){
  int i,j;
  int n;
  int ans=1,count;
  scanf("%d",&n);
  int d[n];
  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
  }
  for(i=1;i<n;i++){
    count=0;
    for(j=i-1;j>-1;j--){
      if(d[i]==d[j]){
        count++;
      }
    }
    if(count==0){
      ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
ll X,Y;
int main() {
    cin >> X >> Y;
    ll res = X;
    int result = 0;
    while (res <= Y){
        result++;
        res *= 2;
    }
    cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
F = [[int(x) for x in input().split()] for i in range(N)]
P = [[int(x) for x in input().split()] for i in range(N)]
ans = -10 ** 9
for i in range(1, 2 ** 10):
  pat = bin(i)[2:]
  pat = ['0' for i in range(10 - len(pat))] + list(pat)
  benefit = 0
  for j in range(N):
    benefit += P[j][sum([int(pat[k]) * F[j][k] for k in range(10)])]
  ans = max(ans, benefit)
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int main(){
	int N;
	cin >> N;
	int a[N];
	int sum = 0;
	FOR (i,0,N){
		cin >>a[i];
		sum  += a[i];
	}
	int ans = 0;
	int tar = sum/N;

	if(sum%N==0){
		FOR(i,0,N) ans += (tar-a[i])*(tar-a[i]);
	}else if (tar >= 0){
		int a1 = 0;
		int a2 = 0;
		FOR(i,0,N){
			a1 += (tar+1-a[i])*(tar+1-a[i]);
			a2 += (tar-a[i])*(tar-a[i]);
		}
		ans = min(a1,a2);
	}else{
		int a1 = 0;
		int a2 = 0;
		FOR(i,0,N){
			a1 += (tar-1-a[i])*(tar-1-a[i]);
			a2 += (tar-a[i])*(tar-a[i]);
		}
		ans = min(a1,a2);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(void)
{
	int H,W;
	while(true)
	{
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) 
		    break;
		for(int i = 0; i < W; i++) 
		    printf("#");
		printf("\n");

		for(int i = 1; i < H-1; i++){
			printf("#");
			for(int j = 1; j < W-1; j++) printf(".");
			printf("#\n");
		}

		if(H > 1){
			for(int i = 0; i < W; i++) printf("#");
			printf("\n");
		}
		printf("\n");
	}
}



Measured memory_bytes: 2588
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n + 1), b(n);
    rep(i, n + 1) cin >> a[i];
    rep(i, n) cin >> b[i];
    ll ans = 0;
    rep(i, n) {
        ll x = min(a[i], b[i]);
        a[i] -= x;
        b[i] -= x;
        ll y = min(a[i + 1], b[i]);
        a[i + 1] -= y;
        b[i] -= y;
        ans += x + y;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const ll mod = 998244353;
const ll N = 300006;
const ll INF = 1e18;
// 1 2 5 4 3
vector<bool>seen;
vector<int>E[N];

void dfs(int node) {
    seen[node] = true;
    for(auto it : E[node]) {
        if(!seen[it]) {
            dfs(it);
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    seen.resize(n + 1, false);
    int cnt = 0;
    for(int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        E[x].pb(y);
        E[y].pb(x);
    }
    for(int i = 1; i <= n; i++) {
        if(!seen[i]) {
            cnt++;
            dfs(i);
        }
    }
    cout << cnt - 1 << '\n';
    return 0;
}

Measured memory_bytes: 14292
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

double dfs(vector<int> V, vector< vector<double> > &D, int N, int M, int t, int i, double ret){
  if(N - i < M - t) return 0.0;
  if(t == M) return ret;
  double r = ret;
  for(int j = 0; j < t; ++j)
    r += D[i][V[j]];
  if(N - i >= M - t) ret = dfs(V,D,N,M,t,i+1,ret);
  V.push_back(i);
  ret = max(ret,dfs(V,D,N,M,t+1,i+1,r));
  return ret;
}

int main(){
  int N, M;
  cin >> N >> M;
  double L[N], a[N], b[N];
  for(int i = 0; i < N; ++i){
    cin >> L[i] >> a[i] >> b[i];
  }
  vector< vector<double> >  D(N,vector<double>(N));
  for(int i = 0; i < N; ++i){
    D[i][i] = 0.0;
    for(int j = i+1; j < N; ++j){
      D[i][j] = (L[i]-L[j])*(L[i]-L[j]) + (a[i]-a[j])*(a[i]-a[j]) + (b[i]-b[j])*(b[i]-b[j]);
      D[j][i] = D[i][j];
    }
  }

  vector<int> V;
  printf("%.10f\n",dfs(V,D,N,M,0,0,0.0));
  return 0;
}

Measured memory_bytes: 3336
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int N; cin >> N;
    vector<int> V(N);
    for(int &v:V){
        cin >> v;
    }
    vector<int> C = V;
    sort(C.begin(), C.end());
    
    int cnt = 0;
    for(int i=0; i<N; i++){
        if(V[i]!=C[i]) cnt ++;
    }
    if(cnt > 2) cout << "NO" << endl;
    else cout << "YES" << endl;
    
    return 0;
}



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

LL A, B, C, D;
map<LL, LL> memo;
LL solve(LL N) {
    if (N == 0) return 0;
    if (N == 1) return D;
    if (memo.count(N)) return memo[N];
    LL l2 = (N/2)*2;
    LL r2 = ((N+1)/2)*2;
    LL l3 = (N/3)*3;
    LL r3 = ((N+2)/3)*3;
    LL l5 = (N/5)*5;
    LL r5 = ((N+4)/5)*5;

    LL res = 1e18;
    if (N < res/D) res = N*D;
    res = min(res, llabs(l2-N)*D + A + solve(l2/2));
    res = min(res, llabs(r2-N)*D + A + solve(r2/2));

    res = min(res, llabs(l3-N)*D + B + solve(l3/3));
    res = min(res, llabs(r3-N)*D + B + solve(r3/3));

    res = min(res, llabs(l5-N)*D + C + solve(l5/5));
    res = min(res, llabs(r5-N)*D + C + solve(r5/5));

    memo[N] = res;

    return res;
}

int main() {
    int T;
    cin >> T;
    for (int t = 0; t < T; t++) {
        memo.clear();
        LL N;
        cin >> N;
        cin >> A >> B >> C >> D;
        cout << solve(N) << "\n";
    }

}


Measured memory_bytes: 4364
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)2e9 + 1;
const ll mod = (ll)1e9 + 7;

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

	d = d * 2 + 1;
	cout << (n + d - 1) / d << endl;
}

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

int main(){
  int n,q;
  cin>>n>>q;
  priority_queue<int>s[n];
  while(q--){
    int a,b,c;
    cin>>a>>b;
    if(!a){
      cin>>c;
      s[b].push(c);
    }
    else if(a==1){
      if(!s[b].empty())cout<<s[b].top()<<endl;
    }
    else if(!s[b].empty())s[b].pop();
  }
}


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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String str,arr[];
		List<String> list = new ArrayList<String>();
		while(null!=(str = in.readLine())){
			arr = str.split(",",0);
			list.add(arr[1]);
		}
		System.out.println(count("A",list));
		System.out.println(count("B",list));
		System.out.println(count("AB",list));
		System.out.println(count("O",list));
	}

	private static long count(String bl,List<String> list){
		int i=0;
		while(list.remove(new String(bl)))i++;
		return i;
	}
}

Measured memory_bytes: 17064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,i,j;
    cin>>n;
    vector<bool> used(n,false);
    vector<int> dist(n,99999999);
    map<int,vector<pair<int,int>>> v;
    for(i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        for(j=0;j<b;j++){
            int to,cost;
            cin>>to>>cost;
            v[i].emplace_back(to,cost);
        }
    }
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
    q.push(make_pair(0,0));
    dist[0]=0;
    while(!q.empty()){
        pair<int,int> e;
        e=q.top();q.pop();
        used[e.second]=true;
        dist[e.second]=min(dist[e.second],e.first);
        for(auto p:v[e.second]){
            if(!used[p.first]){
                q.push(make_pair(dist[e.second]+p.second,p.first));
            }
        }
    }
    for(i=0;i<n;i++){
        cout<<i<<' '<<dist[i]<<endl;
    }
}






Measured memory_bytes: 3160
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from bisect import bisect_left,bisect_right

class MinCostFlow:
    def __init__(self,n):
        self.n=n
        self.edges=[[] for i in range(n)]
    def add_edge(self,fr,to,cap,cost):
        self.edges[fr].append([to,cap,cost,len(self.edges[to])])
        self.edges[to].append([fr,0,-cost,len(self.edges[fr])-1])
    def MinCost(self,source,sink,flow):
        inf=10**15+1
        n,E=self.n,self.edges
        prev_v,prev_e=[0]*n,[0]*n
        mincost=0
        while flow:
            dist=[inf]*n
            dist[source]=0
            flag=True
            while flag:
                flag=False
                for v in range(n):
                    if dist[v]==inf:
                        continue
                    Ev=E[v]
                    for i in range(len(Ev)):
                        to,cap,cost,rev=Ev[i]
                        if cap>0 and dist[v]+cost<dist[to]:
                            dist[to]=dist[v]+cost
                            prev_v[to],prev_e[to]=v,i
                            flag=True
            if dist[sink]==inf:
                return 1
            f=flow
            v=sink
            while v!=source:
                f=min(f,E[prev_v[v]][prev_e[v]][1])
                v=prev_v[v]
            flow-=f
            mincost+=f*dist[sink]
            v=sink
            while v!=source:
                E[prev_v[v]][prev_e[v]][1]-=f
                rev=E[prev_v[v]][prev_e[v]][3]
                E[v][rev][1]+=f
                v=prev_v[v]
        return mincost

n=int(input())
J=[]
L_org,D_org=[1]*n,[1]*n
for _ in range(n):
    x,y,v=map(int,input().split())
    J.append((x,y,v))
m=int(input())
T=[]
for _ in range(m):
    t,a,b=input().split()
    a,b=int(a),int(b)
    T.append((t,a,b))
    if t=='L':
        L_org[b]=a+1
    elif t=='D':
        D_org[b]=a+1
for i in range(1,n):
    L_org[i]=max(L_org[i-1],L_org[i])
    D_org[i]=max(D_org[i-1],D_org[i])

def solve(k):
    L,D=L_org[:k],D_org[:k]
    R,U=[100]*k,[100]*k
    for t,a,b in T:
        if k-b-1>=0:
            if t=='R':
                R[k-b-1]=a-1
            elif t=='U':
                U[k-b-1]=a-1
    for i in range(k-2,-1,-1):
        R[i]=min(R[i],R[i+1])
        U[i]=min(U[i],U[i+1])
    solver=MinCostFlow(2*n+2*k+2)
    for i in range(1,k+1):
        solver.add_edge(0,i,1,0)
        solver.add_edge(2*n+k+i,2*n+2*k+1,1,0)
    for i in range(n):
        v=J[i][2]
        solver.add_edge(k+i+1,n+k+i+1,1,-v)
    for i in range(n):
        x,y=J[i][0],J[i][1]
        l=bisect_right(L,x)
        r=bisect_left(R,x)+1
        d=bisect_right(D,y)
        u=bisect_left(U,y)+1
        for j in range(r,l+1):
            solver.add_edge(j,k+i+1,1,0)
        for j in range(u,d+1):
            solver.add_edge(n+k+i+1,2*n+k+j,1,0)    
    return -solver.MinCost(0,2*n+2*k+1,k)

ans=0
k=1
while True:
    tmp=solve(k)
    ans=max(ans,tmp)
    if tmp==-1 or k==n:
        break
    k+=1
print(ans)

Measured memory_bytes: 121432
S=input()
T=input()

s=len(S)
t=len(T)
s_end=s-t+1

def count_mismatch(a):
    global t
    global T

    c=0
    for i in range(t):
        if a[i] != T[i]:
            c+=1
    return c


ans = t
for i in range(s_end):
    c = count_mismatch(S[i:i+t])
    if c < ans:
        ans = c

print(ans)

Measured memory_bytes: 9124
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
int mod = 1e9+7;

int main() {
  int n; cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  a.push_back(-2);
  int cnt = 0;
  for(int i=1; i<n; i++){
    if( a[i] == a[i-1] ){
      cnt++;
      a[i] = -1;
    }else if(a[i] == a[i+1]){
      cnt++;
      a[i+1] = -1;
    }
  }
  cout << cnt << endl;

  return 0;
}




//


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <iterator>

using namespace std;

#if 1
#define PRINT(x) { cout << #x << ": " << (x) << endl; }
#define PRINT_CONTAINER(x)  { cout << #x << ": ";                       \
        for (size_t ix = 0; ix < (x).size(); ++ix) cout << (x)[ix] << ", "; \
        cout << endl; }
#else
#define PRINT(x)
#define PRINT_CONTAINER(x)
#endif

enum { ODD, EVEN };

void
fill(vector<int>& area, int k, int x, int y)
{
    const int k2 = 2 * k;
    int xmin = x % k2, xmax = (x + k) % k2, ymin = y % k2, ymax = (y + k) % k2;
    if (xmin < xmax)
    {
        if (ymin < ymax)
        {
            ++area[k2 * xmin + ymin];
            --area[k2 * xmin + ymax];
            --area[k2 * xmax + ymin];
            ++area[k2 * xmax + ymax];
        }
        else
        {
            ++area[k2 * xmin + 0];
            --area[k2 * xmin + ymax];
            --area[k2 * xmax + 0];
            ++area[k2 * xmax + ymax];
            ++area[k2 * xmin + ymin];
            --area[k2 * xmax + ymin];
        }
    }
    else
    {
        if (ymin < ymax)
        {
            ++area[k2 * 0    + ymin];
            --area[k2 * 0    + ymax];
            --area[k2 * xmax + ymin];
            ++area[k2 * xmax + ymax];
            ++area[k2 * xmin + ymin];
            --area[k2 * xmin + ymax];
        }
        else
        {
            ++area[k2 * 0    + 0];
            --area[k2 * 0    + ymax];
            --area[k2 * xmax + 0];
            ++area[k2 * xmax + ymax];
            ++area[k2 * xmin + 0];
            --area[k2 * xmin + ymax];
            ++area[k2 * 0 + ymin];
            --area[k2 * xmax + ymin];
            ++area[k2 * xmin + ymin];
        }
    }
}

int main(int argc, char *argv[])
{
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> area(4 * k * k, 0);
    const int k2 = 2 * k;
    for (int i = 0; i < n; ++i)
    {
        int x, y;
        char c;
        scanf("%d %d %c", &x, &y, &c);
        if (c == 'B')
        {
            x += k;
        }
        fill(area, k, x, y);
        fill(area, k, x + k, y + k);
    }
    for (int i = 0; i < k2 - 1; ++i)
    {
        for (int j = 0; j < k2; ++j)
        {
            area[k2 * (i + 1) + j] += area[k2 * i + j];
        }
    }
    for (int i = 0; i < k2; ++i)
    {
        for (int j = 0; j < k2 - 1; ++j)
        {
            area[k2 * i + j + 1] += area[k2 * i + j];
        }
    }
    printf("%d\n", *std::max_element(area.begin(), area.end()));
}


Measured memory_bytes: 15872
H,W,K=map(int,input().split())
s=[]
for i in range(H):
    s.append([c=='#' for c in input()])
# print(s)

a=[[0 for j in range(W)] for i in range(H)]
x=0
for i,si in enumerate(s):
    if any(si):
        if si[0]:
            for j,sij in enumerate(si):
                if sij:
                    x+=1
                a[i][j]=x
        elif si[-1]:
            for j,sij in enumerate(si[::-1]):
                if sij:
                    x+=1
                a[i][W-1-j]=x
        else:
            x+=1
            f=True
            for j,sij in enumerate(si):
                if sij:
                    if f:
                        f=False
                    else:
                        x+=1
                a[i][j]=x

for i in range(H-1):
    if not any(s[i+1]):
        a[i+1]=a[i][:]
for i in range(H-1,0,-1):
    if not any(s[i-1]):
        a[i-1]=a[i][:]
    
for ai in a:
    print(*ai)

Measured memory_bytes: 48620