akhauriyash/Code-Regression huggingface dataset:
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n):
    a[i] -= 1

loop = []
loop_corr = []
ord = [-1]*n
curr = 0
while ord[curr] == -1:
    ord[curr] = len(loop)
    loop.append(curr)
    curr = a[curr]
        
loop_corr = loop[loop.index(curr):len(loop)]

# print(loop)
# print(loop_corr)
if len(loop) > k:
    print(loop[k]+1)
else:
    diff = k - len(loop) + 1
    mod = (diff % len(loop_corr)) -1
    # print(diff)
    # print(mod)
    print(loop_corr[mod]+1)
        
    

Measured memory_bytes: 32376
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
int main(void) {
    int a, b, c; cin >> a >> b >> c;
    cout << (((a-b)>=c)?0:(c-(a-b)));
}


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

int main() {
  int N, M;
  cin >> N >> M;
  int A[N];
  
  int z=0;
  for(int i=0; i<N; i++){
    cin >> A[i];
    z+=A[i];
  }
 
  int count=0;
  for(int i=0; i<N; i++){
    if(z<=A[i]*4*M) count++;
  }
  
  if(count>=M) cout <<"Yes"<<endl;
  else cout << "No"<<endl;
  
}

Measured memory_bytes: 256
n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
sa = [0 for _ in range(n+1)]
for i in range(n):
    sa[i+1] = sa[i] + a[i]

ans = p
for i in range(p, n):
    res = m * ((p - 1) + (n - i)) + \
          (a[i] + m) * (i - p + 1) - (sa[i] - sa[p-1])

    if res >= m * v and a[p-1] <= a[i] + m:
        ans += 1

print(ans)

Measured memory_bytes: 14964
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }


ll n, m, v, p;
vector<ll> a;

bool f(int mid){
  vector<ll> lst = a;
  lst[mid] += m;
  ll x = lst[mid];
  ll need = 1ll * m * (v - 1);
  vector<ll> mogudat(n);
  for(int i = 0; i < n; i++){
    if(i == mid) continue;
    ll ad = min(need, m);
    ll raz = max(0ll, lst[mid] - lst[i]);
    need -= min(raz, ad);
    lst[i] += min(raz, ad);
    mogudat[i] = m - min(raz, ad);
    if(need <= 0) break;
  }
  vector <pair<ll, ll>> novi;
  //cout << need << " " << endl;
  for(int i = 0; i < n; i++){
    //cout << lst[i] << " ";
    novi.emplace_back(lst[i], i);
  }
  // cout << endl;
  // for(int i = 0; i < n; i++){
  //   cout << mogudat[i] << " ";
  // }
  // cout << endl;
  sort(all(novi));
  reverse(all(novi));
  for(int i = 0; i < p; i++){
    if(mogudat[novi[i].second] > 0){
      ll ad = min(need, mogudat[novi[i].second]);
      need -= ad;
      novi[i].first += ad;
    }
    if(need == 0) break;
  }
  sort(all(novi));
  reverse(all(novi));
  // for(int i = 0; i < n; i++){
  //   cout << novi[i].first << " ";
  // }
  // cout << endl;
  // for(int i = 4; i <= 6; i++){
  //   cout << mogudat[i] << " ";
  // }
  // cout << endl;
  bool ok = 0;
  //cout << "trazim " << x << endl;
  for(int i = 0; i < p; i++){
    //cout << lst[i] << " ";
    if(novi[i].first == x){
      ok = 1;
    }
  }
  //cout << endl;
  //cout << need << endl;
  if(ok && need == 0) return 1;
  return 0;
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  cin >> n >> m >> v >> p;
  a.resize(n);
  for(ll& x : a){
    cin >> x;
  }
  sort(all(a));
  int lo = 0, hi = n;
  while(lo < hi){
    int mid = (lo + hi + 1) / 2;
    if(f(mid)){
      hi = mid - 1;
    }
    else lo = mid;
  }
  if(f(lo)){
    cout << n - lo;
    return 0;
  }
  cout << n - (lo + 1);
}

Measured memory_bytes: 8308
n=int(input())
s=input()
q=int(input())
dic=dict()
for i,j in enumerate("qwertyuioplkjhgfdsazxcvbnm"):
    dic[j]=i
No=2
while n>No:
    No*=2
tree=[set()]*(2*No)
def add(k,x):
    k+=No-1
    tree[k]=set([dic[x]])
    while k>0:
        k=(k-1)//2
        tree[k]=tree[2*k+1]|tree[2*k+2]
def query(l,r):
    L=l+No-1
    R=r+No-1
    s=set()
    while L<=R:
        if R&1:
            s|=tree[R]
            R-=2
        else:
            R-=1
        if L&1:
            L-=1
        else:
            s|=tree[L]
        L>>=1;R>>=1
    return len(s)
for i,j in enumerate(s):
    tree[i+No-1]=set([dic[j]])
for i in range(No-2,-1,-1):
    tree[i]=tree[2*i+1]|tree[2*i+2]
for i in range(q):
    a,b,c=input().split()
    a,b=int(a),int(b)
    if a==1:
        add(b-1,c)
    if a==2:
        c=int(c)
        print(query(b-1,c-1))

Measured memory_bytes: 473288
def main():
    n = int(input())
    h = list(map(int,input().split()))
    dp = [0 for i in range(n)]
    dp[1] = abs(h[1]-h[0])
    for i in range(2,n):
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
    print(dp[n-1])
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 20312
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);


int main(){
    std::ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int block=0;
    rep(i,1,s.size()-1){
        if(s[i]!=s[i-1])
            block++;
    }
    cout<<block<<endl;
    return 0;
}

Measured memory_bytes: 512
N,M=map(int,input().split())
LR=set(range(N+1))
l=[]
r=[]
for i in range(M):
    L,R=map(int,input().split())
    l.append(L)
    r.append(R)
ans=min(r)-max(l)+1
if ans<0:
    ans=0
print(ans)

Measured memory_bytes: 25564
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main() {
    int n;
    cin>>n;
    rep(afewjo,n){
        int outc=0;
        int p=0;
        int fie[10]={};

        while(outc<3){
            string eve;
            cin>>eve;
            
            if(eve=="HIT"){
                if(fie[3]==1)p++;
                fie[3]=fie[2];
                fie[2]=fie[1];
                fie[1]=1;
            }else if(eve=="OUT"){
                outc++;
            }else if(eve=="HOMERUN"){
                p+=1+fie[1]+fie[2]+fie[3];
                fie[1]=fie[2]=fie[3]=0;
            }
        }
        cout<<p<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 1212
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC098_B solver = new ABC098_B();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC098_B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            String str = in.next();
            int ans = 0;
            for (int i = 0; i <= n; i++) {
                String x = str.substring(0, i);
                String y = str.substring(i);

                int cnt = 0;
                for (char c = 'a'; c <= 'z'; c++) {
                    if (x.indexOf(c) != -1 && y.indexOf(c) != -1) {
                        cnt++;
                    }
                }
                ans = Math.max(ans, cnt);
            }

            out.print(ans);
        }

    }
}



Measured memory_bytes: 23636
import java.util.Scanner;

public class Main{
	public static void main(String[] args){

		String a =  "No";
		String b = "Yes";

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		if(A == B) {

			if(B == C) {
				if(A == C) {
					System.out.print(a);

				}else {
					System.out.print(b);

				}
			}else {
					System.out.print(b);

			}
		

		}else {
		
	 if(B == C) {
		 System.out.print(b);
	 }else {
		 if(A == C) {
			 System.out.print(b);
		 }else {
			System.out.print(a);
	}
		}
		}
}
}




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

using namespace std;

int main(){

    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //freopen("input.txt", "r", stdin);

    int a, b, c;

    cin >> a >> b >> c;

    if((a <= c  && c <= b) || (a >= c && c >= b))
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define ll long long

using namespace std;

ll mod = 1e9 + 7;

void
solve() {
  ll n;
  cin>>n;

  vector<double> p(n);
  for (ll i=0; i<n; i++)
    cin>>p[i];

  vector<double> dp(2), temp;
  dp[1] = p[0];
  dp[0] = 1-p[0];
  for (ll i=1; i<n; i++) {
    temp = vector<double>(dp.size()+1, 0);
    for (ll j=0; j<dp.size(); j++) {
      temp[j] += dp[j] * (1-p[i]);
      temp[j+1] += dp[j] * p[i];
    }

    swap(dp, temp);
  }

  double ans = 0;
  for (ll i=0; i<dp.size(); i++) 
    if (i > (n-i))
      ans += dp[i];
  printf("%.10lf\n", ans);
}

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

  ll t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 4036
# code-festival-2016-qualcB - K個のケーキ / K Cakes
def main():
    # sandwich A[:-1] with A[-1]
    K, T = tuple(map(int, input().split()))
    A = sorted(map(int, input().split()))
    ans = max(0, A[-1] - 1 - sum(A[:-1]))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include <iostream>
#include <utility>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int,int> D;
int P[100005];
vector<int> G[100005];
int main( void )
{
  ios::sync_with_stdio(false);
  int N, a, b, K, v, p;
  cin >> N;
  for( int i=0; i<N-1; i++ ){
    cin >> a >> b;
    G[b].push_back( a );
    G[a].push_back( b );
  }
  cin >> K;
  priority_queue< D, vector<D>, greater<D> > q;
  for( int i=1; i<=N; i++ ){
    P[i] = -1;
  }
  for( int i=0; i<K; i++ ){
    cin >> v >> p;
    P[v] = p;
    q.push( D(p,v) );
  }
  while( !q.empty() ){
    p = q.top().first;
    v = q.top().second;
    q.pop();
    for( int i=0; i<G[v].size(); i++ ){
      int u = G[v][i];
      if( P[u] >= 0 ){
        if( P[u] != p-1 && P[u] != p+1 ){
          cout << "No" << endl;
          return 0;
        }
      } else {
        P[u] = p + 1;
        q.push( D(P[u], u) );
      }
    }
  }
  cout << "Yes" << endl;
  for( int i=1; i<=N; i++ ){
    cout << P[i] << endl;
  }
}

Measured memory_bytes: 7924
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repeq(i,a,b) for(int i=a;i<=(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, z, w;
    cin >> n >> z >> w;
    vi a(n+1);
    repeq(i,1,n) cin >> a[i];
    //a[0] = z
    vector<vi> x(n,vi(n+1)), y(n,vi(n+1));
    for(int i=n-1; i>=1; --i) {
        x[i][n] = y[i][n] = abs(a[i]-a[n]);
        for(int j=n-1; j>=i+1; --j) {
            x[i][j] = max(x[i][j+1],y[j][j+1]);
            y[i][j] = min(y[i][j+1],x[j][j+1]);
        }
    }
    int best=0;
    rep(i,1,n) {
        int v = y[i][i+1];
        best=max(best,v);
    }
    int ans = max(abs(a[n]-w),best);
    cout<<ans<<endl;
}


Measured memory_bytes: 31744
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

int inputValue();
void inputArray(int *, int);
void inputVector(vector<int> *, int);
template <typename T> void output(T, int);

int main() {
    // source
    int n;
    cin >> n;
    int b = n;
    int index = 10;
    int s = 0;

    while (n != 0) {
        s += n % 10;
        n /= 10;
    }

    if (b % s == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

int inputValue() {
    int a;
    cin >> a;
    return a;
}

void inputArray(int *p, int a) {
    rep(i, a) { cin >> p[i]; }
}

void inputVector(vector<int> *p, int a) {
    rep(i, a) {
        int input;
        cin >> input;
        p->push_back(input);
    }
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}


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

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

    while(t--){
        long long n, a, b, c, d;
        cin >> n >> a >> b >> c >> d;

        map<long long, long long> costs;
        priority_queue<pair<pair<long long, long long>, int> > q;
        q.push({{0, n}, 0});
        long long ans = 1e15;

        while(1){
            auto x = q.top();
            q.pop();

            long long cost = -x.first.first;
            long long num = x.first.second;
            int flag = x.second;

            if(costs.count(num)) continue;
            else{
                costs[num] = cost;
            }

            if((num / 1e9) * d < 2e9) ans = min(ans, cost + num * d);

            if(num == 1) break;

            if(num % 2 == 0){
                q.push({{-cost - a, num / 2}, 0});
            }

            if(num % 3 == 0){
                q.push({{-cost - b, num / 3}, 0});
            }

            if(num % 5 == 0){
                q.push({{-cost - c, num / 5}, 0});
            }

            if(flag > -4){
                q.push({{-cost - d, num - 1}, flag - 1});
            }

            if(flag < 4){
                q.push({{-cost - d, num + 1}, flag + 1});
            }
        }

        cout << ans << endl;
    }

}


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

using namespace std;

const int N = 1e5 + 100, M = 3;

int n, dp[N][M];

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < M; j++) {
			cin >> dp[i][j];
			if (i) {
				int z = 0;
				for (int k = 0; k < M; k++)
					if (j ^ k)
						z = max(z, dp[i - 1][k]);
				dp[i][j] += z;
			}
		}
	}
	cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
const long double PI = acos(-1.0);

#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SORT(v) sort(ALL(v));
#define RSORT(v) sort(RALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;
 
#define HOGE COUT("HOGE")
 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
 
template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}



const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
int main() {
    int n,m;
    cin >> n >> m;
    vector<bool> a(n+2,true);
    REP(i, m){
        IN(int, k);
        a[k] = false;
    }
    vector<mint> dp(n+2,0);
    dp[0] = 1;
    REP(i, n){
        if (a[i+1]) {
            dp[i+1]+=dp[i];
        }
        if (a[i+2]) {
            dp[i+2]+=dp[i];
        }
    }
    COUT(dp[n]);
}


Measured memory_bytes: 3980
#include <iostream>
#include <iomanip>
#include <math.h>

bool IsPrime(int num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	int n;
	int sum = 0;
	std::cin >> n;
	for (int i = 0; i < n; ++i) {
		int value;
		std::cin >> value;
		if (IsPrime(value)) sum++;
	}
	std::cout << sum << std::endl;

}



Measured memory_bytes: 3124
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long K = sc.nextLong();
        long sum = 0;
        long max = N*(N+1)/2; 
        long min = N*(N+1)/2;
        for(long i = N+1; i >= K; i--){
            sum = sum + max - min + 1;
            max = max - N + i - 1; 
            min = min - i + 1;
        }
        System.out.println(sum%(1000000000+7));
    }
} 

Measured memory_bytes: 35808
import java.util.*;
import java.io.*;

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

        int N = Integer.parseInt(sc.next());
        if (N == 1) {
            sc.close();

            out.printf("Hello World\n");
        } else {
            int A = Integer.parseInt(sc.next());
            int B = Integer.parseInt(sc.next());
            sc.close();

            out.printf("%d\n", A + B);
        }

        out.flush();
    }
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vi32 p(a), q(b), r(c);
  cin >> p >> q >> r;
  int pi = 0, qi = 0, ri = 0;
  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());
  sort(r.rbegin(), r.rend());
  int cnt = 0;
  i64 ans = 0;
  while (x + y > cnt) {
    if (x == 0) {
      if (q[qi] >= r[ri]) {
        ans += q[qi++];
        y--;
      } else {
        ans += r[ri++];
        cnt++;
      }
    } else if (y == 0) {
      if (p[pi] >= r[ri]) {
        ans += p[pi++];
        x--;
      } else {
        ans += r[ri++];
        cnt++;
      }
    } else {
      if (p[pi] >= q[qi] && p[pi] >= r[ri]) {
        ans += p[pi++];
        x--;
      } else if (q[qi] >= p[pi] && q[qi] >= r[ri]) {
        ans += q[qi++];
        y--;
      } else {
        ans += r[ri++];
        cnt++;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
    int n,k;
    cin>>n>>k;
    set<int>s;
    while(k--) {
        int d;
        cin>>d;
        while(d--) {
            int a;
            cin>>a;
            s.insert(a);
        }
    }
    cout<<n-s.size()<<endl;
    return 0;

}


Measured memory_bytes: 3580
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,0,-1};
const static int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

int main(){
  int N;
  while(~scanf("%d",&N)){
    for(int m=0;m<N;m++){
      ll bits[9];
      for(int i=0;i<9;i++){
	scanf("%x",bits+i);
      }

      ll key = 0;
      for(int i=0;i<32;i++){
	ll mask = (1LL<<i);
	ll sum = 0;
	for(int j=0;j<8;j++) sum += bits[j] ^ key;
	if((sum & mask) != (bits[8] & mask)){
	    key |= mask;
	}
      }

      printf("%x\n",key);
    }
  }
}

Measured memory_bytes: 1196
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)

#define PI M_PI
#define INF 1000000000
#define MOD 1000000007;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;



int main()
{
	int N;
	cin >> N;
	vi a(N);
	rep(i, N) cin >> a[i];

	int b1, b2, b4;
	rep(i, N)
	{
		if (a[i] % 4 == 0) b4++;
		else if (a[i] % 2 == 0) b2++;
		else b1++;
	}

	if (b2 == 0)
	{
		if (b4 + 1 >= b1) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else
	{
		if (b4 >= b1) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
 int a[3000], b[3000];
int final;
for(int i=0;i<3000;i++){
cin >> a[i] >> b[i];
if(a[i] == 0 && b[i]== 0){
final = i;
 break;
}

}
for(int i=0;i<final;i++){
if(a[i]<b[i])
cout<< a[i] << " " << b[i] << endl;
else 
cout << b[i] << " " << a[i] << endl;
}
return 0;
}



Measured memory_bytes: 3112
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a, b;
    cin >> a >> b;
    ll ans = 0;
    for(int i = 0; i < a.length(); i++) {
    	if(a[i] != b[i]) {
    		ans++;
    	}
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3884
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
void solve()
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	a=min(k,a);
	ll ans=0;
	ans+=a;
	k-=a;
	b=min(k,b);
	k-=b;
	c=min(k,c);
	ans-=k;
	cout<<ans;
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    time_taken_start
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    time_taken_end
}

Measured memory_bytes: 3640
N, Y = map(int, input().split())
Y //= 1000

#a+b+c = n
#10a+5b+c = y
# -> 9a+4b = y-n

#a=(y-n-4b)/9
#b=(y-n-9a)/4

D = Y-N
for i10 in range(D//9 + 1):
  D2 = D-9*i10
  if D2%4:
    continue
  else:
    i5 = D2//4
    if N-i10-i5 >= 0:
      print(i10, i5, (N-i10-i5))
      exit()
print(-1,-1,-1)      

Measured memory_bytes: 3060
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
a=sorted(a)
from collections import deque

if n%2==0:
    front=a[:n//2]
    rear=a[n//2:]
    f1=deque(front)
    f2=deque(front)
    r1=deque(rear)
    r2=deque(rear)
    ans1=0
    ans2=0
    for i in range(n):
        #print(f1,f2,r1,r2)
        if i==0:
            last1=f1.pop()
            last2=r2.popleft()
        elif i%2==1:
            now1=r1.pop()
            now2=f2.popleft()
            ans1+=abs(last1-now1)
            ans2+=abs(last2-now2)
            last1=now1
            last2=now2
        elif i%2==0:
            now1=f1.popleft()
            now2=r2.pop()
            ans1+=abs(last1-now1)
            ans2+=abs(last2-now2)
            last1=now1
            last2=now2
    print(max(ans1,ans2))
else:
    med=a[n//2]
    front=a[:n//2]
    rear=a[n//2+1:]
    f1=deque(front)
    f2=deque(front)
    r1=deque(rear)
    r2=deque(rear)
    ans1=0
    ans2=0
    for i in range(n):
        #print(f1,f2,r1,r2)
        if i==0:
            last1=med
            last2=med
        elif i%2==1:
            now1=r1.pop()
            now2=f2.popleft()
            ans1+=abs(last1-now1)
            ans2+=abs(last2-now2)
            last1=now1
            last2=now2
        elif i%2==0:
            now1=f1.popleft()
            now2=r2.pop()
            ans1+=abs(last1-now1)
            ans2+=abs(last2-now2)
            last1=now1
            last2=now2
    print(max(ans1,ans2))

Measured memory_bytes: 58456
using System;
using System.Linq;

class Atcoder
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine().Split().Select(long.Parse).ToArray();

        var a = s[0];
        var b = s[1];

        var m = Gcd(a, b);

        var gcd = Gcd(a, b);
        long i = 2;
        int res = 1;
        var sqrt = (int)Math.Ceiling(Math.Sqrt(gcd));
        while (i <= sqrt)
        {
            if (gcd % i == 0)
            {
                res++;
                while (gcd % i == 0) gcd /= i;
            }
            i++;
        }
        if (gcd != 1) res++;
        Console.WriteLine(res);
    }

    // ユークリッドの互除法 
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
    
}

Measured memory_bytes: 13396
S = input()
L = len(S)

dp = [[0 for _ in range(L + 1)] for over in range(2)]
dp[0][0] = 0
dp[1][0] = 1

for j, s in enumerate(S, 1):
    n = int(s)
    dp[0][j] = min(dp[0][j - 1] + n, dp[1][j - 1] + (10 - n))
    dp[1][j] = min(dp[0][j - 1] + (n + 1), dp[1][j - 1] + (10 - n - 1))
    
print(dp[0][-1])

Measured memory_bytes: 84936
S = input()
if S[0] == 'R' and S[1]=='R' and S[2]=='R':
  print('3')
elif S[0] == 'R' and S[1]=='R' and S[2]=='S':
  print('2')
elif S[0] == 'S' and S[1]=='R' and S[2]=='R':
  print('2')
elif S[0] == 'S' and S[1]=='S' and S[2]=='R':
  print('1')
elif S[0] == 'S' and S[1]=='R' and S[2]=='S':
  print('1')
elif S[0] == 'R' and S[1]=='S' and S[2]=='S':
  print('1')
elif S[0] == 'R' and S[1]=='S' and S[2]=='R':
  print('1')
elif S[0] == 'S' and S[1]=='S' and S[2]=='S':
  print('0')

  

Measured memory_bytes: 9104
/*
We will not return to the countless mistakes of the past
I will not relive the failures of the man I once was

Only through dedication will I destroy all preconception

No longer will I let myself be truly satisfied with the standard
We will not return to the countless mistakes of the past

Only through dedication will I destroy all preconception

Let this be
Be the day
Day of my
My declaration
Let this be the day of my declaration

Join me,
Walk with me
Shatter the bonds that tie us
To what we strive to never be

Join me,
Walk with me
*/
#include<bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const ll maxn=1000001,mod=1e9+7;


int main(){

int n;
ll sum=0;
int x;
cin>>n;
forn(i,n){
cin>>x;
sum+=x;
}
cout<<sum-n;
return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>  
#include <bitset>
#include <cassert>
#include <ctime>  
#include <cmath>  
#include <cstdlib>  
#include <cstring>  
#include <functional>  
#include <iostream>  
#include <deque>  
#include <stack>
#include <queue>  
#include <vector>  
#include <map>  
#include <set>  
#include <string>  
#include <unordered_map>  
#include <unordered_set>  
#pragma warning(disable:4996)

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

const int INF = 1e9;
const int MAXN = 3e5 + 5;
const int SZ = 1 << 19;

ll N, A[MAXN], B[MAXN], ans;
priority_queue<pll> pq;

void wrong() {
	cout << -1;
	exit(0);
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	for(int i=1; i<=N; i++) cin >> A[i];
	for(int i=1; i<=N; i++) cin >> B[i];

	A[0] = A[N]; A[N+1] = A[1];
	B[0] = B[N]; B[N+1] = B[1];

	for(int i=1; i<=N; i++) {
		if(A[i] > B[i]) wrong();
		if(A[i] < B[i]) pq.push(pii(B[i], i));
	}

	while(!pq.empty()) {
		int i = pq.top().se; pq.pop();

		if(B[i] - A[i] < B[i-1] + B[i+1]) wrong();

		int cnt = (B[i] - A[i]) / (B[i-1] + B[i+1]);
		B[i] -= cnt * (B[i-1] + B[i+1]);
		ans += cnt;

		if(A[i] < B[i]) pq.push(pii(B[i], i));
		if(i == N) B[0] = B[N];
		if(i == 1) B[N+1] = B[1];
	}
	cout << ans;
}


Measured memory_bytes: 10096
N = int( input())
A = [ int( input()) for _ in range(N)]
now = 0
ans = 0
if A[0] != 0:
    ans = -1
else:
   for i in range(1,N):
       # if A[i] > i:
       #     ans = -1
       #     break
       if now + 1 == A[i]:
           ans += 1
           now += 1
       elif now >= A[i]:
           ans += A[i]
           now = A[i]
       else:
           ans = -1
           break
print(ans)

Measured memory_bytes: 11052
#include <map>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char * argv[]) {
    string S;
    cin >> S;

    map<char, int> strmap;
    for(int i = 0; i < S.length(); i++) {
        char c = S[i];
        strmap[c]++;
    }
    if(strmap.size() != 2) {
        cout << "No" << endl;
        return 0;
    }

    for(auto v : strmap) {
        if(v.second != 2) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int,int>P;
#define INF 99999999
#define MOD (ll)(1e9+7)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

/*--------------------------------------------*/
/*ll factorial(ll);
void list_Prime(ll);
ll divisor(ll);*/
/*--------------------------------------------*/


int main(){
   string a,b;cin>>a>>b;
   string num=a+b;
   int n=stoi(num);
   //cout<<n<<endl;
   int flag=0;
   for(int i=2;i<=10000;i++){
       if(n==i*i)flag=1;
   }
   cout<<(flag?"Yes":"No")<<endl;
}











/*--------------------------------------------*/
/*
ll factorial(ll n){
    if(n==1)return 1;
    return n*factorial(n-1);
}


void list_Prime(ll n){//n以下の素数を全て見つける
    ll Limit=(int)sqrt((double)n);
    for(ll i=2;i<=n;i++)prime[i]=1;//最初はみんな素数かも
    //素数の整数倍を消していく(ルートnまで)
    for(ll i=2;i<=Limit;i++){
        if(prime[i]){
            for(ll j=2*i;j<=n;j++){
                if(j%i==0){
                    prime[j]=0;                
                }
            }
        }
    }
}

ll divisor(ll n){
    for(ll i=2;i<=n;i++){
        ll d=1;
        ll tmp=i;
        while(tmp>0){
            d++;
            while(tmp%d==0){
                prime[i]++;
                tmp/=i;
            }
        }
    }
    ll sum=1;
    for(ll i=2;;i<=n;i++){
        sum*=(prime[i]+1)/MOD;
    }    
    cout<<"sum="<<sum<<endl;

    return sum%MOD;
}
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=5005;
const int mod=1e9+7;
int n,sz[N],head[N],cnt;
long long f[N][N],g[N],res[N];
struct edge {int v,nxt;} e[N<<1];
inline int read() {
    int x=0;char ch=getchar();
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
    return x;
}
inline void addedge(int u,int v) {
    e[++cnt]=(edge){v,head[u]},head[u]=cnt;
}
inline void dfs(int u,int fa) {
    sz[u]=f[u][1]=1;
    for (int i=head[u];i;i=e[i].nxt) {
        int v=e[i].v; 
		if (v==fa) continue;
        dfs(v,u);
        for (int j=1;j<=sz[u]+sz[v];j++) res[j]=0;
        for (int j=1;j<=sz[u];++j)
            for (int k=0;k<=sz[v];k++)
                res[j+k]=(res[j+k]+1ll*f[u][j]*f[v][k])%mod;
        sz[u]+=sz[v];
        for (int j=1;j<=sz[u];++j) f[u][j]=res[j];
    }
    for (int i=2;i<=sz[u];i+=2)
        f[u][0]=(f[u][0]-1ll*f[u][i]*g[i]%mod+mod)%mod;
}

int main() {
    n=read();
    for (int i=1;i<n;++i) {
        int u=read(),v=read();
        addedge(u,v),addedge(v,u);
    }
    g[0]=1;
    for (int i=2;i<=n;i+=2) g[i]=1ll*g[i-2]*(i-1)%mod;
    dfs(1,0); 
	printf("%lld\n",mod-f[1][0]);
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  int p[N];
  for(int i = 0; i < N; i++){
    cin >> p[i];
  }
  sort(p, p+N);
  p[N-1] = p[N-1]/2;
  int sum = 0;
  for(int pl : p){
    sum += pl;
  }
  cout << sum << endl;
  return 0;
}


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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 998244353;
const ll LINF = 1e18;

string S;
V idx;

int main() {
    cin >> S;
    int N = S.length();
    idx.emplace_back(-1);
    REP(i, N) {
        if(S[i] != 'A' && S[i] != 'T' && S[i] != 'C' && S[i] != 'G') {
            idx.emplace_back(i);
        }
    }
    idx.emplace_back(N);
    int ans = 0;
    REP(i, idx.size() - 1) { ans = max(idx[i + 1] - idx[i] - 1, ans); }
    cout << ans << "\n";
    return 0;
}


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

int main(){
  long long N;
  cin>>N;
  
  int res=10000;
  
  for(long long i=1;i*i<=N;i++){
    if(N%i==0){
      long long a=N/i;
      int count=to_string(a).size();
      
      res=min(res,count);
    }
  }
  
  cout<<res;
}

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

using namespace std;

#define long long long
#define INF 1e18
#define MOD (long) (1e9 + 7)
#define double __float128

struct Node
{
    long k;
    long count;
    bool visited = false;
    vector<long> adj;
};

long solve(Node &r, auto &nodes, long n)
{
    r.count = r.k * (n - r.k + 1);
    long total = r.count;
    long count = 0;
    r.visited = true;
    for (auto &i : r.adj) {
        Node &u = nodes[i];
        if (u.visited) continue;
        total += solve(u, nodes, n);
        long x = min(r.k, u.k) * (n - max(r.k, u.k) + 1);
        total -= x;
    }
    return total;
}

int main()
{
    long n;
    cin >> n;

    vector<Node> nodes(n+1);
    for (long i = 1; i <= n; i++) {
        nodes[i].k = i;
    }
    for (long i = 0; i < n-1; i++) {
        long u, v;
        cin >> u >> v;
        nodes[u].adj.push_back(v);
        nodes[v].adj.push_back(u);
    }
    long ans = solve(nodes[1], nodes, n);
    printf("%lld\n", ans);
}


Measured memory_bytes: 34176
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(long long I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
ll f(ll b, ll n) {
  if(n < b) return n;
  else return f(b, n / b) + n % b;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, s;
  cin >> n >> s;
  ll ans = 1e15;
  if(n == s) {
    cout << n + 1 << endl;
    return 0;
  } else {
    FOR(b,2,sqrt(n)+1) {
      if(f(b, n) == s) {
        cout << b << endl;
        return 0;
      }
    }
  }
    FOR(p,1,sqrt(n)+1) {
      ll q = s - p;
      if(q < 0) continue;
      if((n - q) % p != 0) continue;
      ll b = (n - q) / p;
      if(b <= 1) continue;
      if(f(b, n) == s) ans = min(ans, b);
    }
  if(ans == 1e15) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define mod 1000000007
#define PI acos(-1)
#include<time.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<map>
#include<queue>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll INF=0x7fffffffffffffff;
const int inf=0x7fffffff;
const int N=1e5+5;
clock_t start,finish;
void time_in(){start=clock();}
void time_out(){finish=clock();double tim=(double)(finish-start)/CLOCKS_PER_SEC;printf("Running time is %lf\n",tim);}
inline ll mul(ll a,ll b){ll s=0;while(b){if(b&1)s=(s+a)%mod;a=(a<<1)%mod;b>>=1;}return s%mod;}
inline ll pow_mul(ll a,ll b){ll s=1;while(b){if(b&1)s=mul(s,a);a=mul(a,a);b>>=1;}return s;}
inline ll poww(ll a,ll b){ll s=1;while(b){if(b&1)s=(s*a)%mod;a=(a*a)%mod;b>>=1;}return s%mod;}
inline bool read(int &ret){char c=getchar();int sgn;if(c==EOF)return 0;while(c!='-'&&(c<'0'||c>'9'))c=getchar();
	sgn=((c=='-')?-1:1);ret=((c=='-')?0:(c-'0'));while(c=getchar(),c>='0'&&c<='9')ret=ret*10+(c-'0');ret*=sgn;return 1;}
inline void write(int x){if(x>9)write(x/10);putchar(x%10+'0');}
int fact[10]={1,1,2,6,24,120,720,5040,40320,362880};
int st[4][2]={1,0,0,1,-1,0,0,-1};
int t,cas;
int n,m,k;
int f[N<<1];
int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
int main()
{
	int a[N<<1],b[N<<1];
	int x,y;
	while(~scanf("%d",&n))
	{
		for(int i=0;i<(N<<1);i++)f[i]=i,a[i]=b[i]=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d%d",&x,&y);
			f[find(x)]=find(y+N);
		}
		for(int i=0;i<N;i++)
		{
			a[find(i)]++;
			b[find(i+N)]++;
		}
		ll ans=0;
		for(int i=0;i<(N<<1);i++)ans+=((ll)a[i]*b[i]);
		printf("%lld\n",ans-n);
	}
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll 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;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;cin>>n>>m;
    vector<ll> a(n);rep(i,n){cin>>a.at(i);}
    priority_queue<double> pq;
    rep(i,n){pq.push(a.at(i));}
    rep(i,m){
        if(pq.empty()){break;}
        double tmp = pq.top();
        pq.pop();
        tmp /=2;
        if(tmp>=1.0){pq.push(tmp);}
    }
    ll res = 0;
    while(!pq.empty()){
        res += ll(pq.top());
        pq.pop();
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2168
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def S(): return input().rstrip()

def main():
    N = I()
    s = [S() for i in range(N)]    
    c = Counter(s).most_common()
    max_n = c[0][1]
    l = []
    for i in c:
        if i[1] == max_n:
            l.append(i[0])
    for i in sorted(l):
        print(i)
if __name__ == '__main__':
    main()


Measured memory_bytes: 113048
n = int(input())
d = {}
inp = map(int, input().split())

for i in inp:
    if i not in d:
        d[i] = 1
    else:
        d[i] += 1

n = int(input())
inp = map(int, input().split())

fl = 0
for i in inp:
    if i in d:
        if d[i] == 0:
            fl = 1
            break
        d[i] -= 1
    else:
        fl = 1
        break

if fl == 0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 44644
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc = 1; 
    //cin >> tc;
    while(tc--){
        int n; cin >> n;
        int ans = 0;
        string s; cin >> s;
        int r = 0, g = 0, b = 0;
        for(auto x:s)
            if(x == 'R')
                r++;
            else if(x == 'G')
                g++;
            else b++;
        ans = r*g*b;
        FOR(i,0,n)
        {
            FOR(j,1,n)
            {
                int ii = i-j;
                int k = j+i;
                if(ii >= 0 and k < n and ii < n and k >= 0 and s[ii] != s[i] and s[ii] != s[k] and s[i] != s[k])
                    --ans;
            }
        }
        cout << ans;
        
    }    
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  bool num = false;
  //char Sarray[N];
  char S;
  for(int j=0; j<N; j++){
    //cin >> Sarray[j];
    cin >> S;
    if(S == 'Y')
      num = true;
  }
  /*int i=0;
  while(Sarray[i] != 'Y')*/
  if(num)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}
    
  


Measured memory_bytes: 256