akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef pair<ll, ll> l4;
typedef long double ld;
typedef pair<ld,ld> ldd;
const ld pi = acosl(-1);
const int maxn = 2010;
const ll mod = 998244353;
const ll inf = 1e18;
const ld eps = 1e-10;
int n,a,b;

int main() {
    scanf("%d%d%d",&n,&a,&b);
    if ((a-b)%2 == 0) {
        printf("Alice");
    } else {
        printf("Borys");
    }
}


Measured memory_bytes: 384
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<long long> fib(n + 1);
	fib.at(0) = 1;
	fib.at(1) = 1;
	for (int i = 2; i <= n; i++) {
		fib.at(i) = fib.at(i - 1) + fib.at(i - 2);
	}
	cout << fib.at(n) << endl;
}


Measured memory_bytes: 3092
#include  <iostream>
#include  <stdio.h>
using namespace std;




int main(){

    int N;
    int K;
    string S;
    cin >> N;
    cin >> S;
    cin >> K;

    string tar;
    string tar_x;
    string ans;
    ans = "";
    tar = S.substr(K-1,1);
    for( int ni = 0 ; ni < N ; ni++ ){
        tar_x = S.substr(ni,1);
        if(tar == tar_x){
            ans = ans + tar;
        }else{
            ans = ans + "*";
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
const input = require("fs").readFileSync("/dev/stdin", "utf8")
const lines = input.split('\n')
const [A, B, N] = lines[0].split(' ').map(Number)

const x = Math.min(N, B - 1)
const res = Math.floor(A * x / B) - A * Math.floor(x / B)

console.log(res)

Measured memory_bytes: 29480
program main

  implicit none
  integer :: a, b, m
  integer,allocatable :: aa(:), bb(:), x(:), y(:), c(:)
  
  integer :: i, tmp
  integer,allocatable :: ans(:)
  
  read(*,*) a, b, m
  allocate( aa(a) )
  allocate( bb(b) )
  read(*,*) aa
  read(*,*) bb
  allocate( x(m) )
  allocate( y(m) )
  allocate( c(m) )
  do i = 1, m
    read(*,*) x(i), y(i), c(i)
  end do

  allocate( ans(m) )

  do i = 1, m
    ans(i) = aa(x(i)) + bb(y(i)) -c(i)
  end do
  
  tmp =  minval( aa ) + minval( bb )
  
  if( minval( ans ) > tmp ) then
    print*, tmp
  else
    print*, minval( ans )
  endif
  
  

end program main


Measured memory_bytes: 3200
n = int(input())
s = input()

ans = 0
for i in range(1, n):
    left = list(s[:i])
    right = list(s[i:])
    
    t = 0
    for j in set(left):
        if j in right:
            t += 1
    
        ans = max(ans, t)
        
print(ans)

Measured memory_bytes: 9088
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

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

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


fn main() {
    input!{n:usize, t:[i64;n], m:usize, p:[(i64,i64);m]};
    for i in 0..m {
        let mut sum = 0;
        for j in 0..n {
            if j+1 == p[i].0 as usize {
                sum += p[i].1;
            } else {
                sum += t[j];
            }
        }
        println!("{}", sum);
    }
}


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

int main(){
  char a;
  cin >> a;
  if (a == 'A') cout << 'T' << endl;
  else if (a == 'T') cout << 'A' << endl;
  else if (a == 'C') cout << 'G' << endl;
  else if (a == 'G') cout << 'C' << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
)

func proc(r io.Reader, w io.Writer) {
	var n, d int
	fmt.Fscanf(r, "%d", &n)
	a := make([]int, n+1)
	b := make([]int, n)
	for i := 0; i < n+1; i++ {
		fmt.Fscanf(r, "%d", &d)
		a[i] = d
	}
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%d", &d)
		b[i] = d
	}

	var prev, cur int
	sum := 0
	f := a[0]
	if f > b[0] {
		f = b[0]
	}
	prev = f
	for i, bb := range b {
		aa := a[i+1]
		if prev > bb {
			prev = bb
			cur = 0
		} else {
			cur = bb - prev
			if cur > aa {
				cur = aa
			}
		}
		sum += prev + cur
		prev = aa - cur
	}

	fmt.Fprintf(w, "%d", sum)
}

func main() {
	proc(os.Stdin, os.Stdout)
}


Measured memory_bytes: 5504
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    gcd = fractions.gcd(a, b)
    cnt = 1

    for i in range(2, int(gcd ** 0.5) + 1):
        if gcd % i == 0:
            cnt += 1
            while True:
                if gcd % i == 0:
                    gcd //= i
                else:
                    break
    print(cnt + 1 if gcd != 1 else cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 64492
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  vector<bool> chk(b, false);
  int n = a % b;
  while(chk.at(n) == false){
    chk.at(n) = true;
    n = (n+a) % b;
  }
  if(chk.at(c)== true) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    string s,t,ans;
    ans="No";
    int co=0;
    cin>>s>>t;
    int n=s.size();
    int j;
    rep(i,n){
      if(s[i]==t[0]){
        for(j=i;j<n+i;j++){
          if(j<=n-1&&s[j]!=t[j-i]){
            co=0;
            break;
          }else if(j>n-1&&s[j-n]!=t[j-i]){
            co=0;
            break;
          }else{
            co++;
          }
             }
             }
      if(co==n){
        break;
      }
             }
    if(co==n){
      ans="Yes";
    }
    cout<<ans<<endl;        
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int>v[100000];
int visited[200000];
int dp[200000];
int dfs(int x)
{
		//cout<<"hguhs";
	if(v[x].size()==0)
	{
    dp[x]=0;
	return 0;
	}
	if(visited[x]==1)
	return dp[x];
	visited[x]=1;
	int m=0,ans=0;
	for(int i=0;i<v[x].size();i++)
	{
		int p=v[x][i];
		if(visited[p]==0)
		{
		 m=dfs(p);
		ans=max(ans,m);
		}
		else
		ans=max(ans,dp[p]);
	}
	dp[x]=1+ans;
	return 1+ans;
}
int main() 
{
	int x,y,i,p,q,l;
	cin>>x>>y;
	for(i=0;i<y;i++)
	{
		cin>>p>>q;
		v[p].push_back(q);
		//cout<<v[p].size();
	}
	for(i=1;i<=x;i++)
	{
		if(visited[i]==0)
		dfs(i);
		//cout<<dp[i];
	}
	l=0;
	for(i=1;i<=x;i++)
	{
		//cout<<dp[i];
		if(l<dp[i])
		l=dp[i];
	}
	cout<<l<<endl;
	return 0;
}


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

int main(){
    long long int A,B,C,K,sum=0;
    cin >> A >> B >> C >> K;
    if(K < A + B + 1){
        sum = min(K,A);
    }
    else{
        sum = A - (K - A - B);
    }
    cout << setprecision(9) << sum;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define po pop_front
#define m(o) memset(o,-1,sizeof(o))
#define fo(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pi pair < int , int > 
const int b=22,dx[]={1,0,-1,0},dy[]={0,1,0,-1};
string in[b];
int far[b][b];
int n,m,ans=-1;
pi a;
int bfs()
{
	deque < pi > p;m(far);
	p.pb(a);
	far[a.first][a.second]=0;
	while(!p.empty())
	{
		pi now=p[0];
		p.po();
		int x=now.first,y=now.second;
		fo(i,4)
		{
			int xx=x+dx[i],yy=y+dy[i];
			if(xx<0||yy<0||yy>=m||xx>=n||in[xx][yy]=='#')	continue;
			if(far[xx][yy]==-1)
			{
				p.pb(mp(xx,yy));
				far[xx][yy]=far[x][y]+1;
			}
		}
	}
	int ans2=0;
	fo(i,n)
		fo(c,m)
			ans2=max(ans2,far[i][c]);
	return ans2;
}
int main()
{
	cin>>n>>m;
	fo(i,n)
		cin>>in[i];
	fo(i,n)
	{
		fo(c,m)
		{
			if(in[i][c]!='#')
			{
				a=mp(i,c);
				int now=bfs();
				ans=max(ans,now);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3516
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int N = (1 << 10) + 1;

int ans[N][N];

void run(int len, int i, int j) {
	if (len == 1) {
		ans[i][j] = 1;
	} else {
		for (int x = 0; x < 2; x++) {
			for (int y = 0; y < 2; y++) {
				run(len / 2, i + x * (len / 2 + 1), j + y * (len / 2 + 1));
			}
		}
		ans[i + len / 2][j + len / 2] = 1;
	}
}

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

	int n, m;
	cin >> n >> m;
	n = (1 << n) - 1;
	m = (1 << m) - 1;
	int t = max(n, m);
	run(t, 0, 0);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cout << ans[i][j];
		}
		cout << '\n';
	}
}


Measured memory_bytes: 5376
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= min(9, n); ++i) {
        if (n % i == 0) {
            int d = n / i;
            if (1 <= d && d <= 9) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
    int n;
    cin >> n;
    V<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = inf;
    sort(all(a));
    for(int i = 0; i <= 2000; i++) {
        int tmp = 0;
        rep(j,n) chmax(tmp, abs(a[j]-i));
        chmin(ans, tmp);
    }
    cout << ans << endl;
}


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

int main() {
    int k;
    string s;
    cin >> k >> s;

    if (k >= s.length()) {
        cout << s << endl;
    } else {
        cout << s.erase(k) << "..." << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

//反転とか
//2回やったら元に戻る
//操作の順序を入れ替えても結果が変わらない。
//この問題の場合、（端から考えることによって）貪欲的に決まっていく。
//計算量削減のため、差分を考えることも重要。

//境界に注目するの大事
//境界を１つずつ減らしていくイメージ

int max(int a, int b){
  if(a>=b){
    return a;
  }
  else{
    return b;
  }
}

int main(){
  string s;
  cin >> s;
  int s_len=s.size();
  int k=s_len;

  srep(i,1,s_len){
    if(s[i-1]!=s[i]){
      if(k>max(i, s_len-i)){
        k=max(i, s_len-i);
      }
    }
  }

  cout << k << endl;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if (x-r<0||x+r>W||y-r<0||y+r>H){
        cout<<"No"<<endl;
    }
    if (x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H){
        cout<<"Yes"<<endl;
    }   
    return 0;
    
   
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define M 2000
bool ab[100000],ac[100000],bc[100000];
bool match(char c1,char c2){
	return(c1== '?' ||c2== '?' ||c1==c2);
}
int main(void){
	int i,j;
	string a,b,c;
	cin>>a>>b>>c;
	int A=a.length();
	int B=b.length();
	int C=c.length();
	REP(i,A)REP(j,B)if(!match(a[i],b[j]))ab[i-j+50000] =true;
	REP(i,A)REP(j,C)if(!match(a[i],c[j]))ac[i-j+50000] =true;
	REP(i,B)REP(j,C)if(!match(b[i],c[j]))bc[i-j+50000] =true;
	int ans= 3 *M;
	for(i=-2*M;i<=2*M;i++)for(j=-2*M;j<=2*M;j++)if(!ab[i+50000] && !ac[j+50000] &&!bc[j-i+50000]){
		int L=min(0,min(i,j));
		int R=max(A,max(B+i,C+j));
		ans=min(ans,R-L);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

int main () {
    int n = 0, m = 0;
    cin >> n >> m;
    int a = 0, b = 0, tmp = 0, two = 0;
    vector<pair<int, ll>> key(m);
    for (int i=0; i<m; i++) {
        cin >> a >> b;
        two = 0;
        for (int j=0; j<b; j++) {
            cin >> tmp;
            tmp--;
            two += (1 << tmp);
        }
        key.at(i).first = two;
        key.at(i).second = a;
    }
    int len = (int)pow(2, n);
    vector<vector<ll>> dp(m+1, vector<ll>(len, 1e16));
    dp.at(0).at(0) = 0;
    for (int i=0; i<m; i++) {
        int tmp = key.at(i).first;
        ll cost = key.at(i).second;
        for (int j=0; j<len; j++) {
            if (dp.at(i).at(j) == 1e16) continue;
            dp.at(i+1).at(j) = min(dp.at(i+1).at(j), dp.at(i).at(j));
            dp.at(i+1).at(j|tmp) = min(dp.at(i+1).at(j|tmp), dp.at(i).at(j) + cost);
        }
    }
    cout << (dp.at(m).at(len-1) == 1e16 ? -1 : dp.at(m).at(len-1)) << endl;
    return 0;
}


Measured memory_bytes: 32384
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
#endif

#ifdef _DEBUG
void init_global_C() {}
#else

#endif

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

    int N;  cin >> N;
    vi A(N); REP(i, N) cin >> A[i];
    vi B(N); REP(i, N) cin >> B[i];
    vi C(N); REP(i, N) cin >> C[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    vl sa(N, 0);
    REP(i,N) {
        int l = 0, r = N;
        while(l < r) {
            int m = (l + r) / 2;

            if (A[m] >= B[i]) r = m;
            else l = m + 1;
        }
        sa[i] = l;
    }

    vl sc(N, 0);
    REP(i, N) {
        int l = 0, r = N;
        while(l < r) {
            int m = (l + r) / 2;

            if (B[i] < C[m]) r = m;
            else l = m + 1;
        }
        sc[i] = N - l;
    }

    ll ans = 0;
    REP(i, N) ans += sa[i]*sc[i];    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3072
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node {
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void init(){
    nil = (Node*)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
        if(cur==nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t){
    if(t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main(){
    int key, n, i;
    int size = 0;
    
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for(i=0; i<n; i++){
        scanf("%s%d", com, &key);
        if(com[0] == 'i') { insert(key); np++; size++; }
        else if(com[0] == 'd'){
            if(strlen(com) > 6){
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L') deleteLast();
            } else {
                deleteKey(key); nd++;
            }
            size--;
        }
    }
    printList();
    
    return 0;
}


Measured memory_bytes: 33992
n, m = gets.strip.split.map(&:to_i)
ab = readlines.map {|line| line.strip.split.map(&:to_i) }.sort_by(&:last)

#p ab
max_a = ab.map(&:first).max

results = []

ab.each do |a, b|
  last_element = results.last
  next if last_element && a <= last_element && last_element < b
  break if results.last.to_i > max_a

  results.push(b-1)
end

p results.length


Measured memory_bytes: 19832
#include<bits/stdc++.h>
#define ins insert
#define pb push_back
#define F first
#define S second
#define var auto
using namespace std;
typedef long long ll;

const int Max = 3e5 + 50;
const int Mod = 1e9 + 7;

vector<int> N[Max];

ll c[Max];
ll w[Max];
pair<ll,ll> cmin[Max];
pair<ll,ll> nocmin[Max];
bool seen[Max];

ll pw(int a , int b)
{
	if(b == 0)
		return 1;
	ll half = pw(a , b / 2);
	if(b % 2)
		return half * half % Mod * a % Mod;
	return half * half % Mod;
}

ll inv(int a)
{
	return pw(a , Mod - 2);
}

void DFS(int v , vector<int> & vec)
{
	seen[v] = true;
	vec.pb(v);

	for(var u : N[v])
		if(!seen[u])
			DFS(u , vec);
}


ll fact[Max];
int main()
{
	int n , x , y;cin >> n >> x >> y;
	for(int i = 1; i <= n ; i++)
		cmin[i] = {2000000000 , -1};

	for(int i = 0; i < n ; i++)
	{
		cin >> c[i] >> w[i];
		cmin[c[i]] = min(cmin[c[i]] , {w[i] , i});
	}

	pair<int,int> firstMn = {2000000000 , -1};
	pair<int,int> secMn = firstMn;

	for(int i = 1; i <= n ;i++)
	{
		if(cmin[i].F <= firstMn.F)
		{
			secMn = firstMn;
			firstMn = {cmin[i].F , i};
		}
		else if(cmin[i].F <= secMn.F)
		{
			secMn = {cmin[i].F , i};
		}
	}

	for(int i = 1; i <= n ; i++)
		if(i != firstMn.S)
			nocmin[i] = cmin[firstMn.S];
		else
			if(secMn.S >= 0)
				nocmin[i] = cmin[secMn.S];
			else
				nocmin[i] = {2000000000 , -1};

	for(int i = 0; i < n ; i++)
		N[i].clear();
	for(int i = 0; i < n ; i++)
	{
		if(w[i] + cmin[c[i]].F <= x)
		{
			N[i].pb(cmin[c[i]].S);
			N[cmin[c[i]].S].pb(i);
		}
		if(w[i] + nocmin[c[i]].F <= y)
		{
			N[i].pb(nocmin[c[i]].S);
			N[nocmin[c[i]].S].pb(i);
		}
	}
	//cout << '\n' << '\n';

	fact[0] = 1;
	for(int i = 1; i <= n + 5; i++)
		fact[i] = (fact[i - 1] * i) % Mod;

	ll ANS = 1;
	for(int i = 0; i < n ; i++)
	{
		if(!seen[i])
		{
			unordered_map<int,int> cnt;

			vector<int> vec;
			DFS(i , vec);
			for(var v : vec)
				cnt[c[v]]++;

			ll ans = fact[vec.size()];
			//cout << ans << " > ";
			for(var x : cnt)
			{
				int a = x.S;
				ans = (ans * inv(fact[a])) % Mod;
				//cout << ans << " => " ;
			}
			//cout << '\n';
			ANS = (ANS * ans) % Mod;
		}
	}
	cout << ANS << '\n';
}



Measured memory_bytes: 33284
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

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

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int a[3];
    int b=0;
    for (int i=0;i<3;i++)
    {
        cin>>a[i];
        if (a[i]%2==0)
        {
            b=1;
        }

    }
    if (b)
    {
        cout<<0;
        return 0;
    }
    sort(a, a+3);
    ull x=(ull)a[0]*a[1];
    cout<<x;

    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  long long n;
  cin >> n;
  vector<long long> k(n+1,1);
  vector<int> u(n+1,0);
  int m;
  cin >> m;
  rep(i,m){
    int a;
    cin >> a;
    u[a]=1;
  }
  if(u[1]==1)k[1]=0;
  rep(i,n-1){
    if(u[i+2]==1){
      k[i+2]=0;
      continue;
    }
    k[i+2]=(k[i]+k[i+1])%1000000007;
  }
  cout << k[n] << endl;
}  


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

int main(){
  int n;
  cin >> n;
  int a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
  }
  int c[n];
  int p[n],q[n];
  for(int i=0;i<n;i++){
    p[i]=0;
    q[i]=0;
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<=i;j++){
      p[i]=p[i]+a[j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=i;j<n;j++){
      q[i]=q[i]+b[j];
    }
  }
  for(int i=0;i<n;i++){
    c[i]=p[i]+q[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    ans=max(ans,c[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut ab: Vec<(usize, usize)> = (0..m).map(|_| {
        let a: usize = sc.read();
        let b: usize = sc.read();
        (a - 1, b - 1)
    }).collect();
    ab.sort_by(|x, y| {
        if x.1 == y.1 {
            return x.0.cmp(&y.0);
        }
        return x.1.cmp(&y.1);
    });
    let mut last_cut: usize = ab[0].1 - 1;
    let mut result: usize = 1;
    for i in 1..m {
        let x = ab[i];
        if !(x.0 <= last_cut && last_cut < x.1) {
            last_cut = x.1 - 1;
            result += 1;
        }
    }
    println!("{}", result);
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 6524
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
using namespace std;
#define endl '\n'
#define pi pair<int, int>

const int maxn = 100000;
int n, k;
int a[maxn], dp[maxn];

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

	return 0;
}

Measured memory_bytes: 1024
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long n;
typedef std::pair<long, long> P;
P a[100005];

int main(){
    scanf("%ld", &n);
    for(long i = 1; i <= n; i++){
        long b;
        scanf("%ld", &b);
        a[i] = P(b, i);
    }
    std::sort(a+1, a+n+1);
    for(int i = 1; i <= n; i++){
        printf("%ld ", a[i].second);
    }
    printf("\n");
}


Measured memory_bytes: 2432
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main() {
    string S;
    int N,K;

    cin>>N>>K;
    cin>>S;
    K--;
    if(S[K]=='A'){
        S[K]='a';
    }
    if(S[K]=='B'){
        S[K]='b';
    }
    if(S[K]=='C'){
        S[K]='c';
    }
    cout<<S<<endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String args[]) throws IOException{
        BufferedReader buff = null;
        buff = new BufferedReader(new InputStreamReader(System.in));
        String s = buff.readLine();
        s = s.replaceAll("eraser","").replaceAll("erase","").replaceAll("dreamer","").replaceAll("dream","");
        if(s.equals("")){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 26068
#include <bits/stdc++.h>
using namespace std;
int n,k;
int main(){
    scanf("%d%d",&n,&k);
    double ans = 0.0;
    for (int i=1;i<=n;i++){
        double tmp = 1.0;
        int t = i;
        while (t < k){
            t<<=1;
            tmp *= 0.5;
        }
//        cout<<"i = "<<i<<"\tt = "<<t<<"\ttmp = "<<tmp<<endl;
        ans += tmp;
    }
    ans /= 1.0 * n;
    printf("%.20f\n",ans);
    return 0;
}


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

int main() {
    int K;
    vector<int> n(3);

    rep(i,3)
        cin >> n.at(i);
    cin >> K;
    sort(n.begin(), n.end());

    cout << n.at(0)+n.at(1)+n.at(2)*pow(2,K) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool vis[100005];

int main(){
	int n;
	cin >> n;
	int arr[n+1];
	for(int i=1;i<=n;i++)
		cin >> arr[i];
	int cur=1,cnt=0;
	bool ok=false;
	while(!vis[cur]){
		vis[cur]=1;
		cur=arr[cur];
		cnt+=1;
		if(cur==2){
			ok=true;
			break;
		}
	}
	
	cout << (ok?cnt:-1) << endl;

	return 0;
}

Measured memory_bytes: 768
using System;
using System.Linq;

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            int value;
            while((value = int.Parse(Console.ReadLine())) != 0) {
                var bestID = int.MaxValue;
                var buffer = double.MaxValue;
                foreach(var i in Enumerable.Range(0, value)) {
                    var data = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
                    var bmi = Math.Abs(22 - data[2] / (Math.Pow((data[1] / 100.0), 2)));
                    if(buffer >= bmi) {
                        if(buffer == bmi) {
                            bestID = Math.Min(bestID, data[0]);
                        }
                        else {
                            bestID = data[0];
                            buffer = bmi;
                        }
                    }
                }
                Console.WriteLine(bestID);
            }
        }
    }
}

Measured memory_bytes: 6104
n = gets.to_i
ps = gets.split.map(&:to_i)
count = 0
(1..n-2).each do |i|
  count += 1 if ps[i] > ps[i-1] && ps[i] < ps[i+1] || ps[i] < ps[i-1] && ps[i] > ps[i+1]
end
puts count

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int gcd(int a,int b){
    a%=b;
    if(a==0)return b;
    return gcd(b,a);
}

int main(){
    int n,k;
    int m=0;
    int s=-1;
    int i,j;
    int a,b,c;
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>a;
        if(s==-1)s=a;
        else s=gcd(s,a);
        if(m<a)m=a;
    }
    if(k<=m && k%s==0)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}
    

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

int main(void){
  long long l,r,mini=2018;
  cin>>l>>r;
  //cout<<r-l<<endl;
  if(r-l>=2019){mini=0;}
  else{
    for(long long i=l;i<r;i++){
      for(long long j=i+1;j<=r;j++){
        //cout<<i<<" "<<j<<" "<<(i*j)%2019<<endl;
        mini=min(mini,(i*j)%2019);
      }
    }
  }
cout<<mini<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define size(v)  (int) v.size()
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}    
ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}
const int N = 10000001;
ll spf[N];
ll prime[N];
void sieve() {

	for(ll i = 1; i < N; i++){ spf[i] = i; prime[i] = 1;}
	prime[0] = prime[1] = 0;
	for(ll i = 2; i < N; i++ ){
		if(prime[i]) {
			for(ll j = i*i; j < N; j+=i) {
				if(spf[j] == j) {
					spf[j] = i;
				}
				prime[j] = 0;
			}
		}
	}
}


int main() {

	fast;
	ll n;
	cin >> n;
	sieve();
	ll ans = 1;
	for(ll i = 2; i <= n; i++) {
		ll number = 1;
		ll curr = i;
		while(curr > 1) {
			ll now = spf[curr];
		
			ll count = 0;
			while(curr%now == 0){
				curr /= now;
				count++;
			}
			number = number * (count + 1);
		}
	
		ans += i*number;
	}	

	cout << ans << endl;

}

Measured memory_bytes: 159900
h,w = gets.chomp.split(" ").map(&:to_i)
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
ans = Array.new
n.times do |i|
  a[i].times do
    ans << i+1
  end
end
h.times do |i|
  if i%2 == 0
    puts ans[i*w..(i+1)*w-1].join("\s")
  else
    puts ans[i*w..(i+1)*w-1].reverse.join("\s")
  end
end

Measured memory_bytes: 2428
n, m = map(int, input().split())

sign = []
for i in range(n):
    sign.append("o")
    
graph = []
for i in range(n):
    graph.append([])
    
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for j in range(n):
        if a == j:
            graph[j].append(b)
        if b == j:
            graph[j].append(a)

def dfs(x, i=0):
    sign[x] = "x"
    if sign == ["x" for k in range(n)]:
        return i + 1
    for j in graph[x]:
        if sign[j] == "o":
            sign[j] = "x"
            i = dfs(j, i)
            sign[j] = "o"
    return i 

print(dfs(0))


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

// long long l[100];

int main() {
  string s;
  cin >> s;
  sort(s.begin(),s.end());

  string t;
  cin >> t;
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if (s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	private static final byte MASK_RIGHT = 0x0F;
	private static int[][] paper = new int[10][10];

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 128);
		String sLine;
		while ((sLine = reader.readLine()) != null) {
			droppingInk(sLine.charAt(0) & MASK_RIGHT, sLine.charAt(2) & MASK_RIGHT, sLine.charAt(4) & MASK_RIGHT);
		}
		calcResult();
	}

	private static void droppingInk(int x, int y, int size) {
		staining(x, y - 1);
		staining(x - 1, y);
		staining(x, y);
		staining(x + 1, y);
		staining(x, y + 1);
		if (size == 1) {
			return;
		}

		staining(x - 1, y - 1);
		staining(x + 1, y - 1);
		staining(x - 1, y + 1);
		staining(x + 1, y + 1);
		if (size == 2) {
			return;
		}

		staining(x, y - 2);
		staining(x - 2, y);
		staining(x + 2, y);
		staining(x, y + 2);
	}

	private static void staining(int x, int y) {
		if (x >= 0 && x < 10 && y >= 0 && y < 10) {
			paper[x][y]++;
		}
	}

	private static void calcResult() {
		int white = 0;
		int maxnoud = 0;
		for (int[] row : paper) {
			for (int colum : row) {
				if (colum == 0) {
					white++;
				} else if (colum > maxnoud) {
					maxnoud = colum;
				}
			}
		}
		System.out.println(white);
		System.out.println(maxnoud);
	}
}

Measured memory_bytes: 16920
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int numN = scan.nextInt();
		int numK = scan.nextInt();
		int numQ = scan.nextInt();

		int[] count = new int[numN];

		for (int i = 0;  i < numQ; i++) {
			int num = scan.nextInt() - 1;
			count[num] += 1;
		}

		for (int i = 0;  i < numN; i++) {
			String result = null;

			if (numK - (numQ - count[i]) > 0 ) {
				result = "Yes";
			} else {
				result = "No";
			}

			System.out.println(result);
		}
	}
}

Measured memory_bytes: 56756
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int A, B;
    cin >> A >> B;

    if(A == B){
        cout << 0 << endl;
    }else if( (A+B)%2 == 0 ){
        cout << (A+B)/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<vector>
 
using namespace std;
 
#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
 
#define X real()
#define Y imag()
typedef complex<double> P;
 
const double EPS = 1e-8;
 
vector<P> vp[400010];
vector<P> vp2[400010];
vector<P> vp3[800010];
 
int main() {
  long long n;
  double r;
  cin >> n >> r;
  long long res = 0;
  rep (i, n) {
    P p;
    cin >> p.X >> p.Y;
    p.X += 2e6;
    p.Y += 2e6;
    int sum1 = 0, sum2 = 0, sum3 = 0;
    for (long long y = max((long long)((p.Y - r) / 10 - 1), 0LL); y <= (long long)((p.Y + r) / 10) + 1; ++y) sum1 += vp[y].size();
    for (long long x = max((long long)((p.X - r) / 10 - 1), 0LL); x <= (long long)((p.X + r) / 10) + 1; ++x) sum2 += vp2[x].size();
    for (long long x = max((long long)((p.X + p.Y - r) / 10 - 1), 0LL); x <= (long long)((p.X + p.Y + r) / 10) + 1; ++x) sum3 += vp3[x].size();
    if (sum1 <= sum2 && sum1 <= sum3) {
      for (long long y = max((long long)((p.Y - r) / 10 - 1), 0LL); y <= (long long)((p.Y + r) / 10) + 1; ++y) {
	rep (j, vp[y].size()) {
	  if (norm(vp[y][j] - p) <= 4 * r * r) {
	    goto aaa;
	  }
	}
      }
    } else if (sum2 <= sum3) {
      for (long long x = max((long long)((p.X - r) / 10 - 1), 0LL); x <= (long long)((p.X + r) / 10) + 1; ++x) {
	rep (j, vp2[x].size()) {
	  if (norm(vp2[x][j] - p) <= 4 * r * r) {
	    goto aaa;
	  }
	}
      }
    } else {
      for (long long x = max((long long)((p.X + p.Y - r) / 10 - 1), 0LL); x <= (long long)((p.X + p.Y + r) / 10) + 1; ++x) {
	rep (j, vp3[x].size()) {
	  if (norm(vp3[x][j] - p) <= 4 * r * r) {
	    goto aaa;
	  }
	}
      }
    }
    ++res;
    vp[(long long)(p.Y / 10)].push_back(p);
    vp2[(long long)(p.X / 10)].push_back(p);
    vp3[(long long)((p.X + p.Y) / 10)].push_back(p);
  aaa:;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 51692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define forx(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)


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

    int n, m, q;
    int l[200010], r[200010], x[510][510], c[510][510];
    cin >> n >> m >> q;
    forx(i,1,m+1){
        cin >> l[i] >> r[i];
        x[l[i]][r[i]]++;
    }

    forx(i,1,n+1)forx(j, 1, n + 1) c[i][j] = c[i][j - 1] + x[i][j];
    
    forx(i,1,q+1){
        int s, t,ans=0;
        cin >> s >> t;
        forx(j, s, t + 1) ans += c[j][t] - c[j][s-1];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 4480
#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 <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long
#define mo 1000000007

vector<pair<int,int> > a;
int tot[300000];
_int64 fac[300000];
_int64 inv[300000];
int minw[300000];

_int64 pow1(int x,int y)
{
  int i;
  _int64 ret;
  ret=1;
  for (i=30;i>=0;i--)
  {
    ret=ret*ret%mo;
    if (((1<<i)&y)!=0)
      ret=ret*x%mo;
  }
  return ret;
}

_int64 c(int x,int y)
{
  return fac[x]*inv[y]%mo*inv[x-y]%mo;
}

int main()
{
  int i,j,n,c1,c2,ind1,ind2,x,y,b1,cnt;
  _int64 ans;
  fac[0]=1;
  inv[0]=1;
  fac[1]=1;
  inv[1]=1;
  for (i=2;i<300000;i++)
  {
    fac[i]=fac[i-1]*i;
    fac[i]%=mo;
    inv[i]=pow1(fac[i],mo-2);
  }
  scanf("%d%d%d",&n,&c1,&c2);
  a.clear();
  for (i=0;i<n;i++)
  {
    scanf("%d%d",&x,&y);
    a.push_back(make_pair(y,x));
  }
  sort(a.begin(),a.end());
  memset(minw,-1,sizeof(minw));
  for (i=a.size()-1;i>=0;i--)
    minw[a[i].second]=a[i].first;
  ind1=0;
  
  ind2=-1;
  for (i=1;i<n;i++)
    if (a[i].second!=a[0].second)
    {
      ind2=i;
      break;
    }
  if (ind2==-1)
  {
    printf("1\n");
    return 0;
  }
  if (a[ind1].first+a[ind2].first>c2)
  {
    printf("1\n");
    return 0;
  }
  
  for (i=1;i<=n;i++)
    if (minw[i]!=-1)
    {
      if (i!=a[ind1].second)
      {
        if (a[ind1].first+minw[i]>c2)
          minw[i]=-1;
      }
    }
  cnt=1;
  memset(tot,0,sizeof(tot));
  tot[a[ind1].second]++;
  //tot[a[ind2].second]++;
  for (i=0;i<n;i++)
  {
    if (minw[a[i].second]==-1) continue;
    if (i==ind1) continue;
    //if (i==ind2) continue;
    b1=0;
    if (a[i].second==a[ind1].second)
    {
      if (a[i].first+a[ind1].first<=c1) b1=1;
    }
    else
    {
      if (a[i].first+a[ind1].first<=c2) b1=1;
    }
    if (a[i].second==a[ind2].second)
    {
      if (a[i].first+a[ind2].first<=c1) b1=1;
    }
    else
    {
      if (a[i].first+a[ind2].first<=c2) b1=1;
    }
    if (a[i].first+minw[a[i].second]<=c1) b1=1;
    if (b1==1)
    {
      cnt++;
      tot[a[i].second]++;
    }
  }
  ans=1;
  for (i=1;i<=n;i++)
  {
    if (tot[i]>0)
    {
      ans*=c(cnt,tot[i]);
      ans%=mo;
      cnt-=tot[i];
    }
  }
  printf("%lld\n",ans);
  return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<long> a(N);
  for (int j = 0; j < N; j++){
    int t;
     cin>>t;
     a[j]= t-(j+1);
   }

   sort(a.begin(),a.end());
   int b = a[N/2];
   //cout<<b<<endl;
   long ans =0;
   for(int i=0;i<N;i++){
     ans += abs(a[i]-b);
   }
   cout<<ans<<endl;

 }


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int N, K;
  string S;
  vector<int> stack;
  cin >> N >> K >> S;
  char pre = S[0];
  int c = 0;
  for (int i = 0; i < N; i++) {
    if (pre == S[i]) c++;
    else {
      if (pre == '0') {
        stack.push_back(-c);
      } else {
        stack.push_back(c);
      }
      c = 1;
    }
    pre = S[i];
  }
  if (S[S.size() - 1] == '1') {
    stack.push_back(c);
  } else {
    stack.push_back(-c);
  }

  c = 0;
  int k = 0;
  int ans = 0;
  for (int i = 0; i < stack.size(); i++) {
    int v = stack[i];
    if (v < 0) k++;
    if (v < 0 && k > K) {
      if (i >= K * 2 + 1)
        c -= abs(stack[i - K * 2 - 1]);
      c -= abs(stack[i - K * 2]);
    }
    c += abs(stack[i]);
    ans = max(c, ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1020