akhauriyash/Code-Regression huggingface dataset:
//author:emre yazicioglu

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define fori(a,b,c) for(ll a = b;a < ll(c);a++)
#define ford(a,b,c) for(ll a = b;a >= ll(c);a--)
#define pb push_back

const int N = 2e6 + 7;
ll n,m,k,ans,cur,ar[N];
ll sum,a,b,c,d;
string str;
vector<ll> v;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);

	// freopen("../in.txt","r",stdin);
	// freopen("../out.txt","w",stdout);
	
	cin >> n >> k;

	fori(i,k - n + 1,n + k)
		cout << i << ' ';	
	

	// read question and limits again
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <climits>
#include <cassert>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

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

#define pb push_back
#define mp make_pair


int main(){
    int N, W;
    cin >> N >> W;

    vector<int> vs(N);
    vector<int> ws(N);
    REP(i, N) cin >> vs[i] >> ws[i];

    // ?????????
    // [??????????????§?????????][??????] = ??????
    int INF = 1e9;
    vector<vector<int>> dp(N+1, vector<int>(W+1));
    FOR(n, 1, N+1) {
        auto weight = ws[n-1];
        auto value = vs[n-1];
        REP(w, W+1) {
            if (w >= weight) 
                dp[n][w] = max(dp[n-1][w - weight] + value, dp[n-1][w]);
            else 
                dp[n][w] = dp[n-1][w];
        }
    }

    int ret = 0;
    REP(w, W+1) {
        ret = max(ret, dp[N][w]);
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 4956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR (a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T>
struct IsC {
  template <typename C>
  static char test(typename C::const_iterator*);
  template <typename C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&, const C&);
template <typename T1, typename T2>
ostream& operator<<(ostream&, const pair<T1, T2>&);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template<size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return o << ", " << get<idx>(t) << ')';
}
template<size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << ", " << get<idx>(t), t);
}
template<size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << '(' << get<idx>(t), t);
}
template<typename T>
ostream& operator<<(ostream& o, const tuple<T>& t) {
  return o << get<0>(t);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
  return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '[';
  for (auto it = c.cbegin(); it != c.cend(); ++it)
    o << *it << (next(it) != c.cend() ? ", " : "");
  return o << ']';
}
template <typename T>
void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) {
  if (!DEBUG) return;
  for (auto& vv : v) {
    for (auto& i : vv) o << setw(width) << i;
    o << endl;
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);

  int n; cin >> n;
  int cnt = 0;
  FOR (i, 1, n + 1) {
    int a; cin >> a;
    cnt += a & i & 1; 
  }
  cout << cnt << endl;
  
  return 0;
}


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

int main(){
	int N,W,v[1001],w[1001];
	int dp[10010];
	cin >> N >> W;
	for(int i=0;i<N;i++){
		cin >> v[i] >> w[i];
	}
	for(int i=0;i<=W;i++){
		dp[i] = -1;
	}
	dp[0] = 0;
	for(int i=0;i<N;i++){
		for(int j=W;j>=0;j--){
			if(j+w[i] > W) continue;
			if(dp[j]==-1) continue;
			dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i]);
		}
	}
	int ans = 0;
	for(int i=0;i<=W;i++){
		ans = max(ans,dp[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1208
from functools import reduce
import sys
input = sys.stdin.readline

N, M = map(int, input().split(" "))
disputes = list()
current = 0
for _ in range(M):
    a, b = map(int, input().split(" "))
    disputes.append((a, b))

disputes = sorted(disputes, key=lambda x: x[1])
count = 1
most_recently_removed = disputes[0][1] - 1
for i, dispute in enumerate(disputes[1:]):
    a, b = dispute
    if a <= most_recently_removed <= b-1:
        pass
    else:
        most_recently_removed = b-1
        count += 1

print(count)









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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef long double LD;
typedef pair<LD, int> PLDI;
typedef pair<LD, LD> PLDLD;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()
const LL MOD = 1e9+7;
const int INF = (1e9);
const double EPS=1.0e-9;
const double PI=atan2(0,-1);


int main()
{
	int h,w;
	cin>>h>>w;
	vector<vector<int> > c(w,vector<int>(h));
	string s;
	REP(j,h)
	{
		cin>>s;
		REP(i,w)
		{
			c[i][j]=s[i]-'a';
		}
	}
	
	LL ans=0;
	vector<vector<int> > cp(2, vector<int>(h));
	vector<vector<int> > cost(h+1, vector<int>(h+1));
		vector<vector<int> > cnt(h+1, vector<int>(h+1, INF));
	REP(i,w-1)
	{
		
		REP(j,h)
			{
				cp[0][j]=c[i][j];
				cp[1][j]=c[i+1][j];
			}
		REP(j,h+1)
		REP(k,h+1)
		{
			cnt[j][k]=INF;
			cnt[j][k]=INF;
		}
		
		/*
		REP(i,h+1)
		REP(j,h+1)
		{
			
			int ct=0;
			int ii=max(i-j,0), jj=max(j-i,0);
			REP(k,min(i,j))
			{
				if(cp[0][k+ii]==cp[1][k+jj])
				ct++;
			}
			cost[i][j]=ct;
		}*/
		
		REP(j,h+1)//sa
		{
			int ct=0;
			cost[j][0]=0;
			for(int k=0;k<h-j;k++)
			{
				if(cp[0][k]==cp[1][k+j])
					ct++;
				
				cost[k+1][(k+j)+1]=ct;
			}
			
			ct=0;
			cost[0][j]=0;
			for(int k=0;k<h-j;k++)
			{
				if(cp[0][k+j]==cp[1][k])
					ct++;
				
				cost[(k+j)+1][k+1]=ct;
			}
		}
		
		cnt[h][h]=0;
		for(int j=h*2;j>=0;j--)
		{
			FOR(k,0,h*2-j +1)
			{
				int l=j-h+k;
				int m=j-l;
				if(!(0<=l&&l<=h) || !(0<=m&&m<=h)) continue;
				
				if((0<=l-1&&l-1<=h))
				{
					cnt[l-1][m]=min(cnt[l-1][m], cnt[l][m]+cost[l][m]);
				}
				if((0<=m-1&&m-1<=h))
				{
					cnt[l][m-1]=min(cnt[l][m-1], cnt[l][m]+cost[l][m]);
				}
			}
		}
		ans+=cnt[0][0];
		
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 1280
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>
#define P 998244353

using namespace std;

typedef long long ll;

bitset <305> bt[305];

int n, m;

ll _2[777];

int main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) {
            int v;
            scanf("%d", &v);
            if(v == 1) bt[i - 1][j - 1] = 1;
        }
    for(int i = 0; i < 777; i++) _2[i] = !i ? 1 : _2[i - 1] * 2 % P;
    int nw = 0;
    for(int i = 0; i < m; i++) {
        for(int j = nw; j < n; j++)
            if(bt[j][i]) {
                swap(bt[j], bt[nw]);
                break;
            }
        if(!bt[nw][i]) continue;
        for(int j = nw + 1; j < n; j++)
            if(bt[j][i]) bt[j] ^= bt[nw];
        nw++;
    }
    int _1 = nw, _0 = n - nw;
    ll ans = _2[m - 1] * (_2[_1] - 1) % P * _2[_0] % P;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    int a[n];
    rep(i,n)cin>>a[i];
    vector<pair<int,int>> pairs(m);
    int b,c;
    rep(i,m){
        cin>>b>>c;
        pairs[i] = make_pair(c,b);
    }

    sort(a,a+n);
    sort(pairs.begin(),pairs.end(),greater<pair<int,int>>());

    int work=0;
    rep(i,m){
        rep(j,pairs[i].second){
            if(j+work >= n)break;
            if(a[j+work] <= pairs[i].first)a[j+work] = pairs[i].first;
        }
        work += pairs[i].second;
        if(work >= n)break;
    }

    long long sum=0;
    rep(i,n)sum += a[i];

    cout<<fixed<<setprecision(0)<<sum;
    //rep(i,m)printf("%d %d\n",pairs[i].first,pairs[i].second);
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<iomanip>
using namespace std;

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

double N;
pair<double, double> a[8];


int main() {
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> a[i].first >> a[i].second;
  }

  vector<int> pat;
  for(int i = 1; i <= N; i++) {
    pat.push_back(i);
  }

  double sum = 0.0000000;

  do {
    for(int i = 1; i < N; i++) {
      double befx = a[pat[i - 1] - 1].first;
      double befy = a[pat[i - 1] - 1].second;
      double nowx = a[pat[i] - 1].first;
      double nowy = a[pat[i] - 1].second;
      sum += pow(pow(nowx - befx, 2) + pow(nowy - befy, 2), 0.5);
    }
  } while(next_permutation(pat.begin(), pat.end()));

  double num = 1;

  for(int i = 1; i <= N; i++) {
    num *= i;
  }

  double ans = sum / num;

  cout << std::fixed << std::setprecision(7) << ans << endl;


  return 0;
}

Measured memory_bytes: 384
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    long N, K;
    scan(N, K);
    auto v = abs(N - K) % K;
    auto ans = min(v, K - v);
    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


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

int main() {
	int N, K;
	cin >> N >> K;

	vector<long> monsters(N);
	for (int i = 0; i < N; ++i) {
		cin >> monsters.at(i);
	}

	long long sum = 0;
	if (K >= N) {
		sum = 0;
	}
	else {
		sort(monsters.begin(), monsters.end());
		monsters.erase(next(monsters.end(), -K), monsters.end());

		for (long t : monsters) {
			sum += t;
		}
	}
	
	cout << sum;

	return 0;
}

Measured memory_bytes: 1792
/**
 * 	author: krayr
 * 	created: 18.05.2019
**/

#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back
#define mp make_pair
#define forn(i, s, n) for(int i = s; i < int(n); i++)

typedef long long ll;
//~ const double pi = 2*acos(0.0);
//~ const long long mod = 1e9+7;
//~ const int MAX_N = 1e6+5;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
       
    #ifdef _DEBUG
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    
	int n; cin >> n;
	
	int x = 0, y = 0;
	int v[n], c[n];
	
	forn(i, 0, n) cin >> v[i];
	forn(i, 0, n) cin >> c[i];
	
	forn(i, 0, n){
		if(v[i] > c[i]){
			x += v[i];
			y += c[i];
		}
	}
	
	cout << x-y << "\n";
    

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,W;
int w[105],v[100005];
int dp[105][100005];

signed main(){
	cin>>N>>W;
	REP(i,N){
		cin>>w[i]>>v[i];
	}
	REP(i,N){
		for(int j=0;j<=W;j++){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(j+w[i]<=W){
				dp[i+1][j+w[i]]=max(dp[i+1][j+w[i]],dp[i][j]+v[i]);
			}
		}
	}
	cout<<dp[N][W]<<endl;
	return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  string t1 = S.substr(0, 2);
  string t2 = S.substr(2, 2);
  if (t1 >= "01" && t1 <= "12" && t2 >= "01" && t2 <= "12") {
    cout << "AMBIGUOUS\n";
  } else if (t1 >= "01" && t1 <= "12") {
    cout << "MMYY\n";
  } else if (t2 >= "01" && t2 <= "12") {
    cout << "YYMM\n";
  } else {
    cout << "NA\n";
  }
  return 0;
}

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

int main(){
  int K, A, B;
  cin>>K>>A>>B;
  
  string ans="NG";
  for(int i=A; i<B+1; i++){
    if(i%K==0){
      ans="OK";
    }
  }
  cout<<ans;
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;

vector<int> S[MAX];
int N;
ll dp[2][MAX],seen[2][MAX],d[MAX],state[MAX];//0のとき白　1のとき黒
queue<int> Q;

void BFS(){
    for(int i=0;i<N;i++){
        d[i]=0;
        state[i]=0;
    }
    Q.push(0);
    d[0]=0;
    state[0]=1;
    while(Q.size()){
        int a=Q.front();
        Q.pop();
        for(int i=0;i<S[a].size();i++){
            int b=S[a][i];
            if(state[b]==0){
                Q.push(b);
                state[b]=1;
                d[b]=d[a]+1;
            }
        }
    }
}

ll pat(int a,int b){
    if(seen[b][a]) return dp[b][a];
    ll ans=1;
    if(b==0){
        for(int i=0;i<S[a].size();i++){
            int c=S[a][i];
            if(d[a]<d[c]){
                ans*=(pat(c,0)+pat(c,1));
                ans=ans%mod;
            }
        }
        seen[b][a]=1;
        return dp[0][a]=ans;
    }else{
        for(int i=0;i<S[a].size();i++){
            int c=S[a][i];
            if(d[a]<d[c]){
                ans=ans*pat(c,0)%mod;
            }
        }
        seen[b][a]=1;
        return dp[1][a]=ans;
    }
}

int main(){
    
    cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        S[a].push_back(b);
        S[b].push_back(a);
    }
    
    BFS();
    
    cout<<(pat(0,0)+pat(0,1))%mod<<endl;
    
}


Measured memory_bytes: 17408
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int LLI;
int main()
{
	int n, i;
	cin >> n;
	LLI arr[n], biggest = 0, second = 0;
	for(int i = 0; i < n; i++)
		cin >> arr[i];
		
	sort(arr,arr+n);
	
	for( i = n-1; i >= 1; i--)
		if( arr[i] == arr[i-1]  )
		{
			biggest = arr[i];
			break;
		}
	for(int j = i-2; j >= 1; j-- )
		if( arr[j] == arr[j-1] )
		{
			second = arr[j];
			break;
		}
	cout << biggest * second;
}

Measured memory_bytes: 4420
from bisect import bisect_left as bl
INF = 10 ** 20

def main():
  
  w, h = map(int, input().split())
  n = int(input())
  
  xlst = []
  ylst = []
  appx = xlst.append
  appy = ylst.append
  for i in range(n):
    x, y = map(int,input().split())
    appx(x)
    appy(y)
  
  sorted_xlst = sorted(xlst)
  sorted_ylst = sorted(ylst)
  accx = accy = 0
  cum_sum_xlst = []
  cum_sum_ylst = []
  appx = cum_sum_xlst.append
  appy = cum_sum_ylst.append

  for i in range(n):
    accx += sorted_xlst[i]
    accy += sorted_ylst[i]
    appx(accx)
    appy(accy)
  
  if n % 2:
    clx = crx = sorted_xlst[n // 2]
    cly = cry = sorted_ylst[n // 2]
  else:
    clx = sorted_xlst[n // 2 - 1]
    crx = sorted_xlst[n // 2]
    cly = sorted_ylst[n // 2 - 1]
    cry = sorted_ylst[n // 2]
  
  ans = ansx = ansy = INF
  
  for i in range(n):
    xi = xlst[i]
    yi = ylst[i]

    if xi <= clx:
      cx = crx
    else:
      cx = clx

    if yi <= cly:
      cy = cry
    else:
      cy = cly
  
    px = bl(sorted_xlst, cx)
    py = bl(sorted_ylst, cy)

    dx = xi - cx
    if dx < 0:
      dx = -dx

    if px:
      csx = cum_sum_xlst[px - 1]
      xlen = (accx - csx * 2 - cx * (n - px * 2)) * 2 - dx
    else:
      xlen = (accx - cx * n) * 2 - dx
 
    dy = yi - cy
    if dy < 0:
      dy = -dy
   
    if py:
      csy = cum_sum_ylst[py - 1]
      ylen = (accy - csy * 2 - cy * (n - py * 2)) * 2 - dy
    else:
      ylen = (accy - cy * n) * 2 - dy
    
    tlen = xlen + ylen

    if ans > tlen:
      ans = tlen
      ansx = cx
      ansy = cy
    elif ans == tlen:
      if ansx > cx:
        ansx = cx
        ansy = cy
      elif ansx == cx:
        if ansy > cy:
          ansy = cy 
  
  print(ans)
  print(ansx, ansy)

main()


Measured memory_bytes: 25176
#!/usr/bin/env python3
import sys

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


n, d = MI()

d = d ** 2
c = 0
for _ in range(n):
    x, y = MI()
    if x ** 2 + y ** 2 <= d:
        c += 1

print(c)


Measured memory_bytes: 9188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
//setprecision(12)
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
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; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll x; cin >> x;
    ll ans = x/500*1000 + x%500/5*5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[])
{

    string word, key;
    cin >> word >> key;
    word += word;
    if(word.find(key)!=string::npos)
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }


    return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
 
const int mxN=2e5;
int n, m;
ll k, a[mxN+1], b[mxN+1];
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	cin >> n >> m >> k;
	for(int i=0; i<n; ++i) {
		cin >> a[i+1];
		a[i+1]+=a[i];
	}
	for(int i=0; i<m; ++i) {
		cin >> b[i+1];
		b[i+1]+=b[i];
	}
	int ans=0;
	for(int i=0, j=m; i<=n; ++i) {
		if(a[i]>k)
			break;
		while(a[i]+b[j]>k)
			--j;
		ans=max(i+j, ans);
	}
	cout << ans;
}

Measured memory_bytes: 6740
_,_,K = gets.split.map(&:to_i)
A = [*gets.split.map(&:to_i),K+1]
B = [0,*gets.split.map(&:to_i),K+1]

n,k,a,b = 0,K-A.sum,A.size,0
begin
	(a-=1; k+=A[a]) while 0<a && k<B[b]
	(k-=B[b]; b+=1) while B[b]<=k
	n = a+b-1 if n<a+b-1
end while 0<a
p n


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int solve(string s){
    string t = "";
    for(auto x : s){
        if(x != 'x'){
            t.push_back(x);
        }
    }
    string u = t;
    reverse(ALL(u));
    if(t != u){
        return -1;
    }
    vector<int> v(t.size() + 1);
    int cnt = 0, j = 0;
    for(auto x : s){
        if(j < t.size() && x == t[j]){
            v[j] = cnt;
            cnt = 0;
            ++j;
        }else{
            ++cnt;
        }
    }
    v[j] = cnt;
    vector<int> w = v;
    reverse(ALL(w));
    int res = 0;
    rep(i, v.size()){
        res += abs(v[i] - w[i]);
    }
    res /= 2;
    return res;
}

int main(){
    string s;
    cin >> s;
    int ans = solve(s);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

#define MAX_PRIME	(1000000)


int prime[MAX_PRIME + 1];

void make_prime(void)
{
    int i;
    int j;
    int n;
    int c;
    
    for (i = 2; i * i <= MAX_PRIME; i++){
        if (prime[i] == 0){
            for (j = i * 2; j <= MAX_PRIME; j += i){
				prime[j] = 1;
            }
        }
    }
}
	


int main(void)
{
	int a, d, n;
    int i;
	int count;
	
	make_prime();

    while (1){
		scanf("%d%d%d", &a, &d, &n);
		if ((a | d | n) == 0){
			break;
		}
		count = 0;
		i = a;
		if (i == 1){
			i += d;
		}
		while (i <= MAX_PRIME){
			if (prime[i] == 0){
				count++;
				if (count == n){
					printf("%d\n", i);
					break;
				}
			}
			i += d;
		}
    }
    
    return (0);
}

Measured memory_bytes: 4504
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int X;
    cin >> X;
    vector<int> m(N);
    for(int i=0; i<N; i++){
        cin >> m.at(i);
    }
    int sum=0;
    for(int i=0; i<N; i++){
        sum+=m.at(i);
    }
    int t=X-sum;
    int mini=1001;
    for(int i=0; i<N; i++){
        mini=min(mini,m.at(i));
    }
    int add=t/mini;
    cout << add+N << endl;
}

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

int main()
{
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  if(a[0] > a[2])
  {
    int tmp = a[0];
    a[0] = a[2];
    a[2] = tmp;
  }
  if(a[1] > a[2])
  {
    int tmp = a[1];
    a[1] = a[2];
    a[2] = tmp;
  }
  if(a[0] > a[1])
  {
    int tmp = a[0];
    a[0] = a[1];
    a[1] = tmp;
  }
  cout << a[2] - a[0] << endl;
}

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

using namespace std;

using int64 = long long;

map<int, int> Compress(const vector<int>& raw_xs) {
  set<int> raw_x_set(raw_xs.begin(), raw_xs.end());
  vector<int> to_raw(raw_x_set.begin(), raw_x_set.end());
  map<int, int> to_index;
  for (int i = 0; i < to_raw.size(); i++) {
    to_index[to_raw[i]] = i;
  }
  return to_index;
}

struct Edge {
  const int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};

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

  int n;
  cin >> n;
  vector<int> xs(n);
  for (int i = 0; i < n; i++) cin >> xs[i];
  map<int, int> count;
  for (int i = 0; i < n; i++) {
    count[xs[i]]++;
  }

  auto to_index = Compress(xs);
  int index_size = to_index.size();

  vector<int> i_to_count(index_size);
  for (int x : xs) {
    i_to_count[to_index[x]]++;
  }

  vector<vector<Edge>> graph(index_size);
  vector<int> self_loop_vector(index_size);
  for (const auto& kv : to_index) {
    int x1 = kv.first;
    // cout << "x1: " << x1 << endl;
    int y = 1;
    while (y <= x1) y *= 2;
    int x2 = y - x1;
    // cout << "x2: " << x2 << endl;
    if (x1 == x2) {
      // cout << "self_loop_vector: " << to_index[x1] << endl;
      self_loop_vector[to_index[x1]] = true;
    } else if (to_index.find(x2) != to_index.end()) {
      int i1 = to_index[x1];
      int i2 = to_index[x2];
      // cout << "i1: " << i1 << " i2: " << i2 << endl;
      graph[i1].emplace_back(i1, i2);
      graph[i2].emplace_back(i2, i1);
    }
  }

  vector<int> visited(index_size);
  int ans = 0;
  function<void(int,int)> dfs = [&](int v, int p) {
    if (visited[v]) return;
    // cout << "v: " << v << endl;

    for (const auto& e : graph[v]) {
      if (e.to == p) continue;
      dfs(e.to, v);
    }
    if (self_loop_vector[v]) {
      int c = i_to_count[v] / 2;
      ans += c;
      i_to_count[v] -= 2 * c;
    }
    if (p >= 0) {
      if (i_to_count[v] > 0 && i_to_count[p] > 0) {
        // cout << "v: " << v << " p: " << p << endl;
        int c = min(i_to_count[v], i_to_count[p]);
        ans += c;
        i_to_count[v] -= c;
        i_to_count[p] -= c;
      }
    }
    visited[v] = true;
  };
  for (int i = 0; i < index_size; i++) dfs(i, -1);
  cout << ans << endl;
}


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

int main() {
	string S;
  cin>>S;
  if(S.length()!=6){cout<<"No"<<endl;return 0;}
  if(S[2]==S[3]&&S[4]==S[5]){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int main() {
	ll A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	int i;
	ll res = A*X + B*Y;
	for (i = 0;i <= 2 * max(X, Y);i += 2) {
		if (res > A*max(X - i / 2, (ll)0) + B*max(Y - i / 2, (ll)0) + C*i) {
			res = A*max(X - i / 2, (ll)0) + B*max(Y - i / 2, (ll)0) + C*i;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 200005
#define M 1000000007
#define ll long long

ll h[N], tree[N], dp[N];

void upd(int n, ll v)
{
    while(n < N)
    {
        tree[n] = max(tree[n], v);
        n += (n & (-n));
    }
}

ll qry(int n)
{
    ll res = 0;
    while(n > 0)
    {
        res = max(res, tree[n]);
        n -= (n & (-n));
    }
    return res;
}

int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n ; i++) cin >> h[i];
    for(int i = 1; i <= n ; i++) cin >> dp[i];
    for(int i = 1; i <= n; i++)
    {
        dp[i] += qry(h[i]);
        upd(h[i], dp[i]);
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++)
        ans = max(ans, dp[i]);
    cout << ans << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  string s;
  cin >> s;
  bool flag = true;
  int cnt = 0;
  if(s[0] != 'A') flag = false;
  for(int i = 1; i < s.size(); i++){
    if('A' <= s[i] && s[i] <= 'Z'){
      if(i == 1 || i == s.size() - 1 || s[i] != 'C') cnt++;
      cnt++;
    }
  }
  if(cnt != 1) flag = false;
  cout << (flag ? "AC" : "WA") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    ll A, B;
    cin >> A >> B;
    if (!(A <= B)) swap(A, B);
    cout << ((A + B) % 2 == 0 ? to_string((A + B) / 2) : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main(void) {
  int n;
  int a[111];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a+i);
  int s = 0;
  for (int i = 0; i < n; i++) s += a[i];
  s /= n;
  int res = 12456789;
  for (int k = s-2; k <= s+2; k++) {
    int c = 0;
    for (int i = 0; i < n; i++) c += (a[i]-k)*(a[i]-k);
    if (res > c) {
      res = c;
    }
  }
  printf("%d\n", res);
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        boolean[][] array = new boolean[4][13];


        for (int i=0; i<n; i++) {
            String s = sc.next();
            switch (s.charAt(0)) {
                case 'S':array[0][sc.nextInt()-1] = true; break;
                case 'H':array[1][sc.nextInt()-1] = true; break;
                case 'C':array[2][sc.nextInt()-1] = true; break;
                case 'D':array[3][sc.nextInt()-1] = true; break;
            }
        }
        char[] c = {'S','H','C','D'};
        for (int i=0; i<4; i++) {
            for (int j=0; j<13; j++) {
                if (!array[i][j]) {
                    System.out.println(c[i]+" "+(j+1));
                }
            }
        }
    }
}


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

// Macros
#define F  first
#define S  second
#define PB push_back

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m, y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// HELPERS
//  Tedious Grid Movements
vector<pii> moves_grid = { {0,1} , {0,-1} , {1,0} , {-1,0} };
inline bool move_okay(int x, int y, int n, int m) { return 0 <= x and x < n and 0 <= y and y < m; }
//  Remember:
//   * vec.assign() GOOD; vec.resize() BAD
//   * comparator uses <


// CODE STARTS HERE

void solve(){
	auto dist = [](auto x, auto y) -> ld {
		return sqrtl(x * x + y * y);
	};

	int n, d;
	cin >> n >> d;

	const ld D = (ld)d + 1e-10;

	int cnt = 0;

	while(n--){
		ll x, y;
		cin >> x >> y;
		cnt += dist(x,y) <= D;
	}

	cout << cnt << "\n";
}

signed main (void){
	// Fast_IO
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// Set Fixed Notation (default sucks), High Precision for Floating-Point Output
	cout << fixed << setprecision(20);

	// Multiple TCs
	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


Measured memory_bytes: 3672
#include <iostream>
#include<cmath>
using namespace std;
const int maxn =1e5+10;
int a[maxn],b[maxn],sum[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cin >> a[1];
    for(int i=2;i<=n+1;i++)
    {
        cin >> a[i];
    }
    for(int i=1;i<=n;i++)
        cin >> b[i];
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
        if(b[i]<=a[i])
        {
            ans+=b[i];
        }
        else
        {
            ans+=a[i];
            b[i]-=a[i];
            if(b[i]>=a[i+1])
            {
                ans+=a[i+1];
                a[i+1]=0;
            }
            else
            {
                ans+=b[i];
                a[i+1]-=b[i];
            }
        }
    }
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <functional>

using namespace std;
static const int INF = 1e8;
typedef pair<int, int> P;

class Edge
{
public:
	int to;
	int cost;
	Edge(int to, int cost) : to(to), cost(cost) {};
};

void solve()
{
	int N, M;
	cin >> N >> M;
	vector< vector<Edge> > G(N);
	for (int i = 0; i < M; ++i)
	{
		int a, b, c;
		cin >> a >> b >> c;
		--a; --b;
		Edge e1(b, c);
		G[a].push_back(e1);
		Edge e2(a, c);
		G[b].push_back(e2);
	}
	deque< deque<bool> > usedGlobal(G.size());
	for (int i = 0; i < N; ++i)
	{
		usedGlobal[i].resize(G[i].size());
	}
	for (int i = 0; i < N; ++i)
	{
		vector<int> d(N, INF);
		d[i] = 0;
		P p1(i, 0);
		priority_queue<P, vector<P>, greater<P> > PQ;
		PQ.push(p1);
		while (!PQ.empty())
		{
			P p = PQ.top();
			PQ.pop();
			int v = p.first;
			for (int j = 0; j < G[v].size(); ++j)
			{
				Edge e = G[v][j];
				if (d[v] < p.second)
				{
					continue;
				}
				if (d[e.to] > d[v] + e.cost)
				{
					d[e.to] = d[v] + e.cost;
					PQ.push(P(e.to, d[e.to]));
				}
			}
		}
		vector<int> d2(N, INF);
		d2[i] = 0;
		P p2(i, 0);
		priority_queue<P, vector<P>, greater<P> > PQ2;
		PQ2.push(p2);
		while (!PQ2.empty())
		{
			P p = PQ2.top();
			PQ2.pop();
			int v = p.first;
			for (int j = 0; j < G[v].size(); ++j)
			{
				Edge e = G[v][j];
				if (d2[v] < p.second)
				{
					continue;
				}
				if (d2[e.to] > d2[v] + e.cost && d2[v] + e.cost == d[e.to])
				{
					usedGlobal[v][j] = true;
					d2[e.to] = d2[v] + e.cost;
					PQ2.push(P(e.to, d2[e.to]));
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < G[i].size(); ++j)
		{
			if (!usedGlobal[i][j])
			{
				++ans;
			}
		}
	}
	cout << ans / 2 << endl;
}

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

Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var code string
	fmt.Scan(&code)

	digit := code[0:1]
	for i := 1; i < len(code); i++ {
		if code[i:i+1] == digit {
			fmt.Println("Bad")
			return
		}
		digit = code[i : i+1]
	}
	fmt.Println("Good")

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin>>n;
  int ans=0;
  for(int i=0;i<n.size();i++){
    if(n[i]=='U'||n[i]=='D'){
      ans++;
    }
    else if(i%2==1&&n[i]=='L'){
      ans++;
    }
    else if(i%2==0&&n[i]=='R'){
      ans++;
    }
  }
  if(ans==n.size()){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	int flag=1;
	while(n--)
	{
		int t,x,y;
		cin>>t>>x>>y;
		if((x+y)==t||((t>x+y)&&(t-x-y)%2==0))
		{
			continue;
		}
		else
		{
			flag=0;
		}
	}
	if(flag==1)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#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;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main() {
    int n, m, x;
    int a[110] = {0};
    cin >> n >> m >> x;
    int tmp;
    REP(i, m) {
        cin >> tmp;
        a[tmp] = 1;
    }

    int tot_forward = 0;
    int tot_backward = 0;
    FOR(i, 1, x) {
        if (a[i] == 1) {
            tot_backward++;
        }
    }
    FOR(i, x, n) {
        if (a[i] == 1) {
            tot_forward++;
        }
    }
    cout << min(tot_backward, tot_forward) << endl;
    return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

// 二項係数計算用配列
ll comb[51][51];

// パスカルの三角形を用いて二項係数を計算
void cal_comb(int N) {
	for (int i = 0; i <= N; ++i) {
		for(int j = 0; j <= i; ++j) {
			if (j == 0 || j == i) {
				comb[i][j] = 1;
			}
			else {
				comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
			}
		}
	}
}

int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> v(N);
    REP(i, N) cin >> v[i];
    sort(ALL(v));
    reverse(ALL(v));

    ll maxNum = v[0];
    ll maxCount = 1;
    for (int i = 1; i < N; ++i)
    {
        if (v[i] == maxNum)
        {
            maxCount++;
        }
        else
        {
            break;
        }
    }

    double ans = 0;
    ll sumNum = 0;
    REP(i, A) sumNum += v[i];
    ans = (double)sumNum / A;

    ll countAll = 0;
    if (maxCount < A)
    {
        int left = -1, right = -1;
        REP(i, N)
        {
            if (v[i] == v[A - 1]) 
            {
                if (left == -1) 
                {
                    left = i;
                }
            }
            else
            {
                if (left != -1) 
                {
                    right = i - 1;
                    break;
                }
            }
        }
        if (right == -1)
        {
            right = N - 1;
        }
        int a = right - left + 1;
        int b = A - 1 - left + 1;
        cal_comb(a);
        countAll = comb[a][b];
    }
    else
    {
        cal_comb(maxCount);
        for (int i = A; i <= min(B, maxCount); ++i)
        {
            countAll += comb[maxCount][i];
        }
    }
    
    cout << fixed;
    cout << setprecision(10) << ans << endl;
    cout << countAll << endl;
}


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

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

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

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

}

Measured memory_bytes: 5172
N = int(input())
Hn = input().split(' ')
Hn.reverse()
max_map = (0,0)
count = 0
for i in range(len(Hn) -1):
    preh = int(Hn[i])
    posth = int(Hn[i+1])
    if posth >= preh:
        count += 1
        if (len(Hn) -1) == (i+1):
            if count > max_map[0]:
                max_map = (count, i +1)
    else:
        if count > max_map[0]:
            max_map = (count, i +1)
        count = 0

print(max_map[0])

Measured memory_bytes: 11132
# -*- coding: utf-8 -*-
"""
B - Red or Blue
https://atcoder.jp/contests/exawizards2019/tasks/exawizards2019_b

"""
import sys


def solve(s):
    red = s.count('R')
    blue = s.count('B')
    if red > blue:
        return 'Yes'
    return 'No'


def main(args):
    _ = int(input())
    s = input()
    ans = solve(s)
    print(ans)


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


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
const int MAX=100005;
const int MODUN=1e9+7;
long long int ans;
int n;
int a[MAX];
int main()
{
	ans=1;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
	}
	stack<int> s;
	for(int i=1;i<=n;++i){
		if(a[i]>=2*s.size()+1){
			s.push(i);
		}
		else{
			ans=(ans*(long long int)(s.size()+1))%MODUN;
		}
	}
	for(int i=1;i<=s.size();++i){
		ans=(ans*(long long int)(i))%MODUN;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

string ap="APPROVED";
string de="DENIED";
void solve(){
    ll n;cin>>n;
    vl a(n);rep(i,n)cin>>a[i];

    rep(i,n){
        if(a[i]%2==0){
            if(a[i]%3!=0&&a[i]%5!=0){
                cout<<de<<endl;
                return;
            }
        }
    }
    cout<<ap<<endl;
}

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


Measured memory_bytes: 256
#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 repn(i,x) for(int i=1;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;
string str;
ll dp[3005][3005];
ll rui[3005][3005];
int main(){
	cin>>n>>str;
	dp[1][1] = 1;
	for(int i=1;i<=n;i++) rui[1][i] = 1;
	for(int i=2;i<=n;i++){
		if(str[i-2]=='<'){
			for(int j=1;j<=i;j++){
				//dp[i][j]
				dp[i][j] = rui[i-1][j-1];
			//	for(int x=1;x<j;x++) dp[i][j] += dp[i-1][x];
			//	dp[i][j]%=mod;
			}
		}
		else{
			for(int j=1;j<=i;j++){
				//dp[i][j]
				dp[i][j] = rui[i-1][i-1]-rui[i-1][j-1];
				dp[i][j] = (dp[i][j]%mod+mod)%mod;
				//for(int x=j;x<=i-1;x++) dp[i][j] += dp[i-1][x];
				//dp[i][j]%=mod;
			}
		}
		for(int x=1;x<=i;x++) rui[i][x]=(rui[i][x-1]+dp[i][x])%mod;
	}
	ll ans = 0;
	for(int i=1;i<=n;i++)ans+=dp[n][i];
	cout<<(ans%mod+mod)%mod<<endl;
}

Measured memory_bytes: 139648
import java.lang.Math.*

fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map {it.toInt()}
    val a = readLine()!!.split(" ").map{it.toInt()}
    val dp = Array(N){1000000000}
    dp[0] = 0
    for(i in 1 until N) {
        for(j in i - 1 downTo max(0, i - K)) {
            dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]))
        }
    }
    println(dp[N-1])
}


Measured memory_bytes: 99336
#include <bits/stdc++.h>
#define rep(i,n) for(i=1; i<=n; ++i)
#define rrep(xyz,n) for(xyz=1; xyz*xyz<n; ++xyz)
using namespace std;
int main(void){
  int N;
  cin >> N;
  int i,score,n,x,y,z;
  rep(i,N){
    score = 0;
    rrep(x,i)rrep(y,i)rrep(z,i){
          n = (x*x+y*y+z*z+x*y+y*z+z*x);
          if(n==i){
            ++score;
            break;
          }
          else if(n>i)
            break;
      }
    cout << score << endl;
  }

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

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

    int C1, C2, C3;
    bool arr[11];
    while (cin >> C1 >> C2 >> C3)
    {
        for (int i = 1; i <= 10; ++i)
            arr[i] = false;
        arr[C1] = true;
        arr[C2] = true;
        arr[C3] = true;

        int sum = C1 + C2;

        int cnt = 0;
        for (int i = 1; i <= 10; ++i)
        {
            if (!arr[i] && sum + i <= 20)
                cnt++;
        }
        if (cnt >= 4)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include <cstdio>
#define ll long long
ll n, m, l, r, c1[300001], c2[600001], c3, mod = 1000000007;
ll big(ll b, ll p){
	if (p == 1) return b;
	ll h = big(b, p / 2);
	ll res = (h * h) % mod;
	if (p % 2 == 1) res = (res * b) % mod;
	return res;
}
void init(){
	c1[0] = 1;
	for (int i = 1; i <= n - m; i++){
		c1[i] = (c1[i - 1] * (n - m - i + 1)) % mod;
		c1[i] = (c1[i] * big(i, mod - 2)) % mod;
	}
	for (int i = 0; i < n; i++) c2[i] = 0;
	c2[n] = 1;
	for (int i = n + 1; i <= n + r; i++){
		c2[i] = (c2[i - 1] * i) % mod;
		c2[i] = (c2[i] * big(i - n, mod - 2)) % mod;
	}
	c3 = 1;
	for (int i = 1; i <= m; i++){
		c3 = (c3 * (n - i + 1)) % mod;
		c3 = (c3 * big(i, mod - 2)) % mod;
	}
}
ll f(ll k){
	ll sum = 0;
	for (ll x = 1; x <= k; x++){
		for (ll i = 0; k - x * m - x * i >= 0; i++){
			if (i > n - m) break;
			ll t = k - x * m - x * i + n;
			sum += mod + ((i % 2 == 0) ? 1 : -1) * ((c1[i] * (((t - m < 0) ? 0 : c2[t - m]) - c2[t])) % mod);
			sum %= mod;
		}
	}
	sum = (sum * c3) % mod;
	return (c2[n + k] + sum) % mod;
}
int main(){
	scanf("%lld %lld %lld %lld", &n, &m, &l, &r);
	init();
	printf("%lld\n", (f(r) + mod - f(l - 1)) % mod);
}

Measured memory_bytes: 7168