akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

const int dx[] = { -1,0,1,0 };
const int dy[] = { 0,-1,0,1 };

const int ddx[] = { -1,0,1,0,0,1,1,  0,2, 1,-1,-2, 2, 2, -2,-2,1,-1,1,-1,2,2,-2,-2 };
const int ddy[] = { 0,-1,0,1,2,1,-1,-2,0, 1, 1, 0,2, -2,  2,-2,2,2, -2,-2, 1,-1,1,-1 };

int main() {
	int H, W;
	cin >> H >> W;
	int ch, cw, dh, dw;
	cin >> ch >> cw >> dh >> dw;
	ch--; cw--; dh--; dw--;
	vector<string> S(H);
	for (int n = 0; n < H; ++n) {
		cin >> S[n];
	}

	vector<vector<int>> D(H, vector<int>(W, 1e9));//回数
	priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>> > q;
	q.push(make_pair(0,make_pair(ch, cw)));
	D[ch][cw] = 0;

	while (!q.empty()) {
		int x = q.top().second.first;
		int y = q.top().second.second;
		int z = q.top().first;
		q.pop();
		if ((x == dh) && (y == dw)) {
			cout << D[dh][dw] << endl;
			return 0;
		}	
		if (D[x][y] < z) {
			continue;
		}
		//範囲内かつ0を4セット
		for (int l = 0; l < 4; ++l) {
			int x1 = x + dx[l];
			int y1 = y + dy[l];
			if ((0 <= x1) && (H > x1) && (0 <= y1) && (W > y1) && ('.' == S[x1][y1])) {
				if (D[x1][y1] > D[x][y]) {
					D[x1][y1] = D[x][y];
					pair<int,pair<int, int>> p = make_pair(D[x1][y1],make_pair(x1, y1));
					q.emplace(p);
				}
			}
		}
		//範囲内かつ0を24セット
		for (int l = 0; l < 24; ++l) {
			int x1 = x + ddx[l];
			int y1 = y + ddy[l];
			if ((0 <= x1) && (H > x1) && (0 <= y1) && (W > y1) && ('.' == S[x1][y1])) {
				if (D[x1][y1] > D[x][y]) {
					D[x1][y1] = D[x][y] + 1;
					pair<int,pair<int, int>> p = make_pair(D[x1][y1],make_pair(x1, y1));
					q.emplace(p);
				}
			}
		}
	}
	cout << -1 << endl;
	return 0;
}


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

using namespace std;

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

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

#endif

/**
 * Library
 * --------------------------------------------------------
 */
class UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<int> size;
    vector<vector<int>> group;
public:
    UnionFind(int n = 1) {
        par.resize(n + 1);
        rank.resize(n + 1);
        size.resize(n + 1);
        group.resize(n + 1);
        for (int i = 0; i <= n; ++i) {
            par[i] = i;
            rank[i] = 0;
            size[i] = 1;
            group[i].push_back(i);
        }
    }

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

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

    bool unit(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return false;
        } else {
            if (rank[x] < rank[y]) {
                swap(x, y);
            }
            if (rank[x] == rank[y]) {
                ++rank[x];
            }
            par[y] = x;
            size[x] += size[y];
            return true;
        }
    }

    int get_size(int x) {
        return size[find(x)];
    }

    void merge(int x, int y) {
        x = find(x);
        y = find(y);
        if (group[x].size() > group[y].size()) {
            swap(x, y);
        }
        copy(group[y].begin(), group[y].end(), back_inserter(group[x]));
        group[y].clear();
        par[y] = x;
    }
};
/**
 * --------------------------------------------------------
 */

void Main() {
    ll N, M; cin >> N >> M;
    UnionFind un(N);
    rep(i, M){
        ll a, b, c; cin >> a >> b >> c; a--; b--;
        // un.merge(a, b);
        un.unit(a, b);
    }
    set<ll> x;
    rep(i, N){
        x.insert(un.find(i));
    }
    cout << x.size() << endl;
}

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


Measured memory_bytes: 11648
<?php
$MAX_BLDG  = 4;
$MAX_FLOOR = 3;
$MAX_ROOM  = 10;

$arr = array_fill(0, $MAX_BLDG * $MAX_FLOOR * $MAX_ROOM, 0);

$num_data = trim(fgets(STDIN));

while ($num_data-- > 0) {
  $input = trim(fgets(STDIN));
  List($b, $f, $r, $v) = explode(" ", $input);

  $idx = ($b-1) * ($MAX_FLOOR*$MAX_ROOM)
       + ($f-1) * ($MAX_ROOM)
       + ($r-1);
  $arr[$idx] += $v;
}

for ($b=0; $b<$MAX_BLDG; $b++) {
  if ($b > 0) {
    echo "####################" . PHP_EOL;
  }

  for ($f=0; $f<$MAX_FLOOR; $f++) {
    for ($r=0; $r<$MAX_ROOM; $r++) {
      $idx = $b * ($MAX_FLOOR*$MAX_ROOM)
           + $f * ($MAX_ROOM)
           + $r;
      echo " {$arr[$idx]}";
    }
    echo PHP_EOL;
  }
}

Measured memory_bytes: 15392
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <map>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

bool p[1010];
vector<int> primes;
int n;
map<int,int> cnt;

int main() {
    memset(p,0,sizeof(p));
    for (int i=2;i<=1000;i++) {
        if (!p[i]) {
            primes.pb(i);
        }
        for (int j=0;j<primes.size()&&i*primes[j]<=1000;j++) {
            p[i*primes[j]]=1;
            if ((i%primes[j])==0) break;
        }
    }
    scanf("%d",&n);
    for (int i=2;i<=n;i++) {
    	int tmp=i;
    	for (int j=0;j<primes.size()&&primes[j]<=i;j++) {
    		while ((tmp%primes[j])==0) {
    			cnt[primes[j]]++;
    			tmp/=primes[j];
    		}
    	}
    }
    ll ans=1;
    for (auto& entry:cnt) {
    	ans=(ans*(entry.second+1))%MOD;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

H_W = [[0] * W for _ in range(H)]

h = 0
w = 0
for idx, a in enumerate(A):
    num = idx + 1
    for _ in range(a):
        H_W[h][w] = num
        if w % 2 == 0:
            if 0 <= h + 1 < H:
                h += 1
            else:
                w += 1
        else:
            if 0 <= h - 1 < H:
                h -= 1
            else:
                w += 1

for a in H_W:
    print(" ".join(map(str, a)))

Measured memory_bytes: 40944
function battle(x)
	if x == 'a'
		1
	elseif x == 'b'
		2
	elseif x == 'c'
		3
	end
end

function main()
	sa = chomp(readline())
	sb = chomp(readline())
	sc = chomp(readline())
	na = 1
	nb = 1
	nc = 1
	turn = 1
	while na <= length(sa)+1 && nb <= length(sb)+1 && nc <= length(sc)+1
		if turn == 1
      		if na > length(sa)
      			println("A")
        		break
      		else
				turn = battle(sa[na])
				na += 1
			end
		elseif turn == 2
      		if nb > length(sb)
      			println("B")
        		break
      		else
  			    turn = battle(sb[nb])
				nb += 1
			end
		elseif turn == 3
      		if nc > length(sc)
      			println("C")
        		break
      		else
		        turn = battle(sc[nc])
				nc += 1
			end
		end
	end
end

main()

Measured memory_bytes: 110728
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (int i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": ";
    printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e12;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll N;
  cin >> N;
  vector<P> lr; // [L, R)
  ll mx = -1; // max of l
  ll mn = INF; // min of r
  rep(i, N) {
    ll l, r;
    cin >> l >> r;
    ++r;
    lr.emplace_back(l, r);
    chmax(mx, l);
    chmin(mn, r);
  }

  ll ans = 0;

  // Check "[mx, mn) + 1 problem" case
  for (auto x : lr) {
    chmax(ans, max(0LL, mn-mx) + (x.second - x.first));
  }

  // Check "[mx, r) + [l, mn)" case
  vector<P> t;
  rep(i, N) {
    ll a = max(0LL, mn-lr[i].first);
    ll b = max(0LL, lr[i].second-mx);
    t.emplace_back(b, -a); // to sort by (b, -a). Increasing by b, decreasing by a.
  }
  sort(all(t));

  ll c = INF; // the min of a in front elements of t.
  rep(i, N) {
    ll a, b;
    tie(b, a) = t[i];
    a = -a;
    if (i > 0) {
      chmax(ans, c+b);
    }
    chmin(c, a);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4848
N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for i in range(N)]

from heapq import *

h = []

AB = sorted(AB)

result = 0
p = 0
for i in range(1, M + 1):
    while p < len(AB) and AB[p][0] <= i:
        heappush(h, -AB[p][1])
        p += 1
    if h:
        result -= heappop(h)
    
print(result)


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

typedef long long ll;

using namespace std;

const int inf=1000000007;

double a[200005];
int n, k;

string s;

bool fun(double d)
{
    int ans=0;
    for(int i=0;i<n;i++)
    {
        ans=ans+ceil(a[i]/d);
        ans--;
        if(ans>k)
        {
            return 0;
        }
    }
    if(ans<=k)
    {
        return 1;
    }
    return 0;
}

double erfen(double l,double r)
{
    while(r-l>=0.000001)
    {
        double z=(l+r)/2;
        if(fun(z))
        {
            r=z;
        }
        else
        {
            l=z;
        }
    }
    return r;
}

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
        scanf("%lf",&a[i]);
    }
    double z=erfen(0.0,1000000007.0);
    //printf("z=%f\n",z);
    printf("%.0f\n",max(1.0,ceil(z-0.000001)));
    return 0;
}


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

A = [-10 ** 18] + A
ans = "Yes"

for i in range(N):
    if A[i] == A[i + 1]:
        continue
    elif A[i] + 1 <= A[i + 1]:
        A[i + 1] -= 1
    else:
        ans = "No"
        break

print(ans)


Measured memory_bytes: 14396
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> vec) {
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

#define solvsh
//#define multi
#ifdef solvsh

const int MAXN = 2e6 + 20;

int has[MAXN];

void solve() {

    vector<int> v;
    int n;cin >>n;

    for (int i = 0; i < n; ++ i){
        int curr;
        cin >> curr;
        v.push_back(curr);
        ++has[curr];
    }
    int answr = 0;
    for (int i = 0; i < n; ++ i){
        int curr = v[i];
        --has[curr];
        bool ok = true;
        for (int j = 1; j * j <= curr; ++j){
            if (curr % j == 0){
                if (has[j] || has[curr / j]){
                    ok = false;
                }
            }
        }
        ++has[curr];
        if (ok)
            ++answr;
    }

    cout << answr;
}

#else

void solve() {

}

#endif


void multisolve() {

    int t;
    cin >> t;

    int i = 1;
    while (t--) {
//        cout << "Mission #" << (i++) << ": \n";

        solve();
        cout << "\n";
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);


#ifdef multi
    multisolve();
#else
    solve();
    //    gen();
#endif

}


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

using namespace std;

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

using _loop_int = 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 CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    int x;
    cin>>x;
    while(true){
        bool ok = true;
        for(int y=2; y*y<=x; y++){
            if(x%y==0){
                ok = false; break;
            }
        }
        if(ok)break;
        x++;
    }
    printf("%d\n",x);
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a:i32,
        b:i32,
        c:i32,
    }
    let ans = std::cmp::max(c-a+b, 0);
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N;
    cin >> N;
    vector<ll> H(N);
    rep(i,N){
        cin >> H[i];
    }
    ll last = H[N-1];
    repBack(i,N-2){
        if(last>=H[i]){
            last = H[i];
        }else if(last>=H[i]-1){
            last = H[i]-1;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;


    return 0;
}

Measured memory_bytes: 1024
from sys import stdin

n = int(stdin.readline().rstrip())
a = {i + 1: int(x) for i, x in enumerate(stdin.readline().rstrip().split())}

a_sorted = sorted(a.items(), key=lambda x: x[1])

final = []
for i in range(n):
    final.append(a_sorted[i][0])

print(*final)


Measured memory_bytes: 25876
K = $stdin.read.to_i
sum = 0
1.upto(K) do |a|
  1.upto(K) do |b|
    ab_gcd = a.gcd(b)
    #puts "a=#{a}, b=#{b} => #{ab_gcd}"
    1.upto(K) do |c|
      abc_gcd = c.gcd(ab_gcd)
      #puts "a=#{a}, b=#{b}, c=#{c} => #{abc_gcd}"
      sum += abc_gcd
    end
  end
end
puts sum


Measured memory_bytes: 14392
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <complex>

using P = std::complex<long long>;

namespace std {
	bool operator<(std::complex<long long> p1, std::complex<long long> p2) {
		bool a = std::imag(p1) > 0 || (std::imag(p1) == 0 && std::real(p1) >= 0);
		bool b = std::imag(p2) > 0 || (std::imag(p2) == 0 && std::real(p2) >= 0);
		if (a != b) return a;
		long long c = std::real(p2) * std::imag(p1);
		long long d = std::real(p1) * std::imag(p2);
		if (c != d) return c < d;
		return std::norm(p1) < std::norm(p2);
	}
}

P input() {
	int x, y;
	std::cin >> x >> y;
	return P(x, y);
}

bool solve() {
	long long w, h;
	int n;
	std::cin >> w >> h >> n;

	h *= 2;
	w *= 2;

	std::vector<std::pair<P, int>> ps;
	for (int i = 0; i < n; i++) {
		P p = input();
		P q = input();
		p *= 2LL;
		q *= 2LL;

		if ((p.real() == 0 || p.real() == w || p.imag() == 0 || p.imag() == h) &&
			(q.real() == 0 || q.real() == w || q.imag() == 0 || q.imag() == h)) {
			p -= P(w / 2, h / 2);
			q -= P(w / 2, h / 2);

			ps.emplace_back(p, i);
			ps.emplace_back(q, i);
		}
	}

	if (ps.size() == 0) {
		return true;
	}

	std::sort(ps.begin(), ps.end());

	std::vector<int> labels;
	for (int i = 0; i < ps.size(); i++) {
		labels.push_back(ps[i].second);
	}

	const int N = labels.size();
	for (int i = 0; i + 1 < N; i++) {
		if (labels[i] == labels[i + 1]) {
			std::rotate(labels.begin(), labels.begin() + i + 1, labels.end());

			std::vector<int> stack;

			std::vector<bool> used(n);

			for (int j = 0; j < N; j++) {
				int l = labels[j];
				if (used[l]) {
					if (stack.empty() || stack.back() != l) {
						return false;
					}
					stack.pop_back();
				} else {
					stack.push_back(l);
					used[l] = true;
				}
			}
			return true;
		}
	}

	return false;
}

int main() {
	puts(solve() ? "YES" : "NO");
}

Measured memory_bytes: 8432
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

const ll N_MAX=100100;
ll depth[N_MAX];
vector<pair<ll,ll>> tree[N_MAX];

void dfs(ll p,ll q,ll r){
  depth[p]=r;
  for(auto &e:tree[p]){
    if(e.first==q)continue;
    //depth[e.first]=depth[p]+e.second;
    dfs(e.first,p,r+e.second);
  }
  return;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  ll a,b,c;
  for(int i=0;i<N-1;i++){
    cin >> a >> b >> c;
    a--;
    b--;
    tree[a].push_back({b,c});
    tree[b].push_back({a,c});
  }
  ll Q,K;
  cin >> Q >> K;
  K--;
  dfs(K,-1,0);
  ll x,y;
  for(int i=0;i<Q;i++){
    cin >> x >> y;
    x--;
    y--;
    cout << depth[x]+depth[y] << endl;
  }
  return 0;
}

Measured memory_bytes: 14336
N = int(input())
P = [int(p) for p in input().split()]

ans = 0
i = 0
while i < N-1:
    if P[i] == i+1 and P[i+1] == i+2:
        ans += 1
        i += 1
    elif P[i] == i+1:
        ans += 1
    i += 1
        
if P[N-1] == N and i == N-1:
    ans += 1

print(ans)

Measured memory_bytes: 13880
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", _dmp_(#__VA_ARGS__, __VA_ARGS__);
void _dmp_(const char*) { cerr << endl; }
template <class T, class... U>
void _dmp_(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; _dmp_(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S> const& p) { return is >> p.first >> p.second; }
struct _Init_ { _Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } _init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
#define YesNo(c) ((c) ? "Yes" : "No")
////////////////////////////////

int32_t main() {
    int n,k; cin >> n >> k;
    string s; cin >> s;

    int x = 0;
    rep (i,n-1) if (s[i]==s[i+1]) x++;
    cout << min(n-1,x+2*k) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;

int main() {
int x, a;
cin >> x >> a;
if (a == 0) {
  cout << 10 << endl;
} else if (x/a == 0) {
  cout << 0 << endl;
} else {
  cout << 10 << endl;
}
}


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

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

typedef long long ll;
typedef std::vector<int> vint;
const ll MOD = 1e9 + 7;
const int MAX_N = 1000;

std::vector<vint> to(MAX_N * MAX_N);
std::vector<vint> id(MAX_N, vint(MAX_N));

int toID(int i, int j) {
  if(i > j) std::swap(i, j);
  return id[i][j];
}

vint dp(MAX_N * MAX_N, -2);
bool calculated[MAX_N * MAX_N];
int dfs(int v) {
  if(dp[v] != -2) {
    if(! calculated[v]) return -1;
    return dp[v];
  }
  dp[v] = 1;

  for(int u : to[v]) {
    int res = dfs(u);
    if(res == -1) return -1;
    dp[v] = std::max(dp[v], res + 1);
  }
  calculated[v] = true;
  return dp[v];
}

int main() {
  int N;
  std::cin >> N;
  std::vector<vint> A(N, vint(N - 1));

  int V = 0;
  rep(i, N) {
    rep(j, N) {
      if(i < j) id[i][j] = V++;
    }
  }

  rep(i, N) {
    rep(j, N - 1) {
      std::cin >> A[i][j];
      --A[i][j];
      A[i][j] = toID(i, A[i][j]);
    }
    rep(j, N - 2) {
      to[A[i][j + 1]].push_back(A[i][j]);
    }
  }

  int ans = 0;
  rep(i, V) {
    int res = dfs(i);
    if(res == -1) {
      std::cout << -1 << '\n';
      return 0;
    }
    ans = std::max(ans, res);
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 51584
n=gets.to_i
count = 0
ans =[]
n.times do
  a,b=gets.split.map(&:to_i)
	a==b ? ans << true : ans << false
end
ans.each_cons(3) do |i,j,k|
  if i&&j&&k
    puts "Yes"
    exit
  end
end
puts "No"


Measured memory_bytes: 14324
#include <cstdio>
#include <cmath>
#include <algorithm>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>

using namespace std;

int N,x[301],y[301];

double get_r(double X, double Y){
    double ret = 0;
    
    for(int i = 0;i < N;++i)
        ret = max(ret,(X - x[i]) * (X - x[i]) + (Y - y[i]) * (Y - y[i]));
    
    return ret;
}

double searchY(double X){
    double lo = 0,hi = 1000;
    
    for(int it = 0;it < 300;++it){
        double a = (2 * lo + hi) / 3;
        double b = (lo + 2 * hi) / 3;
        
        double ra = get_r(X,a);
        double rb = get_r(X,b);
        
        if(ra < rb) hi = b;
        else lo = a;
    }
    
    return get_r(X,lo);
}

double searchX(){
    double lo = 0,hi = 1000;
    
    for(int it = 0;it < 300;++it){
        double a = (2 * lo + hi) / 3;
        double b = (lo + 2 * hi) / 3;
        
        double ra = searchY(a);
        double rb = searchY(b);
        
        if(ra < rb) hi = b;
        else lo = a;
    }
    
    return searchY(lo);
}

int main(){
	cout << fixed << setprecision(18);
    scanf("%d",&N);
    
    for(int i = 0;i < N;++i)scanf("%d %d",&x[i],&y[i]);
    
    //printf("%.2f\n",sqrt(searchX()) );
    cout<<sqrt(searchX())<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}



int main() {
    ll n,q;cin>>n>>q;
    dsu d(n);
    rep(i,q){
        ll t,u,v;cin>>t>>u>>v;
        if(!t)d.merge(u, v);
        else if(d.same(u,v))out(1);
        else out(0);
    }
}


Measured memory_bytes: 3916
n = int(input())
list_a = [i for i in range(1,n+1) if i % 3 ==0]
list_b = []
for i in range (1,n+1):
    j = i
    while True:
        if j == 0:
            break
        elif j % 10 == 3:
            list_b.append(i)
            break
        j = j // 10
    
a = set(list_a)
b = set(list_b)
c =list(a | b)
c.sort()
print(" " + " ".join(map(str,c)))

Measured memory_bytes: 8440
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,a,b,c;
    cin >>a>>b>>c;



    {
        if(a==b&&b==c)cout <<"Yes"<<endl;
        else cout <<"No"<<endl;
    }

    dbg cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
import collections
n = int(input())
ls = [int(input()) for i in range(n)]
ls.sort()
c = collections.Counter(ls)
d = list(c)
p = 0
for j in range(len(c)):
    if c[d[j]] % 2 ==0:
        continue
    else:
        p += 1
print(p)


Measured memory_bytes: 16564
#include <iostream>
using namespace::std;
int main()
{

        int H, W, r, c;
        cin >> H >> W;
         while((H!=0) || (W!=0)){
                for(r = 0; r < H; r++) {
                        for(c = 0; c<W; c++) {
                                if((r==0) || (r==H-1) || (c==0) || (c==W-1))
                                        cout<<"#";
                                else
                                        cout<<".";
                        }
                        cout<<endl;
                }
                cout<<"\n";
                cin >> H >> W;
        }
}



Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
int main() {
    char N_str[10];
    scanf("%s", &N_str);
    int N = atoi(&N_str);
    int harshad = 0;
    for(int i = 0; i < strlen(N_str); i++) {
        harshad += N_str[i] - '0';
    }
    if(N % harshad == 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

#define FOR(I, A, B) for(int I = (A); I < (B); I++)

#define N (800)

int H, W, K;
char map[N + 1][N + 1];
int q[N * N][2];

int is_edge(int x, int y) {
	return x == 0 || y == 0 || (H - 1) == x || (W - 1) == y;
}

int min(int x, int y) {
	return x < y ? x : y;
}

int score(int p[2]) {
	int x = p[0];
	int y = p[1];
	return min(min(x, H - 1 - x), min(y, W - 1 - y));
}

void core() {
	int sx = 0, sy = 0;
	scanf("%d%d%d", &H, &W, &K);
	FOR(i, 0, H)
	{
		scanf("%s", map[i]);
		FOR(j, 0, W)
		{
			if (map[i][j] == 'S') {
				sx = i;
				sy = j;
			}
		}
	}
	//
	int l = 0, r = 1;
	q[0][0] = sx;
	q[0][1] = sy;
	FOR(k, 0, K)
	{
		if (l == r) {
			break;
		}
		int d = 0;
		FOR(i, l, r)
		{
			int x = q[i][0];
			int y = q[i][1];
			if (!is_edge(x, y)) {
				if (map[x - 1][y] == '.') {
					q[r + d][0] = x - 1;
					q[r + d][1] = y;
					map[x - 1][y] = 'x';
					d++;
				}
				if (map[x + 1][y] == '.') {
					q[r + d][0] = x + 1;
					q[r + d][1] = y;
					map[x + 1][y] = 'x';
					d++;
				}
				if (map[x][y - 1] == '.') {
					q[r + d][0] = x;
					q[r + d][1] = y - 1;
					map[x][y - 1] = 'x';
					d++;
				}
				if (map[x][y + 1] == '.') {
					q[r + d][0] = x;
					q[r + d][1] = y + 1;
					map[x][y + 1] = 'x';
					d++;
				}
			}
		}
		l = r;
		r += d;
	}
	int min_score = score(q[0]);
	FOR(i, 1, r)
	{
		min_score = min(min_score, score(q[i]));
	}
	printf("%d\n", (int) ceil(((double) min_score) / K) + 1);
}

int main() {
	core();
	return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int x[8], y[8];
  for(int i=0;i<N;i++)
  {
    cin >> x[i] >> y[i];
  }
  double ans=0;
  for(int i=0;i<N;i++)
  {
    for(int j=0;j<N;j++)
    {
      if(i!=j) ans+=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
    }
  }
  int Nbi=0;
  
  ans=ans/N;
  
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    x, k, d = map(int, input().split())
    if x == 0:
        if k % 2 == 0:
            return 0
        else:
            return d
    else:
        n = int(abs(x)/d)
        if n > k:
            return abs(abs(x)-k*d)
        else:
            if (k-n) % 2 == 0:
                return abs(abs(x)-n*d)
            else:
                return abs(abs(x)-(n+1)*d)


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 9124
pr = [True] * 50001
for i in range(2,225):
    if pr[i]:
        for j in range(i * 2, 50001, i):
            pr[j] = False

prime = [2] + [i for i in range(3, 50001, 2) if pr[i]]

def gold_count(n):
    res = 0
    for i in prime:
        if i > n // 2:
            break
        if pr[n - i]:
            res += 1
    return res

while True:
    n = int(input())
    if n == 0:
        break
    print(gold_count(n))

Measured memory_bytes: 7892
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
using namespace std;




const int MAX_N = 110000;
const int INF = 1LL<<30;

typedef int VAL;     // モノイドの型
typedef int DELAY;   // 作用 (遅延評価) の型

const VAL UNITY_VAL = INF;    // モノイドの単位元
const DELAY UNITY_DELAY = 0;  // 作用の単位元

static int SIZE_SEG;
struct SegTree {
  VAL val[4*MAX_N];  
  DELAY delay[4*MAX_N]; 

  SegTree(int n = MAX_N, VAL v = UNITY_VAL) {
	init(n, v);
  }
    
  void init(int n = MAX_N, VAL v = UNITY_VAL) {
	SIZE_SEG = 1;
	while (SIZE_SEG < n) SIZE_SEG *= 2;
	for (int i = 0; i < 2*SIZE_SEG-1; ++i) val[i] = v, delay[i] = UNITY_DELAY;
  }


  ///////////////////////////////
  // モノイド演算の定義、作用の定義: ここだけ書き換えれば OK
  ///////////////////////////////

  // モノイド演算
  inline VAL merge(VAL a, VAL b) {

	// Starry Sky Tree の場合: min
	VAL res = min(a, b);
	return res;
  }

  // 作用元での演算
  inline void add(DELAY &d, DELAY x) {

	// Starry Sky Tree の場合: +
    d += x;
  }

  // モノイドへの作用
  inline void reflect(VAL &a, DELAY d) {

	// Starry Sky Tree の場合: 加算
	a += d;
  }


  ///////////////////////////////
  // ここから下は書き換え不要！！！
  ///////////////////////////////
    
  inline void redelay(int k, int l, int r) {
	reflect(val[k], delay[k]);
	if (k < SIZE_SEG-1) {
	  add(delay[k*2+1], delay[k]);
	  add(delay[k*2+2], delay[k]);
	}
	delay[k] = UNITY_DELAY;
  }
    
  inline void renode(int k, int l, int r) {
	val[k] = merge(val[k*2+1], val[k*2+2]);
  }
    
  inline void set(int a, int b, DELAY x, int k = 0, int l = 0, int r = SIZE_SEG) {
	if (a <= l && r <= b) {                 // included
	  add(delay[k], x);
	  redelay(k, l, r);
	}
	else if (a < r && l < b) {              // intersected
	  redelay(k, l, r);
	  set(a, b, x, k*2+1, l, (l+r)/2);
	  set(a, b, x, k*2+2, (l+r)/2, r);
	  renode(k, l, r);
	}
	else {                                  // no-intersected
	  redelay(k, l, r);
	}
  }
    
  inline VAL get(int a, int b, int k = 0, int l = 0, int r = SIZE_SEG) {
	redelay(k, l, r);
	if (a <= l && r <= b) {                 // included
	  return val[k];
	}
	else if (a < r && l < b) {              // intersected
	  VAL t1 = get(a, b, k*2+1, l, (l+r)/2);
	  VAL t2 = get(a, b, k*2+2, (l+r)/2, r);
	  renode(k, l, r);
      
	  return merge(t1, t2);
	}
	else {                                  // no-intersected
	  return UNITY_VAL;
	}
  }

  /*
  inline VAL operator [] (int i) {return get(i, i+1);}
  
  void print(long long r = SIZE_SEG) {
	long long t = 2;
	for (int i = 0; i < r*2-1; ++i) {
	  cout << make_pair(val[i], delay[i]) << ",";
	  if (i == t-2) {cout << endl; t *= 2;}
	}
	for (int i = 0; i < r; ++i) {
	  cout << get(i, i+1) << ", ";
	}
	cout << endl << endl;
  }
  */
};



int main() {
  int n, q;
  cin >> n >> q;
  SegTree seg(n, 0);
  for (int i = 0; i < q; ++i) {
	int type, left, right;
	cin >> type >> left >> right;
	if (type == 0) {
	  int val;
	  cin >> val;
	  seg.set(left, right+1, val);
	}
	else {
	  int res = seg.get(left, right+1);
	  cout << res << endl;
	}
  }
}




Measured memory_bytes: 5144
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int a[3][3];
    int temp;
    int n;

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> temp;
            a[i][j] = temp;
        }
    }
    cin >> n;

    vector<int> b;
    
    for (int i = 0; i < n; i++) {
        cin >> temp;
        b.push_back(temp);
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (a[j][k] == b[i]) {
                    a[j][k] = 0;
                }
            }
        }
    }

    bool bans = false;

    for (int i = 0; i < 3; i++) {
        if (a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) bans = true;
        if (a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) bans = true;
        if (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) bans = true;
        if (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0) bans = true;
    }

    if (bans == true) {
        cout << "Yes";
    } else {
        cout << "No";
    }




    /*84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
61
97*/

    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1000000007;

int main(void){
	int n; cin>>n;
	int alp[50][26];
	for(int i=0;i<n;i++){
		for(int j=0;j<26;j++){
			alp[i][j] = 0;
		}
	}
	string S,ans;
	for(int i=0;i<n;i++){
		cin>>S;
		for(int j=0;j<S.size();j++){
			alp[i]['z' - S[j]]++;
		}
	}
	
	/*for(char i = 'z';i >= 'a';i--)cout<<i<<" ";
	cout<<endl;
	for(int i=0;i<n;i++){
		for(int j=0;j<26;j++){
			cout<<alp[i][j]<<" ";
		}
		cout<<endl;
	}*/


	string alphabet = "abcdefghijklmnopqrstuvwxyz";
	reverse(alphabet.begin(), alphabet.end());
	//cout<<alphabet<<endl;
	for(int j=0;j<26;j++){
		int cnt=0, k;
		int arr[60]={0};
		for(int i=0;i<n;i++){
			k = j;
			if(alp[i][j] != 0){
				cnt++;
				arr[i] = alp[i][j];
			}
		}
		//cout<<cnt<<" "<<k<<endl;
		if(cnt == n){
			sort(arr, arr+n);
			for(int m=0;m<arr[0];m++){
				ans += alphabet[k];
			}
		}
	}

	sort(ans.begin(), ans.end());

	printf("%s\n", ans.c_str());

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

vector<int> dp(2000);

int main() {
  IOS;
  int s; cin >> s;
  dp.resize(s);

  dp[0] = 1;
  for (int i = 3; i <= s; i++) {
    for (int j = 3; j <= s; j++) {
      if (i < j) break;

      dp[i] += dp[i-j];
      dp[i] %= mod;
    }
  }

  COUT(dp[s]);
  return 0;
}

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

long long int d[20010] = {};
long long int sum[20010] = {};
long long int to[20010] = {};

int main() {

  string s;
  cin >> s;

  long long int ma = 0;
  long long int mi = 0;

  long long int cnt = 0;

  for ( long long int i = 0; i < s.size(); i++ ) {

    if ( s[i] == '/' ) {
      cnt++;
    }else if ( s[i] == '_' ) {
    }else {
      cnt--;
    }
    ma = max( ma, cnt );
    mi = min( mi, cnt );

  }

  for ( long long int i = 0; i < ma - mi + 1; i++ ) {
    d[ i ] = -1;
  }
  for ( long long int i = 0; i < s.size() + 1; i++ ) {
    to[ i ] = -1;
  }

  long long int ans = 0;

  cnt = -mi;
  d[ cnt ] = 0;
  sum[ 0 ] = 0;

  for ( long long int i = 0; i < s.size(); i++ ) {

    if ( s[i] == '/' ) {
      cnt++;
      if ( d[ cnt ] != -1 ) {
	ans += ( i + 1 ) - d[ cnt ] - 1;
	to[ d[ cnt ] ] = i + 1;
      }
    }else if ( s[i] == '_' ) {
    }else {
      cnt--;
    }
    d[ cnt ] = i + 1;
    sum[ i + 1 ] = ans;

  }

  vector< long long int > v;

  for ( long long int i = 0; i < s.size() + 1; i++ ) {

    if ( to[ i ] != -1 ) {

      v.push_back( sum[ to[i] ] - sum[ i ] );
      i = to[i] - 1;

    }

  }

  cout << ans << endl;
  cout << v.size();
  for ( long long int i = 0; i < v.size(); i++ ) {
    cout << " " << v[i];
  }
  cout << endl;

  return 0;

}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b; cin >> a >> b;
    bool ok = (a * b % 2 == 1);

    cout << (ok ? "Yes":"No") << endl;

    return 0;
}


Measured memory_bytes: 256
s = input()

count = 0
try:
    for i in range(0,len(s),2):
        if s[i] == '0':
            count += 1 
        if s[i+1] == '1':
            count +=1
except :
    pass
if count <= int(len(s)/2):
    print(count)
else:
    print(len(s)-count)

Measured memory_bytes: 3188
n = int(input())
sides = []
ws = []
ss = []
for _ in range(n):
    sides.append(list(map(int,input().split())))
for i in range(n):
    for j in range(i+1,n):
        if sides[i][j] >= 0:
            ws.append([sides[i][j],i,j])
rs = [(i) for i in range(n)]
def root(x):
    global rs
    if rs[x] == x:
        return(x)
    else:
        return(root(rs[x]))
ws.sort()
ans = 0
while(len(ws)):
    if root(ws[0][1]) != root(ws[0][2]):
        ans += ws[0][0]
        rs[root(rs[ws[0][2]])] = root(ws[0][1])
        ss.append(ws[0])
    del(ws[0])
print(ans)



Measured memory_bytes: 6252
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: i32 = read();
    println!("{}", if n % 2 == 0 { n } else { n * 2 });
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    string T; cin >> T;
    string ans;
    for (int i = 0; i < T.length(); ++i)
    {
        char ch = T[i];
        if (ch == '?') ans += 'D';
        else ans += ch;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m,x,y;
char f[55][55];
int rui[55][55];
int calc(int a,int b,int c,int d){
	return rui[b][d]-rui[a-1][d]-rui[b][c-1]+rui[a-1][c-1];
}
int dp[45][45][45][45];
int rec(int a,int b,int c,int d){
	if(dp[a][b][c][d] < 100000) return dp[a][b][c][d];
	int &ret = dp[a][b][c][d];
	ret = min(calc(a,x,c,y),ret);
	ret = min(calc(a,x,y,d),ret);
	ret = min(calc(x,b,c,y),ret);
	ret = min(calc(x,b,y,d),ret);
	for(int X=x;X<=b;X++) for(int Y=y;Y<=d;Y++){
		if(X==b && Y==d) continue;
		ret = min(ret,calc(X+1,b,c,Y)+calc(a,X,Y+1,d)+rec(a,X,c,Y));
	}
	for(int X=x;X<=b;X++) for(int Y=c;Y<=y;Y++){
		if(X==b && Y==c) continue;
		ret = min(ret,calc(X+1,b,Y,d)+calc(a,X,c,Y-1)+rec(a,X,Y,d));
	}
	for(int X=a;X<=x;X++) for(int Y=y;Y<=d;Y++){
		if(X==a && Y==d) continue;
		ret = min(ret,calc(a,X-1,c,Y)+calc(X,b,Y+1,d)+rec(X,b,c,Y));
	}
	for(int X=a;X<=x;X++) for(int Y=c;Y<=y;Y++){
		if(X==a && Y==c) continue;
		ret = min(ret,calc(a,X-1,Y,d)+calc(X,b,c,Y-1)+rec(X,b,Y,d));
	}
	return ret;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		string str; cin>>str;
		for(int j=1;j<=m;j++){
			f[i][j] = str[j-1];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(f[i][j] == 'P'){
				x = i;
				y = j;
			}
			rui[i][j] = (f[i][j]=='#'?1:0);
			rui[i][j] += rui[i-1][j];
			rui[i][j] += rui[i][j-1];
			rui[i][j] -= rui[i-1][j-1];
		}
	}
	rep(i,45)rep(j,45)rep(k,45)rep(l,45)dp[i][j][k][l] = INF;
	cout << rec(1,n,1,m) << endl;
}


Measured memory_bytes: 16384