akhauriyash/Code-Regression huggingface dataset:
### constant

MAX_D = 6

WEST = 0
EAST = 1

D_FW = 0
D_BW = 1

EW2D = { 'W' => WEST, 'E' => EAST }

### main

loop do
  x, y = gets.split.map(&:to_i)
  break if (x | y) == 0

  x2 = x * 2
  
  edges = x2.times.map{x2.times.map{nil}}
  nbrs = x2.times.map{[]}
  y.times do
    pis, qis = gets.strip.split
    pi = (pis[0].to_i << 1) + EW2D[pis[1]]
    qi = (qis[0].to_i << 1) + EW2D[qis[1]]
    edges[pi][qi] = edges[qi][pi] = true
    nbrs[pi] << qi
    nbrs[qi] << pi
  end
  #p edges

  st = []
  x.times do
    tr = gets.strip
    st << (tr == '-' ? '' : tr)
  end
  #p st

  gl = []
  x.times do
    tr = gets.strip
    gl << (tr == '-' ? '' : tr)
  end
  #p gl

  dists = {}
  dists[st] = 1
  dists[gl] = -1
  q = [[st, D_FW], [gl, D_BW]]

  min_d = nil
  
  while ! q.empty?
    u, ufb = q.shift
    #p [dists[u], ud, u]

    nvd = dists[u] + (ufb == D_FW ? 1 : -1) 

    for i in (0...x)
      tri = u[i]
      next if tri == ''

      uiw = i * 2 + WEST
      uie = i * 2 + EAST
      
      for j in (0..tri.length)
        triw = tri[0...j]
        trie = tri[j...tri.length]

        if triw != ''
          for view in nbrs[uiw]
            vi = view >> 1
            vew = view & 1

            v = u.clone
            v[i] = trie
            v[vi] = (vew == WEST) ? triw.reverse + v[vi] : v[vi] + triw

            if dists[v].nil?
              dists[v] = nvd
              q << [v, ufb]
            elsif ufb == D_FW && dists[v] < 0
              min_d = nvd - dists[v] - 2
              break
            elsif ufb == D_BW && dists[v] > 0
              min_d = -nvd + dists[v] - 2
              break
            end
          end
        end
        break if min_d
        
        if trie != ''
          for view in nbrs[uie]
            vi = view >> 1
            vew = view & 1

            v = u.clone
            v[i] = triw
            v[vi] = (vew == EAST) ? v[vi] + trie.reverse : trie + v[vi]

            if dists[v].nil?
              dists[v] = nvd
              q << [v, ufb]
            elsif ufb == D_FW && dists[v] < 0
              min_d = nvd - dists[v] - 2
              break
            elsif ufb == D_BW && dists[v] > 0
              min_d = -nvd + dists[v] - 2
              break
            end
          end
        end
        break if min_d
      end
      break if min_d
    end
    break if min_d
  end

  puts min_d
end

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

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

  if (a+b==3) {
    cout << "3" << endl;
  }
   if (a+b==4) {
    cout << "2" << endl;
  }
   if (a+b==5) {
    cout << "1" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

int main()
{
	long long int A, B;
	cin >> A >> B;

	cout << (A*B)/gcd(A, B) << "\n";

	return 0;

}

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

typedef long long ll;
int cnt;
ll ans;
string str;

inline int getint() {
	char ch = getchar(); int res = 0, ops = 1;
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') ops = 0;
	for(; isdigit(ch); ch = getchar()) res = res * 10 + ch - '0';
	return ops ? res : -res;
}

int main() {
	cin >> str;
	for(int i = 0; i < str.length(); i++) {
		if(str[i] == 'B') cnt++;
		else ans += (ll)cnt;
	}
	cout << ans << endl;
	return 0;
} 

/*
BBBWWWBWBWBWWWBBW
*/

Measured memory_bytes: 640
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    ll n, h;
    cin >> n >> h;

    vector<ll> a(n), b(n);
    rep(i, n){
        cin >> a.at(i) >> b.at(i);
    }

    sort(b.rbegin(), b.rend());
    ll amax = 0;
    rep(i, n){
        amax = max(amax, a.at(i));
    }

    ll cnt = 0;
    rep(i, n){
        if(amax>b.at(i)){
            break;
        }

        h -= b.at(i);
        cnt++;
        if(h<=0){
            break;
        }
    }

    if(h<=0){
        cout << cnt << endl;
    }
    else{
        ll tmp = (h+amax-1)/amax;
        cout << cnt + tmp << endl;
    }

    return 0;
}


Measured memory_bytes: 1792
//abc175_d.cpp
//Sat Aug 15 20:46:11 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n,k;
	cin >> n >> k;

	int p[n];
	ll c[n];
	rep(i,n) {
		cin >> p[i];
		p[i]--;
	} 
	rep(i,n) cin >> c[i];

	vector<int> loop(n,-1);
	vector<int> groupnum(5000,0);
	vector<ll> grouptotal(5000,0);
	vector<ll> gmem[5000];
	int g = 0;
	rep(i,n){
		if (loop[i]==-1){
			loop[i] = g;
			grouptotal[g] += c[i];
			gmem[g].push_back(c[i]);
			int tmp = p[i];
			groupnum[g]++;
			while (loop[tmp]==-1){
				loop[tmp] = g;
				grouptotal[g] += c[tmp];
				gmem[g].push_back(c[tmp]);
				tmp = p[tmp];
				groupnum[g]++;
			}
			g++;
		}
	}

	ll ans = -1e18;
	rep(i,g){
		ll tmp = 0;
		ll num = groupnum[i];
		if (grouptotal[i]>0){
			tmp += grouptotal[i]*(k/groupnum[i]);
			num = k%groupnum[i];
			if (num==0 && k/groupnum[i]>0){
				tmp -= grouptotal[i];
				num = groupnum[i];
			}
		}
		ll tmp2 = -1e18;
		ll dp[groupnum[i]+1][groupnum[i]];
		rep(j,groupnum[i])dp[0][j] = 0;
		rep(j,num){
			rep(k,groupnum[i]){
				dp[j+1][(k+1)%groupnum[i]] = dp[j][k]+gmem[i][k];
				tmp2 = max(tmp2,dp[j+1][(k+1)%groupnum[i]]);
			}
		}
		if (num==0)tmp2=max(tmp2,0LL);
		ans = max(ans,tmp+tmp2);
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e6;
const ld pi = acos(-1);
const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 0, (int)A.size()) out << A[i] << " ";
    return out;
}

template <class T1, class T2>
ostream &operator<<(ostream &out, map<T1, T2> &A) {
    for (auto x : A) cout << x.ff << " # " << x.ss << endl;
    return out;
}

int32_t main() {
    IOS int x, n;
    cin >> x >> n;
    set<int> sy;
    for (int i = 0; i < n; i++){
        int ele;    cin>>ele;
        sy.insert(ele);
    } 
    int l=x,r=x;
    while(l>0){
        if(sy.count(l)) l--;
        else break;
    }
    while(r<inf){
        if(sy.count(r)) r++;
        else break;
    }
    int ans;
    if(abs(x-l) <= abs(x-r)){
        ans = l;
    }else{
        ans = r;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  int ans = 0;
  cin >> x;
  if(x == 2){
    ans = 2;
  }
  if(x%2 == 0)x++;
  while(ans == 0){
    bool det = true;
    for(int i = 3; i < sqrt(x); i++){
      if(x % i == 0){
        det = false;
      }
    }
    if(det)ans = x;
    x += 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  cout << (1000 - (n % 1000)) % 1000 << endl;
}

Measured memory_bytes: 3632
#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 N, M, a, b, S, T, dist[100000][3];
vector<int>v[100000];
queue<pair<int, pair<int, int>>>q;

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		cin >> a >> b;
		--a;
		--b;
		v[a].push_back(b);
	}
	cin >> S >> T;
	--S;
	--T;
	for (int i = 0; i < N; ++i) {
		dist[i][0] = dist[i][1] = dist[i][2] = -3;
	}
	q.push(mkp(0, mkp(S, 0)));
	while (!q.empty()) {
		int d = q.front().first;
		int x = q.front().second.first;
		int t = q.front().second.second;
		q.pop();
		if (dist[x][t] == -3) {
			dist[x][t] = d;
			t = (t + 1) % 3;
			for (int i : v[x]) {
				q.push(mkp(d + 1, mkp(i, t)));
			}
		}
	}
	cout << dist[T][0] / 3 << endl;
}


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


int main(){
    int h,w,k;
    cin >> h >> w >> k;
    int num=0;
    char c[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> c[i][j];
            if(c[i][j]=='#'){
                num++;
            }
        }
    }

    int ans=0;
    for(int bit1=0;bit1<(1<<h);bit1++){
        bitset<6> B1(bit1);
        for(int bit2=0;bit2<(1<<w);bit2++){
            int cnt = num;
            for(int i=0;i<h;i++){
                bitset<6> B2(bit2);
                for(int j=0;j<w;j++){
                    if(B1[i] || B2[j]){
                        if(c[i][j]=='#'){
                            cnt--;
                        }
                    }
                }
            }
            if(cnt==k){
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
from heapq import heappop, heappush
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
ans = 0
Y = 0
D = []

if sum(A) < sum(B):
  print(-1)
  exit()
  
for i in range(N):
  heappush(D,-(A[i]-B[i]))
  if A[i] < B[i]:
    Y += B[i]-A[i]
    ans += 1

while Y > 0:
  d = -1*heappop(D)
  Y -= d
  ans += 1
print(ans)

Measured memory_bytes: 19256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int a, b, c, d;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b >> c >> d;
  cout << max(0, min(b,d)-max(a,c)) << endl;
}

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

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

  int n,l;
  cin >> n >> l;
  string s;
  vector<string>ve;
  for (int i = 0; i < n; i++) {
    cin >>s;
    ve.push_back(s);
  }
  sort(ve.begin(),ve.end());

  for(auto it :ve){
    cout<<it;
  }
  return 0;

}

Measured memory_bytes: 3696
import sys
import math

a = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
res = []

def ad(v):
    q = math.floor(v / len(a))
    s = v % len(a)
    q -= 1 if s == 0 else 0
    s = len(a) if s == 0 else s
    res.append(s)
    if len(a) < q:
        ad(q)
    elif len(a) < v:
        res.append(q)
    return "".join([a[i - 1] for i in reversed(res)])

st1 = input()
st = int(st1)
print(ad(st))

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

#define get_variable_name(x) #x
#define debug(x) cout << #x << " = " << x << endl

#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())
#define REVERSE(x) reverse( (x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define PW(x) (1LL<<(x))

using namespace std;
using ll = int64_t;
using P = pair<int, int>;

template<class T,class U>
ostream& operator<<(ostream &os, const pair<T, U> &p) {
    os << get_variable_name(p) << " = (" << p.first <<", " << p.second << ")";
    return os;
}

template<class T>
ostream& operator <<(ostream& os, const vector<T> &v){
    cout << get_variable_name(v) << " = [";
    for(auto i : v) 
        os << " " << i;
    os << " ]";
    return os;
}


const int INF = 1e8;

int main() {
    ios::sync_with_stdio(false);

    string X;
    cin >> X;
    stack<char> s;
    int ans = X.size();
    for(auto c : X) {
        if(s.size() > 0) {
            char t = s.top();
            if(t == 'S' and c == 'T') {
                s.pop();
                ans -= 2;
            } else {
                s.push(c);
            }
        } else {
            s.push(c);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 720
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		int n, m, p;
		while (true) {
			n = sc.nextInt();
			m = sc.nextInt();
			p = sc.nextInt();
			if (n == 0 && m == 0 && p == 0) break;
			int sum = 0, ac = 0, a;
			for (int i = 1; i <= n; i++) {
				a = sc.nextInt();
				if (i == m) ac = a;
				sum +=a; 
			}
			sum = sum*(100-p);
			if (ac == 0) 
				out.println(0);
			else
				out.println(sum/ac);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 27744
n, m = map(int, input().split())
a = list()
for i in range(n) :   #1行ずつn行まで読み込みlistに格納
 a.append(list(map(int, input().split())))
b = list()
for j in range(m) :
 b.append(int(input()))
    
for i in range(n) :
 s = 0
 for j in range(m) :
   s += a[i][j] * b[j]
 print(s)


Measured memory_bytes: 6004
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define int64 long long
#define debug cout << __FILE__ << ":" << __LINE__ << endl;

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

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

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

    vector<char> ans;
    rep(i, S.size()) {
        if (S[i] != 'B') ans.push_back(S[i]);
        else if (ans.size()) ans.pop_back();
    }

    string a;
    rep(i, ans.size()) a += ans[i];
    cout << a << endl;
}


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

int main(){
    ll n;
    cin >> n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        if(!(i%3==0||i%5==0)){
            ans += ll(i);
        }
    }
    cout << ans << endl;
}

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

const int A = 1000005;
ll gcd(ll a, ll b){return b ? gcd(b,a%b):a;}

int main(){
    int n;
    cin >> n;
    vi a(n);
    vi c(A);
    rep(i,n){
        cin >> a[i];
        c[a[i]]++;
    }
    bool pairwise = true;
    for (int i = 2; i < A; i++){
        int cnt = 0;
        for (int j = i; j < A; j += i){
            cnt += c[j];
        }
        if (cnt > 1){
            pairwise = false;
            break;
        }
    }
    if (pairwise){
        cout << "pairwise coprime" << endl; 
        return 0;
    }
    int g = 0;
    rep(i,n) g = gcd(g,a[i]);
    if (g == 1) {
        cout << "setwise coprime" << endl; 
        return 0;
    }
    cout << "not coprime" << endl; 
    return 0;
}

Measured memory_bytes: 11104
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"
#define Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything 42

signed main(){
	cout<<fixed<<setprecision(7);
	int a, b;
	cin>>a>>b;
	a = a*pow(10,(int)(log10(b)+1))+b;
	b = sqrt(a);
	
	// cout<<a<<endl;
	// for(){
	// }
	
	if(b*b == a)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

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

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i=a;i>b;i--)
#define int long long

//constant--------------------------------------------------------------------------------------
const int inf = 100100100100000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//general_method--------------------------------------------------------------------------------
vector<int> cs(vector<int> arr){vector<int> ret = arr;rep(i,1,arr.size()){ret[i] += ret[i-1];}return ret;}
int ceil(int a, int b){if(a%b == 0) return a/b;else return a/b + 1;}
int digitlen(int i){int t = i;int count = 0;while(t){count += 1;t /= 10;}return count;}
int gcd(int m, int n){if((0== m)||(0 == n))return 0;while(m != n){if(m > n)m = m - n;else n = n - m;}return m;}
int lcm(int n, int m){return n*m/gcd(n,m);}

//io_method-------------------------------------------------------------------------------------
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
void print(int n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(string s){cout << s << endl;}
void print(pair<int, int> p){cout << p.first << " " << p.second;}
void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}}

//main------------------------------------------------------------------------------------------

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

    string s = raw_input();
    string t = raw_input();
    
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(), t.end());

    if(s < t) print("Yes");
    else print("No");

 




}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const int mod = 1000000007;

int main(){
  int N;
  string s1,s2;
  cin >> N >> s1 >> s2;

  ll ret = 3;
  if(s1[0] == s1[1]) ret = 6;

  for(int i=0;i<N-1;i++){
    if(s1[i] == s1[i+1]) continue;
    if(s1[i] == s2[i] && s1[i+1] == s2[i+1]){
      ret = (ret*2)%mod;
    }else if(s1[i] == s2[i] && s1[i+1] != s2[i+1]){
      ret = (ret*2)%mod;
    }else if(s1[i] != s2[i] && s1[i+1] != s2[i+1]){
      ret = (ret*3)%mod;
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// GeneratePermutation returns n! in a [][]int style.
func GeneratePermutation(n int) [][]int {
	interim, residual := []int{}, []int{}
	for i := 1; i < n+1; i++ {
		residual = append(residual, i)
	}

	return recursion(interim, residual)
}

// recursion finally returns only leaf node of a tree diagram
func recursion(interim, residual []int) [][]int {
	if len(residual) == 0 {
		return [][]int{interim}
	}

	permutation := [][]int{}
	for i, r := range residual {
		copiedInterim := make([]int, len(interim))
		copy(copiedInterim, interim)
		copiedResidual := deleteElement(residual, i)

		copiedInterim = append(copiedInterim, r)
		p := recursion(copiedInterim, copiedResidual)
		permutation = append(permutation, p...)
	}
	return permutation
}

func deleteElement(s []int, i int) []int {
	newS := []int{}
	for j, e := range s {
		if j == i {
			continue
		}
		newS = append(newS, e)
	}
	return newS
}

// -----------------

var n, m int
var adjMatrix [15][15]bool

func main() {
	tmp := NextIntsLine()
	n, m = tmp[0], tmp[1]
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			adjMatrix[i][j] = false
		}
	}
	for i := 0; i < m; i++ {
		row := NextIntsLine()
		j, k := row[0], row[1]
		adjMatrix[j][k] = true
		adjMatrix[k][j] = true
	}

	answer := 0
	patterns := GeneratePermutation(n)
	for _, p := range patterns {
		if p[0] != 1 {
			continue
		}

		ok := true
		for i := 0; i < n-1; i++ {
			prev, next := p[i], p[i+1]
			if !adjMatrix[prev][next] {
				ok = false
				break
			}
		}
		if ok {
			answer++
		}
	}

	fmt.Println(answer)
}


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

int n, k;

inline int f(int x) {
	int ans = n / k;
	if (x <= n % k) ans++;
	if (x == 0) ans--;
	return ans;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> k;
	long long ans = 0;
	for (int i = 0; i < k; i++) {
		if ((2 * i) % k) continue;
		int a = f(i);
		int c = f((k - i) % k);
		int b = f((k - i) % k);
		ans += (long long)a * b * c;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3652
#include <set>
#include <iostream>

#define int long long

using namespace std;

const int N = 2e5 + 10;

int32_t main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);    
    int n, k;
    cin >> n >> k;
    set<int> s;
    while (k--)
    {
        int d;
        cin >> d;
        while (d--)
        {
            int x;
            cin >> x;
            s.insert(x);
        }
    }
    cout << n - s.size();
    return 0;
}


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


int A, B;

void Main() {
  cin >> A >> B;

  rep(i, 3) {
    if (i + 1 != A && i + 1 != B) {
      cout << i + 1 << endl;
    }
  }

}

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int A,B;
  cin >> A >> B;
  vector<int> x={0,14,2,3,4,5,6,7,8,9,10,11,12,13};
  if(x.at(A)>x.at(B)) cout << "Alice" << endl;
  else if(x.at(A)==x.at(B)) cout << "Draw" << endl;
  else  cout << "Bob" << endl;

  return 0;
}


Measured memory_bytes: 256
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 3010;

int n;
double p[N];
double dp[N];

int main()
{
  cin >> n;
  for(int i = 0 ; i < n ; i++)
    cin >> p[i];
  dp[0] = 1;
  for(int i = 1 ; i <= n ; i++) {
    for(int j = i ; j >= 0 ; j--) {
      dp[j] = dp[j] * (1 - p[i - 1]) + dp[j - 1] * p[i - 1];
    }
  }
  double sum = 0;
  for(int i = n / 2 + 1; i <= n ; i++)
    sum += dp[i];
  cout << fixed << setprecision(10) << sum << endl;
  return 0;
}


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

#ifdef DEBUG
    #include "debug.h"
    #define DEB
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define DEB if (false)
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//////////////////

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

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)



void solve(){

    int X;
    cin >> X;
    int ans;
    for(ans=1;;ans++){
        if(X * ans %360==0){
            cout << ans << endl;
            return;
        }
    }
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 3648
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    int x = Integer.parseInt(sc.next());
    if(a + b >= x && x >= a){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 24916
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
ll int MOD=998244353;
#define INF 1e9
#define N 310000
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    int n;
    cin>>n;
    vector<pii> v;
    ll int x[N],y[N];
    rep(i,n){
        cin>>x[i]>>y[i];
        v.pb({x[i],i});v.pb({y[i],i});
    }
    sort(v.begin(),v.end());
    rep(i,n){
        if(x[i]<y[i]) swap(x[i],y[i]);
    }
    ll int xM=0,xm=INF,yM=0,ym=INF;
    rep(i,n){
        if(x[i]>xM) xM=x[i];
        if(x[i]<xm) xm=x[i];
        if(y[i]>yM) yM=y[i];
        if(y[i]<ym) ym=y[i];
    }
    ll int ans1=(xM-xm)*(yM-ym);
    ll int a=v[0].first,b=v[2*n-1].first;
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> p;
    ll int d=0;
    rep(i,n){
        if(y[i]==a){
            p.push({x[i],(ll)i});
            d=max(d,x[i]);
        }
        else {
            p.push({y[i],(ll)i});
            d=max(d,y[i]);
        }
    }
    ll int c=p.top().first,range=d-c;
    while(1){
        pii pp=p.top();
        if(pp.first==x[pp.second]){
            break;
        }
        else if(x[pp.second]!=b){
            p.pop();
            p.push({x[pp.second],pp.second});
            c=p.top().first;d=max(d,x[pp.second]);
            range=min(range,d-c);
        }
        else break;
    }
    ll ans2=(b-a)*range;
    cout<<min(ans1,ans2);
    return 0;
}


Measured memory_bytes: 16364
N = int(input())
src = [tuple(map(int,input().split())) for i in range(N)]
src.sort(key=lambda x:x[0]+x[1])

dp = [None] * (20001)
dp[0] = 0
for w,s,v in src:
    for s0 in range(s,-1,-1):
        if dp[s0] is None: continue
        if dp[s0+w] is None:
            dp[s0+w] = dp[s0] + v
        else:
            dp[s0+w] = max(dp[s0+w], dp[s0] + v)
print(max(v for v in dp if v is not None))

Measured memory_bytes: 45660
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    cin >> n;
    vector<int> arr(n, 0);
    for(int& val: arr)
        cin >> val;
    deque<int> ans;
    for(int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            ans.push_back(arr[i]);
        } else {
            ans.push_front(arr[i]);
        }
    }
    if (n % 2 == 1)
        reverse(ans.begin(), ans.end());
    for(int i = 0; i < n; i++)
        cout << ans[i] << " ";
    return 0;
}



Measured memory_bytes: 3840
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int tax8 = scanner.nextInt();
        int tax10 = scanner.nextInt();
        int price = 0;
        if (20 < (tax10 - tax8) || (tax10- tax8) < 0) {
            price = -1;
        } else {
            for(int i = 0; i <= 9; i++) {
                int pPrice10 = tax10 * 10;
                int p10 = (int) ((pPrice10 + i)* 0.08);
                if(tax8 != p10) {
                    price = -1;
                    continue;
                } else {
                    price = pPrice10 + i;
                    break;
                }
            }
        }
        System.out.println(price);
    }
}

Measured memory_bytes: 24020
#include<iostream>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i = 0; i<s.size(); i++){
    if(s[i]==s[i+1]){
      cout<<"Bad"<<endl;
      return 0;
    }
  }
  cout<<"Good"<<endl;
  return 0;
}


Measured memory_bytes: 256
N = gets.to_i

N.times do
 x = gets()
 y = x.split()
 a = y[0].to_i
 b = y[1].to_i
 c = y[2].to_i

 aa = a * a
 bb = b * b
 cc = c * c

 if aa == bb + cc
  puts "YES"
  elsif bb == aa + cc
  puts "YES"
  elsif cc == bb + aa
  puts "YES"
  else
  puts "NO"
 end
end


Measured memory_bytes: 6884
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	int A, B, M;
	cin >> A >> B >> M;
	int a_min = MOD;
	int b_min = MOD;
	vector<int> a(A);
	rep(i, A) { scanf("%d", &a[i]);a_min=min(a[i],a_min); }
	vector<int> b(B);
	rep(i, B) { scanf("%d", &b[i]); b_min = min(b[i], b_min); }
	int ans = a_min + b_min;
	rep(i, M) {
		int x, y, c;
		scanf("%d %d %d", &x, &y, &c);
		x--; y--;
		ans = min(ans, a[x] + b[y] - c);
	}
	cout << ans;
}

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

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

    int ans=0;
    rep(i,N){
        int cnt=0;
        for(char c='a';c<='z';++c){
            bool l=0,r=0;
            for(int j=0;j<i;++j){
                if(S.at(j)==c){
                    l=1;
                }
            }
            for(int j=i;j<N;++j){
                if(S.at(j)==c){
                    r=1;
                }
            }
            if(l&&r){
                ++cnt;
            }
        }
        if(ans<cnt){
            ans = cnt;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
inline int add(int a,int b)
{a+=b;return a>=MOD?a-MOD:a;}
inline int mul(int a,int b)
{return 1LL*a*b%MOD;}
int ksm(int a,int b)
{
	int ans=1;
	for(;b;b>>=1,a=mul(a,a))
		if(b&1)ans=mul(ans,a);
	return ans;
}
const int Q=2005;
int fac[Q*Q],ifac[Q*Q];
int F(int n,int m)
{return mul(fac[n+m-1],mul(ifac[m-1],ifac[n]));}
void Init(int n)
{
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],MOD-2);
	for(int i=n;i;--i)
		ifac[i-1]=mul(ifac[i],i);
}
int f[Q][Q];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	if(k==1)return 0&puts("1");
	Init(n*k);
	f[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=i;j>=0;--j)
			f[i][j]=add(f[i][j+1],j==0?0:mul(f[i-1][j-1],mul(n-i+1,F(k-2,(i-1)*k-(j-1)+1))));
	printf("%d\n",f[n][0]);
	return 0;
}

Measured memory_bytes: 46464
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N = 1e5 + 5;
int n , fr[N];
ll sum;
int main(){
	scanf("%d",&n);
	for (int i = 0,x; i < n; ++i){
		scanf("%d",&x);
		fr[x]++;
		sum += 1ll*x;
	}
	int q;
	scanf("%d",&q);
	while(q--){
		int a,b;
		scanf("%d%d",&a,&b);
		sum -= 1ll * fr[a] * a;
		sum += 1ll * fr[a] * b;
		fr[b] += fr[a];
		fr[a] = 0;
		printf("%lld\n" , sum);
	}
	

}	

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

using namespace std;

const int maxn = 1e6 + 6;

int n, ans = 0;
char a[maxn], b[maxn];
deque<int> q;

int main() {
  scanf("%d%s%s", &n, a + 1, b + 1);
  q.push_back(n + 1);
  for (int i = n, j = n + 1, del = 0; i >= 1; i--) {
    int tmp = j;
    while (j && (j > i || a[j] != b[i])) j--;
    if (!j) return puts("-1"), 0;
    if (tmp == j) {
      while (!q.empty() && q.back() - del >= i) q.pop_back();
      q.push_back(i + del);
    } else {
      del++;
      if (i != j) {
        ans = max(ans, (int)q.size());
        q.push_front(j + del);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
typedef double D;
typedef complex<D> P;
typedef vector<string> vs;

#define SZ(x) ((int)(x).size())

#define fill(x,y) memset(x,y,sizeof(x))

// with compile option -DLOCAL
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

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

#define pcnt __builtin_popcount
#define pcntll __builtin_popcountll

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};



#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

const int MOD = 1e9 + 7;

signed main() {
    int x, y;
    cin >> x >> y;
    cout << x + (y / 2) << endl;
}



Measured memory_bytes: 256
n=int(input())
if n<2:
  print(1)
elif 2<=n<4:
  print(2)
elif 4<=n<8:
  print(4)
elif 8<=n<16:
  print(8)
elif 16<=n<32:
  print(16)
elif 32<=n<64:
  print(32)
else:
  print(64)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int N, K, C;
string S;
vector<int> m[2];
int a(int k, int c) {
    // ->
    if (k >= N) return 0;
    if (m[c][k] != -1) return m[c][k];
    if (S[k] == 'x') {
        return m[c][k] = a(k+1, c);
    }
    return m[c][k] = 1 + a(k+C+1, c);
}
int main () {
    cin >> N >> K >> C >> S;
    for (int i = 0; i < N; i++) {
        m[0].push_back(-1);
        m[1].push_back(-1);
    }
    for (int i = N-1; i >= 0; i--) {
        int x = a(i, 0);
    }
    reverse(S.begin(), S.end());
    for (int i = N-1; i >= 0; i--) {
        int x = a(i, 1);
    }
    reverse(m[1].begin(), m[1].end());
    reverse(S.begin(), S.end());
    for (int i = 0; i < N; i++) {
        int a = 0, b = 0;
        if (i-1 >= 0) {
            a = m[1][i-1];
        }
        if (i+1 < N) {
            b = m[0][i+1];
        }
        if (a+b < K) {
            cout << i+1 << endl;
        }
    }
}

Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
 
ll gcd(ll x, ll y)
{
    ll r;
    while((r = x % y) != 0)  
    {
        x = y;
        y = r;
    }
    return y;
}
 
int main(){
  ll i, j;
  ll n, y;
  cin >> n >> y;
  vector<ll> x(n + 1);
  
  for(i = 0; i < n; i++)
    cin >> x[i];
  x[n] = y;
  sort(ALL(x));
  ll result = x[1] - x[0];
  for(i = 2; i <= n; i++)
    result = gcd(result, x[i] - x[i - 1]);
  cout << result << endl;
 
 
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <cmath>
using namespace std;
vector<int> v,memo(1000005,999999),memo2(1000005,999999);
int a;
int main ()
{
	v.push_back(0);
	for(int i=1;i<=300;i++)
	{
		v.push_back(i*(i+1)*(i+2)/6);
	}
	memo[0]=memo2[0]=0;
	for(int i=0;i<=1000000;i++)
	{
		for(int l=0;l<v.size();l++)
		{
			if(i+v[l]>1000000)break;
			if(v[l]%2==1)memo2[i+v[l]]=min(memo2[i+v[l]],memo2[i]+1);
			memo[i+v[l]]=min(memo[i+v[l]],memo[i]+1);
		}
	}
	// for(int i=1;i<100;i++)cout<<memo[i]<<" "<<memo[i]<<endl;
	while(cin>>a&&a)
	{
		cout<<memo[a]<<" "<<memo2[a]<<endl;
	}
	return 0;
}

Measured memory_bytes: 8864
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

string s;
int main() {
	cin >>s ;
	ll cnt=0;
	ll ans = inf;
	REP(i,0,s.size()){
		if(s[i]==i%2 + '0'){
			cnt++;
		}
	}
	ans = cnt;
	cnt = 0;
	REP(i,0,s.size()){
		if(s[i]==(i+1)%2 + '0'){
			cnt++;
		}
	}
	ans =min(ans, cnt);
	p(ans);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int cnt = 0;
vi G{1};
inline void insertionSort(vi& a, int n, int g) {
	rep(i, g, n) {
		int v = a[i];
		int j = i - g;
		while(j >= 0 && a[j] > v) {
			a[j + g] = a[j];
			j = j - g;
			++cnt;
		}
		a[j + g] = v;
	}
}
inline void shellSort(vi& a, int n) {
	for (int tmp = 4; tmp < n; tmp = tmp * 3 + 1) {
		G.eb(tmp);
	}
	rrep(i, len(G) - 1, -1) {
		insertionSort(a, n, G[i]);
	}
}
int main() {
	int n; cin >> n;
	vi v(n); rep(i, 0, n) cin >> v[i];
	shellSort(v, n);
	P(len(G));
	rrep(i, len(G) - 1, -1) cout << G[i] << (i == 0 ? "\n" : " ");
	P(cnt);
	rep(i, 0, len(v)) P(v[i]);
	return 0;
}

Measured memory_bytes: 6780
#pragma GCC optimze("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll inf=1e18, N=50005;
vector<ll> adj[N];
inline ll mult(ll x,ll y){x%=hell;y%=hell;return (1LL*x*y)%hell;}
inline ll add(ll x,ll y){x+=y;return x%hell;}
inline ll powMod(ll base,ll expo){
	if(base==0)return 0;
	ll ans=1;
	while(expo){
		if(expo&1)ans=mult(ans,base);
		base=mult(base,base); 
		expo>>=1;
	}
	return ans;
}
void solve(){
	ll n, k;
	cin>>n>>k;
	vector<ll> v(n);
	rep(i,0,n)
		cin>>v[i];
	vector<ll> dp(n+2,inf);
	dp[0]=0;
	rep(i,0,n){
		rep(j,i+1,min(i+k+1,n))
			dp[j]=min(dp[j],dp[i]+abs(v[j]-v[i]));
	}
	cout<<dp[n-1];
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int n;
    string s;
    int ans=0;
    cin >> n >> s;
    rep(i,n-2){
        if(s[i]=='A' and s[i+1]=='B' and s[i+2]=='C')ans++;
    }

    cout << ans;

}

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

int main() {
  int a, b;
  cin >> a >> b;
  string x, y;
  for (int i = 0; i < a; i++) x += to_string(b); 
  for (int i = 0; i < b; i++) y += to_string(a);
  cout << ((x < y) ? x : y) << "\n"; 
}

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

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


int main(){

    ll N;
    cin >> N;

    if(N % 2 == 0){
        cout << N;
    }else{
        cout << N * 2;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct{
  int p;
  int h;
  int dep;
  int deg;
  int left,right;
  int s;
}Tree;

Tree T[25];

void rootedtree(int);
void depth(int);
void height(int);

int main(){
  int n,id,i,j,root,hei;

  scanf("%d",&n);
  
  //T = malloc(sizeof(Tree) * n);
  
  for(i = 0; i < n; i++){
    T[i].p = -1;
    T[i].s = -1;
    T[i].dep = 0;
    T[i].deg = 0;
  }
  
  for(i = 0; i < n; i++){
    scanf("%d",&id);
    rootedtree(id);
  }
  
 for(i = 0; i < n; i++){
   if(T[i].p == -1) root = i;
 }
 
 depth(root);

 for(i = 0; i < n; i++){
   if(T[i].deg == 0 ){
     T[i].h=0;
     if(T[i].p != -1)
       height(i);
   }
 }
 
 for(i = 0; i < n; i++){
   printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,T[i].p,T[i].s,T[i].deg,T[i].dep,T[i].h);
   if(T[i].dep == 0) printf("root");
   else if(T[i].deg > 0) printf("internal node");
   else printf("leaf");
   printf("\n");
   
 }
 
 //free(T);
 
 return 0;
}

void rootedtree(int id){
  int i;
  scanf("%d%d",&T[id].left,&T[id].right);
  
  if(T[id].left != -1 && T[id].right != -1)
    T[id].deg = 2;
  if(T[id].left != -1 && T[id].right == -1)
    T[id].deg = 1;
  if(T[id].left == -1 && T[id].right != -1)
    T[id].deg = 1;
  T[T[id].left].s = T[id].right;
  T[T[id].left].p = id;
  T[T[id].right].s = T[id].left;
  T[T[id].right].p = id;
}

void depth(int id){
  if(T[id].deg > 0){
    if(T[id].left != -1){
      T[T[id].left].dep = T[id].dep + 1;
      depth(T[id].left);
    }
    if(T[id].right != -1){
      T[T[id].right].dep = T[id].dep + 1;
      depth(T[id].right);
    }
  }
}

void height(int id){
  if( T[T[id].p].h < T[id].h + 1){
    T[T[id].p].h = T[id].h + 1;
    if( T[T[id].p].p != -1)
      height(T[id].p);
  }
}



Measured memory_bytes: 2100
void main()
{
    string s = readln.chomp;

    writeln(s[0..4], " ", s[4..$]);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256