akhauriyash/Code-Regression huggingface dataset:
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];

    sort(all(a));
    sort(all(b));
    sort(all(c));
    ll ans = 0;
    rep(i, n){
        ll idx = lower_bound(all(a), b[i]) - a.begin() - 1;  
        ll idx2 = upper_bound(all(c), b[i]) - c.begin();
        //cout << idx << " " << idx2 << endl;
        ans += (idx + 1LL) * (n - idx2);
    }

    cout << ans << endl;


}   

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

int main(){
	int n,x,a,b;
    cin >> n >> x;
  	int l[100];
  	a=0;
  for(int i=0;i<n;i++){
   cin >> l[i]; 
  }
  for(int i=0;i<n;i++){
    b += l[i];
  if(b<=x){
  a++;
  }
  }
  cout << a+1 << endl;
}

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

int n;
int flag[300000];
int s[300000];
int l,r;

int main()
{
    for (int i=2; i<=200000; ++i)
        flag[i]=1;
    for (int i=2; i<=200000; ++i)
    {
        for (int j=i*2; j<=200000; j+=i)
         flag[j]=0;
    }
    for (int i=2; i<=200000; ++i)
        s[i]=s[i-1]+(flag[i] && flag[(i+1)>>1]);
    cin>>n;
    for (int i=1; i<=n; ++i)
    {
        cin>>l>>r;
        cout<<s[r]-s[l-1]<<endl;
    }
    return 0;
}


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

int main() {
	vector<int>abc(3);
	for (int i = 0; i < 3; i++)cin >> abc.at(i);
	sort(abc.begin(), abc.end());
	if (abc.at(0) + abc.at(1) == abc.at(2))cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll md = 1000000007;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
vl p, fac(2, 1), ifac(2, 1);

ll add(ll a, ll b) {
    return (a%md + b%md + md) % md;
}

ll mul(ll a, ll b) {
    return ( (a%md) * (b%md) ) % md;
}

ll power(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = ((res%mod) * (x%mod))%mod;
        n = (n >> 1);
        x = ((x%mod) * (x%mod))%mod;
    }
    return res;
}

void cachefact(ll lim, ll mod = md) {
    for(int i = 2; i <= lim; i++) {
        ifac.push_back((ifac[mod%i] * (mod - mod/i) % mod)%mod);
    }
    for(ll i = 2; i <= lim; i++) {
        fac.push_back((fac[i-1] * i)%mod);
        ifac[i] = (ifac[i-1] * ifac[i])%mod;
    }
}

ll C(int n, int r) {
    if(n < r) return 0;
    return mul(fac[n], mul(ifac[r], ifac[n-r]));
}

ll P(int n, int r) {
	if(n < r) return 0;
	return mul(fac[n], ifac[n-r]);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cachefact(2e6);
    int n, m, total = 0;
    cin >> n >> m;
    for(int i = 0; i <= n; i++) {
    	total = (total + (i&1 ? -1 : 1) * C(n, i)%md * C(m, i)%md * fac[i]%md * power(P(m-i, n-i)%md, 2)%md + md)%md;
    }
    cout << total << "\n";
    return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b && b==c) 
    cout << "1" << endl;
  else if(a!=b && b!=c && c!=a)
    cout << "3" << endl;
  else
    cout << "2" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
  ll n;
  cin>>n;
  //vector<ll> a;
  ll ans;
  for(ll i=1;i*i<=n;i++){
    if((i+1)*(i+1)>n) ans=i*i;
  }
  cout<<ans<<endl;
}

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

template<typename T>
struct FlowGraph {
private:
  struct edge {
    const int to;
    T cap;
    const int r_idx;
    edge(int t, T c, int i) :
      to(t), cap(c), r_idx(i) {}
  };

  vector<vector<edge>> G;

  T dfs(int v, int sink, T min_cap, vector<bool>& visited){
    visited[v] = true;
    if(v == sink) return min_cap;
    for(auto& e : G[v]){
      if(e.cap == T()) continue;
      if(visited[e.to]) continue;
      T min_cap_ = min(min_cap,e.cap);
      T flowed = dfs(e.to,sink,min_cap_, visited);
      if(flowed == T()) continue;
      e.cap -= flowed;
      G[e.to][e.r_idx].cap += flowed;
      return flowed;
    }
    return T();
  }
  
public:
  FlowGraph(size_t n) : G(n) {}
  void add_edge(int from, int to, T cap){
    int i = G[to].size(), i_ = G[from].size();
    G[from].emplace_back(to,cap,i);
    G[to].emplace_back(from,0,i_);
  }
  T max_flow(int from, int to){
    T ret = 0, INF = 1e9;
    while(true){
      vector<bool> visited(G.size());
      T f = dfs(from,to,INF,visited);
      if(f == T()) break;
      ret += f;
    }
    return ret;
  }
};

int main(){
  int V, E;
  cin >> V >> E;
  FlowGraph<long long> G(V);
  for(int i = 0; i < E; ++i){
    int u, v, c;
    cin >> u >> v >> c;
    G.add_edge(u,v,c);
  }
  cout << G.max_flow(0,V-1) << endl;
}



Measured memory_bytes: 3160
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=15;

int mat[N][N];

void solve()
{
    int n,m,x;
    cin>>n>>m>>x;

    vi cost(n);
    for(int i=0;i<n;++i)
    {
        cin>>cost[i];

        for(int j=0;j<m;++j)
            cin>>mat[i][j];
    }

    int tot=(1ll<<n);

    int ans=inf;

    vi tmp(m);
    int cur;
    bool fl;
    for(int i=1;i<tot;++i)
    {
        fill(all(tmp),0);
        cur=0;
        for(int j=0;j<n;++j)
        {
            if(i&(1<<j))
            {
                cur+=cost[j];
                for(int k=0;k<m;++k)
                    tmp[k]+=mat[j][k];
            }
        }

        fl=0;
        for(int k=0;k<m;++k)
        {
            if(tmp[k]<x)
            {
                fl=1;
                break;
            }
        }

        if(!fl)
        {
            ans=min(ans,cur);
        }
    }

    if(ans==inf)
        ans=-1;

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    int K, A, B;
    bool can = false;
    cin >> K >> A >> B;
    FOR(i, A, B+1) {
        if (i % K == 0) {
            can = true;
        }
    }
    if (can) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(void)
{
	int n,a,b,r=0,i,j;
	scanf("%d%d%d",&n,&a,&b);
	for(i=1;i<=n;i++){
		int s = 0;
		j=i;
		for(;j;j/=10){
			s+=j%10;
		}
		if(a<=s && s<=b){
			r+=i;
		}
	}
	printf("%d\n",r);
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <numeric> //lcm


#define ERROR() cout << "ERROR!!" << endl; return 0;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1000000000; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

inline bool maxch(int& a, int b) { if (a < b) { a = b; return true; } else return false; }

int main() {
	double a, b;
	cin >> a >> b;

	rep(i, 1001) {
		if (a <= i * 0.08 && i * 0.08 < a + 1
			&& b <= i * 0.1 && i * 0.1 < b + 1) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;
	
}




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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

ll gcd(ll a,ll b){ //最大公約数 O(log(min(a,b)))
    if(b==0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){ //最小公倍数
    ll gc=gcd(a,b);
    ll ans=(a*b)/gc;
    return ans;
}

int main(){
    ll A,B; cin >> A >> B;
    cout << lcm(A,B) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
//freopen("explicit.in", "r", stdin);
//freopen("explicit.out", "w", stdout);
 
void SieveOfEratosthenes() 
{ 
    bool prime[10000001];
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=10000000; p++) 
    { 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=10000000; i += p) {
                prime[i] = false; 
            }
        } 
    }  
} 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
ll nCrModpDP(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C));   
    C[0] = 1;
    for (ll i = 1; i <= n; i++) 
    {
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll nCrModp(ll n, ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
  
   return (nCrModp(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p; 
} 
int32_t main() 
{
    fio
	long double t,l,r,c,h,k,m,maxi,d,x;
	ll i,j,n;
	cin>>n>>d;
	c=0;
	for(j=0;j<n;j++)
	{
		cin>>l>>x;
		if(sqrt(l*l+x*x)<=d)
		{
			c++;
		}
	}
	cout<<c;
}


	

		

Measured memory_bytes: 3868
package main

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

func routine(r io.Reader, w io.Writer) {
	var a, b, c, d int
	fmt.Fscanf(r, "%d\n", &a)
	fmt.Fscanf(r, "%d\n", &b)
	fmt.Fscanf(r, "%d\n", &c)
	fmt.Fscanf(r, "%d\n", &d)
	ab := a
	if a > b {
		ab = b
	}
	cd := c
	if c > d {
		cd = d
	}
	fmt.Fprint(w, ab+cd)
}
func main() {
	routine(os.Stdin, os.Stdout)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n,m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

vi vans;

ll f(ll n, ll m)
{
	if ((ll)log10(n) + 1 != m) {
		n = n*pow(10, m - (ll)log10(n) - 1);
	}
	vi v;
	for (int i = m - 1; i >= 0; i--) {
		ll b = pow(10, i);
		ll a = n / b;
		v.push_back(a);
		n -= a*b;
	}
	sort(ALL(v));
	ll mx = 0;
	REP(i, m)
	{
		mx += v[i] * pow(10, i);
	}
	sort(RALL(v));
	ll mi = 0;
	REP(i, m)
	{
		mi += v[i] * pow(10, i);
	}
	/*cout << mx << ' ' << mi << endl;
	cout << mx - mi << endl;
	cout << endl;*/
	vans.push_back(mx - mi);
	return mx - mi;
}


int main()
{
	while (1) {
		cin >> n >> m;
		vans.push_back(n);
		if (n == 0 && m == 0) {
			return 0;
		} else {
			if (n == 0) {
				cout << 0 << ' ' << 0 << ' ' << 1 << endl;
				vans.clear();
			} else {
				cnt = 0;
				ll p = -1;
				while (1) {
					ll a = f(n, m);
					if (a == 0) {
						cout << vans.size() - 1 << ' ' << 0 << ' ' << 1 << endl;
						vans.clear();
						break;
					}
					REP(i, vans.size() - 1)
					{
						if (a == vans[i]) {
							p = i;
							break;
						}
					}
					if (p != -1) {
						cout << p << ' ' << a << ' ' << vans.size() - 1 - p << endl;
						vans.clear();
						break;
					}
					n = a;
				}
			}
		}
	}
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  vector<double> E(N);
  for (int i = 0; i < N; i++)
    cin >> p[i];
  double ans = 0.0;
  double now1, now2;
  for (int i = 0; i < K; i++)
  {
    now1 = 0.0;
    now2 = 0.0;
    for (int j = 1; j <= p[i]; j++)
    {
      now1 = j * (1.0 / p[i]);
      now2 += now1;
    }
    ans += now2;
    E[i] = now2;
  }
  double res = ans;
  double now3, now4;
  for (int i = 1; i < N - K + 1; i++)
  {
    ans -= E[i - 1];
    now3 = 0.0;
    now4 = 0.0;
    for (int j = 1; j <= p[i - 1 + K]; j++)
    {
      now3 = j * (1.0 / p[i - 1 + K]);
      now4 += now3;
    }
    E[i - 1 + K] = now4;
    ans += E[i - 1 + K];
    res = max(res, ans);
  }
  cout << fixed << setprecision(10) << res << endl;
}


Measured memory_bytes: 2560
/**
*  author: chaitanya
*  created: 05:34:10 PM, 13 September 2020
**/
#include <bits/stdc++.h>
using namespace std;

const int N = 300009;
const int mod = 1000000007;

#define intll 0
#define interactive 0

#ifdef chaitanya
#include "/home/chaitanya/.templates/header.h"
#else
#define debug(x...)
#endif

#if !interactive
#define IOS                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);                      \
  cin.exceptions(cin.failbit);
#define endl "\n"
#else
#define IOS
#endif

#if intll
#define int long long int
#endif

#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define F first
#define S second
inline int add(int a, int b) {
  a += b;
  if (a >= mod)
    a -= mod;
  return a;
}
inline int sub(int a, int b) {
  a -= b;
  if (a < 0)
    a += mod;
  return a;
}
inline int mul(int a, int b) {
  return (int)((long long)a * b % mod);
}
inline int binpow(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1)
      res = mul(res, a);
    a = mul(a, a);
    b /= 2;
  }
  return res;
}
inline int inv(int a) {
  return binpow(a, mod - 2);
}
int gcd(int a, int b, int& x, int& y) {
  if (a == 0) {
    x = 0, y = 1;
    return b;
  }
  int x1, y1;
  int d = gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}

vi fac(N, 1);
vi invfac(N, 1);

void pre() {
  rep(i, 1, N) fac[i] = mul(fac[i - 1], i);
  rep(i, 1, N) invfac[i] = mul(invfac[i - 1], inv(i));
}

int nCr(int a, int b);

int32_t main() {
  IOS;
  pre();

  int n;

  cin >> n;

  int ans = binpow(10,n);
  ans = sub(ans,binpow(9,n));
  ans = sub(ans,binpow(9,n));
  ans = add(ans,binpow(8,n));

  cout << ans << endl;

  return 0;
}

int nCr(int a, int b) {
  int ans = fac[a];
  ans = mul(ans, invfac[a - b]);
  ans = mul(ans, invfac[b]);
  return ans;
}

Measured memory_bytes: 5452
s = input()

l = [[] for _ in range(26)]

for i in range(len(s)):
    l[ord(s[i]) - 97].append(i)

for i in l:
    if len(i) < 2:
        continue

    j = 1
    while j < len(i):
        if i[j] - i[j-1] > 2:
            j += 1
            continue
        else:
            print(i[j-1] + 1, i[j] + 1)
            exit()

print(-1, -1)

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &v : a)
    cin >> v;

  vector<int> b(a);
  sort(b.begin(), b.end());

  int max1 = *b.rbegin();
  int max2 = *(b.rbegin() + 1);
  for (auto &v : a)
    cout << ((v != max1) ? max1 : max2) << endl;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define inf 1<<29
#define linf (1e16)
#define eps (1e-8)
#define Eps (1e-12)
#define mod 1000000007
#define pi acos(-1.0)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define pld(a) printf("%.10Lf\n",(ld)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

int main()
{
  string s;
  int dir = 0, ans = 0, flag = 0;
  cin>>s;
  FOR(i,0,s.length()){
    if(s[i]=='R'){
      dir = (dir+1)%4;
      if(dir==1)flag = 1;
      if(dir==0 && flag==1){
        ans++;
        flag = 0;
      }
    }
    else {
      dir = (dir-1+4)%4;
      if(dir==0)flag = 0;
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3212
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] arr = new int[3];
		arr[0] = sc.nextInt();
		arr[1] = sc.nextInt();
		arr[2] = sc.nextInt();
		Arrays.sort(arr);
		System.out.println(((arr[2] * 10) + arr[1]) + arr[0]);
	}
}

Measured memory_bytes: 23124
#include<iostream>
#include<cassert>
#include<queue>
#include<cstdlib>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define mp make_pair
#define airdata first
#define costdata second

typedef pair<int,int> pii;

const int inf = (1<<27);
const int N = 10;
const int AIR = 51;
const int L = 10;
const int R = 10;
int air[N][N];
int cost[N][N];

int dp[N][N][L][R][AIR];

class st{
public:
  int y,x,l,r,air;
  int cost;
  bool operator<(const st& a)const{
    return cost > a.cost;
  }
};

int dx[2]={1,-1};
int solve(int r,int c,int airlim,int iniair){
  rep(i,r)rep(j,c)rep(k,c)rep(l,c)rep(m,airlim+1)dp[i][j][k][l][m]=inf;
  priority_queue<st> Q;
  rep(j,c){
    int a=cost[0][j];
    int tmp=iniair-1;
    if (tmp == 0)continue;
    int b=min(tmp+air[0][j],airlim);
    Q.push((st){0,j,j,j,b,a});
    dp[0][j][j][j][b]=a;
  }

  while(!Q.empty()){
    st now=Q.top();Q.pop();
    if (dp[now.y][now.x][now.l][now.r][now.air] != now.cost)continue;
    if (now.y == r-1 && now.air >= 1)return now.cost;
    if (now.air <= 1)continue;
    //cout << now.y <<" " << now.x <<" " << now.air << endl;

    //dig
    st next=now;
    next.y++;
    next.l   =now.x;
    next.r   =now.x;
    next.air--;
    next.air =min(next.air+air[next.y][next.x],airlim);
    next.cost=now.cost+cost[next.y][next.x];
    if (next.air >= 1 && dp[next.y][next.x][next.l][next.r][next.air] > next.cost){
      dp[next.y][next.x][next.l][next.r][next.air]=next.cost;
      Q.push(next);
    }

    rep(i,2){
      int nex=now.x+dx[i];
      if (nex==-1||nex==c)continue;
      st next=now;
      next.x=nex;
      if (nex < now.l)next.l--;
      if (nex > now.r)next.r++;
      next.air--;
      if (now.l <= nex && nex <= now.r);
      else {
	next.cost=now.cost+cost[now.y][nex];
	next.air =min(next.air+air[now.y][nex],airlim);
      }
      if (dp[next.y][next.x][next.l][next.r][next.air] > next.cost){
	dp[  next.y][next.x][next.l][next.r][next.air] = next.cost;
	Q.push(next);
      }
    }
  }
  return inf;
}

main(){
  int c,r;
  int f,airlim,iniair;
  while(cin>>c>>r && c){
    cin>>f>>airlim>>iniair;
    //assert(iniair >= 3);
    rep(i,r){
      rep(j,c){
	int tmp; 
	cin>>tmp;
	if (tmp > 0)air[i][j]=tmp;
	else air[i][j]=0;
	if (tmp < 0)cost[i][j]=-tmp;
	else        cost[i][j]=0;
      }
    }
    int ans = solve(r,c,airlim,iniair);
    if (ans > f)cout << "NA"<<endl;
    else cout << ans << endl;
  }
  return false;
}

Measured memory_bytes: 0
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get { () => (get().parse().unwrap()) }
    
    let a: i32 = get!();
    let b: i32 = get!();
    let z = (a+b+1) / 2;
    println!("{}", z);
    
}

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

int n;
int a[20];

int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) cin >> a[i];
		
		int ssum = 0;
		for (int i = 0; i < n; i++) ssum += a[i];
		
		int ans = 1145141919;
		for (int i = 0; i < (1 << n); i++) {
			int x = 0;
			for (int j = 0; j < n; j++) {
				if ((i >> j) % 2) {
					x += a[j];
				}
			}
			ans = min(ans, abs(ssum - 2 * x));
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n; cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s; cin >> s;
        mp[s]++;
    }
    int m; cin >> m;
    rep(i, m) {
        string t; cin >> t;
        mp[t]--;
    }
    int maxi = 0;
    for (auto e : mp) {
        maxi = max(maxi, e.second);
    }
    cout << maxi << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = 2000000000;
// const ll MOD = 1000000007;

int A, B, K;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> A >> B >> K;
  for (int i = 0; i < K; i++) {
    if (i % 2 == 0) {
      A /= 2;
      B += A;
    } else {
      B /= 2;
      A += B;
    }
  }

  cout << A << " " << B << endl;
  return 0;
}

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

const int aaa = 2019;

//int solve(long l, long r)
//{
//  const auto a = l / aaa;
//  const auto b = r / aaa;
//  return a == b ? l * (l + 1) % aaa : 0;
//}

int solve(long l, long r)
{
  int result = aaa;
  r = std::min(r, l + 2019);
  for (auto i = l; i <= r; ++i) {
    for (auto j = i + 1; j <= r; ++j) {
      result = std::min<int>(result, i * j % aaa);
      if (result == 0) return 0;
    }
  }
  return result;
}

int main()
{
  long l, r;
  std::cin >> l >> r;

  std::cout << solve(l, r) << std::endl;
}


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

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    mint choose(int n, int a){
        mint x = 1 ,y = 1;
        for(int i=0; i<a; ++i){
            x *= n-i;
            y *= i+1;
        }
        return x / y;
    }
    friend istream& operator>>(istream& is, mint& m){
        is >> m.x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

mint dp[105][5][5][5];

int main(){
    int n;
    cin>>n;
    dp[0][0][0][0]=1;
    rep(i,n){
        rep(a,5)rep(b,5)rep(c,5)rep(d,5){
            if(d == 0)continue;
            if(b == 1 && c == 2 && d == 3)continue;
            if(b == 2 && c == 1 && d == 3)continue;
            if(b == 1 && c == 3 && d == 2)continue;
            if(a == 1 && b == 2 && d == 3)continue;
            if(a == 1 && c == 2 && d == 3)continue;
            dp[i+1][b][c][d]+=dp[i][a][b][c];
        }
    }
    mint ans=0;
    for(int a=1; a<=4; ++a)
    for(int b=1; b<=4; ++b)
    for(int c=1; c<=4; ++c)
    ans+=dp[n][a][b][c];
    cout<<ans<<endl;
}

Measured memory_bytes: 3700
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

string fld[52];
int w_cnt[51], b_cnt[51], r_cnt[51];

signed main()
{
	omajinai;
	int N, M; cin >> N >> M;

	rep(i, N) {
		cin >> fld[i];

		rep(j, M) {
			w_cnt[i] += fld[i][j] == 'W';
			b_cnt[i] += fld[i][j] == 'B';
			r_cnt[i] += fld[i][j] == 'R';
		}
	}

	int mi = inf;

	int w_sum = 0;
	for (int i = 0; i < N - 2; ++i) {
		w_sum += M - w_cnt[i];

		int b_sum = 0;
		for (int j = i + 1; j < N - 1; ++j) {
			b_sum += M - b_cnt[j];

			int r_sum = 0;
			for (int k = j + 1; k < N; ++k) {
				r_sum += M - r_cnt[k];
			}

			chmin(mi, w_sum + b_sum + r_sum);
		}
	}

	cout << mi << endl;
}

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


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

    double A[N];
    for (int i = 0; i < N; i++) cin >> A[i];

    double reverse = 0;
    for (int i = 0; i < N; i++){
        reverse += 1/ A[i];
    }

    cout << 1/ reverse << endl;
    
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O2") 
#include <bits/stdc++.h>
using namespace std;

#define dbg(x) cerr << #x"=" << x << endl;
typedef long long LL;
int a[220];

int main(){
	//freopen("in.txt","r",stdin);    
	ios::sync_with_stdio(0); cin.tie(0);
	int n, l;
	cin >> n >> l;
	LL sum = 0;
	int mn = 1e9;
	int id = 0;
	for(int  i = 1; i <= n; ++i) {
		a[i] = l+i-1;
		sum += a[i];
		if(abs(a[i]) < mn){
			mn = abs(a[i]);
			id = i;
		}
	}
	cout << sum - a[id] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,c=0;
	bool b=false;
	vector<int> v;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>m;
		v.push_back(m);
	}

	int i=0;
	while(b!=true){
		if(i>=n) i=0;
	
		if(v[i]%2!=0 or v[i]==0){
			b=true;
		} else {
			v[i]=v[i]/2;
			if(i==n-1) c++;
		}

		i++;
	}

	cout<<c<<"\n";
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n+1], b[n+1], c[n];
    memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c));
    for(int i=1; i<=n; i++)
        cin >> a[i];
    for(int i=1; i<=n; i++)
        cin >> b[i];
    for(int i=1; i<n; i++)
        cin >> c[i];
    long long sum = 0;
    for(int i=0; i<=n; i++){
        sum += b[a[i]];
        if(i<n && a[i+1]==a[i]+1)
            sum += c[a[i]];
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		int m; cin >> m;
		if(!m)break;
		int n; cin >> n;
		string s; cin >> s;
		int res=0;
		for(int i=0;i+2<n;i++){
			if(s.substr(i,3)=="IOI"){
				int cnt=1;
				i+=3;
				while(1+i<n&&s[i]=='O'&&s[i+1]=='I'){
					cnt++;
					i+=2;
				}
				res+=max(0,cnt-m+1);
				i--;
			}
		}
		printf("%d\n",res);
	}
}


Measured memory_bytes: 4644
/*
Please Chant The Holy Name Of Lord Krisna(The Supreme Personality Of Godhead)

      "Hare Krisna Hare Krisna Krisna Krisna Hare Hare
       Hare Rama Hare Rama Rama Rama Hare Hare ......."

Surrender yourself to the Lotus Feet of Krisna, serve devotees and Srila Prabhupada
*/

//13-9-20
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define pb emplace_back
#define sz(s) (int)s.size()
#define all(v)                            v.begin(),v.end()
#define fr(i,n)                           for(int i=0;i<n;i++)
#define fr1(i,n)                          for(int i=1;i<=n;i++)
#define fro(i,a,b)                        for(int i=a;i<=b;i++)
#define d(a)                              cout << #a << " : " << a << " ";
#define dl(a)                             cout<< #a <<" : " << a << endl;
#define print(v)  for(auto x : v)         {cout<<x<<" ";   }  cout<<endl;
#define PRINT(v)  for(auto x : v)         {cout<<x.first<<" "<<x.second<<endl;}
#define TEST                              int tc;cin>>tc; while(tc--)

using namespace std;

const int N   = 2e5 + 7;
const int MOD = 1e9 + 7;
int arr[N];
int n,m,k,x,y,i,j;

void solve()
{
    // Can you solve it by brute force?
    // kkp
    // Are you sure you want to code so soon?? -_-
    // Simplify your code a little more. :)

    int a,b,c,d;
    cin>>a>>b>>c>>d;

    int x,y,z,k;
    x = a*c;
    y = a*d;
    z = b*c;
    k = b*d;

    int aa = max({x,y,z});
    cout<<max(aa,k)<<endl;

}

int32_t main()
{
    //IOS;

    //TEST
    solve();

    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

string S;

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

	cin >> S;

	int ansz = 0,anso = 0;
	REP(i,S.size()){
		if(i%2){
			if(S[i] == '0') ansz++;
		}else{
			if(S[i] == '1') ansz++;
		}	
	}

	REP(i,S.size()){
		if(i%2){
			if(S[i] == '1') anso++;
		}else{
			if(S[i] == '0') anso++;
		}	
	}

	cout << min(ansz,anso) << endl;

}

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

using namespace std;

#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 rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m, x;
    cin >> n >> m >> x;
    int res = Inf;
    vector<int> c(n);
    vector<vector<int> > a(n, vector<int>(m));
    rep (i, n) {
        cin >> c[i];
        rep (j, m) cin >> a[i][j];
    }
    rep (bit, (1 << n)) {
        vector<int> alg(m);
        int tmp = 0;
        rep (i, n) {
            if (bit & (1 << i)) {
                tmp += c[i];
                rep (j, m) {
                    alg[j] += a[i][j];
                }
            }
            bool ok = true;
            rep (j, m) {
                if (alg[j] < x) ok = false;
            }
            if (ok) res = min(res, tmp);
        }
    }
    if (res == Inf) cout << -1 << endl;
    else cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 3664
#include<iostream>
#include<cstdlib>
#include<vector>
#include<algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i) 
#define REP(i,n) FOR(i,0,n)
#define EACH(x,a) for(auto& (x):(a))
#define ALL(obj) (obj).begin(),(obj).end()
#define Yes(n) cout<<((n)?"Yes":"No")<<endl;
#define CO(x) cout<<(x)<<endl;
#define COSP(x) cout<<(x)<<" ";
#define DICIMAL(x) fixed<<setprecision(x)
using namespace std;
using ll=long long;
using vi=vector<int>;
const int INF=1e9;
const ll LINF=1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

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

  int N; cin>>N;
  vi h(N); REP(i,N) cin>>h[i];

  vi dp(N);
  dp[0] = 0;
  dp[1] = abs(h[0]-h[1]);
  FOR(i,2,N){
    dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]),
                dp[i-1]+abs(h[i-1]-h[i]));
  }

  cout<<dp[N-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
N = int(input())

sum = 0

def summation(a, d, n):
    return (n * a) + int(((n * d) * (n - 1)) / 2)

all = summation(1, 1, N)
fizzbuzz = summation(15, 15, int(N / 15))
fizz = summation(3, 3, int(N / 3))
buzz = summation(5, 5, int(N / 5))

print(all + fizzbuzz - fizz - buzz)

Measured memory_bytes: 9204
//129a.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
/*namespace*/
using namespace std;
/*define macro*/
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPi(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int P,Q,R;
    cin>>P>>Q>>R;
    cout<<P+Q+R-max(P,max(Q,R))<<endl;
}

Measured memory_bytes: 764
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
long long a,b,ans=65,n;
long long Read() {
	long long x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
	return x*f;
}
int main() {
	a=Read();
	for(int s=0; s<a; s++) {
		b=Read();
		n=0;
		while(b%2==0) {
			b=b/2;
			n++;
		}
		ans=min(ans,n);
	}
	printf("%ld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define md 1000000007
#define ll long long int 
double PI=3.1415926535;
const int N =  (int)(1 * 1e6 + 10);

using namespace std;

int main()

{
    ll n;
    cin>>n;
    ll h[n+1];
    h[0]=0;
    for(ll i = 1 ; i <= n ; i++)cin>>h[i];

    ll dp[n+1];
    memset(dp,0,sizeof(dp));
    dp[1]=0;
    dp[2] = abs(h[2]-h[1]);
    for(ll i = 3 ; i <=n ; i++)
    {
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }

    cout<<dp[n]<<endl;

}

Measured memory_bytes: 5076
#pragma GCC optimize("O3")
//#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

struct Mo {

    int width;
    vector< int > left, right, order;
    vector< bool > v;

    Mo(int N, int Q) : width((int)sqrt(N)), order(Q), v(N) {
        iota(begin(order), end(order), 0);
    }

    void add(int l, int r) { // [l, r) 
        left.emplace_back(l);
        right.emplace_back(r);
    }

    template<class ADD, class DEL, class REM>
    int run(const ADD& add, const DEL& del, const REM& rem) {
        assert(left.size() == order.size());
        sort(begin(order), end(order), [&](int a, int b) {
            int ablock = left[a] / width, bblock = left[b] / width;
            if (ablock != bblock) return ablock < bblock;
            if (ablock & 1) return right[a] < right[b];
            return right[a] > right[b];
            });
        int nl = 0, nr = 0;
        auto push = [&](int idx) {
            v[idx].flip();
            if (v[idx]) add(idx);
            else del(idx);
        };
        for (auto idx : order) {
            while (nl > left[idx]) push(--nl);
            while (nr < right[idx]) push(nr++);
            while (nl < left[idx]) push(nl++);
            while (nr > right[idx]) push(--nr);
            rem(idx);
        }
        return 0;
    }
};
int main() {
    io_init;
    int N, Q;
    cin >> N;
    cin >> Q;

    vector< int > A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector< int > f(1000001);
    Mo mo(N, Q);
    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        mo.add(--l, r);
    }
    int ret = 0;
    auto add = [&](int idx) { if (f[A[idx]]++ == 0) ret++; };
    auto del = [&](int idx) { if (f[A[idx]]-- == 1) --ret; };
    vector< int > ans(Q);
    auto rem = [&](int idx) { ans[idx] = ret; };
    mo.run(add, del, rem);
    for (int i = 0; i < Q; i++) {
        cout << ans[i] << "\n";
    }
}


Measured memory_bytes: 17680
# import sys
X = int(input())
# if 1 <= X and X < 100:
#     print("0")
#     sys.exit()
i = 0
dp = [0]*(X+1)
dp[0] = 1
for i in range(100, X+1):
    for j in range(6):
        if dp[i-(100+j)] == 0:
            pass
        else:
            dp[i] = 1
print(dp[X])


Measured memory_bytes: 3828
#include<stdio.h>

int main(){
  int N;
  int i,j,k;
  int v;

  scanf("%d",&N);

  int A[N];

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

  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(k=0;k<N-1;k++){
      printf("%d ",A[k]);
    }
    printf("%d\n",A[k]);
  }
  return 0;
}
  



Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long ll;


int main()
{

    //#ifndef oj
    //freopen("in", "r", stdin);
    //freopen("out.txt","w",stdout);
    //#endif
    //system("cls");
    //getchar();
    ll n,m;
    cin>>n>>m;
    ll sum=0;
    for(int i=0;i<m;i++)
    {
        ll a;
        cin>>a;
        sum+=a;
    }
    if(n>=sum)
    cout<<n-sum<<endl;
    else
        cout<<-1<<endl;
}


Measured memory_bytes: 3624
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<ll> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<pll> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	ll ans = 10000000 ;
	for(ll i=0;i<=n;i++){
		ll sub = i ;
		ll cnt = 0 ;
		while(sub!=0){
			cnt += sub%6 ; sub /= 6 ;
		}
		sub = n-i ;
		while(sub!=0){
			cnt += sub%9 ; sub /= 9 ;
		}
		if(ans>cnt) ans = cnt ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main () {
    let mut s_iter = read::<String>().chars().collect::<Vec<char>>().into_iter();
    let z = s_iter.rposition(|x| x == 'Z').unwrap() + 1;
    let a = s_iter.position(|x| x == 'A').unwrap();
    
    println!("{}",z - a);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <sstream>



using namespace std;

int rot90_x(int vx, int vy) {
	return -vy;
}
int rot90_y(int vx, int vy) {
	return vx;
}

int main()
{
	string str;
	getline(cin, str);
	istringstream iss(str);
	iss >> str;
	int x1 = stoi(str);
	iss >> str;
	int y1 = stoi(str);
	iss >> str;
	int x2 = stoi(str);
	iss >> str;
	int y2 = stoi(str);
	int vecx = x2 - x1;
	int vecy = y2 - y1;
	int vecx_old = vecx;
	int vecy_old = vecy;
	vecx = rot90_x(vecx_old, vecy_old);
	vecy = rot90_y(vecx_old, vecy_old);
	int x3 = x2 + vecx;
	int y3 = y2 + vecy;
	vecx_old = vecx;
	vecy_old = vecy;
	vecx = rot90_x(vecx_old, vecy_old);
	vecy = rot90_y(vecx_old, vecy_old);
	int x4 = x3 + vecx;
	int y4 = y3 + vecy;
	cout << x3 << " " << y3 << " " << x4 << " " << y4;
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  string O, E;
  cin >> O >> E;
  for (int i = 0; i < 2 * E.length(); i++)
  {
    if (i % 2 == 0)
      cout << O[i / 2];
    else
      cout << E[i / 2];
  }
  if (O.length() - E.length() == 1)
    cout << O[O.length() - 1];
  cout << '\n';
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split(" ").map(&:to_i).slice(0,n)

BUY ="buy"
SELL="sell"
NO  = ""

chart =[]
last =0
a.each_index{|d|
    action = NO
    if d == 0
        action = BUY
    else
        if a[d] >= a[d-1]
            action=SELL
            chart[d-1]=NO if chart[d-1] == SELL
        elsif a[d] < a[d-1]
            action = BUY
            chart[d-1]=NO if chart[d-1]==BUY
        end
    end
    chart.push(action)
}

for i in 0..n-1
    d = n-1 - i
    if chart[d] == SELL
        break
    elsif chart[d] == BUY
        chart[d] = NO
        break
    end
end




money = 1000
stock=0
chart.each_index { |d|
    action = chart[d]
    price  = a[d]
    case action
    when BUY then
        count = money / price
        money = money - count * price
        stock += count
    when SELL then
        money += stock * price
        stock = 0
    end
}

puts  money < 1000 ? 1000 : money


Measured memory_bytes: 14092
def main():
    N = int(input())
    S = [input() for _ in range(N)]#list()

    #for i in range(N):
    #    S.append(input())
    #    S_uniquie = sorted(set(S))

#    S_uniquie = sorted(set(S))
#    c = 0
    target = {}

    for word in S:
        if word in target:
            target[word] += 1
        else:
            target[word] = 1
#    for i in S_uniquie:
#        c = S.count(i)
#        target[i] = c

    maximum = max(target.values())

    for key,val in sorted(target.items()):
        if(val == maximum):
            print(key)

if __name__ == '__main__':
    main()

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

#define FOR(x,y,z) for(int x=y,x##_=z;x<=x##_;++x)
#define DOR(x,y,z) for(int x=y,x##_=z;x>=x##_;--x)
#define FOR_(x,y,z,s) for(int x=y,x##_=z;x<=x##_;x+=s)
#define FOR__(x,y,z) for(int x=y,x##_=z;x<=x##_;x<<=1)
#define EOR(x,y) for(int x##_=head[x],y=edge[x##_].e;x##_;y=edge[x##_=edge[x##_].to].e)
#define EGOR(x,y,z) for(int x##_=head[x],y=edge[x##_].e,z=edge[x##_].c;x##_;y=edge[x##_=edge[x##_].to].e,z=edge[x##_].c)

#define clr(x,y) memset(x,y,sizeof(x))
#define szf(x) sizeof(x)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)

#define read2(x,y) read(x),read(y)
#define read3(x,y,z) read(x),read(y),read(z)
#define read4(x,y,z,w) read3(x,y,z),read(w)
#define reads(str) sf("%s",str)

#define ts (*this)
#define sf scanf
#define pf printf

#define ll long long
#define ull unsigned long long
#define db double
#define ct clock_t
#define ck() clock()
#define rd rand()
#define rmx RAND_MAX
#define RD T*(rd*2-rmx)


using namespace std;

template<class T>bool tomin(T &x,T y){return y<x?x=y,1:0;}
template<class T>bool tomax(T &x,T y){return x<y?x=y,1:0;}
template<class T>void read(T &x){
    char c;
    x=0;
    int f=1;
    while(c=getchar(),c<'0'||c>'9')if(c=='-')f=-1;
    do x=(x<<3)+(x<<1)+(c^48);
    while(c=getchar(),c>='0'&&c<='9');
    x*=f;
}

const db Pi=acos(-1);
int main(){
    srand(time(NULL));
    int x;
    read(x);
    pf("%d",3*x*x);
    return 0;
}


Measured memory_bytes: 256