akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    stack<char>hoge;
    string s;
    cin>>s;
    bool flag=false;
    ll ans=0,cnt=s.length()-1;
    for(int i=0;i<s.length();i++){
        if(cnt<=i)break;
        if(s[i]=='B'){
            while(true){
                if(cnt<=i)flag=true;
                if(flag)break;
                if(s[cnt]=='W')break;
                cnt--;
            }
            if(flag)break;
            ans+=cnt-i;
            cnt--;
        }
    }
    cout<<ans<<endl;
}

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

const int MAXN = 3010;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

int st[MAXN], to[MAXN<<1];
int nxt[MAXN<<1], e;
inline void Add(int u, int v) {
	to[++e] = v, nxt[e] = st[u];
	st[u] = e;
}

int n, a[MAXN];

bool dfs(int u, int fa) {
	int i;
	for(i = st[u]; i; i = nxt[i]) {
		int v = to[i];
		if(v == fa) continue;
		if(a[v] < a[u] && !dfs(v, u)) return true;
	}
	return false;
}

int main() {

	int i;
	n = read();
	generate(a+1, a+n+1, read);

	for(i = 1; i < n; i++) {
		int u = read(), v = read();
		Add(u, v), Add(v, u);
	}

	for(i = 1; i <= n; i++) 
		if(dfs(i, 0)) printf("%d ", i);
	printf("\n");
	return 0;
}


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

int main(){
    vector<int> A;
    int x;
    for(int i = 0; i < 3; i++){
        cin >> x;
        A.push_back(x);
    }
    sort(A.begin(), A.end());
    cout << A[0] << " " << A[2] <<endl;
    return 0;
}


Measured memory_bytes: 3148
def main():
    N = int(input())
    I = tuple(int(input()) for _ in range(N))

    ans = 0
    for i in I:
        if is_prime(i):
            ans += 1
    print(ans)

def is_prime(n):
    if n < 2:
        return False
    else:
        for i in range(2, n):
            if i * i > n:
                break
            elif n % i == 0:
                return False
        return True

main()

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


def solve(N: int, L: int, S: "List[str]"):
    return "".join(sorted(S))


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    print(solve(N, L, S))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9180
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<functional>
#include<cmath>
#include<vector>
#include<assert.h>
//using namespace std;
using std::min;
using std::max;
using std::swap;
using std::sort;
using std::reverse;
using std::random_shuffle;
using std::lower_bound;
using std::upper_bound;
using std::unique;
using std::vector;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef std::pair<int,int> pii;
typedef std::pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
    char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
void open2(const char *s){
#ifdef DEBUG
    char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
int rd(){int s=0,c,b=0;while(((c=getchar())<'0'||c>'9')&&c!='-');if(c=='-'){c=getchar();b=1;}do{s=s*10+c-'0';}while((c=getchar())>='0'&&c<='9');return b?-s:s;}
void put(int x){if(!x){putchar('0');return;}static int c[20];int t=0;while(x){c[++t]=x%10;x/=10;}while(t)putchar(c[t--]+'0');}
int upmin(int &a,int b){if(b<a){a=b;return 1;}return 0;}
int upmax(int &a,int b){if(b>a){a=b;return 1;}return 0;}
const ll p=1000000007;
const int N=310;
void add(ll &a,ll b)
{
    a=(a+b)%p;
}
int n;
int a[2*N];
ll f[2*N][N][N];
int b[2*N];
int c[2*N];
int t;
int main()
{
    open2("f");
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++)
        scanf("%d",&a[i]);
    int cnt=0;
    for(int i=1;i<=2*n;i+=2)
        if(a[i]!=-1&&a[i+1]!=-1)
            b[a[i]]=b[a[i+1]]=2;
        else if(a[i]!=-1)
            b[a[i]]=1;
        else if(a[i+1]!=-1)
            b[a[i+1]]=1;
        else
            cnt++;
    for(int i=1;i<=2*n;i++)
        if(b[i]==1)
            c[++t]=1;
        else if(b[i]==0)
            c[++t]=2;
    f[t][0][0]=1;
    for(int i=t;i>=1;i--)
        for(int j=0;j<=t&&j<=n;j++)
            for(int k=0;k<=t&&k<=n;k++)
                if(c[i]==1)
                {
                    add(f[i-1][j+1][k],f[i][j][k]);
                    if(k)
                        add(f[i-1][j][k-1],f[i][j][k]);
                }
                else
                {
                    add(f[i-1][j][k+1],f[i][j][k]);
                    if(k)
                        add(f[i-1][j][k-1],f[i][j][k]);
                    if(j)
                        add(f[i-1][j-1][k],f[i][j][k]*j);
                }
    ll ans=f[0][0][0];
    for(int i=1;i<=cnt;i++)
        ans=ans*i%p;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 450688
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

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

   int n;
   cin >> n;
   ll ans = 1, prev = 1;
   bool zero = false;
   bool over = false;
   rep(i, 0, n) {
      ll a;
      cin >> a;
      ans *= a;
      if (ans > ll(1e18) || prev > ans) {
         over = true;
      }
      if (a == 0) zero = true;
      prev = ans;
   }
   if (zero || !over)
      cout << ans << endl;
   else
      cout << -1 << endl;
   return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N;
    N--;
    vector<int> C(N), S(N), F(N);
    REP(i, N) { cin >> C[i] >> S[i] >> F[i]; }
    REP(i, N) {
        int time = 0;
        for(int j = i; j < N; j++) {
            time = max(time, S[j]);
            int d = (time - S[j]) % F[j];
            int c = 0;
            if(d != 0) {
                c = F[j] - d;
            }
            // cout << "a" << time << endl;
            time += (c + C[j]);
            // cout << "b" << time << endl;
        }

        cout << time << endl;
    }
    cout << "0" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

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

int main(){
  char buf[1024];
  int N;
  char s[10];

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d", &N);

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%s", s);

  if(N>=3200){
    printf("%s\n", s);
  }
  else{
    printf("red\n");
  }

}


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

using namespace std;
typedef long long               ll;
typedef long double             ld;

#define min3(a, b, c)           min((a), min((b), (c)))
#define max3(a, b, c)           max((a), max((b), (c)))
#define lcm(a,b)                (a / __gcd(a,b) ) *b
#define gcd(a,b)                __gcd(a,b)
#define dist(x1,y1,x2,y2)       sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define distl(x1,y1,x2,y2)      sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define sqr(a)                  ((a)*(a))
#define FOR(a, b)               for(int i=a; i<b; i++)
#define fRead(x)                freopen(x,"r",stdin)
#define fWrite(x)               freopen (x,"w",stdout)
#define pb                      push_back
#define mk                      make_pair
#define ff                      first
#define ss                      second
#define lb                      lower_bound
#define ub                      upper_bound
#define all(a)                  a.begin(),a.end()
#define FASTIO                  ios_base::sync_with_stdio(0);cin.tie(NULL);
ll BMod(ll B,ll P,ll M)
{
    ll R=1;
    B=B%M;
    while(P)
    {
        if(P&1)
            R=(R*B)%M;
        P >>= 1;
        B=(B*B)%M;
    }
    return R;
}

ll invMOD(ll num,ll M)
{
    return BMod(num,M-2,M);
}


int main()
{
    FASTIO

    int n, k;
    vector<pair<int,int> > v;
    cin >> n >> k;

    FOR (0, n)
    {
        int x, y;
        cin >> x >> y;
        if (y <= k)
            v.push_back({x, y});
    }

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

    if (!v.empty())
        cout << v[0].ff;
    else
        cout << "TLE";
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=998244353;

ll N,K;
ll L[10],R[10];

int main(){
    cin>>N>>K;
    rep(i,K) cin>>L[i]>>R[i];

    vector<ll> dp(N+1,0);
    dp[1]=1;
    vector<ll> sum(N+1,0);
    repn(i,N){
        rep(j,K){
            ll l=max((ll)0,i-R[j]-1);
            ll r=max((ll)0,i-L[j]);
            dp[i]+=sum[r]-sum[l];
            dp[i]%=MOD;
        }
        sum[i]+=sum[i-1]+dp[i];
        sum[i]%=MOD;
    }
    //repn(i,N) cout<<dp[i]<<' ';cout<<endl;

    ll ans=(dp[N]+MOD)%MOD;
    cout<<ans<<endl;
}

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

int main() {
  int N, K, a, b;
  cin >> N >> K;
  b = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> a;
    if (a < K - a) {
      b += 2 * a;
    }
    else {
      b += 2 * (K - a);
    }
  }
  
  cout << b << endl;
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define ALL(x) (x).begin(), (x).end()

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

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

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

    int N[3];
    rep(i, 3)
        cin >> N[i];

    int ans = 0;

    sort(N, N+3);
    while(N[0] <= N[2]-2) {
        N[0] += 2;
        ans++;
    }
    while(N[1] <= N[2]-2) {
        N[1] += 2;
        ans++;
    }

    // このとき
    // 0, 0, 0 or -1, 0, 0, or -1, -1, 0 or 0, -1, 0
    if(N[0] == N[1]) {
        if(N[1] != N[2]) {
            ans++;
        }
    } else {
        ans += 2;
    }

    cout << ans << endl;

    return 0;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

int main(){
#define int ll
  int n,m; cin >> n >> m;
  vvi g(n);
  int a,b;
  rep(i,m){
    cin >> a >> b;
    a--; b--;
    g[a].pb(b); g[b].pb(a);
  }
  vi isin(n);
  list<int> path;
  int tmp = g[0][0];
  path.pb(0); path.pb(tmp);
  g[tmp].erase(find(all(g[tmp]),0));
  g[0].erase(g[0].begin());
  isin[0] = isin[tmp] = 1;
  int s,t;
  while(1){
    if(sz(g[path.front()]) != 0){
      s = g[path.front()][0];
      t = path.front();
      if(isin[s] == 0){
	path.push_front(s);
	isin[s] = 1;
      }
      g[t].erase(g[t].begin());
      g[s].erase(find(all(g[s]),t));
    }else if(sz(g[path.back()])!=0){
      s = g[path.back()][0];
      t = path.back();
      if(isin[s] == 0){
	path.push_back(s);
	isin[s] = 1;
      }
      g[t].erase(g[t].begin());
      g[s].erase(find(all(g[s]),t));
    }else break;
  }
  cout << sz(path) << endl;;
  for(auto x : path){
    if(x == path.front()) cout << x+1;
    else cout << " " << x+1;
  }
  cout << endl;
}

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


def solve(N: int, B: "List[int]"):
    sm = 0
    for i in range(1, N-1):
        sm += min(B[i-1], B[i])
    sm += B[0] + B[-1]
    print(sm)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    B = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

long long factorial(long long a)
{
	long long tmp = a;
	while(--a > 0)
	{
		tmp *= a;
		tmp %= 1000000007;
	}
	
	return tmp;
}

int main()
{
	int n, m;
	cin >> n >> m;
	
	int difference = n - m > 0 ? n - m : m - n;
	long long ans = 0;
	if(difference >= 2)
	{
		cout << ans << endl;
	}
	else if(difference == 1)
	{
		cout << (factorial(n) * factorial(m)) % 1000000007 << endl;
	}
	else if(difference == 0)
	{
		long long tmp = (factorial(n) * factorial(m)) % 1000000007;
		cout << (tmp * 2) % 1000000007 << endl;
	}
	return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

int main() {
  int n, d;
  cin >> n >> d;
  cout << ((n - 1) / (2*d + 1) + 1) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<numeric>
#include<string>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const ll MOD = 1000000007;
 
using namespace std;

int main()
{
    ll X, K, D; cin >> X >> K >> D;
    ll cnt = 0;
    cnt = abs(X)/D;
    if(cnt <= K){
        if(X >= 0){
            X -= cnt*D;
            if((K - cnt)%2 == 0)    cout << abs(X);
            else    cout << abs(X - D);
        }else{
            X += cnt*D;
            if((K - cnt)%2 == 0)    cout << abs(X);
            else    cout << abs(X + D);
        }
    }else{
        if(X >= 0)  cout << abs(X - K*D);
        else    cout << abs(X + K*D);
    }
}

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

using namespace std;

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <iostream>
#include <stdio.h>

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pairll;

#define sll(x) scanf("%lld",&x);
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout)

#define ff first
#define ss second

inline ll ADD(ll a, ll b, ll mod)
{
    return (a + b + mod + mod)%mod;
}

inline ll SUBS(ll a, ll b, ll mod)
{
    return (a-b+mod + mod) %mod;
}

inline ll MUL(ll a, ll b, ll mod)
{
    return (a*b + mod)%mod;
}

ll bigMod(ll base, ll power, ll mod)
{
    if(!power) return 1;
    if(!base) return 0;

    ll temp = bigMod(base, power/2, mod);

    if(power%2 == 0)
    {
        return (temp*temp)%mod;
    }
    else return (((temp*temp)%mod)*base)%mod;
}

inline ll modInverse(ll a, ll modp)
{
    return bigMod(a, modp -2, modp);
}

inline ll modInverseExtended(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        // q is quotient 
        ll q = a / m; 
        ll t = m; 
  
        // m is remainder now, process same as 
        // Euclid's algo 
        m = a % m, a = t; 
        t = y; 
  
        // Update y and x 
        y = x - q * y; 
        x = t; 
    } 
  
    // Make x positive 
    if (x < 0) 
       x += m0; 
  
    return x; 
} 
  
int getOdd(int n, int r)
{
    // if(n == r) return 1;
    // else if(n % 2 == 0 && r%2==1) return 0;
    // return getOdd(n/2,r/2);

    if(r & n-r) return 0;
    return 1;
}

void autoinput()
{
    READ; 
    //WRITE;
}

int main()
{
    //autoinput();

    ll n; cin >> n;

    ll arr[n+1];
    ll arra[n+1];

    bool one = false;
    for(ll i = 0; i < n; i++)
    {
        int in;
        scanf("%1d",&in);
        arr[i] = in - 1;
        if(in == 2){
            if(!one) memset(arra, 0, sizeof arra);
            one = true;
            arra[i] = 1;
        }
        else if(!one)
        {
            arra[i] = arr[i]/2;
        }
    }

    ll cur = 0;

    for(ll i = 0; i < n; i++)
    {
        //cout << getOdd(n-1,i);
        //cout << arra[i];
        cur ^= arra[i] * getOdd(n-1,i);
    }
    if(!one) cur *= 2;
    
    cout << cur << endl;
}



Measured memory_bytes: 16000
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
using namespace std;


int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> status(n);
    vector<int> WA_count(n);
    int ans = 0;
    int penalties = 0;
    for(int i = 0; i < m; ++i){
        int id;
        string s;
        cin >> id >> s;
        if(s == "AC"){
            if(!status[id]){
                penalties += WA_count[id];
                status[id] = true;
                ans++;
            }
        }
        else{
            WA_count[id]++;
        }
    }
    cout << ans << " " << penalties << endl;
    return 0;
}


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

using namespace std;

pair<string,int>a[55];

string p;

int main()
{
    int n,sum=0,i,j;
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i].first>>a[i].second;
    cin>>p;
    for(i=1;i<=n&&a[i].first!=p;i++)
            ;
    for(j=i+1;j<=n;j++)
        sum+=a[j].second;
    cout<<sum<<"\n";
    return 0;
}


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

long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}

vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }
signed main() {
    int x, y;
    cin >> x >> y;
    if ((2 * y - x) % 3 != 0 || (2 * x - y) % 3 != 0) {
        cout << 0 << endl;
    } else if (2 * y - x < 0 || 2 * x - y < 0) {
        cout << 0 << endl;
    } else {
        cout << nCkmod(((2 * y - x) / 3 + (2 * x - y) / 3), (2 * x - y) / 3) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int x, y, sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	x = tx - sx;
	y = ty - sy;
	string S = "sample";
	cout << string(y, 'U') << string(x, 'R');
	cout << string(y, 'D') << string(x, 'L');
	cout << 'L' << string(y+1, 'U') << string(x+1, 'R') << 'D';
	cout << 'R' << string(y+1, 'D') << string(x+1, 'L') << 'U';
	return 0;
}

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

int main() {
  double a,b,x;
  cin >> a >> b >>x;
  double high = x/(a*a);
  double theta;
  double ans;
  if(high <= b/2){
    theta = atan(0.5*a*b*b/x);
  }else{
    theta = atan(2*(a*a*b - x)/(a*a*a));
  }
  ans = theta*180/ M_PI;
  cout << fixed << setprecision(10) << ans << endl;
}

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

#[derive(Clone)]
struct Card {
    suit: char,
    value: u32,
}

impl std::fmt::Display for Card {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}{}", self.suit, self.value)
    }
}

impl PartialEq for Card {
    fn eq(&self, other: &Self) -> bool {
        self.suit == other.suit && self.value == other.value
    }
}

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")
}

fn bubble_sort(target_array: &mut Vec<Card>) {
    let n = target_array.len();
    let mut flag = true;

    while flag {
        flag = false;
        for j in (1..n).rev() {
            if target_array[j as usize].value < target_array[(j - 1) as usize].value {
                target_array.swap(j as usize, (j - 1) as usize);
                flag = true;
            }
        }
    }
}

fn selection_sort(target_array: &mut Vec<Card>) {
    let n = target_array.len();

    for i in 0..n {
        let mut min_j = i;
        for j in i..n {
            if target_array[j as usize].value < target_array[min_j as usize].value {
                min_j = j
            };
        }
        if min_j != i {
            target_array.swap(i as usize, min_j as usize);
        }
    }
}

fn is_equal(base_array: &mut Vec<Card>, target_array: &mut Vec<Card>) -> bool {
    let n = target_array.len();

    for i in 0..n as usize {
        if base_array[i] != target_array[i] {
            return false;
        }
    }

    true
}

fn display_array<T: std::fmt::Display>(target_array: &mut Vec<T>) {
    let n = target_array.len();

    for index in 0..n {
        if index != n - 1 {
            print!("{} ", target_array[index as usize]);
        } else {
            print!("{}", target_array[index as usize]);
        }
    }
    println!("");
}

fn main() {
    let n: u32 = read();

    let base_array: Vec<Card> = (0..n)
        .map(|_| read::<String>())
        .map(|input_v| Card {
            suit: input_v.chars().nth(0).unwrap(),
            value: input_v.chars().nth(1).unwrap().to_digit(10).unwrap(),
        })
        .collect();

    let mut target_array1 = base_array.to_vec();
    bubble_sort(&mut target_array1);
    display_array::<Card>(&mut target_array1);
    println!("Stable");

    let mut target_array2 = base_array.to_vec();
    selection_sort(&mut target_array2);
    display_array::<Card>(&mut target_array2);
    if is_equal(&mut target_array1, &mut target_array2) {
        println!("Stable");
    } else {
        println!("Not stable");
    }
}



Measured memory_bytes: 5024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        Dictionary<string, List<int>> dic = new Dictionary<string, List<int>>();
        List<string> keys = new List<string>();
        string[] pair = new string[N];
        
        for (int i = 0; i < N; i++)
        {
            var read = Console.ReadLine();
            var split = read.Split();
            pair[i] = read;
            if (keys.Contains(split[0]))
            {

            }
            else
            {
                keys.Add(split[0]);
                dic[split[0]] = new List<int>();
            }
            dic[split[0]].Add(int.Parse(split[1]));

        }
        keys.Sort();
        for (int i = 0; i < keys.Count; i++)
        {
            var the_list = dic[keys[i]];
            the_list.Sort();
            the_list.Reverse();

            for (int j = 0; j < the_list.Count; j++)
            {
                string the_key = keys[i] + " " + the_list[j];
                int output =Array.IndexOf(pair, the_key);
                Console.WriteLine(output+1);
            }

        }
        ;
    }
}

Measured memory_bytes: 11360
ranknum, goal = list(map(int, input().split()))
probnum = [0] * ranknum
bonus = [0] * ranknum
compscore = [0] * ranknum

for i in range(ranknum):
    probnum[i], bonus[i] = list(map(int, input().split()))
    # 各ランクをコンプした場合に得られる得点をcompscoreに格納しておく。
    compscore[i] = 100 * (i + 1) * probnum[i] + bonus[i]

from itertools import product
from math import ceil

# 得点Gを達成する最小の問題正解数minprobを初期化。前提により必ず1000以下になるので、1001で初期化しておく。
minprob = 1001

# 各ランクの問題をコンプするか否かの2^ranknum通りをループ処理する。
for c in product(range(2), repeat=ranknum):
    score = 0
    solvedprob = 0
    notcompedindex = -1

    # コンプした問題について、得点をcompscoreに、正解数をsolvedprobnumに格納する。
    for i in range(ranknum):
        if c[i] == 1:
            score += compscore[i]
            solvedprob += probnum[i]
        # コンプされていないランクのインデックスのうち最大のものをnotcompedindexに格納しておく。
        else:
            notcompedindex = i

    # コンプした問題だけでgoalに達さず、かつ、コンプしていない最高ランクの問題をコンプ寸前まで解けばゴールに達する場合、
    # ゴールをぎりぎり達成するところまで正解した状態へと、scoreとsolvedprobを更新する。
    if score < goal and score + 100 * (notcompedindex + 1) * (probnum[notcompedindex] - 1) >= goal:
        solvedprob += ceil((goal - score) / (100 * (notcompedindex + 1)))
        score += ceil((goal - score) / (100 * (notcompedindex + 1))) * 100 * (notcompedindex + 1)

    # 最終的にゴールを達成している場合、正解数が暫定最小ならば、それをminprobに格納しておく。
    if score >= goal:
        minprob = min(minprob, solvedprob)

print(minprob)

Measured memory_bytes: 3064
N=int(input())
a=list(map(int, input().split()))
q=0
b=0
for i in a:
  if i%4==0:
    q += 1
  elif i%2==0:
    b += 1

s = "No"
if N//2 <= q or N <= 2*q+b:
  s = "Yes"
print(s)

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


int main(){

    int X,Y,A,B,C;
    cin >> X >> Y >> A >> B >> C;

    vector<long> VA(A,0);
    vector<long> VB(B,0);
    vector<long> Vall(X+Y+C,0);
    
    for(size_t i=0;i<A;i++){ cin >> VA[i]; }    sort(VA.begin(),VA.end());
    for(size_t i=0;i<B;i++){ cin >> VB[i]; }    sort(VB.begin(),VB.end());

    for(size_t i=0,j=A-X;j<A;i++,j++){
        Vall[i] = VA[j];
    }
    for(size_t i=X,j=B-Y;j<B;i++,j++){
        Vall[i] = VB[j];
    }

    for(size_t i=0;i<C;i++){ cin >> Vall[X+Y+i]; }  sort(Vall.begin(),Vall.end());

    long result=0;
    for(size_t i=C;i<X+Y+C;i++){
        result += Vall[i];
    }

    cout << result << endl;

    return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  string s;
  cin >> s;

  a--;
  b--;
  c--;
  d--;

  bool can = true;
  // そもそも辿り着けるか
  for (int i = a; i < c; i++)
    if (s[i] == '#' && s[i + 1] == '#') can = false;
  for (int i = b; i < d; i++)
    if (s[i] == '#' && s[i + 1] == '#') can = false;

  if (can == false) {
    cout << "No" << endl;
    return 0;
  }

  if (d < c) {  // 途中で追い越せるか
    can = false;
    for (int i = b; i <= d; i++)
      if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') can = true;
  }

  cout << ((can) ? "Yes" : "No") << endl;
}


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

#define endl '\n'

int main(){
	int n;
	double m;
	scanf("%d",&n);
	m=n/2+(n%2!=0);
	printf("%.7lf\n",m/n);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main () {
    ll n;
    cin >> n;
    ll mi = n;
    for(ll i = 1; pow(i,2) <= n; i++) {
        if (n %i == 0) {
            mi = min(mi, i + n/i-2);
        }
    }
    cout << mi << endl;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

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

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

inline int gcd(int a, int b) { return (a%b == 0) ? b : gcd(b, a%b); }
inline int fac(int n) { return (n==0) ? 1 : n * fac(n - 1); }

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

    const string keyence = "keyence";

    int start = -1;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] != keyence[i]) {
            start = i;
            break;
        }
    }
    
    if (start == -1) {
        cout << "YES" << endl;
        return 0;
    }

    int length = keyence.length() - start;
    if (s.substr(s.length() - length, length) == keyence.substr(start, length))
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

        return 0;
}


Measured memory_bytes: 3588
use std::io::Read;
use std::collections::HashMap;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut map: HashMap<&str, usize> = HashMap::with_capacity(n);
    for _i in 0..n {
        *map.entry(iterator.next().unwrap()).or_insert(0) += 1;
    }

    let mut max_count: usize = 0;
    for (_, &v) in &map {
        max_count = max(max_count, v);
    }

    let filtered = map.into_iter()
        .filter(|&(_, v)| v == max_count)
        .collect::<HashMap<&str, usize>>();

    let mut keys = Vec::with_capacity(filtered.len());
    for &key in filtered.keys() {
        keys.push(key)
    }

    keys.sort();

    return keys.join("\n");
}

#[test]
fn test() {
    assert_eq!(
        solve(
            r"7
beat
vet
beet
bed
vet
bet
beet"
        ),
        "beet
vet"
    );
//    assert_eq!(
//        solve(
//            r""
//        ),
//        ""
//    );
//    assert_eq!(
//        solve(
//            r""
//        ),
//        ""
//    );
}


Measured memory_bytes: 28456
n=int(input())
l=list(map(int,input().split()))
l.insert(0,0)
l.append(0)
wa=0
for i in range(n+1):
  wa+=abs(l[i+1]-l[i])

  
for j in range(n):  
  if abs(l[j+2]-l[j])<abs(l[j+1]-l[j])+abs(l[j+2]-l[j+1]):
    if abs(l[j+1]-l[j])<abs(l[j+2]-l[j+1]):
      print(wa-2*abs(l[j+1]-l[j]))
    else:
      print(wa-2*abs(l[j+2]-l[j+1]))
  else:
    print(wa)
         

Measured memory_bytes: 14172
import sys

input = sys.stdin.readline


def ii():
    return int(input())


def il():
    return list(map(int, input().split()))


N, X = il()
A = sorted(il())
if X == sum(A):
    print(N)
    exit()

for i in range(1, N + 1):
    if sum(A[:i]) > X:
        break
print(i - 1)


Measured memory_bytes: 3060
// Vicfred
// https://atcoder.jp/contests/abc160/tasks/abc160_a
// implementation
use std::io;

fn main() {
    let mut s = String::new();

    io::stdin()
        .read_line(&mut s)
        .unwrap();

    let s = s.trim();

    let s: Vec<char> = s.chars().collect();

    if &s[2] == &s[3] && &s[4] == &s[5] {
        println!("Yes");
    } else {
        println!("No");
    }

}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<ll, ll>
#define to second
#define cost first
typedef long long ll;
typedef long double ld;
using namespace std;

struct cht {
	vector<ll> m, b;
	int ptr = 0;

	bool bad(int l1, int l2, int l3) {
		return 1.0 * (b[l3] - b[l1]) * (m[l1] - m[l2]) <= 1.0 * (b[l2] - b[l1]) * (m[l1] - m[l3]);
	}

	void add(ll _m, ll _b) {
		m.pb(_m); b.pb(_b);
		int sz = m.size();

		while(sz >= 3 && bad(sz-3, sz-2, sz-1)) {
			sz--;
			m.erase(m.end()-2);
			b.erase(b.end()-2);
		}
	}

	ll f(ll i, ll x) { return m[i]*x + b[i]; }
	
	ll query(ll x) {
		int lo = 0, hi = m.size()-1;

		while(lo < hi) {
			int mid = (lo + hi) >> 1;

			if(f(mid, x) < f(mid+1, x)) hi = mid;
			else lo = mid+1;
		}
		return f(lo, x);
	}
} ds;

//ll p[100005], s[100005];
ll h[200005], dp[200005];

int main()
{
	int n, i, j;
	ll c;

	cin >> n >> c;
	for(int i = 1; i <= n; i++) cin >> h[i], dp[i] = 1e18+7;

	dp[1] = 0;
	ds.add(-2*h[1], dp[1] + h[1]*h[1]);

	for(int i = 2; i <= n; i++) {
		dp[i] = ds.query(h[i]) + c + h[i]*h[i];
		ds.add(-2*h[i], h[i]*h[i] + dp[i]);
	}
	cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 6756
N,M = map(int,input().split())
divs = set()
n = 1
while n*n <= M:
    if M%n == 0:
        divs.add(n)
        divs.add(M//n)
    n += 1

ans = 0
for d in divs:
    if d*N <= M:
        ans = max(ans, d)
print(ans)

Measured memory_bytes: 3060
n, m = (int(i) for i in input().split())
a = {int(input()) for i in range(m)}
MOD = 10**9 + 7

d = [0] * (n+5)
d[1] = (0 if 1 in a else 1)
d[2] = (0 if 2 in a else d[1] + 1)

for i in range(2,n):
    d[i+1] = (d[i] + d[i-1])%MOD
    if i+1 in a:
        d[i+1] = 0
print(d[n]%MOD)

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

using namespace std;

typedef long long LL;
typedef pair<int,int> pi;
typedef vector<int> vi;
#define ST first
#define ND second
#define PB push_back
#define DET(a,b,c) (LL(b.x-a.x)*LL((c.y-a.y))-LL((c.x-a.x))*LL((b.y-a.y)))

const int MAXN = 101;
const int MAXK = 100*1000+1;
bool dp[MAXK];
int n,k,a[MAXN];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k;
    for(int i=0; i<=k;i++) dp[i]=1;
    for(int i=0; i<n;i++) cin>>a[i];
    for(int j=0; j<=k;j++) {
        for(int i=0; i<n;i++) {
            if(j-a[i]<0) continue;
            if(dp[j-a[i]]==1) dp[j] = 0;
        }
    }
    if(dp[k]) cout<<"Second";
    else cout<<"First";
}


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

int main(){
    int n;
    cin >> n;
    bool b=false;
    for(int c=0;c<=n;c++){
        for(int d=0;d<=n;d++){
            int sam=4*c+7*d;
            if(sam==n){
                b=true;
            }
        }
    }
    if(b==false){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int digit(ll N) {
	int ret = 0;
	while (N > 0) {
		N /= 10;
		ret ++;
	}
	return ret;
}
int main() {
	ll N;
	cin >> N;
	int res = digit(N);
	for (ll A = 1; A*A <= N; A++) {
		if (N % A != 0) continue;
		ll B = N / A;
		res = min(res, max(digit(A), digit(B)));
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
import math
import collections

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        n = int(n)
        table.append(n)
    return table

def num(y):
    count = 0
    for i in x:
        if x[i] >= y:
            count += 1
    return count

N = int(input())
li = []
for i in range(1, N+1):
    li += prime_decomposition(i)
# print(collections.Counter(li))
x = collections.Counter(li)
ans = num(74) + num(24) * (num(2) - 1) + num(14) * (num(4) - 1)  + num(4) * (num(4) - 1) * (num(2) - 2) // 2
print(ans)

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

const long long INF = 1LL << 60;

int main()
{
    string s;
    int ans = 0;
    cin >> s;
    for (int i = 0; i < 4; i++)
    {
        if (s[i] == '+')
            ans++;
        else
            ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3568
#include "bits/stdc++.h"
#include <fstream>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

typedef pair<int, int> P;
int N, K;
vector<int> Back[100010];
vector<int> Forward[100010];
int used[3][100010];
vector<int> d[100010];


void bfs(int s) {
    queue<P> que;
    que.push({s, 0});
    while(que.size()) {
        P v = que.front(); que.pop();
        used[0][v.first] = true;
        d[v.second].push_back(v.first);
        for(auto next: Back[v.first]) {
            if (!used[0][next])
                que.push({next, v.second + 1});
        }
    }
}
void dfs2(int s, int depth) {
    //cout << s << " " << depth << endl;
    used[1][s] = true;
    if (depth >= K) return;
    for(auto next: Back[s]) {
        dfs2(next, depth + 1);
    }
}
void dfs(int s, int K){
    used[1][s] = true;
    if (K == 1 && Forward[s][0] != 1) {dfs2(s, K); return;}
    if (K == 0) {dfs2(s, K);return;}
    for(auto next: Forward[s]) {
        if (!used[1][next])
            dfs(next, K - 1);
    }
}


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    cin >> N >> K;
    
    int a[100010];
    rep(i, N) cin >> a[i];
    int ans = 0;
    if (a[0] != 1) ans++;
    a[0] = 1;
    rep(i, N) {
        Forward[i + 1].push_back(a[i]);
        Back[a[i]].push_back(i + 1);
    }
    bfs(1);
    /*
    rep(i, 10) {
        cout << i << ":";
        rep(j, d[i].size()) {
            cout << d[i][j] << " ";
        }
        cout << endl;
    }
    */
    RREP(i, 100000, K + 1) {
        //rep(j, N + 1) cout << used[1][j] <<" ";
        //cout << endl; 
        if (d[i].size()) {
            for(auto v: d[i]) {
                if (!used[1][v]) {
                    //cout << "!" << v << " ";
                    ans++;
                    dfs(v, K);
                }
            }
            //cout << endl;
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 24448
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    bool ctr=true;
    while(a>0 && c>0){
        if(ctr) c-=b;
        else a-=d;
        ctr=(!ctr);
    }
    if(a>0) cout<<"Yes\n";
    else cout<<"No\n";
}

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

    solve();
    return 0;
}

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

using namespace std;
using Int = long long;

signed main(){
    string s;
    cin >> s;
    string before_c = s.substr(0, 1);
    bool  ans = false;
    for (int i = 1; i < 4; i++){
        string tmp = s.substr(i, 1);
        if (before_c == tmp) {
            ans = true;
            break;
        }
        before_c = tmp;
    }

    if (ans) {
        cout << "Bad" << endl;
    } else{
        cout << "Good" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
import heapq

sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10 ** 9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)

ans = 0
def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n - k])) % MOD

def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret

def kaijyo_kai(n, k):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * (k+i))% MOD)
    return ret


def dijkstra(graph, start, n):
    h = []
    heapq.heappush(h, (0, start))
    costs = [INF for _ in range(n)]
    while h:
        cost, cur = heapq.heappop(h)
        if costs[cur] != INF:
            continue
        costs[cur] = cost
        for edge in graph[cur]:
            ecost, tgt = edge
            if costs[tgt] == INF:
                heapq.heappush(h, (cost + ecost, tgt))

    return costs

def solve():
    n, m = getList()
    graph = [[] for i in range(10)]
    magic = []
    for i in range(10):
        mg = getList()
        for j, mm in enumerate(mg):
            if i != j:
                graph[i].append((mm, j))

    for i in range(10):
        magic.append(dijkstra(graph, i, 10))
    # print(graph)
    # print(magic)


    ans = 0
    for i in range(n):
        for j in getList():
            if j != -1:
                ans += magic[j][1]

    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 68644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;cin>>n;
	string s;cin>>s;
	map<char, int> mp[n];
	mp[n-1][s[n-1]]++;
	set<char> st = {'R', 'G', 'B'};
	for(int i = n - 2; i >=0; --i){
		for(auto x : st){
			mp[i][x] = mp[i+1][x];
		}
		mp[i][s[i]]++;
	}
	ll ans = 0;
	for(int i  = 0; i < n-2; ++i){
		for(int j = i + 1; j < n-1; ++j){
			if(s[i]!=s[j]){
				set<char> temp = st;
				temp.erase(s[i]);
				temp.erase(s[j]);
				char c = *temp.begin();
				ans += (ll)mp[j][c];
				if(j + j - i < n && s[j + j-i]==c) --ans;
			}
			
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 4408
import math
n=int(input())
n_=int(math.sqrt(n))

list_ans=[]
for i in range(2,n_+1):
  if n%i==0:
    ans=i+(n//i)-2
    list_ans.append(ans)
    
  
if not list_ans:
  print(n-1)
  exit()
print(min(list_ans))

Measured memory_bytes: 64288
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


char s[100005];
int main(void){
	scanf("%s",s);
	int ls=strlen(s);
	int cs[3]={0,0,0};
	rep(i,ls){
		cs[s[i]-'a']++;
	}
	
	int ma=0,mi=1000000;
	
	rep(i,3){
		ma=max(ma,cs[i]);
		mi=min(mi,cs[i]);
	}
	
	puts((ma-mi<=1)?"YES":"NO");
	
	return 0;
}






Measured memory_bytes: 384