akhauriyash/Code-Regression huggingface dataset:
// Lets go to the next level 
// AIM CM at CF *__* asap 
// Hit A,B,C and D faster and reach Candidate Master
// Remember you were also a novice when you started, 
// hence never be rude to anyone who wants to learn something
// Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts 
// Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure.  


#include <bits/stdc++.h>
using namespace std;
#define mod (int)1000000007
#define MOD (int)10000000007
// Big two primes 
#define X 1001100011100001111ll
#define M 26388279066623ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for0e(i, n) for (int i = 0; i <= n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int long long 
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int> 
#define F first
#define S second
#define pi pair<int, int>
#define ppi pair<pair<int,int> , int >
#define vii vector<pi>
const int MAXN = (int)((1e5) + 100);
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}  
int cbrt(int x){ int lo=1,hi=min(2000000ll,x);while(hi-lo>1){int mid=(lo+hi)/2;if(mid*mid*mid<x){lo=mid;}else hi=mid;}if(hi*hi*hi<=x) return hi;else return lo;} 
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const int N =  (int)(1e6+5); 


signed main(){
//   #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
//   #endif
  fio;
    string str;
    cin>>str;
    bool flag;
    for(int i=0;i<str.length();i++){
       if((i+1)&1){
           if(str[i] == 'R' || str[i] == 'U' || str[i] == 'D'){
               flag = true;
           }
           else{
               flag = false;
               break;
           }
       }
       else{
           if(str[i] == 'L' || str[i] == 'U' || str[i] == 'D'){
               flag = true;
           }
           else{
               flag = false;
               break;
           }
       }
    }


    if(flag) cout<<"Yes";
    else cout<<"No";
  rr;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool is[200];
int main(){
	string s;cin>>s;
	for(auto u:s)is[u]=true;
	char f=s[0],se=s[s.length()-1];
	if(f!=se){
		string tt="";tt+=f;tt+=se;
		int cnt=0;
		char now=0;
		for(int i=0;i<s.length();i++){
			if(s[i]==tt[now]){
				now=!now;
			}else cnt++;
		}
		if(cnt&1){
			cout<<"First"<<endl;
		}else{
			cout<<"Second"<<endl;
		}
	}else{
		string tt="";tt+=f;tt+=" ";
		bool win=false;
		for(char i='a';i<='z';i++){
			if(i==f||is[i]==false){
				continue;
			}else{
				tt[1]=i;
				int cnt=0;
				int now=0;
				for(int j=0;j<s.length();j++){
					if(s[j]==tt[now]){
						now=!now;
					}else{
						cnt++;
					}
				}
				if(cnt==0){
					win=false;
					break;
				}
				if(cnt&1){
					win=true;
					break;
				}
			}
		}
		if(win){
			cout<<"First"<<endl;
		}else{
			cout<<"Second"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>
using namespace std;
#define all(x) (x).begin(), (x).end()

const int N = 500000;
const long long MOD = 1e9 + 7;

long long n, L;
string s;

int go[2][500000];
int sz = 1;
int dph[500000];

long long g(long long x)
{
    long long v = 1;
    while (x % 2 == 0) x /= 2, v *= 2;
    return v;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> L;
    for (int i = 0; i < N; i++) go[0][i] = go[1][i] = -1;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        int pnt = 0;
        for (int j = 0; j < s.size(); j++)
        {
            if (go[s[j] - '0'][pnt] == -1)
            {
                go[s[j] - '0'][pnt] = sz;
                dph[sz] = dph[pnt] + 1;
                sz++;
            }
            pnt = go[s[j] - '0'][pnt];
        }
    }
    long long ans = 0;
    for (int i = 0; i < N; i++)
    {
        if ((go[0][i] == -1) + (go[1][i] == -1) == 1)
        {
            ans = ans ^ g(L - dph[i]);
        }
    }
    if (ans == 0)
    {
        cout << "Bob";
    }
    else
    {
        cout << "Alice";
    }
}


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

int main(void){
    int n;
    scanf("%d",&n);
    int i, j, x, y, p, count=0;
    for(i=0;i<n;i++){
        scanf("%d",&x);
        y = sqrt(x);
        p = 1;
        for(j=2;j<=y;j++){
            if(x%j==0){p = 0; break;} 
        }
        if(p==1) count += 1;
    }
    printf("%d\n",count);
}


Measured memory_bytes: 2044
#include <numeric>
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
signed main(){
    int n,k;cin>>n>>k;
    int a[114514];rep(i,0,n)cin>>a[i];
    cout<<(n-1+k-2)/(k-1)<<endl;
    return 0;
}



Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
ans = 0


def resolve():
    n, m, q = map(int, input().split())
    ABCD = [list(map(int, input().split())) for _ in range(q)]

    A = [0] * n

    def dfs(idx):
        global ans
        if idx == n:
            score = 0
            for i in range(q):
                a, b, c, d = ABCD[i]
                if A[b - 1] - A[a - 1] == c:
                    score += d
            ans = max(ans, score)
        else:
            if idx == 0:
                k = 1
            else:
                k = A[idx - 1]

            for i in range(k, m + 1):
                A[idx] = i
                dfs(idx + 1)

    dfs(0)
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9168
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;

int main(void) {
  string s;
  int k;
  cin >> s >> k;
  s += 'x';
  for(int i = 0; i < k; i++) {
    if(s[i] == 'x') {
      cout << 1 << endl;
      return 0;
    }
    if(s[i] != '1') {
      cout << s[i] << endl;
      return 0;
    }
    if(i == k - 1) {
      cout << s[i] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n,T,k,a;
int main() 
{
    cin>>n>>T;
    for(int i=1;i<=T;i++) 
        cin>>a,k=max(k,a);
    cout<<max(k-1-(n-k),0)<<endl;
    return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(void){
 int a,b,c,n;cin >> a >> b >> c >> n;
 ll sum = 0;
 for(int i = 0;i*a<=n;i++){
   for(int j = 0;i*a+j*b<=n;j++){
      int t = n-i*a-j*b;
      int d = t/c;
      if(d*c == t ){
        sum += 1;
        //cout << i <<" "<< j <<" "<< t/c << endl;
      }
   }
 }
 cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int r;

	cin >> r;
	cout << 3 * r * r << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

// 入力は全て正
// 素数判定O(√n)

bool is_prime(int n) {
  for (int i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}

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

  int p = x;
  while (!is_prime(p)) p++;

  cout << p << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int H,W,h,w;

    scanf("%d %d",&H,&W);
    scanf("%d %d",&h,&w);

    int a,b;

    a=H*W;
    a=a-h*W;
    b=H-h;
    a=a-b*w;

    printf("%d\n",a);

    return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {

    val (A, B, Q) = readLine()!!.split(' ').map { it.toInt() }
    val ss = listOf(-100000000000L, *((0 until A).map { readLine()!!.toLong() }.toTypedArray()), 100000000000L)
    val ts = listOf(-100000000000L, *((0 until B).map { readLine()!!.toLong() }.toTypedArray()), 100000000000L)
    val xs = (0 until Q).map { readLine()!!.toLong() }

    xs.forEach { x ->

        val si = -(ss.binarySearch(x) + 1)
        val ti = -(ts.binarySearch(x) + 1)

        val res = arrayOf(ss[si - 1], ss[si]).map { s ->
            arrayOf(ts[ti - 1], ts[ti]).map { t ->
                val d1 = Math.abs(x - s) + Math.abs(s - t)
                val d2 = Math.abs(x - t) + Math.abs(t - s)
                Math.min(d1, d2)
            }.min()!!
        }.min()!!

        println(res)
    }

}

Measured memory_bytes: 79680
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

N=intput()
A=lint()
B=lint()
C=lint()
A.sort()
B.sort()
C.sort()
AB=[0]*N
A.append(INF)
a=0
b=0
while b<N:
    if A[a]<B[b]:
        a+=1
    else:
        AB[b]=(AB[b-1] if b>0 else 0)+a
        b+=1
ABC=[0]*N
AB=[0]+AB[:]
B.append(INF)
b=0
c=0
while c<N:
    if B[b]<C[c]:
        b+=1
    else:
        ABC[c]=(ABC[c-1] if c>0 else 0)+AB[b]
        c+=1
print(ABC[-1])

Measured memory_bytes: 101056
#include <algorithm>
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
inline char gc() {
	return getchar();
	static char buf[100000],*l=buf,*r=buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void rd(T &x) {
	x=0; int f=1,ch=gc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=gc();}
	x*=f;
}
template<class T> inline bool Cmax(T &x,T y) {return x<y?x=y,1:0;}
template<class T> inline bool Cmin(T &x,T y) {return x>y?x=y,1:0;}
typedef long long ll;
const int inf=1e9+1;
const int maxN=50+5;
const int maxn=maxN*maxN*maxN;
int N,X,D,p[maxN];
int num0[maxN],num1[maxN];
int dp[maxn];
struct node {
	ll x; int y,id;
	inline bool operator <(const node &other) const {
		return y*other.x>other.y*x;
	}
} a[maxN];
int sol(int X) {
	int an=0;
	for(int i=1;i<=N;++i) {
		int d=min(num0[i],int(X/a[i].x));
		an+=d*a[i].y,X-=d*a[i].x;
	}
	return an;
}
int main() {
	rd(N),rd(X),rd(D);
	rd(a[1].x),a[1].id=1;
	for(int i=2;i<=N;++i) rd(a[i].x),rd(p[i]),a[i].id=i;
	for(int i=N;i>=1;--i) {
		++a[i].y;
		a[p[i]].x+=a[i].x,a[p[i]].y+=a[i].y;
	}
	sort(a+1,a+N+1);
	for(int i=1;i<=N;++i) {
		num0[i]=a[i].id==1?inf:D;
		num1[i]=min(num0[i],N),num0[i]-=num1[i];
	}
	int n=N*N*N;
	for(int i=1;i<=n;++i) dp[i]=inf;
	for(int i=1;i<=N;++i) {
		for(int j=1,t=num1[i];t;t-=j,j=min(j<<1,t)) {
			int v=a[i].y*j; ll w=a[i].x*j;
			for(int k=n;k>=v;--k) dp[k]=min((ll)dp[k],dp[k-v]+w);
		}
	}
	int an=0;
	for(int i=0;i<=n;++i) if(dp[i]<=X) {
//		debug("%d %d\n",i,dp[i]);
		Cmax(an,i+sol(X-dp[i]));
	}
	printf("%d\n",an);
	return 0;
} 

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

bool isprime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

int main(){
    int n;
    cin>>n;
    if(isprime(n)) cout<<n<<endl;
    else{
        n++;
        while(!isprime(n)){
            n++;
        }
        cout<<n<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;


int main(void)
{
	map<char,string> MP; cin >> MP['a'] >> MP['b'] >> MP['c'];
	map<char, int> mp;
	mp['a'] = 0, mp['b'] = 0, mp['c'] = 0;
	char tmp = 'a', winner;
	while (true) {
		if (tmp == 'a') {
			tmp = MP['a'][mp['a']];
			mp['a']++;
		}
		else if (tmp == 'b') {
			tmp = MP['b'][mp['b']];
			mp['b']++;
		}
		else if (tmp == 'c') {
			tmp = MP['c'][mp['c']];
			mp['c']++;
		}

		if (mp[tmp] >= MP[tmp].length()) {
			winner = tmp;
			break;
		}
	}
	char WINNER = winner + 'A' - 'a';
	cout << WINNER << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <algorithm>
#include <iterator>

using namespace std;

int main(int argc, char* argv[]) {
  int N, M;
  cin >> N >> M;

  set<int> first;
  set<int> last;
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      first.insert(b);
    else if (b == N)
      last.insert(a);
  }

  set<int> intersect;

  set_intersection(first.begin(), first.end(), last.begin(), last.end(),
                   inserter(intersect, intersect.end()));

  if (intersect.size() > 0)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  return 0;
}

Measured memory_bytes: 9600
from collections import deque
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  x1 = 0
  for i in range(n):
    if i%2 == 0:
      x1  += a[i]
    else:
      x1  -= a[i]
  query = deque([x1])
  x = x1
  for i in range(n-1):
    tmp = a[i]-x//2
    tmp *= 2
    query.append(tmp)
    x  = tmp
  print(*query)
solve()


Measured memory_bytes: 14512
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;
// const ll mod =  998244353 ;
const ll mod =  1000000007 ;
const ll inf = 9;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
template<typename T, typename F> ll sum(T begin, T end, F func) {return accumulate(begin, end, 0ll, func);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

using Pair = pair<ll, ll>;

signed main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> l(n);
  REP(i, n) cin >> l[i];
  sort(all(l));
  ll ans = 0;
  REP(i, n) {
    REP_FROM(j, i+1, n) {
      auto upper = lower_bound(all(l), l[j] + l[i]);
      ans += upper - l.begin() - j - 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
 
int main() {
    int n,d;
    cin >> n >>d;
    int a[n][d];
    for(int i=0;i<n;i++){
      for(int j=0;j<d;j++){
      cin >> a[i][j];
      }
    }
    int sum=0;
    int h;
    int t;
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        h = 0;
        for(int k=0;k<d;k++){
        h += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
        }
        t = (int)sqrt(double(h));
        if( t*t == h ) sum++;
        else sum += 0;
      }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MN 3000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
char s[MN*2+5];
int n,posb[MN+5],posa[MN+5],anum,bnum,match[MN*2+5],no[MN*2+5];
string f[MN*2+5];
string Max(string a,string b)
{
    int n=a.length(),m=b.length();
    for(int j=0;j<min(n,m);++j)
    {
        if(a[j]<b[j]) return b;
        if(a[j]>b[j]) return a;
    }
    return n<=m?b:a;
}
int main()
{   
    n=read();scanf("%s",s+1);
    for(int i=1;i<=n<<1;++i)
        if(s[i]=='a') posa[++anum]=i;
        else posb[++bnum]=i;
    for(int i=1;i<=n;++i) match[posa[i]]=posb[i],match[posb[i]]=posa[i],no[posb[i]]=no[posa[i]]=i;
    for(int i=n<<1;i;--i)
        if(match[i]<i) f[i]=f[i+1];
        else if(s[i]=='a') f[i]=Max(f[i+1],string("ab")+f[match[i]+1]);
        else
        {
            int j=no[i],k=no[i];
            while(k<n&&posb[k+1]<posa[k]) ++k;
            for(int l=i;l<=posa[k];++l)
                if(no[l]>=j&&no[l]<=k) f[i]+=s[l];
            f[i]=Max(f[i]+f[posa[k]+1],f[i+1]);
            //cout<<i<<" "<<j<<" "<<k<<" "<<f[i]<<endl;
        }
    cout<<f[1];
    return 0;
}

Measured memory_bytes: 11136
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    int x;cin>>x;
    v[i]=x;
  }
  vector<int> c(n);
  c[0]=0;c[1]=abs(v[0]-v[1]);
  for(int i=2;i<n;i++){
    c[i]=min(c[i-2]+abs(v[i]-v[i-2]),c[i-1]+abs(v[i]-v[i-1]));
  }
  cout<<c[n-1];
}


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

using namespace std;

struct random_class {
	struct xorshift {
		using result_type = unsigned int;
		result_type x=123456789u,y=362436069u,z=521288629u,w;
		static constexpr result_type min() {return 0u;}
		static constexpr result_type max() {return UINT_MAX;}
		xorshift(result_type a) : w(a) {}
		result_type operator()() {
			result_type t;
			t = x ^ (x << 11);
			x = y; y = z; z = w;
			return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
		}
	};
	random_device rd;
	xorshift xor128;
	using u64 = uint_fast64_t;
	random_class() : rd(), xor128(rd()) {}
	random_class(unsigned int seed) : rd(), xor128(seed) {}
	u64 make_random(u64 min_v, u64 max_v) { return uniform_int_distribution<u64>(min_v, max_v)(xor128);}
	u64 make_random_max() { return uniform_int_distribution<u64>(numeric_limits<u64>::min(), numeric_limits<u64>::max())(xor128);}
};

random_class R;

template<class T>
struct Treap {
	struct node {
		T val;
		uint_fast64_t pri;
		node *lch, *rch;
		int cnt;
		node(T v) : val(v), lch(nullptr), rch(nullptr), cnt(1) {
			pri = R.make_random_max();
		}
	};
	node* top;
	Treap(node* t = nullptr) : top(t) {}
	node* update(node* n) {
		n->cnt = count(n->lch) + count(n->rch) + 1;
		return n;
	}
	inline int count(node* n) {
		return !n ? 0 : n->cnt;
	}
	node* merge(node* l, node* r) {
		if (!l || !r) return !l ? r : l;
		if (l->pri > r->pri) {
			l->rch = merge(l->rch, r);
			return update(l);
		} else {
			r->lch = merge(l, r->lch);
			return update(r);
		}
	}
	pair<node*, node*> split(node* t, int k) {
		if (!t) return make_pair(nullptr, nullptr);
		if (k <= count(t->lch)) {
			pair<node*, node*> s = split(t->lch, k);
			t->lch = s.second;
			return make_pair(s.first, update(t));
		} else {
			pair<node*, node*> s = split(t->rch, k - count(t->lch) - 1);
			t->rch = s.first;
			return make_pair(update(t), s.second);
		}
	}
	void insert(const T&& val) {
		int pos = 0;
		node* n = top;
		while (n) {
			if (val < n->val) n = n->lch;
			else pos += count(n->lch) + 1, n = n->rch;
		}
		auto t = split(top, pos);
		n = merge(t.first, new node(val));
		top = merge(n, t.second);
	}
	void insert(const T& val) { insert((T&&) val);}
	const T& at(int idx) {
		assert(0 <= idx && idx < size());
		node* n = top;
		for (int sz = count(n->lch) + 1; sz != idx + 1; sz = count(n->lch) + 1) {
			if (sz <= idx) idx -= sz, n = n->rch;
			else n = n->lch;
		}
		return n->val;
	}
	inline const int size() {
		return count(top);
	}
};

int main() {
	Treap<int> T;
	int N;
	cin >> N;
	vector<int> v;
	for (int i = 0; i < N; i++) {
		int t; cin >> t;
		t -= i;
		T.insert(t);
		v.push_back(t);
	}
	int b = T.at(N / 2);
	long long res = 0;
	for (auto x : v) {
		res += abs(x - b);
	}
	cout << res << endl;
}

Measured memory_bytes: 10356
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  string N;
  int K;
  cin >> N >> K;

  int memo[110][4][2];
  rep(i, 0, 110) rep(j, 0, 4) rep(k, 0, 2) memo[i][j][k] = INF;
  auto dfs = [&](auto fun, int i, int k, bool less) -> int {
    if (k < 0) return 0;
    if (i == sz(N)) {
      return k == 0;
    }
    auto &MEMO = memo[i][k][less];
    if (MEMO != INF) return MEMO;

    int ret = 0;
    if (less) {
      rep(d, 0, 10) { ret += fun(fun, i + 1, k - (d != 0), true); }
    } else {
      {
        int d = N[i] - '0';
        ret += fun(fun, i + 1, k - (d != 0), false);
      }
      rep(d, 0, N[i] - '0') { ret += fun(fun, i + 1, k - (d != 0), true); }
    }
    return MEMO = ret;
  };
  cout << dfs(dfs, 0, K, false) << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
		sc.close();
		long ans = a * c;
		ans = Math.max(ans, a * d);
		ans = Math.max(ans, b * c);
		ans = Math.max(ans, b * d);
		System.out.println(ans);
	}
}


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

int main() {
    ll n,k;
    std::cin >> n>>k;
    vector<ll> a(n);
    vector<ll> f(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        std::cin >> f[i];
    }
    sort(a.begin(),a.end());
    sort(f.rbegin(),f.rend());
    
    ll r = 1e14;
    ll l = -1;
    while(r-l>1){
        ll m = (r+l)/2;
        ll rem = k;
        for (int i = 0; i < n; i++) {
            if(a[i]*f[i]>m){
                rem -= ( (a[i]*f[i]-m)+f[i]-1) /f[i];
            }
        }
        if(rem<0){
            l = m;
        }else{
            r = m;
        }
    }
    std::cout << r << std::endl;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define V vector
#define pb push_back
#define mkp make_pair
#define pi pair<int,int>//struct pi {int fi,se;};
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define ln length()
#define sz size()
const int N=100005;
///////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    // int t;cin>>t;while(t--)
    {
        int i,j,k,n,m,ans=1000,cnt=0,sum=0,minn = INT_MAX,maxx = 0,pre;
        cin>>n;
        int a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        pre = a[0];
        rep(i,1,n){
            if(a[i] > pre){
                j = ans/pre;
                //k = ans%pre;
                ans -= (j*pre);
                ans += (j*a[i]);
                pre = a[i];
            }
            if(a[i] < pre){
                pre = a[i];
            }
        }
        cout << ans <<endl;
    }
}

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

const int INF = 0x3fffffff;

int K;
int N;
char buf[114514];
int match[14][14];
int dp[1 << 14][14];
string tmp[114];
vector<string> names;

bool cmp(const string &a, const string &b) {
  /*if (a.size() != b.size()) */return a.size() < b.size();
}

bool Contains(string &s, string &p) {
  for (size_t i=0; i<=s.size()-p.size(); i++) {
    if (s.substr(i, p.size()) == p) return true;
  }
  return false;
}

int Match(string &s, string &t) {
  int ret = (int)min(s.size(), t.size());
  while (ret > 0) {
    if (s.substr(s.size()-ret, ret) == t.substr(0, ret)) return ret;
    ret--;
  }
  return ret;
}

int main() {
  while (1) {
    scanf("%d", &K);
    if (K == 0) return 0;

    for (int i=0; i<K; i++) {
      scanf("%s", buf);
      tmp[i] = buf;
    }
    sort(tmp, tmp+K, cmp);

    names.clear();
    for (int i=0; i<K; i++) {
      bool found = false;

      for (int j=i+1; j<K; j++) {
        if (Contains(tmp[j], tmp[i])) {
          found = true;
          break;
        }
      }

      if (!found) {
        names.emplace_back(tmp[i]);
      }
    }

    N = names.size();
    for (int i=0; i<N; i++) {
      for (int j=0; j<N; j++) {
        if (i == j) continue;
        match[i][j] = Match(names[i], names[j]);
      }
    }

    int lim = 1 << N;
    fill(dp[0], dp[lim], INF);
    for (int i=0; i<N; i++) {
      dp[1 << i][i] = names[i].size();
    }
    
    for (int st=0; st<lim; st++) {
      for (int i=0; i<N; i++) {
        if (dp[st][i] == INF) continue;
        for (int j=0; j<N; j++) {
          if (st >> j & 1) continue;
          int nst = st | (1 << j);
          int k = match[i][j];
          dp[nst][j] = min(dp[nst][j], dp[st][i] + ((int)names[j].size()) - k);
        }
      }
    }

    int ans = INF;
    for (int i=0; i<N; i++) {
      ans = min(ans, dp[lim-1][i]);
    }
    printf("%d\n", ans);
  }
}



Measured memory_bytes: 4196
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {

        static void Main()
        {
            //ここから
            DateTime date = DateTime.Parse(Console.ReadLine());
            DateTime heisei = DateTime.Parse("2019/4/30");
            string ans;
            if (date <= heisei)
            {
                ans = "Heisei";
            }
            else
            {
                ans = "TBD";
            }

            //ここまで


            Console.WriteLine(ans);
            Console.ReadKey();
        }


        static public void Swap<T>(ref T a,ref T b) { T temp = a;a = b;b = temp; }
        static public long GCD(int a, int b){ return b != 0 ? GCD(b, a % b) : a;}
        static public long LCM(int a, int b){ return (long)a * b / GCD(a, b); }



        
        static public string ReadLineToString(){return Console.ReadLine();}
        static public int ReadLineToInt(){return int.Parse(Console.ReadLine());}
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public string[] ReadLineToStringArray(){return Console.ReadLine().Split(' ').ToArray();}
        static public int[] ReadLineToIntArray(){return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();}
        static public long[] ReadLineToLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<string> ReadLineToStringList(){return Console.ReadLine().Split(' ').ToList();}
        static public List<int> ReadLineToIntList(){return Console.ReadLine().Split(' ').Select(int.Parse).ToList();}
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }



    }
}


Measured memory_bytes: 13660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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 divisor(ll n,map<ll,ll>&mp){
    for(long long i = 1; i * i <= n; i++) {
        if(n%i==0){
            mp[i]++;
            if (!(i * i == n)) mp[n / i]++;
        }
    }
    return;
}
int main(){
    ll n;
    cin >> n;
    map<ll, ll> mp;
    divisor(n,mp);
    ll ans = 0;
    for (auto i:mp){
        if (i.first == 1) continue;
        ll t = i.first;
        t--;
        if (n / t == n % t) ans += t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3860
use std::io::Read;
use std::str::SplitWhitespace;
use std::str::FromStr;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse<T> {
    fn parse(&mut self) -> T;
}

impl<'a, T> Parse<T> for SplitWhitespace<'a>
where
    T: FromStr,
{
    fn parse(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n: usize = iter.parse();
    let hs: Vec<u32> = (0..n).map(|_| iter.parse()).collect();

    let mut c = 0;
    for (i, &h) in hs.iter().enumerate() {
        if i == 0 {
            c += 1;
            continue;
        }

        if (0..i).all(|j| hs[j] <= h) {
            c += 1;
        }
    }

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

Measured memory_bytes: 4352
import java.util.*;
class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        if(n==m){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main()
{
    int x, n;
    cin >> x >> n;
    set<int> s;
    rep(i, n) {
        int p;
        cin >> p;
        s.insert(p);
    }

    int diff = 114514;
    int ans = 0;
    rep(i, 102) {
        if(s.find(i) != s.end()) continue;
        if(abs(x-i) < diff) {
            diff = abs(x-i);
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
	int n, m, c, matrix[100][100], vector[100];
	int i, j;

	scanf("%d %d", &n, &m);

	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d", &matrix[i][j]);
		}
	}
	for(j=0;j<m;j++)
		scanf("%d", &vector[j]);


	for(i=0;i<n;i++){
		c = 0;

		for(j=0;j<m;j++)
			c += matrix[i][j] * vector[j];

		printf("%d\n", c);
	}

	return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std; 

int M, a, b, t[100000], vis[100000], c[100000];
vector<int>v[100000];
ll res, A, B, C, N;

int T(int x) {
	if (t[x] < 0)return x;
	return t[x] = T(t[x]);
}

void U(int x, int y) {
	x = T(x);
	y = T(y);
	if (x != y) {
		if (t[x] < t[y]) {
			t[x] += t[y];
			t[y] = x;
		}
		else {
			t[y] += t[x];
			t[x] = y;
		}
	}
}

void dfs(int x, int t) {
	vis[x] = t;
	for (int i : v[x]) {
		if (!vis[i]) {
			dfs(i, (t & 1) + 1);
		}
	}
}

int main() {
	cin >> N >> M;
	memset(t, -1, sizeof t);
	for (int i = 0; i < M; ++i) {
		cin >> a >> b;
		--a;
		--b;
		v[a].push_back(b);
		v[b].push_back(a);
		U(a, b);
	}
	for (int i = 0; i < N; ++i) {
		if (!vis[i]) {
			dfs(i, 1);
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j : v[i]) {
			if (vis[i] == vis[j]) {
				c[T(i)] = 1;
			}
		}		
	}
	for (int i = 0; i < N; ++i) {
		if (t[i] < 0) {
			if (v[i].empty()) {
				++C;
			}
			else if (c[i]) {
				++A;
			}
			else {
				++B;
			}
		}
	}
	for (int i = 0; i < N; ++i) {
		if (t[i] < 0) {
			if (v[i].empty()) {
				res += N;
			}
			else if (c[i]) {
				res += A + B + C * -t[i];
			}
			else {
				res += A + B * 2 + C * -t[i];
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<sqrt(n);i++)
    {
        if(n%i==0)
        {
          c++;
        }
    }
    c=c*2;
    if(pow(sqrt(n),2)==(sqrt(n)*sqrt(n)))
        c++;
    return  c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
  string str;
  cin>>str;
  int cmin=INT_MAX;
  for(int i=0;i<=str.length()-3;i++)
  {
    int h=(str[i]-48)*100 + (str[i+1]-48)*10 + str[i+2]-48;
     cmin=min(cmin,abs(h-753));
  }
  cout<<cmin;
  
 return 0;
}








Measured memory_bytes: 3600
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var N = cin.ReadInt;
            var A = cin.ReadInt;
            var B = cin.ReadInt;

            int ans = 0;
            for (int i=1; i<=N; ++i)
            {
                var cnt = 0;
                int tmp = i;
                while (tmp != 0)
                {
                    cnt += tmp%10;
                    tmp /= 10;
                }
                if (A <= cnt & cnt <= B)
                    ans += i;
            }
            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11348
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    int count=0;
    std::cin >> s;
    for (int i=0;i<s.size();i++){
        if (s[i]=='x')count++;
    }
    if(count>7)
    std::cout << "NO" << std::endl;
    else
    std::cout << "YES" << std::endl;
}


Measured memory_bytes: 256
while 1:
    n,m=map(int,input().split())
    if n==m==0:break
    ai=0
    nl=[n]
    while 1:
        ai+=1
        ni=int("".join(map(str,sorted(str(n).zfill(m))[::-1])))-int("".join(map(str,sorted(str(n).zfill(m)))))
        if ni in nl:
            break
        else:
            n=ni
            nl.append(ni)
    print(nl.index(ni),ni,ai-nl.index(ni))


Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <cmath>

using ll = long long;

int main()
{
    std::string S;
    std::cin >> S;

    char now = '0';
    char now2 = '1';
    int cnt = 0;
    int cnt2 = 0;
    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] != now)
        {
            cnt++;
        }
        if (S[i] != now2)
        {
            cnt2++;
        }
        now = '1' - now + '0';
        now2 = '1' - now2 + '0';
    }

    std::cout << std::min(cnt, cnt2) << std::endl;

    return 0;
}

Measured memory_bytes: 512
n, x = map(int, input().split())

a = list(map(int, input().split()))

a = sorted(a)
ans = 0
f = 1
for i in range(n):
    x -= a[i]
    if x<0:
        f = 0
        break
    ans += 1
    
if x != 0 and f == 1:
    ans -= 1
    
print(ans)


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

First = True
ans = 1
status = None
for i in range(1, N):
    if First:
        if A[i-1] < A[i]:
            status = "up"
            First = False
            continue
        elif A[i-1] > A[i]:
            status = "down"
            First = False
            continue

    if (status == "up") & (A[i-1] > A[i]):
        ans += 1
        First = True
        continue

    if (status == "down") & (A[i-1] < A[i]):
        ans += 1
        First = True
        continue

print(ans)






Measured memory_bytes: 14252
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 10000000;
using namespace std;
/** Problem0175 : A King in Hawaii **/
int main()
{
	int n;
	while (cin>>n, n!=-1) {
		string ans;
		while (1) {
			ans+=(n%4)+'0';
			n/=4;
			if (n == 0) break;
		}
		reverse(ans.begin(), ans.end());
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
using llint = long long int;
using namespace std;

int main() {
    fastIO;

    unsigned long long int a, b, k;
    cin >> a >> b >> k;
    if (a + b < k)
        cout << 0 << " " << 0 << endl;
    else if (a >= k)
        cout << a - k << " " << b << endl;
    else
        cout << 0 << " " << b - (k - a) << endl;
}


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
	char X[1000],A[1000];
	int N,D,count=0;
	cin >> N;
	cin >> X;
	cin >> D;
	for(int i=0;i<=N;i++){
		A[i] = X[i];
	}
	for(int i=0;i<N;i++){
		if(count == D){
			break;
		}
		if(X[i]=='0'){
			A[i]='1';
			count++;
		}
	}
	if(count < D){
		for(int i=N-1;i>=0;i--){
			if(count == D){
				break;
			}
			if(X[i]=='1'){
				A[i]='0';
				count++;
			}
		}
	}
	cout << A << "\n";
	return 0;
}

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



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

using namespace std;



typedef long long ll;

typedef pair<int,int> P;




int main(){

int n ; cin >>n ;
vector<int> A(n);
vector<int> B(n);
vector<int> C(n-1);
rep(i,n){//この配列に入ってるものの順番に飯を食う。
	cin>>A[i];
  }
rep(i,n){
	cin>>B[i];
  }
rep(i,n-1){
	cin>>C[i];
  }
  int bef=0;//1 ko mae ni tabeta yatu
  int ans = 0;//manzokudoh
  rep(i,n){
	int a;
	a=A[i];//A i の飯、配列的にはA[i]-1 を見る	
	ans += B[a-1];
	if(bef==a-1&&i>0){
		ans+=C[a-2];
	//	cout<<ans<<endl;
	//	cout<<"C足したよ"<<endl;
	  }
	bef=a;
	//cout<<"bef:"<<bef<<endl;
	}
	cout << ans <<endl;


}

	



Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())

xmove, ymove = tx - sx, ty- sy
move = "U"*ymove + "R" * xmove + "D" * ymove + "L" * xmove
move += "L" + "U" * (ymove+1) + "R" * (xmove+1) + "DR" + "D" * (ymove+1) + "L" * (xmove+1) + "U"
print(move)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  priority_queue<double,vector<double>,greater<double> > s;
  REP(i,N){
    double v;
    cin>>v;
    s.push(v);
  }
  while(s.size()>=2){
    double v1,v2;
    v1=s.top();
    s.pop();
    v2=s.top();
    s.pop();
    s.push((v1+v2)/(double)2.0);
  }
  //固定小数点
  cout<<fixed;
  //桁数固定
  cout<<setprecision(6);
  cout<<s.top()<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a,b,x,t = 0;

    scanf("%d%d", &a,&b);
    for(int i = 0; i < a; i ++){
        scanf("%d",&x);
        if(b <= x){
            t ++;
        }
    }
    printf("%d",t);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <cstdio>
#include <iomanip>
#include <tuple>
#include <stack>
using namespace std;
typedef long long ll;

int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

int lcm(int a,int b){
    return a*b/gcd(a,b);
}

int main(){
    ll a,b,c,d,e,m,n,o1=0,o2=0,o3=0,p,q,r,x,y,z,max1=0,ans=0,o=0;
    string s,t,u;
    cin>>a;
    for(ll i=0;i<50000;i++){
         double aa=i*1.08;
        ll bb=aa;
        if(bb==a){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
}






Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    double n;
    while(cin>>n,n>=0){
        string str = "";
        int a = n;
        double b = n - (int)n;
        if(a > (1<<8)){
            cout<<"NA"<<endl;
            continue;
        }
        b*=2;
        for(int i = 0;i < 4;i++){
            int x = 0;
            if(b>=1)x = 1;
            str += (char)(x + '0');
            if(b>=1.0)b-=1.0;
            b*=2;
        }
        if(b>=1.0)b-=1.0;
        if(b>1e-8){
            cout<<"NA"<<endl;
            continue;
        }
        str = '.' + str;
        for(int i = 0;i < 8;i++){
            str = char(a%2 + '0') + str;
            a /= 2;
        }
        cout<<str<<endl;
    }
}

Measured memory_bytes: 1232