akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pllll = pair<ll, ll>;
using vll = vector<ll>;
using vllll = vector<vector<ll>>;

int main() {

    string r, a;
    while (cin >> r >> a, r != "0") {

        ll hit = 0;
        vector<bool> ext(10, false);
        for (ll i = 0; i < 4; i++) {
            if (r[i] == a[i]) {
                hit++;
            }
            ext[r[i] - '0'] = true;
        }
        ll blow = -hit;
        for (ll i = 0; i < 4; i++) {
            if (ext[a[i] - '0']) {
                blow++;
            }
        }

        cout << hit << ' ' << blow << endl;

    }

}


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

int main() {
  cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;++i){
        cin >> vec.at(i);
    }
    reverse(vec.begin(),vec.end());
    for(int i=0;i<n-1;++i){
        cout << vec.at(i) << " ";
    } 
    cout << vec.at(n-1) << endl;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n;
int a[111111];
vector<int> len;

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  rep(i,n)cin>>a[i];
  a[n]=a[n-1];
  n++;
  int pre=a[0];
  int l=0;
  repl(i,1,n){
    if(a[i]==pre){
      len.push_back(i-l);
      l=i;
    }
    pre=a[i];
  }
  ll res=0;
  len.push_back(0); len.push_back(0);
  rep(i,len.size()-2){
    maxch(res,len[i]+len[i+1]+len[i+2]);
  }
  cout<<res<<endl;
	return 0;
}

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

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

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

int main(){
	ll n;
	cin>>n;
	ll cnt_ac=0,cnt_wa=0,cnt_tle=0,cnt_re=0;
	while(n--){
		string s;
		cin>>s;
		if(s=="AC")
		cnt_ac++;
		else if(s=="WA")
		cnt_wa++;
		else if(s=="TLE")
		cnt_tle++;
		else
		cnt_re++;
	}
	cout<<"AC"<<" "<<"x"<<" "<<cnt_ac<<endl;
	cout<<"WA"<<" "<<"x"<<" "<<cnt_wa<<endl;
	cout<<"TLE"<<" "<<"x"<<" "<<cnt_tle<<endl;
	cout<<"RE"<<" "<<"x"<<" "<<cnt_re<<endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) 
{
    return (ll)(log(x) / log(base));
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll n,i,j,l,m,h,w,c,f,k,need,ans,cur,x,y,a,b;
    	cin>>x>>y>>a>>b>>c;
    	ll p[a],q[b],r[c],s[x+y];
    	rep(i,0,a)
    	cin>>p[i];
    	rep(i,0,b)
    	cin>>q[i];
    	rep(i,0,c)
    	cin>>r[i];
		n=x+y;
		sort(p,p+a);
		sort(q,q+b);
    	sort(r,r+c);
    	j=0;
    	per(i,a-1,a-x)
    	s[j++]=p[i];
    	per(i,b-1,b-y)
    	s[j++]=q[i];
    	sort(s,s+n);
    	i=0; j=c-1; ans=0;
    	while(i<n && j>=0 && r[j]>s[i])
    	{
    		s[i]=r[j];
    		i++; j--;
		}
		rep(i,0,n)
		ans+=s[i];
    	cout<<ans;
	}
	return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cerr<<endl; \
  }while(0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int H, W;
  cin >> H >> W;
  VI row(H), col(W);
  cin >> row >> col;

  RSORT(row);
  UNIQ(row);
  RSORT(col);
  UNIQ(col);

  if(SZ(row) != H || SZ(col) != W){
    cout << 0 << endl;
    return 0;
  }

  LL ans = 1;
  LL emp = 0;

  int n = H * W;
  for(int y=0,x=0;n>0;){
    if(y == H || n > row[y]){
      if(x == W || n > col[x]){
        (ans *= emp) %= MOD;
        --emp;
        if(!ans) break;
      }
      else if(n == col[x]){
        (ans *= y) %= MOD;
        if(!ans) break;
        emp += y - 1;
        ++x;
      }
    }
    else if(n == row[y]){
      if(x == W || n > col[x]){
        (ans *= x) %= MOD;
        if(!ans) break;
        emp += x - 1;
        ++y;
      }
      else if(n == col[x]){
        emp += y + x;
        ++y;
        ++x;
      }
    }
    //DEBUG(n,ans,emp);
    --n;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int n;
  n=s.size();
  int c=0;
  vector<int> sn(n);
  for (int i=0; i<n; i++){
    if(s[i]=='0')sn[i]=0;
    else sn[i]=1;
  }
  for (int i=0; i<n; i++){
    if (sn[i] == i%2) c++;
  }
  cout << min(c,n-c) << endl;
}

Measured memory_bytes: 896
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

int main() {
	int n;
	cin >> n;
	map<int, int> S;
	hei(int) a(n);
	rep(i, 0, n) {
		cin >> a[i];
		S[a[i] + 1]++;
		S[a[i]]++;
		S[a[i] - 1]++;
	}
	int ans = 0;
	rep(i, 0, n) {
		rep(j, -1, 2) {
			ans = max(ans, S[a[i] + j]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5120
function Main(input) {
  input = input.trim()
  input = input.split(" ").map(Number);
  input.sort(function(a,b){
        if( a < b ) return -1;
        if( a > b ) return 1;
        return 0;
});
  console.log(Math.abs(input[0]-input[2]));
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7624
//abc080_d.cpp
//Sat Feb 24 10:45:18 2018

#include <iostream>
#include <string>
using namespace std;

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

	int array[300000][c+1];
	int maxt = 0;

	for (int i=0;i<300000;i++){
		for (int x=0;x<c+1;x++){
			array[i][x] = 0;
		}
	}

	for (int i=0;i<n;i++){
		int s, t, cn;
		cin >> s;
		cin >> t;
		cin >> cn;
		s = 2*s;
		t = 2*t;

		if (array[s][cn] == -1){
			array[s][cn]++;
			array[s][0]++;
		}else{
			array[s-1][cn]++;
			array[s-1][0]++;
		}

		if (array[t-1][cn] == 1){
			array[t-1][cn]--;
			array[t-1][0]--;
		}else{
			array[t][cn]--;
			array[t][0]--;
		}

		if (t>maxt){
			maxt = t;
		}
	}

	int answer = 0;

	for (int i=1;i<maxt+1;i++){
		array[i][0] = array[i][0]+array[i-1][0];
//		cout << array[i][0] << " ";
		if (answer < array[i][0]){
			answer = array[i][0];
		}
	}
//	printf("\n");
	cout << answer << endl;
}

Measured memory_bytes: 36608
#include<iostream>
using namespace std;
struct mat
{
	int w;
	int h;
};
typedef struct mat mat_t;
long long min(long long a,long long b);

int n;
mat_t a[101];
long long dp[101][101] ;

int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i].h >> a[i].w;
	}
	for(int x = 0;x<n;x++){
		for(int y =0;y<n;y++){
			dp[x][y] = 2000000;
			if(x == y) dp[x][y] = 0;
		}
	}
	int i = 0;
	int j = 1;
	for(int l = 1;l<n;l++){
		i = 0;
		for(j=l;j<n;j++){
			for(int k = i;i <= k && k < j;k++){
				dp[i][j] = min(dp[i][j],dp[i][k] + dp[k+1][j] + a[i].h *a[k].w * a[j].w);
			}
			i++;
		}
	}
	cout << dp[0][n-1] << endl;
}

long long min(long long a,long long b) {
	return a<b? a:b;
}

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

int main(){
    int n;
    cin >> n;
    int a[200000];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int p[200000] = {};
    for(int i=0; i<n; i++){
        p[a[i]-1] = i+1;
    }
    for(int i=0; i<n-1; i++){
        cout << p[i] << " ";;
    }
    cout << p[n-1] << endl;
    return 0;
}

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

string A[1<<17];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n; cin >> n;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    sort(A[i].begin(), A[i].end());
  }
  sort(A, A + n);
  for (int i = 0, j = 0; i < n; i = j) {
    while (j < n and A[i] == A[j]) ++j;
    ans += (j - i) * 1ll * (j - i - 1) / 2;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B,C,D;
  cin >> A >> B >>C >>D;
  int L = A + B;
  int R = C + D;
  if ( L < R )  {
  cout << "Right"<<endl;}
  else if ( L == R )  {
  cout << "Balanced"<<endl;}
  else if ( L > R )  {
  cout << "Left"<<endl;}
}

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

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

  if ((N%1000/100 == N%100/10)&&((N%100/10 == N%10)||(N%100/10 == N/1000))) {
     cout << "Yes" << endl;
   }
  else {
    cout << "No" << endl;
  }
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int N, M;
  cin >> N >> M;

  vector<int> ac(N), pena(N);
  for (int i = 0; i < M; i++) {
    int p;
    string s;
    cin >> p >> s;
    --p;

    if (!ac[p]) pena[p] += (s == "WA");
    ac[p] += (s == "AC");
  }

  int a = 0, b = 0;
  for (int i = 0; i < N; i++) {
    if (ac[i]) {
      a ++;
      b += pena[i];
    }
  }
  cout << a << " " << b << endl;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<vector>
#include<algorithm>

#define REP(i,a,n) for(int i = 0;i < n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int in(){int x; scanf("%d",&x); return x;}
int main(void){
   int n;
   while(scanf("%d",&n),n){
      int ma = 0;
      vector<pair<int,int> > field;
      rep(i,n) field.push_back(make_pair(in(),in()));
      sort(field.begin(),field.end());

      rep(i,n-1){
         REP(j,i+1,n){
            int _x = field[i].first-field[j].first,_y = field[i].second-field[j].second;
            if(_x*_y >= 0){
               if(binary_search(field.begin(),field.end(),make_pair(field[i].first-_y,field[i].second+_x))&
                  binary_search(field.begin(),field.end(),make_pair(field[j].first-_y,field[j].second+_x))){
                     ma = max(ma,_x*_x+_y*_y);
               }
               if(binary_search(field.begin(),field.end(),make_pair(field[i].first+_y,field[i].second-_x))&
                  binary_search(field.begin(),field.end(),make_pair(field[j].first+_y,field[j].second-_x))){
                  ma = max(ma,_x*_x+_y*_y);
               }
            }
            else{
               if(binary_search(field.begin(),field.end(),make_pair(field[i].first+_y,field[i].second+_x))&
                  binary_search(field.begin(),field.end(),make_pair(field[i].first-_y,field[i].second-_x))){
                  ma = max(ma,_x*_x+_y*_y);
               }
            }
         }
      }
      printf("%d\n",ma);
   }
   return 0;
}

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

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

int main() {
    int w,h,n; cin >> w >> h >> n;
    int A[w][h]; rep (i,w) rep (j,h) A[i][j] = 0;
    rep (hoe, n) {
        int x,y,a; cin >> x >> y >> a;
        rep (i,w) {
            rep (j,h) {
                if (a == 1 && i < x) A[i][j] = 1;
                if (a == 2 && i >= x) A[i][j] = 1;
                if (a == 3 && j < y) A[i][j] = 1;
                if (a == 4 && j >= y) A[i][j] = 1;
            }
        }
    }
    int ans = 0;
    rep (i,w) {
        rep (j,h) {
            ans += (A[i][j] == 0);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
s = gets.split('')

v = []

s.each do |s|
    if s == "0"
        v.push("0")
    elsif s == "1"
        v.push("1")
    elsif s == "B"
        if v.any?
            v.pop
        else
            v.push("")
        end
    end
end

puts v.join

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

int main() {
    int d;
    long long n;
    cin >> d >> n;
    //仮に'n = 100', 'd = 1'のときn = 100のときは100でちょうど2回割り切れる数になってしまうのでn + 1した数が100番目に小さい数となる。
    if (n == 100)
    {
        n++;
    }

    switch (d)
    {
    case 0:
        cout << n << endl;
        break;
    case 1:
        cout << n * 100 << endl;
        break;
    case 2:
        cout << n * 10000 << endl;
        break;
    default:
        break;
    }
}


Measured memory_bytes: 256
/*
"Won't stop until I'm phenomenal."
- Phenomenal, Eminem
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    int n,m; cin>>n>>m;
    multiset<ll,greater<ll>> s;
    for(int i = 0 ; i < n; i++){
        ll k; cin>>k; s.insert(k);
    }
    for(int i = 0 ; i < m; i++){
        ll operate = *s.begin();
        s.erase(s.begin());
        s.insert(operate>>=1);
    }
    ll ans = 0;
    for(auto p : s)
        ans+= p;
    cout<<ans<<endl;
    return 0;
}

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

int func(int n){
  int cnt=0;
  for(int i=1;i<=sqrt(n);i++){
    for(int j=1;j<=i;j++){
      for(int k=1;k<=j;k++){
        if(i*i +j*j +k*k +i*j +j*k +k*i == n){
          if(i > j && j > k) cnt += 6;
          else if(i > j && j == k) cnt += 3;
          else if(i == j && j > k) cnt += 3;
          else cnt++;
        }
      }
    }
  }  
  
  return cnt;
}

int main(){
  int n;
  cin >> n;
  for(int i=1;i<=n;i++){
    cout << func(i) << endl;
  }
  
  return 0;
}  


Measured memory_bytes: 3476
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
    private static int MOD = 1000000007;


    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        int k = readInteger(br);
        String s = br.readLine();

        if(k < s.length() ){
            System.out.println(s.substring(0, k) + "...");
        } else {
            System.out.println(s);
        }

    }


    private static int readInteger(BufferedReader br) throws IOException {
        return Integer.parseInt(br.readLine());
    }

    private static int[] readIntegers(BufferedReader br) throws IOException {
        String[] s = br.readLine().split(" ");
        int[] ret = new int[s.length];
        for (int i = 0; i < s.length; i++) {
            ret[i] = Integer.parseInt(s[i]);
        }
        return ret;
    }

}


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

#define infile "../test/sample-1.in"
// #define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#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 _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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

int L[5002][5000];
int R[5002][5000];

int solve(){
  int n,k;cin>>n>>k;
  int a[n+2];
  rep(i, 1, n+1){ cin>>a[i]; }

  L[0][0]=1;
  R[n+1][0]=1;

  rep(i, 1, n+1){
    rep(x, k){
      L[i][x] = L[i-1][x] || ((x-a[i]>=0)?L[i-1][x-a[i]]:0);
    }
  }
  rrep(i, 1, n+1){
    rep(x, k){
      R[i][x] = R[i+1][x] || ((x-a[i]>=0)?R[i+1][x-a[i]]:0);
    }
  }
  dump_2d(L, n+2, k);
  dump_2d(R, n+2, k);

  // acsum
  rep(i, n+2){ rep(j, 1, k){ R[i][j] += R[i][j-1]; } }

  int need = 0;
  rep(i, 1, n+1){
    rep(x, k){
      // y in [k-a[i]-x, k-1-x]
      if (L[i-1][x]==1){
        int p = R[i+1][k-1-x];
        int q = ((k-a[i]-x-1>=0)?R[i+1][k-a[i]-x-1]:0);
        if (p-q>0){
          dump(i, x, p-q, p, q);
          need++;
          break;
        }
      }
    }
  }
  cout << n-need << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 195712
h, w = map(int, input().split())
s = [input() for _ in range(h)] # #.のグリッドの場合
seen = [[0] * w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            seen[i][j] = 1
for i in range(h):
    for j in range(1, w):
        if s[i][j] == '#' and s[i][j-1] == '#':
            seen[i][j] = 0
            seen[i][j-1] = 0
for i in range(1, h):
    for j in range(w):
        if s[i-1][j] == '#' and s[i][j] == '#':
            seen[i-1][j] = 0
            seen[i][j] = 0

if sum(list(map(sum, seen))) > 0:
    print('No')
else:
    print('Yes')




Measured memory_bytes: 40048
#include <bits/stdc++.h>
using namespace std;
int n,fa[120000];
set <int> st[120000];
map <pair <int,int> ,int> mp;
queue <pair <int,int> > q;
int find(int x) {if(fa[x]==x) return x;return fa[x]=find(fa[x]);}
signed main() {
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n*2-2;i++) {
		int x,y;
		cin>>x>>y;
		st[x].insert(y);st[y].insert(x);
		mp[make_pair(x,y)]++;
		mp[make_pair(y,x)]++;
		if(mp[make_pair(x,y)]==2) q.push(make_pair(x,y));
	}
	for(int i=1;i<=n;i++) fa[i]=i;
	while(!q.empty()) {
		int x=q.front().first,y=q.front().second;
		q.pop();
		x=find(x);y=find(y);
		st[x].erase(y);
		st[y].erase(x);
		if(st[x].size()<st[y].size()) swap(x,y);
		for(set <int> :: iterator it=st[y].begin();it!=st[y].end();it++) {
			int now=*it;
			mp[make_pair(now,y)]=mp[make_pair(y,now)]=0;
			st[now].erase(y);
			st[now].insert(x);
			mp[make_pair(now,x)]++;
			mp[make_pair(x,now)]++;
			if(mp[make_pair(now,x)]==2) q.push(make_pair(now,x));
			st[x].insert(now);
		}
		fa[y]=x;
		st[y].clear();
	}
	int s=0;
	for(int i=1;i<=n;i++) if(fa[i]==i) s++;
	if(s==1) cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 57088
import sys
H, W = map(int, input().split())
s = [input() for _ in range(H)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            for k in range(4):
                try:
                    if s[i + dy[k]][j + dx[k]] == '#':
                        flag = False
                        break
                    else:
                        flag = True
                except IndexError:
                    pass
            if flag:
                print('No')
                sys.exit()
print('Yes')


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	uint64_t n; cin>>n;
	vector<int>v;
	while(n){
		--n;
		v.emplace_back(n%26);
		n/=26;
	}
	for(auto i=v.rbegin();i!=v.rend();++i)cout<<(char)(*i+'a');
	cout<<"\n"s;
}

Measured memory_bytes: 3652
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

N = INT()
xy = [LIST() for _ in range(N-1)]
tree = [[] for _ in range(N)]
for x, y in xy:
    tree[x-1].append(y-1)
    tree[y-1].append(x-1)

def rec(n, par):
    f, g = 1, 1
    for node in tree[n]:
        if node == par:
            continue
        fn, gn = rec(node, n)
        f *= gn
        f %= mod
        g *= fn
        g %= mod
 
    return (f+g)%mod, g
 
print(rec(0, None)[0])


Measured memory_bytes: 124516
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

val br = BufferedReader(InputStreamReader(System.`in`))
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    // 回答をここに書く
    val (a,b) = listOfInt()
    val sum = a+b
    val r = if(sum%2 == 0) sum / 2 else sum / 2 +1
    println(r)
}

// 入力取得
fun next() = br.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
            .filter { value % it == 0L }
            .map { listOf(it, value / it) }
            .flatten()
            .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

fun println(value : Any) {
    pw.println(value)
}

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

using namespace std;

typedef long long int ll;

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

  ll n;
  cin >> n;
  vector < ll > a(n), b(n), c(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  for(int i = 0; i < n; i++) cin >> c[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  vector < ll > bb(n);
  for(int i = 0; i < n; i++){
    bb[i] = c.end() - upper_bound(c.begin(), c.end(), b[i]);
  }

  vector < ll > aa(n);
  aa[n - 1] = bb[n - 1];
  for(int i = n - 2; i >= 0; i--){
    aa[i] += aa[i + 1] + bb[i];
  }

  ll ans = 0;
  for(int i = 0; i < n; i++){
    int ind_b = upper_bound(b.begin(), b.end(), a[i]) - b.begin();
    if(ind_b != n) ans += aa[ind_b];
  }

  cout << ans << '\n';
}


Measured memory_bytes: 4224
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


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

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    int n,y,m,d;
    cin>>n;
    rep(i,n){
        cin>>y>>m>>d;
        int ans = (y-1)*195+(y-1)/3*5+20*(m-1)-min(1,y%3)*((m-1)/2)+d;
        cout<<196471-ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 3072
pub struct ProconReader<R: std::io::Read> {
    reader: R,
}

impl<R: std::io::Read> ProconReader<R> {
    pub fn new(reader: R) -> Self {
        Self { reader }
    }
    pub fn get<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&byte| byte == b' ' || byte == b'\n' || byte == b'\r')
            .take_while(|&byte| byte != b' ' && byte != b'\n' && byte != b'\r')
            .collect::<Vec<_>>();
        std::str::from_utf8(&buf)
            .unwrap()
            .parse()
            .ok()
            .expect("Parse Error.")
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut rd = ProconReader::new(stdin.lock());

    let d: usize = rd.get();
    let t: usize = rd.get();
    let s: usize = rd.get();

    println!("{}", if t * s >= d { "Yes" } else { "No" });
}

Measured memory_bytes: 2104
if __name__ == "__main__":
    N = int(input())
    H = list(map(int,input().split()))
    tmpH = sorted(H)
    for i in range(N):
        if H[i] != tmpH[i] and abs(H[i] - tmpH[i]) > 1:
            print("No")
            exit()
    print("Yes")
            


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

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

const long long INF = 1LL << 60;

typedef unsigned long long ll;

const long long MOD = 1000000000 + 7;

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

int main(){
    int s,w;
    cin >> s >> w;
    if(s > w) {
        cout << "safe" << endl;
    }else{
        cout << "unsafe" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x *= i;
    return x;
}

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

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



int main(){
    ll n;
    cin>>n;
    vector<ll> x(n),y(n);
    rep(i,n) cin>>x[i]>>y[i];
    double sum=0;
    rep(i,n){
        for(ll j=0;j<i;j++){
            sum += factorial(n)/n * sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
    }
    cout<<fixed<<setprecision(10)<<sum*2/factorial(n)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define p 1000000007
ll fac[100055];
int num[105];
inline ll qpow(int x,int a)
{
	ll ans=1;
	while(a)
	{
		if(a&1) ans=1ll*ans*x%p;
		x=1ll*x*x%p;
		a>>=1;
	}
	return ans;
}
inline ll C(int n,int m)
{
	return fac[n]*qpow(fac[m],p-2)%p*qpow(fac[n-m],p-2)%p;
}
int main()
{
	int n,m,cnt;
	fac[0]=1;
	for(int i=1;i<=100050;++i)
		fac[i]=fac[i-1]*i%p;
	scanf("%d%d",&n,&m);
	int tmp=sqrt(m);
	for(int i=2;i<=tmp;++i)
	{
		if(m%i) continue;
		num[++cnt]=0;
		while(!(m%i))
			m/=i,++num[cnt];
	}
	if(m!=1) num[++cnt]=1;
	ll ans=1;
	for(int i=1;i<=cnt;++i)
		ans=ans*C(n+num[i]-1,num[i])%p;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if (n == 0 && m == 0)
				break;
			int[][] cost = new int[m][3];
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < 3; j++) {
					cost[i][j] = scanner.nextInt();
				}

			}
			int[] p = new int[n];
			for (int i = 0; i < n; i++) {
				p[i] = i;
			}
			Arrays.sort(cost, new Comparator<int[]>() {
				@Override
				public int compare(int[] a, int[] b) {
					return a[2] - b[2];
				}
			});
			int ans = 0;
			for (int i = 0; i < m; i++) {
				int a = cost[i][0];
				int b = cost[i][1];
				a = root(a, p);
				b = root(b, p);
				if (a == b) {
					continue;
				}
				merge(a, b, p);
				ans += cost[i][2];
			}
			System.out.println(ans);

		}
	}

	private static void merge(int a, int b, int[] p) {
		/*a = root(a, p);
		b = root(b, p);*/
		p[a] = b;
	}

	private static int root(int a, int[] p) {
		if (a == p[a]) {
			return a;
		} else {
			return p[a] = root(p[a], p);
		}
	}
}

Measured memory_bytes: 23256
#include<iostream>

void print_list(int* a, int n){
  for(int i = 0; i < n - 1; i++){
    std::cout << a[i] << " ";
  }
  std::cout << a[n - 1] << std::endl;
}

void selectionSort(int* a, int n){
  int swap_count = 0;
  for(int i = 0; i < n - 1; i++){
    int minj = i;
    for(int j = i; j < n; j++){
      if(a[j] < a[minj]){
	minj = j;
      }
      
    }
    if(i != minj){
      int t = a[i]; a[i] = a[minj]; a[minj] = t;
      swap_count++;
    }
  }

  print_list(a, n);
  std::cout << swap_count << std::endl;
}

int main(){
  int n;
  std::cin >> n;

  int a[n];
  for(int i = 0; i < n; i++){
    std::cin >> a[i];
  }
  
  selectionSort(a, n);
 
  return 0;
}



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

using namespace std;


int main(){
    long N;
    cin>>N;
    vector<tuple<long long,long,long>> tapi(N);

    for(int i=0;i<N;++i){
        long t,a;
        cin>>t>>a;
        tapi[i]=make_tuple(t+a,t,a);
    }

    long long ans=0;

    sort(tapi.rbegin(),tapi.rend());

    for(int i=0;i<N;++i){
        if(i%2==0){
            ans+=get<1>(tapi[i]);
        }else{
            ans-=get<2>(tapi[i]);
        }
    }

    cout<<ans<<endl;

}

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

int main()
{
    int t;
    int a[1000],b[1000];

    cin>>t;

    for(int i=0;i<t;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<t;i++)
    {
        cin>>b[i];
    }
    int sum=0;
    for(int i=0;i<t;i++)
    {
        if(a[i]-b[i]>0)
        {
            sum=sum+(a[i]-b[i]);
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> v;
    for(int i=0;i<n;i++)
    {
        int tmp;cin>>tmp;
        v.push_back(make_pair(tmp,i));
    }
    sort(v.begin(),v.end());
    
    int ans[n];
    for(int i=0;i<(n/2);i++)
    {
        ans[v[i].second]=v[n/2].first;
    }
    for(int i=n/2;i<n;i++)
    {
        ans[v[i].second]=v[n/2-1].first;
    }
    for(int i=0;i<n;i++)
    cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 4720
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

int main()
{
  ll n;
  cin>>n;
  repn(i, 1, 3500)
    repn(j, 1, 3500)
    {
      if((4*i*j - i*n - n*j) == 0) continue;
      if(((n*i*j) % (4*i*j - i*n - n*j)) == 0)
      {
        ll w = (n*i*j) / (4*i*j - i*n - n*j);
        if(w <= 3500 && w > 0)
        {
          cout<<j<<" "<<i<<" "<<w<<endl;
          return 0;
        }
      }
    }
}


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

int N, E[300000], W[300000], mn;
string S;

int main() {
	cin >> N >> S;
	for (int i = 0; i != N; ++i) {
		if (S[i] == 'E')++E[i];
		else ++W[i];
	}
	for (int i = 1; i != N; ++i) {
		W[i] += W[i - 1];
	}
	for (int i = N - 2; i != -1; --i) {
		E[i] += E[i + 1];
	}
	mn = 0xe869120;
	for (int i = 0; i != N; ++i) {
		mn = min(mn, E[i] + W[i] - 1);
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 3076
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() }

    var free = 0
    val set = mutableSetOf<Int>()
    for (i in 0 until n) {
        if (a[i] >= 3200) free++
        else set.add(a[i] / 400)
    }
    val c = set.count()
    if (c == 0) {
        println("1 $free")
    } else {
        println("$c ${c + free}")
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

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

int main() {
	long long H;
	cin >>H;
	long long p;
	p=(log(H)/log(2))/1;
	long long a;
	a=pow(2,p+1)-1;
	to_string(a);
	cout << a;

	

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string S;
  cin>>S;
  int ans=0;
  for(int i=0;i<S.length();i++)
    if(S[i]!=S[S.length()-1-i])
      ans++;
  cout<<ans/2<<endl;
  return 0;
}

Measured memory_bytes: 256
//2019.9.2 by ljz
//email 573902690@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define unl __int128
#define eps 5.6e-8
#define RG register
#define db double
#define pc(x) __builtin_popcount(x)
//#define pc(x) __builtin_popcountll(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define ull unsigned LL
#define gc getchar
//template <class T>using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
//inline int read() {
//    res s=0,ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
inline int read() {
    res s=0,ch=gc(),w=1;
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s*w;
}
inline LL Read() {
    RG LL s=0;
    res ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline void write(RG unl x){
//    if(x>10)write(x/10);
//    putchar(int(x%10)+'0');
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//clock_t start=clock();
//inline void ck(){
//    if(1.0*(clock()-start)/CLOCKS_PER_SEC>0.1)exit(0);
//}
namespace MAIN{
    int n,A,B;
    inline void MAIN(){
        n=read(),A=read(),B=read();
        if((B-A)&1)puts("Borys");
        else puts("Alice");
    }
}
int main(){
//    srand(19260817);
//    freopen("signin.in","r",stdin);
//    freopen("signin.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
int a[101010];
vector<pair<int, int>>ans;
int main(){
    cin >> n;
    REP(i, n)cin >> a[i];
    sort(a, a + n);
    LL b = a[0];
    for(int i = 1;i < n - 1;i++){
        if(a[i] >= 0){
            ans.emplace_back(make_pair(b, a[i]));
            b -= a[i];
        }else{
            ans.emplace_back(make_pair(a[n - 1], a[i]));
            a[n - 1] -= a[i];
        }
    }
    ans.emplace_back(make_pair(a[n - 1], b));
    a[n - 1] -= b;
    cout << a[n - 1] << endl;
    REP(i, n - 1){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}

Measured memory_bytes: 3188
#include <iostream>

class Dice{
public:
  Dice(){
    number = new int[6];
    work = new int[6];
  }
  ~Dice(){
    delete[] number;
    delete[] work;
  }

  void setLabel(int index, int num){
    number[index] = num;
  }

  void roll(char dst){
    for(int i=0; i<6; i++) work[i] = number[i];
    switch(dst){
      case 'E':
        setNumber(work[3], work[1], work[0], work[5], work[4], work[2]);
        break;
      case 'N':
        setNumber(work[1], work[5], work[2], work[3], work[0], work[4]);
        break;
      case 'S':
        setNumber(work[4], work[0], work[2], work[3], work[5], work[1]);
        break;
      case 'W':
        setNumber(work[2], work[1], work[5], work[0], work[4], work[3]);
        break;
    }
  }

  int returnPeek(){
    return number[0];
  }

private:
  void setNumber(int n0, int n1, int n2, int n3, int n4, int n5){
    number[0] = n0;
    number[1] = n1;
    number[2] = n2;
    number[3] = n3;
    number[4] = n4;
    number[5] = n5;
  }

private:
  int* number;
  int* work;
};

int main(){
  Dice dice;
  int label;
  std::string str;
  for(int i=0; i<6; i++){
    std::cin >> label;
    dice.setLabel(i, label);
  }
  std::cin >> str;
  for(int i=0; i<str.size(); i++){
    dice.roll(str[i]);
  }
  std::cout << dice.returnPeek() << std::endl;;
}



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

public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        String s = in.nextLine(), str = s + s;
        String patt = in.nextLine();

        if(str.indexOf(patt) >= 0)System.out.println("Yes");
        else System.out.println("No");
    }
}


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

int n;
int w;
vector<int> weight, value;
vector<int> dp;

main(){
	
	cin >> n >> w;
	
	weight.resize(n+1);
	value.resize(n+1);

	dp.resize(w+1);

	for(int i=1; i<=n; i++){
		cin >> weight[i] >> value[i];
	}

	for(int j=1; j<=n; j++){
		for(int i=w; i>=0; i--){
			if(i - weight[j] >= 0){
				dp[i] = max(dp[i], value[j] + dp[i-weight[j]]);
			}
		}
	}

	cout << dp[w] << "\n";
}

/*

knapp(k, w) = valor max do subproblema com os k primeiros elementos e peso maximo de w

knapp(k, w) = max(knapp(k-1, w - peso[k]), knapp(k-1, w));

*/

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

int main(){
    int k,s;
    cin>>k>>s;
    int ans=0;
    for(int x=0;x<=k;x++){
        for(int y=0; y<=k; y++){
            int z=s-x-y;
            if(z>=0 && z<=k) ans++;
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 1000005
int n,t1,t2,cnt[N];bool fl;char a[N];
int main()
{
	scanf("%d %s",&n,a);
	if(n==2) {printf("%d\n",abs(a[0]-a[1]));return 0;}
	for(int i=1;i<=n;++i) if(!(i%2)) cnt[i]=cnt[i/2]+1;
	for(int i=1;i<=n;++i) cnt[i]+=cnt[i-1];
	for(int i=0,x,t;i<n-1;++i)
	{
		x=abs(a[i]-a[i+1]);
		if(cnt[i]<cnt[n-2]-cnt[n-2-i]) t=0;else t=1;
		if(x==1) t1=(t1+t)%2,fl=1;if(x==2) t2=(t2+t)%2; 
	}if(t1) puts("1");else if(fl || (!fl && !t2)) puts("0");else puts("2");
	return 0;
}

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

int main() {
  int n;
  string s;
  cin >>n >>s;
  int k=0;
  string a="ABC";
  rep(i,n-2){
    if(s.substr(i,3)==a){
      k++;
    }
  }
    
  cout << k <<endl;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,i,j,sum=0;
	cin>>a;
	int b[a+1];
	for(i=1;i<=a;i++)
	cin>>b[i];
	int c[a+1];
	for(i=1;i<=a;i++)
	cin>>c[i];
	int d[a+1];
	for(i=1;i<=a-1;i++)
	cin>>d[i];
	for(i=1;i<=a;i++)
	{
		j=i+1;
		sum=sum+c[b[i]];
		if(j>a)
		break;
		if(b[j]-b[i]==1)
		sum+=d[b[j]-1];
	}
	cout<<sum<<endl;
	return 0;
 } 

Measured memory_bytes: 256