akhauriyash/Code-Regression huggingface dataset:
h,w=map(int,input().split())
s=["*"*(w+2)]
for i in range(h):
  s.append("*"+input()+"*")
s+=["*"*(w+2)]
a=[[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    if s[i+1][j+1]=="#":
      a[i][j]="#"
    else:
      a[i][j]=(s[i][j:j+3]+s[i+1][j:j+3]+s[i+2][j:j+3]).count("#")
for i in a:
  print("".join(map(str,i)))

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
  int n,count;
  while(cin>>n){
    count = 0;
    for(int a=0;a<=9;a++){
      for(int b=0;b<=9;b++){
	for(int c=0;c<=9;c++){
	  for(int d=0;d<=9;d++){
	    if(a+b+c+d==n) count++;
	  }
	}
      }
    }
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int N,T;
long int A[100001];

int func(int a){
	int i;
	int maxA=a+1;
	for(i=a+1;i<N;i++){
		if(A[maxA]<=A[i])
			maxA=i;
	}
	return maxA;
}

int main(){


	scanf("%d %d",&N,&T);
	int i,j;
	for(i=0;i<N;i++){
		scanf("%ld",&A[i]);
	}

	int maxprofit=0;
	int AOfmax=0;
	int minA=A[0];
	int maxA=i;
	int fmaxA;

	for(i=0;i<N;i++){
		if(A[maxA]<=A[i])
			maxA=i;
	}
	fmaxA = maxA;

	for(i=0;i<N;i++){
		if(i==maxA){
			maxA = func(i);
		}

		if(A[maxA]-A[i]>maxprofit){
			maxprofit=A[maxA]-A[i];
			AOfmax=1;
		}
		else if(A[maxA]-A[i]==maxprofit)
			AOfmax++;
	}
	/*
	maxA=fmaxA;
	minA=A[0];
	for(i=0;i<N;i++){
		if(i==maxA){
			maxA = func(i);
		}

		if(A[maxA]-A[i]==maxprofit)
			AOfmax++;
	}*/

	printf("%d\n",AOfmax);

	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;

//public class Problem1000_AplusBProblem {
public class Main {
	public static void main(String[] args) {
		try {
		//	Problem1000_AplusBProblem test = new Problem1000_AplusBProblem();
			Main test = new Main();
			
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			
			String line;
			while((line = reader.readLine()) != null) {
				String[] textArray = line.split(" ");
				System.out.println(test.plus(Integer.parseInt(textArray[0]), Integer.parseInt(textArray[1])));
			}
			
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	int plus(int a, int b) {
		return a + b;
	}
}

Measured memory_bytes: 9780
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<usize>();
    let s = input::<String>().chars().collect::<Vec<char>>();

    let mut sum_w = vec![0; n + 1];
    for i in 0..n {
        sum_w[i + 1] = sum_w[i];
        if s[i] == 'W' {
            sum_w[i + 1] += 1;
        }
    }

    let mut ans = usize::max_value();
    for i in 0..n {
        let c = sum_w[i] + n - i - 1 - (sum_w[n] - sum_w[i + 1]);
        ans = std::cmp::min(ans, c);
    }
    println!("{}", ans);
}


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

const int mod = 1e9+7;
const int INF = 2000000;
const double PI = acos(-1.0);

int main() {
    
    string S;
    cin >> S;

    bool c[4] = {false};

    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'N') c[0] = true;
        else if(S[i] == 'S') c[1] = true;
        else if(S[i] == 'W') c[2] = true;
        else c[3] = true; 
    }
    if((c[0] && c[1] && !c[2] && !c[3]) ||
        (!c[0] && !c[1] && c[2] && c[3]) ||
        (c[0] && c[1] && c[2] && c[3])) {
            cout << "Yes" << endl;
        }
    else cout << "No" << endl;
    
}

Measured memory_bytes: 3576
# -*- coding: utf-8 -*-
"""
A - Transfer
https://atcoder.jp/contests/abc136/tasks/abc136_a

"""
import sys


def solve(A, B, C):
    return max(0, C - (A - B))


def main(args):
    A, B, C = map(int, input().split())
    ans = solve(A, B, C)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
int main()
{
    int A, B, M;
    cin >> A >> B >> M;

    // read values
    vector<int> a_values(A), b_values(B);
    rep(i, 0, A) cin >> a_values[i];
    rep(i, 0, B) cin >> b_values[i];

    int min_money = *min_element(a_values.begin(), a_values.end()) + *min_element(b_values.begin(), b_values.end());
    rep(i, 0, M)
    {
        int x, y, c;
        cin >> x >> y >> c;
        --x, --y;
        min_money = min(min_money, a_values[x]+b_values[y]-c);
    }
    cout << min_money << endl;
    return 0;
}


Measured memory_bytes: 1024
import bisect as bi

N = int(input().strip())
A = list(map(int,input().strip().split(' ')))
B = list(map(int,input().strip().split(' ')))
C = list(map(int,input().strip().split(' ')))

A.sort()
B.sort()
C.sort()
ans = 0

for b in B:
    i = bi.bisect_left(A, b) # A[0],...,A[i - 1] < b
    k = bi.bisect_right(C, b) # b < C[k],...C[N-1]
    ans += i * (N - k)

print(ans)

Measured memory_bytes: 23360
#include <iostream>
#include <vector>

int main(){
    int n, d, x;
    std::cin >> n >> d >> x;

    int a;
    int j;
    int count = 0;
    for(int i = 0; i < n; ++i){
        std::cin >> a;
        j = 1;
        while(j <= d){
            ++count;
            j += a;
        }
    }
    
    std::cout << count + x << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

char s[200001];
int main(void){
	int n=nextint();
	nextstr(s);
	int l=0, r=n-1;
	int ans=0;
	while(r+1>l){
		if(s[l]=='R'){
			l++;
		}else if(s[r]=='W'){
			r--;
		}else{
			ans++;
			l++;
			r--;
		}
	}
	printf("%d\n", ans);
}


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

class DAG {
public:
    DAG(const vector<vector<int>> &edges)
    : tsort_done(false), acyc(false) {
        V = edges.size();
        E.resize(V);
        for(int i = 0; i < V; ++i) {
            for(int to : edges[i]) {
                E[i].push_back(to);
            }
        }
    }

    bool tsort() {
        vector<int> indeg(V, 0);
        for(int i = 0; i < V; ++i) {
            for(int to : E[i]) ++indeg[to];
        }

        stack<int> done;
        for(int i = 0; i < V; ++i) {
            if(indeg[i] == 0) done.push(i);
        }

        while(!done.empty()) {
            int cur = done.top();
            done.pop();
            order.push_back(cur);
            for(int to : E[cur]) {
                --indeg[to];
                if(indeg[to] == 0) done.push(to);
            }
        }

        tsort_done = true;
        acyc = (order.size() == V);
        return acyc;
    }

    int longest_path() {
        if(!tsort_done) tsort();
        if(!acyc) return -1;

        dp.resize(V);
        for(int i = 0; i < V; ++i) {
            int cur = order[i];
            for(int to : E[cur]) {
                dp[to] = max(dp[to], dp[cur] + 1);
            }
        }

        return *max_element(begin(dp), end(dp));
    }

    bool acyclic() {
        if(!tsort_done) tsort();
        return acyc;
    }

    int operator[](int i) {
        if(!tsort_done) tsort();
        return order[i];
    }

private:
    int V;
    vector<vector<int>> E;
    vector<int> order;
    bool tsort_done;
    bool acyc;
    vector<int> dp;
};

int pp(int a, int b) {
    return max(a, b) + 1000 * min(a, b);
}
 
static const int MAX_NN = 1000000;
 
int main() {
    int N;
    cin >> N;
    vector<vector<int>> edges(MAX_NN);
    for(int i=0; i<N; ++i) {
        int prev;
        cin >> prev;
        --prev;
        for(int j=1; j+1<N; ++j) {
            int next;
            cin >> next;
            --next;
            edges[pp(i, prev)].push_back(pp(i, next));
            prev = next;
        }
    }

    DAG dag(edges);
    dag.tsort();
    cout << (dag.acyclic() ? dag.longest_path() + 1 : -1) << endl;
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int n; cin >> n;

    REPI(i, 10){
        REPJ(j, 10){
            if(n == i * j){
                cout << "Yes";
                return 0;
            }
        }
    }cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

template<class T> inline bool chmax(T& a, T b) { if (a <= b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }


struct UnionFind {
	UnionFind(int n) {
		par = new int[n + 1];
		size = new int[n + 1];
		height = new int[n + 1];
		for (int i = 0; i <= n; ++i) {
			par[i] = i;
			size[i] = 1;
			height[i] = 1;
		}
	}

	void unite(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) return;
		if (height[a] < height[b]) {
			par[a] = b;
			size[b] += size[a];
		}
		else {
			par[b] = a;
			size[a] += size[b];
			if (height[a] == height[b]) {
				height[a]++;
			}
		}

	}

	int root(int a) {
		return par[a] == a ? a : par[a] = root(par[a]);
	}

	int getSize(int a) {
		return size[root(a)];
	}

	bool isSame(int a, int b) {
		return root(a) == root(b);
	}

	int* size;
	int* height;
	int* par;
};


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

	ll n,m; cin >> n >> m;
	vector<int> p(n); rep(i,n) { cin >> p[i]; p[i]--;} 

	UnionFind uf(n);
	rep(i, m) {
		int x,y; cin >> x >> y;
		uf.unite(x-1,y-1);
	}

	map<int, set<int>> mp;
	rep(i, n) {
		mp[uf.root(i)].insert(i);
	}

	ll ans = 0;

	for (auto& pa : mp) {
		auto& st = pa.second;
		for (int x : st) {
			if (st.lower_bound(p[x]) != st.end() && *st.lower_bound(p[x]) == p[x]) ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 15872
N,K=map(int,input().split())
a=[[0,0] for _ in range(N)]
for i in range(N):
    a[i][0],a[i][1]=map(int,input().split())
a.sort()
ans=a[0][0]
Sum=0
i=0
while Sum<K:
    Sum+=a[i][1]
    if Sum>=K:
        ans=a[i][0]
    i+=1
print(ans)

Measured memory_bytes: 21676
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std;
using namespace placeholders;

using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VS = vector< string >;
using SS = stringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< vector< T > >;
template < typename T = int > using LIM = numeric_limits< T >;

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
#define ALL( c ) begin( c ), end( c )
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + ( p ), ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

template < typename T > inline bool chmin( T &a, const T &b ){ if ( b < a ) { a = b; return true; } return false; }
template < typename T > inline bool chmax( T &a, const T &b ){ if ( a < b ) { a = b; return true; } return false; }

#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );
	cout << setprecision( 12 ) << fixed;

	string S;
	cin >> S;

	const int L = SZ( S );

	reverse( ALL( S ) );

	LL res = 0;
	REP( bits, 1 << ( L - 1 ) )
	{
		LL b = 1;
		REP( i, L )
		{
			res += ( S[i] - '0' ) * b;
			b *= 10;
			if ( bits & 1 << i )
			{
				b = 1;
			}
		}
	}

	cout << res << endl;

	return 0;
}


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

#define ll long long
#define ld long double
#define pi 3.14159265359

int main(){
    ll N, A, B; cin >> N >> A >> B;
    ll p = N / (A + B);
    ll q = N % (A + B);
    if (A != 0) {
        if (q / A >= 1) {
            q = A;
        }
    }
    else {
        q = 0;
    }
    ll ans = A * p + q;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    cout << (n < 1000 ? "ABC" : "ABD") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;

int main(){
    //隣り合っていなくてもよい
    int N;
    cin >> N;
    char c[200000];
    int r=0,w=0;
    for(int i=0; i<N; i++){
        cin>>c[i];
        if(c[i]=='R'){
            r++;
        }else{
            w++;
        }
    }
    if(r==N || w==N){
        cout<<0<<endl;
        return 0;
    }
    
    int left=0;
    int right=N-1;
    ll ans=0;
    while(left<right){
        if(c[left]=='W' && c[right]=='R'){
            c[left]='R';
            c[right]='W';
            ans++;
        }else{
            if(c[left]=='R'){
                left++;
            }else if(c[right]=='W'){
                right--;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3776
n,k = map(int,input().split())
p = list(map(int,input().split()))

def f(p):
    #(p*(p+1)/2)/p
    return (p+1)/2


p2 = []

for p_tmp in p:
    p2.append(f(p_tmp))

p3 = [p2[0]]

for i in range(1,len(p2)):
    p3.append(p2[i]+p3[i-1])

ans = p3[k-1]
for i in range(k,n):
    ans = max(ans,p3[i]-p3[i-k])

print('{:.20f}'.format(ans))

Measured memory_bytes: 25060
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int x, n;
    cin >> x >> n;

    set<int> st;
    rep(i, n){
        int p;
        cin >> p;
        st.insert(p);
    }

    int ans = x;
    rep(dif, 1000){
        if(!st.count(x - dif)){
            ans = x - dif;
            break;
        }else if(!st.count(x + dif)){
            ans = x + dif;
            break;
        }
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 3656
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<bitset>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9
 
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    unsigned long a;
    bitset<32> aa = 0;
    vector<unsigned long> vb;
    rep(n){
        cin >> a;
        aa ^= bitset<32>(a);
        vb.push_back(a^(a-1));
    }
    sort(rall(vb));
    unique(all(vb));
    int i = 31, ans = 0;
    for(auto bb_n : vb){
        bitset<32> bb = bitset<32>(bb_n);
        // cout << aa << endl;
        while(i >= 0 && !aa.test(i)) i--;
        if(i == -1) break;
        if(aa.test(i) && bb.test(i) && !bb.test(i+1)){
            aa ^= bb;
            ans++;
        }
    }
    if(aa.any()) ans = -1;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1528
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(void){

    long long N, K;
    cin >> N >> K;
    
    long long amari = N % K;

    if(amari != 0){
        long long ans = abs(amari - K);
        if(N < ans){
            cout << N << endl;
        }
        else{
            cout << ans << endl;
        }
    }
    else{
        cout << amari << endl;
    }
    
}


Measured memory_bytes: 256
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);

int main(){
	lint N; cin >> N;
	if(N%2==0) cout << N << endl;
	else cout << 2*N << endl;
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;

	s1[0] = 'A' + (s1[0] - 'a');
	s2[0] = 'A' + (s2[0] - 'a');
	s3[0] = 'A' + (s3[0] - 'a');

	cout << s1[0] << s2[0] << s3[0] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
	long long n,a,b,c,d,e;
	cin >> n >> a >> b >> c >> d >> e;
	cout << 5+((n-1)/(min(a,min(b,min(c,min(d,e))))));
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string s;
  cin>>s;
  cout<<(4 - 2*count(ALL(s),'-'))<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    H = nl()
    ans = 0
    while not all([h == 0 for h in H]):
        if len(set(H)) == 1:
            ans += H[0]
            H = [0] * n
        else:
            h_max = max(H)
            prev = -10
            for i in range(n):
                if H[i] == h_max:
                    if prev != i - 1:
                        ans += 1
                    prev = i
                    H[i] -= 1
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
    int N, box[MAXV], t;
    cin >> N;
    rep(i, N){
        box[i] = 0;
    }
    rep(i, N-1){
        cin >> t;
        box[t-1]++;
    }
    rep(i, N){
        cout << box[i] << endl;
    }



}

Measured memory_bytes: 4412
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_n, i, max = 0, temp = 0;
    number_n = Integer.parseInt(sc.next());
    int[] number = new int[number_n];
    for(i = 0; i < number_n; i++) number[i] = Integer.parseInt(sc.next());
    for(i = 0; i < number_n; i++) {
      if(max < number[i]) {
        temp = max;
        max = number[i];
      } else if(temp < number[i]) {
        temp = number[i];
      }
    }
    for(i = 0; i < number_n; i++) {
      if(number[i] != max) System.out.println(max);
      else System.out.println(temp);
    }
  }
}


Measured memory_bytes: 88220
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int n, x;
    cin >> n >> x;
    int l[n];
    rep(i, n) cin >> l[i];
    int t = 0;
    int ans = 1;
    rep(i, n){
        t = t + l[i];
        if(t > x) break;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
be = list()
ab = list()
for i in range(n):
    j,k=a[i],b[i]
    if j<k:
        be.append(k-j)
    elif j>k:
        ab.append(j-k)
p=len(be)
be=sum(be)
ab.sort(reverse=True)
k=0
if be==0:
    print(0)
    exit()
for i in range(len(ab)):
    k+=ab[i]
    if k >= be:
        print(p+i+1)
        exit()
print(-1)

Measured memory_bytes: 18356
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

struct UnionFind{
	std::vector<int> data;
	
	UnionFind(int n){
		data.assign(n, -1);
	}
	
	bool unite(int x, int y){
		x = find(x); y = find(y);
		if(x == y) return false;
		if(data[x] > data[y]) std::swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}
	
	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; scanf("%d", &n);
	std::vector<std::pair<i64, int>> X, Y;
	for(int i = 0; i < n; i++) {
		int x, y; scanf("%d%d", &x, &y);

		X.push_back({x, i});
		Y.push_back({y, i});
	}
	sort(begin(X), end(X)); sort(begin(Y), end(Y));

	std::vector<std::pair<i64, std::pair<int, int>>> edges;
	for(int i = 0; i < n - 1; i++) {
		edges.push_back({X[i + 1].first - X[i].first, {X[i].second, X[i + 1].second}});
		edges.push_back({Y[i + 1].first - Y[i].first, {Y[i].second, Y[i + 1].second}});
	}
	sort(begin(edges), end(edges));

	i64 ans = 0;
	UnionFind uf(n);
	for(auto e: edges) {
		int x = e.second.first, y = e.second.second;
		if(uf.unite(x, y)) ans += e.first;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 9700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll N;
	cin>>N;
	ll sum = (N+1)*N/2;
	ll a3 = N/3;
	ll a5 = N/5;
	ll a15 = N/15;
	sum -= 3*(a3+1)*a3/2;
	sum -= 5*(a5+1)*a5/2;
	sum += 15*(a15+1)*a15/2;
	
	cout << sum << endl;
	return 0;
}


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

int main() {
  string S;
  cin >> S;

  map<char, int> count;
  for (char c : S) count[c]++;
  for (char c = 'a'; c <= 'z'; c++) {
    if (count[c] == 0) {
      cout << c << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}


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


int main(){
	/*input*/
	int n;
	cin >> n;
	int h[20];
    for(int i = 0; i < n; i++){
    	cin >> h[i];
    }

    /*calc*/
    int  ans = 1;
    int max = h[0];
    for(int i = 1; i < n; i++){
    	if(max <= h[i]){
    		ans += 1;
    		max = h[i];
    	}
    }
    /*output*/
	   	cout<< ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    
    ll p = a*x + b*y;
    ll q;
    if (x <= y) {
        q = 2*c*x + b*(y-x);
    }
    else q = 2*c*y + a*(x-y);
    ll s = 2 * c * max(x, y);

    cout << min({p,q,s}) << endl;

    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var K, X int
	fmt.Scanf("%d %d", &K, &X)

	start := X - K + 1
	max := X + K - 1
	flag := false
	for i := start; i <= max; i++ {
		if -1000000 <= i && i <= 1000000 {
			if flag {
				fmt.Print(" ")
			} else {
				flag = true
			}
			fmt.Print(i)
		}
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#define mod 1000000007
#define ll long long
using namespace std;
int n,k,tot;
int s[2005],f[2005];
int po(int a,int b){
	int an=1;
	while(b!=0){
		if(b&1) an=(ll)an*a%mod;
		a=(ll)a*a%mod;b=(b>>1);
	}
	return an;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i*i<=n;i++)
		if(n%i==0){
			s[++tot]=i;
			if(i*i!=n) s[++tot]=n/i; 
		}
	sort(s+1,s+1+tot);f[1]=k;
	for(int i=2;i<=tot;i++){
		f[i]=po(k,(s[i]+1)/2);
		for(int j=1;j<i;j++)
			if(s[i]%s[j]==0) f[i]=(f[i]-f[j]+mod)%mod;
	}
	int ans=0,ni=po(2,mod-2);
	for(int i=1;i<=tot;i++){
		if(s[i]%2==0) ans=(ans+(ll)f[i]*ni%mod*s[i]%mod)%mod;
		else ans=(ans+(ll)f[i]*s[i]%mod)%mod; 
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 200000

int main(void){
	
	int n;
	scanf("%d",&n);
	
	int A[N],B[N];
	for(int i = 1; i < n; i++){
		scanf("%d", &A[i]);
	}
	for(int i = 0; i < n; i++){
		B[i] = 0;
	}
	for(int i = 1; i < n; i++){
		B[A[i]-1]++;
	}
	for(int i = 0; i < n; i++){
		printf("%d\n", B[i]);
	}
	
}

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

int main(){
 	int H, W, i, j;
 	
	while(1) {
 		cin >> H >> W;
		if(H == 0 && W == 0) {
			break;
		}
 		for(i = 0; i < H; i++) {
			for(j = 0; j < W; j++) {
				if( (i + j) % 2 == 0) {
				cout << '#';
			}else{
				cout << '.';
			}
		}
 		cout << endl;
 		}
	cout << endl;
	}
 	return 0;
}

Measured memory_bytes: 3088
N = int(input())
xyh = []

tmp = -1
for i in range(N):
    x,y,h = map(int,input().split())
    xyh.append((x,y,h))
    if h > 0: tmp = i

def check(cx,cy,H,i):
    if xyh[i][2] == max(H-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy),0): return True
    else: return False

flg = False
for cx in range(101):
    for cy in range(101):
        H = xyh[tmp][2] + abs(xyh[tmp][0]-cx) + abs(xyh[tmp][1]-cy)
        if all([check(cx,cy,H,i) for i in range(N)]):
            flg = True
            break
    if flg: break

print(cx,cy,H)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll i,j,k,n,m;
    std::cout.precision(10);
    int yes=0;
  	cin>>n>>m;
  	while(m--)
    {
      cin>>i;
      n-=i;
    }
  if(n<0)
  {
   	cout<<"-1"; 
  }
  else
    cout<<n;
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
	int a[100010]={};
	int n,t,ans;
	scanf("%d", &n);
    ans=n;
	for (int i = 0; i < n; i++)
	{
      scanf("%d", &t);
      if(t <= 100000){
        a[t]++;
      }
	}
	for (int i = 1; i <= 100000; i++)
	{
      if(a[i]>=i){
        ans -= i;
      }
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
using namespace std;

int main() {
   ll n,i,cnt=0;
   cin>>n;
   ll a[n];
   for(i=0;i<n;i++){
       cin>>a[i];
   }
   for(i=0;i<n-2;i++){
       if(a[i+1]<a[i]){
           if(a[i+2]<a[i+1]){
               cnt++;
           }
       }
        if(a[i+1]>a[i]){
           if(a[i+2]>a[i+1]){
               cnt++;
           }
       }
   }
   cout<<cnt;
}


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

using namespace std;

int main(){

  string S;
  cin >> S;

  for(int i=0;i<(int)S.size();++i){
    if(i%2 == 0){
      if(S[i]=='L'){
        cout<<"No"<<endl;
      return 0;
      }
    }else{
      if(S[i]=='R'){
        cout<<"No"<<endl;
      return 0;
      }
    }
  }
  cout<<"Yes"<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static int gcd(int x,int y)
    {
        int r;
        if(y>x){
            r=x;
            x=y;
            y=r;
        }
        while(y>0){
            r=x%y;
            x=y;
            y=r;
        }
        return x;
    }

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt(),x=sc.nextInt(),a[]=new int[n];
        for(int i=0;i<n;++i){
            a[i]=sc.nextInt();
            a[i]=Math.abs(x-a[i]);
        }
        sc.close();
        for(int i=1;i<n;++i)a[i]=gcd(a[i-1],a[i]);
        System.out.print(a[n-1]);
    }
}

Measured memory_bytes: 47784
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dp[200010];

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

    int n = s.size();
    int times = 1;
    for (int i = n-1; i >= 0; i--) {
        dp[i] = dp[i+1] + times * (s[i] - '0');
        dp[i] %= 2019;
        times *= 10;
        times %= 2019;
    }

    vector<ll> cnt(2020, 0);
    cnt[0]++;
    rep(i, n) cnt[dp[i]]++;

    ll ans = 0;
    rep(i, 2020) ans += cnt[i] * (cnt[i] - 1) / 2;
    cout << ans << endl;
}


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

using namespace std;

#define N 105

int K, n, i;
char S[N];

int main (void)
{
	scanf("%d",&K);
	scanf("%s",S+1);
	n=strlen(S+1);
	if (n<=K) puts(S+1);
	else {
		for (i=1; i<=K; i++) putchar(S[i]);
		puts("...");
	}
	return 0;
}

Measured memory_bytes: 3764
#include <stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N], col[N], dpos[2*N-1], dneg[2*N-1];
int X[N][N];

void printBoard()
{

  int i, j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]){
	if(row[i]!=j){
	  return;
	}
      }
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }

}

void putQueen(int i)
{

  int j;
  
  if(i == N){
    printBoard();
    return;
  }
  
  for(j=0;j<N;j++){
    if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE){
      continue;
    }
    // put a queen at (i, j)
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    // try the next row
    putQueen(i+1);
    // remove the queen at (i, j) for backtracking
    col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }

}

int main()
{

  int i, j, k, r, c;

  for(i=0;i<N;i++){
    row[i] = FREE;
    col[i] = FREE;
  }
  
  for(i=0;i<2*N-1;i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      X[i][j] = 0;
    }
  }

  scanf("%d",&k);

  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    X[r][c] = 1;
  }

  putQueen(0);

  return 0;

}




Measured memory_bytes: 2108
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

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

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

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


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

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

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BFriendlyRabbits {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        vi A(n);
        in >> A;
        trav(x, A) {
            x--;
        }
        int res = 0;
        FOR(i, 0, n) {
            res += A[A[i]] == i;
        }
        res /= 2;
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BFriendlyRabbits solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int[][] c = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                c[i][j] = sc.nextInt();
            }
        }

        int[] a = new int[3];
        int[] b = new int[3];

        a[0] = 0;
        for (int i = 0; i < 3; i++) b[i] = c[0][i] - a[0];
        for (int i = 0; i < 3; i++) a[i] = c[i][0] - b[0];

        boolean good = true;

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (a[i] + b[j] != c[i][j]) good = false;
            }
        }

        System.out.println(good ? "Yes" : "No");
    }
}


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

int main(){
  int a,b,c,d;
  cin >>a >>b >>c >>d;
  int L = a+b;
  int R = c+d;
  if(L>R) cout << "Left" << endl;
  if(L==R) cout << "Balanced" << endl;
  if(L<R) cout << "Right" << endl;
  return 0;
}


Measured memory_bytes: 256
import fractions

def make_divisor_list(num):
    i = 1
    table = []
    while i * i <= num:
        if num%i == 0:
            table.append(i)
            table.append(num//i)
        i += 1
    table = list(set(table))
    return table

N = int(input())

divisors = sorted(make_divisor_list(N))
center = int(len(divisors) / 2)

if len(divisors) % 2 == 1:
    ans = (divisors[center] - 1) * 2
else:
    ans = divisors[center] - 1 + divisors[center-1] - 1

print(ans)


Measured memory_bytes: 5944
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
  #define DUMP(i) 
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());

using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

struct Edge{
public:
  int from,to,cost;
  Edge(){}
  Edge(int _from,int _to,int _cost){
    from = _from;
    to = _to;
    cost = _cost;
  }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


const int EPS = 1e-9;
const int MOD = 1e9+7;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int w,h,n;
  cin >> w >> h >> n;
  int lx = 0;
  int rx = w;
  int uy = h;
  int ly = 0;
  REP(i,n){
    int x,y,a;
    cin >> x >> y >> a;
    switch(a){
    case 1:
      lx = max(lx,x);
      break;
    case 2:
      rx = min(rx,x);
      break;
    case 3:
      ly = max(ly,y);
      break;
    case 4:
      uy = min(uy,y);
    }
  }
  int ans = max(0,rx-lx)*max(0,uy-ly);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
ok=0
for i in range(n-2):
    for j in range(i,n-1):
        for k in range(j,n):
            p=l[i]
            q=l[j]
            r=l[k]
            if p!=q and q!=r and r!=p and p+q>r and r+q>p and p+r>q:
                ok+=1
print(ok)


Measured memory_bytes: 9208
data = list(map(int, input("").split()))

x_max = data[2] + data[4]
x_min = data[2] - data[4]
y_max = data[3] + data[4] 
y_min = data[3] - data[4] 

if x_min >= 0 and x_max <= data[0] and y_min >= 0 and y_max <= data[1]:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 5596
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 100100)

	s := getString()
	Q := getInt()

	l := list.New()
	for i := 0; i < len(s); i++ {
		l.PushBack(s[i])
	}

	rev := false
	for i := 0; i < Q; i++ {
		t := getInt()
		if t == 1 {
			rev = !rev
		} else {
			f, c := getInt(), getString()[0]
			if f == 1 {
				if rev == true {
					l.PushBack(c)
				} else {
					l.PushFront(c)
				}
			} else {
				if rev == true {
					l.PushFront(c)
				} else {
					l.PushBack(c)
				}
			}
		}
	}

	ans := make([]byte, l.Len())

	if rev == true {
		idx := 0
		for e := l.Back(); e != nil; e = e.Prev() {
			ans[idx] = e.Value.(byte)
			idx++
			//fmt.Println(e.Value)
		}
	} else {
		idx := 0
		for e := l.Front(); e != nil; e = e.Next() {
			ans[idx] = e.Value.(byte)
			idx++
			//fmt.Println(e.Value)
		}
	}

	out(string(ans))
}


Measured memory_bytes: 17664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {
    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB"){
        cout << "No" << endl;
    }else cout << "Yes" << endl;


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#define bitcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int MOD=1e9+7;
int main()
{
	int n; cin>>n;
	int a[21][21];
	for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin>>a[i][j];
	int dp[22][1<<21]={};
	dp[0][0]=1;
	for(int i=0; i<n; i++){
		for(int j=0; j<(1<<n); j++){
			if(bitcount(j)!=i) continue;
			for(int k=0; k<n; k++){
				if(a[i][k] && (j&(1<<k))==0){
					dp[i+1][j^(1<<k)]+=dp[i][j];
					dp[i+1][j^(1<<k)]%=MOD;
				}
			}
		}
	}
	cout<<dp[n][(1<<n)-1]<<endl;
	return 0;
}

Measured memory_bytes: 180480
N, K = map(int, input().split())

if K == 0 :
    ans = N**2
else :
    ans = 0
    for b in range(K+1, N+1) :
        maxQ = N // b
        ans += (b - K) * maxQ
        ans += max(N - K - (maxQ * b) + 1, 0)

print(ans)

Measured memory_bytes: 3060