akhauriyash/Code-Regression huggingface dataset:
#include <atcoder/dsu>
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, q;

    cin >> n >> q;

    atcoder::dsu t(n);

    while (q--) {
        int op, u, v;
        cin >> op >> u >> v;
        if (op == 0) {
            t.merge(u, v);
        } else {
            cout << (int)t.same(u, v) << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 3840
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
using namespace std;
int n,f[100][10],p[100][11],add0=-1000000000;
bool c[10];
void dfs(int x)
{
    if (x==10)
    {
        bool flag=false;
        int add=0;
        for (int i=0; i<=n-1; ++i)
        {
            int t=0;
            for (int j=0; j<=9; ++j)
                if (c[j]&&f[i][j])
                    t++,flag=true;
            add+=p[i][t];
        }
        if (flag)add0=max(add,add0);
    }
    else
    {
        c[x]=true;
        dfs(x+1);
        c[x]=false;
        dfs(x+1);
    }
}
int main()
{
    cin>>n;
    for (int i=0; i<=n-1; ++i)
        for (int j=0; j<=9; ++j)
            cin>>f[i][j];
    for (int i=0; i<=n-1; ++i)
        for (int j=0; j<=10; ++j)
            cin>>p[i][j];
    dfs(0);
    cout<<add0;
}


Measured memory_bytes: 384
package main

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

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

func main() {
	var length int
	var idx int
	var str string
	fmt.Scan(&length, &idx, &str)

	s := ""

	for i := 0; i < length; i++ {
		if i == idx-1 {
			l := strings.ToLower(string(str[i]))
			s += string(l)
		} else {
			s += string(str[i])
		}
	}
	fmt.Println(s)
}

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

var dx = []int{0, 1, 0, -1, 0}
var dy = []int{1, 0, -1, 0, 0}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

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

func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}

func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

var nextReader func() []byte

func init() {
	nextReader = newScanner()
	log.SetFlags(log.Lshortfile)
}

func newScanner() func() []byte {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() []byte {
		r.Scan()
		return r.Bytes()
	}
}

func nextBytes() []byte {
	return nextReader()
}

func nextString() string {
	return string(nextReader())
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(string(nextReader()), 10, 64)
	return v
}

func nextInt() int {
	v, _ := strconv.Atoi(string(nextReader()))
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(string(nextReader()), 64)
	return f
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) VL (vec)(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define eb emplace_back
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define cont const auto
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
#define PQ priority_queue
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  str s[2];
  cin>>n>>s[0]>>s[1];
  
  ll res;
  int prev;
  if(s[0][0]==s[1][0])prev=1;
  else prev=2;
  if(prev==1)res=3;
  else res=6;
  reps(i,n-1){
    if(prev==2)i++;
    int now;
    if(s[0][i]==s[1][i])now=1;
    else now=2;
    if(prev==2){
      if(now==1)res*=1;
      else res*=3;
    }
    else{
      res*=2;
    }
    prev=now;
    res%=MOD;
  }
  out(res);
  
  
  
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
 
int main(int argc, const char * argv[]) {

    int count[4][3][10]={0};
    int n, b, f, r, v, i, j, k;
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%d %d %d %d", &b, &f, &r, &v);
        count[b-1][f-1][r-1]+=v;
    }
    for(i=0; i<4; i++){
        for(j=0; j<3; j++){
            for(k=0; k<10; k++){
                printf(" %d",count[i][j][k]);
            }
            printf("\n");
        }
        if(i<3){
            printf("####################\n");
        }
    }

return 0;
}

Measured memory_bytes: 612
#include<cstdio>
#include<iostream>
#define N 3005

using namespace std;

inline int In(){
	char c=getchar(); int x=0,ft=1;
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') ft=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
	return x*ft;
}

const int P=1e9+7,inv2=5e8+4;
int n,q,A[N],f[N][N],ans=0;

inline int fpow(int x,int k){
	int s=1,t=x;
	for(;k;k>>=1,t=1ll*t*t%P) if(k&1) s=1ll*s*t%P;
	return s;
}

int main(){
	n=In(); q=In();
	for(int i=1;i<=n;++i) A[i]=In();
	for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
	if(i^j) f[i][j]=(A[i]>A[j]);
	for(int i=1,x,y;i<=q;++i){
		x=In(); y=In(); if(x>y) swap(x,y);
		f[x][y]=f[y][x]=1ll*(f[x][y]+f[y][x])%P*inv2%P;
		for(int j=1;j<=n;++j) if(j^x&&j^y)
		f[x][j]=f[y][j]=1ll*(f[x][j]+f[y][j])%P*inv2%P,
		f[j][x]=f[j][y]=1ll*(f[j][x]+f[j][y])%P*inv2%P;
	}
	for(int i=1;i<=n;++i) for(int j=i+1;j<=n;++j)
	ans=(ans+f[i][j])%P; ans=1ll*fpow(2,q)*ans%P;
	printf("%d\n",ans);
	return 0;
}

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

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


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

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    lli n,i;
    cin>>n;
    lli a[n],aa[n];
    for(i=0;i<n;i++)
        cin>>a[i];
        aa[0]=0; aa[1]=abs(a[1]-a[0]);
    //    cout<<abs(a[3]-a[1])+aa[1]<<":"<<endl;
        for(i=2;i<n;i++)
        {
            aa[i]= min(abs(a[i-1]-a[i])+aa[i-1],abs(a[i-2]-a[i])+aa[i-2]);
            //cout<<aa[i]<<endl;
        }
        cout<<aa[n-1];

	return 0;
}
//4
//10 30 40 20


Measured memory_bytes: 1792
#include<stdio.h>

int main(void){

    long int N,min_carriable,Total_Time,Transpotation[5];
    int i;

    scanf("%ld",&N);
    for(i = 0;i < 5;i++){
        scanf("%ld",&Transpotation[i]);
    }

    min_carriable = Transpotation[0];
    for(i = 1;i < 5;i++){
        if(Transpotation[i] < min_carriable){
            min_carriable = Transpotation[i];
        }
    }

    if(N % min_carriable == 0){
        Total_Time = (N / min_carriable) + 4;
    }else{
        Total_Time = (N / min_carriable) + 5;
    }

    printf("%ld",Total_Time);
    return 0;
}

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

int main(void)
{
    int S,W;
    cin >> S >> W;
    if(S<=W){
      cout << "unsafe" << endl;
    }
    else{
      cout << "safe" << endl;  
    }

    return 0;

}

Measured memory_bytes: 3608
//abc046_a.cpp
//Fri Oct 19 22:36:07 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int a[3];
	for (int i=0;i<3;i++){
		cin >> a[i];
	}

	sort(a,a+3);
	int ans = 0;
	if (a[0] == a[1] && a[1] == a[2]){
		cout << 1 << endl;
	}else if (a[0] == a[1] || a[0] == a[2] || a[1] == a[2]){
		cout << 2 << endl;
	}else {
		cout << 3 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

ll N, K;
vector<ll> A;
vector<ll> B;

int main()
{
    cin >> N >> K;
    A.resize(N);
    B.resize(N+1);
    for(int i = 0;i < N;i++)
    {
        cin >> A[i];
    }
    ll logN = log2(N)+100;
    for(ll i = 0;i < min(K, logN) ;i++)
    {
        fill(B.begin(), B.end(), 0LL);
        for(ll j = 0; j < N;j++)
        {
            B[max(j-A[j], 0LL)]++;
            if(j+A[j] < N-1)B[j+A[j]+1]--;
        }
        for(ll j = 0;j < N;j++)
        {
            A[j] = B[j];
            B[j+1] += B[j];
        }
    }
    for(ll i = 0;i < N;i++)
    {
        cout << B[i];
        if(i == N-1)
        {
            cout << endl;
        }
        else
        {
            cout << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 6004
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

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 int long long
signed main(){
    int n,a,b;
    cin >> n >> a >> b;
    if(a+b>n+1){
        cout << -1 << endl;
        return 0;
    }
    if(a==1){
        if(b==n){
            for(int i=n;i>=1;i--){
                cout << i;
                if(i!=1){
                    cout << " ";
                }
            }
            cout << endl;
        }else{
            cout << -1 << endl;
        }
        return 0;
    }
    if(b==1){
        if(a==n){
            for(int i=1;i<=n;i++){
                cout << i;
                if(i!=n){
                    cout << " ";
                }
            }
            cout << endl;
        }else{
            cout << -1 << endl;
        }
        return 0;
    }
    if(b+a-1<=n&&n<=b*a){
        int c = (n-b)/(a-1);
        vector<int> v(a,c);
        v[0] = b;
        int tmp = n-b-(a-1)*c;
        for(int i=1;i<=tmp;i++){
            v[i]++;
        }
        int x = 0;
        for(int i=0;i<a;i++){
            x += v[i];
            for(int j=0;j<v[i];j++){
                cout << x-j;
                if(!(i==a-1&&j==v[i]-1)){
                    cout << " ";
                }
            }
        }
        cout << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int main(){
  int w, h, n;
  cin >> w >> h >> n;
  int x1 = w, y1 = h;
  int x0 = 0, y0 = 0;

  int ans = 0;
  rep(i,n){
    int a, b, ai;
    cin >> a >> b >> ai;
    if (ai == 1 && a > x0) x0 = a;
    else if (ai == 2 && a < x1) x1 = a;
    else if (ai == 3 && b > y0) y0 = b;
    else if (ai == 4 && b < y1) y1 = b;
    ans = (x1 - x0) * (y1 - y0);
    if (ans < 0){
      ans = 0;
      break;
    }
  }
  cout << ans << endl;
}


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

int main() {
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	if(a >= k){
		cout << k;
	} else if(a+b >= k){
		cout << a;
	} else if(a+b+c >= k){
		cout << a - (k-(a+b));
	}
}

Measured memory_bytes: 3544
#include<iostream>

int main(){
    int r, g, b;
    std::cin >> r >> g >> b;
    int num = 100 * r + 10 * g + b;
    if(num % 4 == 0) std::cout << "YES" << std::endl;
    else std::cout << "NO" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool cmp(long long int x,long long int y)
{
   return x>y;
}
int main(void)
{
   long long int t,n,a,b;
   vector<long long int> v,v1,v2;
   vector< pair <long long int,long long int> >p,p1,p2;
   set<long long int> st;
   priority_queue<long long int> pq;
   priority_queue< long long int,vector<long long int>,greater<long long int> > lpq;
   priority_queue< pair<long long int,long long int>,vector< pair<long long int,long long int> >,greater< pair <long long int,long long int> > > plpq;
   string s;
   cin>>n;
   cin>>a>>b;
   for(long long int i=a;i<=b;i++)
   {
      if(i%n==0)
      {
         cout<<"OK"<<endl;
         return 0;
      }
   }
   cout<<"NG"<<endl;
   return 0;
}


Measured memory_bytes: 3632
import java.util.*;
 

public class Main {
    public static void main(String[] args) {   
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int x[] = new int[N]; 
        int count = 0;

        for(int i=0; i<N; i++){
            x[i] = sc.nextInt();
            if(x[i]<K-x[i]){
               count += 2*x[i];
            }else{
                count += 2*(K-x[i]);
            }
        }

        System.out.println(count);
        
    }
    
}    





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

int main()
{
  string S ;
  cin>>S ;
  
  int min=1e9 ;
  int SIZE=S.size() ;
  for(int i=0;i<SIZE-2;i++){
    int X=100*(S.at(i)-'0')+10*(S.at(i+1)-'0')+(S.at(i+2)-'0') ;
    int dif=(X>753?X-753:753-X) ;
    if(dif<min) min=dif ;
  }
  
  cout<<min<<endl ;
  
  return 0 ;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

template <typename T1, typename T2>
bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

class UnionFind {
    using i64 = std::int64_t;

private:
    std::vector<i64> par;
    std::vector<i64> sz;

public:
    UnionFind(i64 N) : par(N), sz(N, 1) {
        for (i64 i = 0; i < N; ++i) par[i] = i;
    }
    i64 root(i64 x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }
    bool same(i64 x, i64 y) {
        return root(x) == root(y);
    }
    void unite(i64 x, i64 y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (sz[x] < sz[y]) std::swap(x, y);
        par[y] = x;
        sz[x] += sz[y];
    }
    i64 size(i64 x) {
        return sz[root(x)];
    }
    void reset(i64 N) {
        par.resize(N);
        for (i64 i = 0; i < N; ++i) par[i] = i;
        sz.assign(N, 1);
    }
};

void solve() {
    ll N, M;
    cin >> N >> M;
    UnionFind uf(N);
    for (ll i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        uf.unite(a, b);
    }
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        chmax(ans, uf.size(i));
    }
    prints()(ans);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(nullptr), cout.tie(nullptr);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 6344
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main(){
  int n,f;
  cin>>n;
  bitset<10> b[n];
  ll p[n][11], ans=LLONG_MIN;
  rep(i,n)
    rep(j,10){
       cin>>f;
       if(f)
        b[i].set(j); 
    }
  rep(i,n)
    rep(j,11)
       cin>>p[i][j];
  rep(i,1023){
     bitset<10> jo(i+1);
     ll sum=0;
     rep (j,n)
       sum+=p[j][(jo&b[j]).count()];
     ans=max(ans,sum);
  }
  cout<<ans;
  return 0;
}

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

int max(int a, int b){
  if(a > b){
    return a;
  }else{
    return b;
  }
}

int main(){
  int n, k;
  scanf("%d %d", &n, &k);
  int m = max(n + 1, k);
  double p_inv[m];
  for(int i = 1; i < m; i++){
    p_inv[i] = 1;
  }
  
  int i = k - 1;
  int index = 0;
  int now = k;
  while(i >= 1){
    now = (now - 1) / 2 + 1;
    index++;
    double p_inv_tmp = pow(2, index);
    while(i >= now){
      p_inv[i] = p_inv_tmp;
      i--;
    }
  }
  
  double prob = 0;
  for(int i = 1; i <= n; i++){
    prob += 1 / p_inv[i];
  }
  prob /= (double)n;
  
  printf("%.11lf", prob);
  
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(abs(a-x)<abs(b-x)){
    cout<<'A'<<endl;
  }
  else{
    cout<<'B'<<endl;
  }
  return(0);
}


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

typedef long long int ll;

using namespace std;

ll max(ll a,ll b)
{
	if(a>b)
		return a;
	return b;
}

ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

int main()
{
	
	int n;
	string s;
	cin>>n;
	cin>>s;
	//n=s.length();
	int count=0;
	int i=0;
	while(i<n)
	{
		if(s[i]=='A'&&i+2<n&&s[i+1]=='B'&&s[i+2]=='C')
		{
			i+=2;
			count++;
		}
		i++;
	}
cout<<count<<endl;

	return 0;
}


Measured memory_bytes: 256
DOWN = []
EDGE = []
POOL = []

for i, c in enumerate(input()):
    if c == '\\':
        DOWN.append(i)
    elif c == '/':
        if DOWN:
            e = DOWN.pop()
            Li = i - e # Calcurate 1 line.  \______/ 
            while EDGE: # Merge connected pools.
                if EDGE[-1] > e:
                    EDGE.pop()
                    Li += POOL.pop()
                else:
                    break
            EDGE.append(e)
            POOL.append(Li)

print(sum(POOL))
print(len(POOL), *POOL)

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

int main()
{
    int n, m;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    cin >> m;
    vector<string> t(m);
    rep(i, m) cin >> t[i];

    int ans = 0;
    rep(i, n)
    {
        int tmp = 0;
        rep(k, n) if (s[i] == s[k]) tmp++;
        rep(j, m) if (s[i] == t[j]) tmp--;

        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return (0);
}


Measured memory_bytes: 3584
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

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

  vector<ll> count(n+1, 0);

  ll ai;
  for (int i = 0; i < q; i++) {
    cin >> ai;
    count[ai] += 1;
  }

  for (int i = 1; i < n+1; i++) {
    if(k - (q - count[i]) > 0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1408
n,k=map(int,input().split())
a=list(map(int,input().split()))
def card(N,K,A):
    card = sorted(A,reverse=True)
    s=0
    ans=0
    for i in card:
        if s+i<K:
            s+=i
            ans+=1
        else:
            ans=0
    return ans
print(card(n,k,a))



                
        


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int n;
bool g[700][700]={};
int num[700]={};
vector<pair<int,int>> sz;
int b,w;

bool dfs(int v,int c){
    if(c==1)++b;
    else ++w;
    num[v]=c;
    rep(i,n){
        if(i==v)continue;
        if(!g[v][i]){
            if(num[i]==c)return false;
            if(num[i]==0&&!dfs(i,-c))return false;
        }
    }
    return true;
}

int main(){
    int m;
    cin>>n>>m;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        --a,--b;
        g[a][b]=g[b][a]=true;
    }
    rep(i,n){
        if(num[i]==0){
            b=0,w=0;
            if(!dfs(i,1)){
                cout<<-1<<endl;
                return 0;
            }
            sz.push_back(make_pair(b,w));
        }
    }
    int s=sz.size();
    bool dp[s+1][n+1]={};
    dp[0][0]=true;
    rep(i,s){
        for(int j=0;j<=n;++j){
            if(j+sz[i].first<=n)dp[i+1][j+sz[i].first]|=dp[i][j];
            if(j+sz[i].second<=n)dp[i+1][j+sz[i].second]|=dp[i][j];
        }
    }
    int ans=inf;
    rep(i,n+1){
        if(dp[s][i]){
            ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1152
#include<cstdio>
int gcd(int a,int b)
{
	if(b==0)return a;
	else return gcd(b,a%b);
}
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)==2)
	{
		int d = gcd(n,m),ans = n/d*m;
		printf("%d %d\n",d,ans);
	}
	return 0;
} 

Measured memory_bytes: 1024
n,m=map(int,input().split())
p_list=[list(map(lambda x:int(x)-1,input().split()))[1:] for _ in [0]*n]

p_check=[False for _ in [0]*n]
l_check=[False for _ in [0]*m]
l_list=[[] for _ in [0]*m]

for k,i in enumerate(p_list):
    for j in i:
        l_list[j].append(k)

for i,j in enumerate(l_list):
    if j!=[]:
        q=[i]
        break

l_check[q[0]]=True

while q:
    qq=q.pop()
    p=l_list[qq]
    for pp in p:
        if p_check[pp]==False:
            p_check[pp]=True
            for l in p_list[pp]:
                if l_check[l]==False:
                    l_check[l]=True
                    q.append(l)

print(["NO","YES"][all(p_check)])

Measured memory_bytes: 30340
N,M = map(int,input().split())
H = list(map(int,input().split()))
AB = [list(map(int,input().split())) for i in range(M)]

ans = [0] * N
for i in range(M):
    if H[AB[i][0]-1] > H[AB[i][1]-1]:
        ans[AB[i][1]-1] += 1
    if H[AB[i][0]-1] < H[AB[i][1]-1]:
        ans[AB[i][0]-1] += 1
    if H[AB[i][0]-1] == H[AB[i][1]-1]:
        ans[AB[i][0]-1] += 1
        ans[AB[i][1]-1] += 1
print(ans.count(0))

Measured memory_bytes: 31832
#include <iostream>

int main(){
    int a, b, k;
    std::cin >> a >> b >> k;
    int mem=0;
    for(int i=0; i<k; ++i){
        if(a+i>b) break;
        std::cout << a+i << std::endl;
        mem = a+i;
    }
    for(int i=k-1; i>=0; --i){
        if(b-i<a) break;
        if(mem<b-i) std::cout << b-i << std::endl;
    }
    return 0;
}


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

int main() {
	int k, x;
	std::cin >> k >> x;
	if(k*500>=x){
	    std::cout << "Yes" << std::endl;
	}else{
	    std::cout << "No" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int main()
{
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for(int i = 0; i < N; ++i) cin >> L[i];
    int cnt = 0;
    int pos = 0;
    for(auto l : L){
        if(pos > X) break;
        cnt++;
        pos += l;
    }
    if(cnt == L.size() && pos <= X) cnt++;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = list(input())
# print(s)

a = [0] * n
b = [0] * n
c = [0] * n

for i in range(1, n):
    a[i] = a[i - 1]
    if s[i - 1] == 'W':
        a[i] += 1

for i in range(1, n):
    b[n - i - 1] += b[n - i]
    if s[n - i] == 'E':
        b[n - i - 1] += 1

# print(a)
# print(b)
for i in range(n):
    c[i] = a[i] + b[i]

print(min(c))


Measured memory_bytes: 40588
def solve(string):
    n = len(string)
    ans = [0] * n
    count = 0
    for i, a in enumerate(string):
        if a == "R":
            count += 1
            continue
        if count > 0:
            ans[i] += count // 2
            ans[i - 1] += (count + 1) // 2
            count = 0
    for i, a in enumerate(string[::-1]):
        if a == "L":
            count += 1
            continue
        if count > 0:
            ans[n - i - 1] += count // 2
            ans[n - i] += (count + 1) // 2
            count = 0
    return " ".join([str(a) for a in ans])


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 10492
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <string>
#include <tuple>
#include <cmath>
 
using namespace std;
typedef long long ll;

int N, A, B;

signed main() {
    cin >> N >> A >> B;
    if ((B - A) % 2 == 1) {
        cout << "Borys" << endl;
    } else {
        cout << "Alice" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

    //Scanner cin = new Scanner(new FileReader("input.txt"));
   Scanner cin = new Scanner (System.in);

    String num = cin.next();
    StringBuffer res = new StringBuffer();
    for (int i=0;i<num.length();i++){
      if (num.charAt(i)=='1') res.append('9');
      else if (num.charAt(i)=='9') res.append('1');
    }
    System.out.println(res.toString());

  }

}

Measured memory_bytes: 22612
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

vector<string> res;

string s;
int n;
void dfs(int ind, int m) {
	if (ind == n) {
		res.push_back(s);
		return;
	}
	REP(i, m+1) {
		s[ind] = (char)('a' + i);
		if (i == m) {
			dfs(ind + 1, m+1);
		} else {
			dfs(ind + 1, m);
		}
		
	}
}

int main() {
	IOS;
	//ll n;
	cin >> n;
	REP(i, n) {
		s += ".";
	}
	dfs(0, 0);
	sort(all(res));
	REP(i, res.size()) {
		put(res[i]);
	}
	return 0;
}

Measured memory_bytes: 7796
import collections
import numpy as np

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0 for _ in range(Q)]
C = [0 for _ in range(Q)]
for i in range(Q):
  B[i], C[i] = map(int, input().split())
  
a = collections.Counter(A)
S = np.sum(A)
for i in range(Q):
  S += (C[i]-B[i]) * a[B[i]]
  a[C[i]] += a[B[i]]
  a[B[i]] = 0

  print(S)

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

map<int, int> cnt;

int main(){
    int n; cin >> n;
    for(int i=0;i<n;i++){
        int a; cin >> a;
        
        auto itr = cnt.find(a);
        if(itr==cnt.end()) cnt[a] = 1;
        else itr->second++;
    }

    int ans = 0;
    for(auto itr : cnt){
        if(itr.first <= itr.second) ans += itr.second - itr.first;
        else ans += itr.second;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> a(n), cnt(n);
  rep(i,n) cin >> a[i];
  vector<vector<int> > grid(h, vector<int>(w, -1));
  int cur = 0;
  rep(y,h) {
    if (y % 2 == 0) {
      rep(x, w) {
        grid[y][x] = (cur+1);
        cnt[cur]++;
        if (cnt[cur] == a[cur]) cur++;
      }
    }
    else {
      for (int x = w-1; x >= 0; --x) {
        grid[y][x] = (cur+1);
        cnt[cur]++;
        if (cnt[cur] == a[cur]) cur++;
      }
    }
  }
  rep(y, h) {
    rep(x, w) {
      if (x < w-1) cout << grid[y][x] << " ";
      else cout << grid[y][x];
    }
    cout << "\n";
  }
  return 0;
}

Measured memory_bytes: 384
/**
 * author:    Ziel
 * created:   22.04.2020 20:49:37
**/

// ~zaletaet~

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define pb push_back

using namespace std;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const ll N = 2e5 + 123, MOD = 1e9 + 7, oo = 1e9 + 9, INF = 1e18 + 9;
const double EPS = 1e-9, PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int tt[N], sm[N];

main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	int n, ch;
	cin >> n >> ch;
	vector<int> s(n), t(n), c(n);
	for (int i = 0; i < n; i++)
		cin >> s[i] >> t[i] >> c[i];
		
	for (int j = 1; j <= ch; j++) {
		for (int i = 0; i <= 200000; i++) tt[i] = 0;
		for (int i = 0; i <= n; i++) {
			if (c[i] == j) tt[s[i] * 2 - 1]++, tt[t[i] * 2]--;
		}
		for (int i = 1; i <= 200000; i++) tt[i] += tt[i - 1];
		for (int i = 0; i <= 200000; i++) {
			if (tt[i] > 0) sm[i]++;
		}
	}
	
	int mx = 0;
	for (int i = 0; i <= 200000; i++) mx = max(mx, sm[i]);
	cout << mx;
	return 0;
}

/*
	Raise your standard.
*/

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    cout << fixed << setprecision(15) ;
    int n,k;
    cin >> n >> k;
    double ans = 0;
    rep(i,n){
        double num = i+1;
        double cnt = 0;
        double numans = 1;
        while(num<k){
            num*=2;
            cnt++;
        }
        numans/=n;
        rep(j,cnt)numans/=2;
        ans+=numans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
typedef pair<int,int> pii;

struct Edge{
    int to,mai,t;
    Edge(){}
    Edge(int to,int mai,int t){
        this->to = to;
        this->mai = mai;
        this->t = t;
    }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef tuple<ll,ll,ll> T;
const ll INF = 1e+15;
ll dp[50][2501];
ll c[50],d[50];
int main(){
    int n,m,s;
    cin>>n>>m>>s;

    Graph g(n);
    rep(i,m){
        int u,v,a,b;
        cin>>u>>v>>a>>b;
        u--;v--;
        g[u].push_back(Edge(v,a,b));
        g[v].push_back(Edge(u,a,b));
    }
    rep(i,n) cin>>c[i]>>d[i];


    rep(i,n) rep(j,2501) dp[i][j]=INF;

    s = min(s,2500);
    priority_queue<T,vector<T>,greater<T>> que;
    que.push(T(0,0,s));

    while(!que.empty()){
        T now = que.top();que.pop();

        ll t = get<0>(now);
        ll pos =get<1>(now);
        ll mai = get<2>(now);
        if(dp[pos][mai]<=t) continue;
        dp[pos][mai]=t;
        rep(i,g[pos].size()){
            Edge e = g[pos][i];
            if(mai>=e.mai){
                que.push(T(t+e.t,e.to,mai-e.mai));
            } 
        }
        que.push(T(t+d[pos],pos,min((ll)2500,mai+c[pos])));
    }
    
    for(int i = 1;i<n;i++){
        ll ans = INF;
        rep(j,2501){
            ans = min(ans,dp[i][j]);
        }
        cout<<ans<<endl;
    }
    return 0;

}

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
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;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;

ll mpow(ll x, ll n, ll m){
  if(m<=0){ return 0;}
  ll r = 1;
  while(n>0){
    if(n&1){ r = r*x%m; }
    x = x*x%m;
    n >>= 1;
  }
  return r;
}

int popcount(ll n){
  // n =(n&0x55555555)+(n>>1&0x55555555);
  // n =(n&0x33333333)+(n>>2&0x33333333);
  // n =(n&0x0f0f0f0f)+(n>>4&0x0f0f0f0f);
  // n =(n&0x00ff00ff)+(n>>8&0x00ff00ff);
  // n =(n&0x0000ffff)+(n>>16&0x0000ffff);
  return __builtin_popcount(n);
}

int func(ll n){
  if(n==0){ return 0;}
  else{ return func(n%popcount(n))+1; }
}


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

  ll p = count(ALL(s),'1');
  ll x1 = 0; //必要な値を前処理
  ll x2 = 0;
  REP(i,N){
    char c = s[i];
    if(c=='1'){
      if(p==1){
        x1 = 0;
      }else{
        x1 += mpow(2,N-i-1,p-1);
        x1 %= (p-1);
      }
      x2 += mpow(2,N-i-1,p+1);
      x2 %= (p+1);
    }
  }
  REP(i,N){
    char c = s[i];
    ll ans;
    if(c=='1'){ //前処理の値を使ってステップ1用の値を作り計算
      if(p==1){
        ans = 0;
      }else{
        ans = 1 + func( (x1-mpow(2,N-i-1,p-1)+p-1)%(p-1) );
      }
    }else{
      ans = 1 + func(  (x2+mpow(2,N-i-1,p+1))%(p+1) );
    }
    cout << ans << "\n";
  }
  
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int n,q,a,b,x,y;
vector<vector<int>> d(200010);
vector<int> t(200010,0),v(200010);
map<pair<int,int>,bool> m;
int c=0;
void dfs(int p){
  c+=t[p];
  v[p]=c;
  for(auto au:d[p]){
    if(!m[pair<int,int>(min(au,p),max(au,p))]){
      m[pair<int,int>(min(au,p),max(au,p))]=true;
      dfs(au);
    }
  }
  c-=t[p];
}
int main(){
  cin>>n>>q;
  for(int i=0;i<n-1;i++){
    cin>>a>>b;
    d[a].push_back(b);
    d[b].push_back(a);
  }
  for(int i=0;i<q;i++){
    cin>>x>>y;
    t[x]+=y;
  }
  dfs(1);
  for(int i=1;i<=n;i++){
    cout<<v[i]<<" ";
  }
}


Measured memory_bytes: 52352
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
int f[1<<18][2];
int n;
int _max(int x, int y) { return x > y ? x : y; }
int main() {
	int i, j, k;
	scanf("%d", &n);
	for(i = 0; i < 1<<n; i++) scanf("%d", &f[i][0]);
	for(i = 0; i < n; i++){
		for(j = 0; j < 1<<n; j++){
			if(j&(1<<i)){
				int p = j^(1<<i);
				if(f[p][0] > f[j][0]) f[j][1] = f[j][0], f[j][0] = f[p][0];
				else if(f[p][0] > f[j][1]) f[j][1] = f[p][0];
				if(f[p][1] > f[j][1]) f[j][1] = f[p][1];
			}
		}
	}
	int ans = 0;
	for(i = 1; i < 1<<n; i++){
		ans = _max(ans, f[i][0]+f[i][1]);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int a,b ;

    cin >> a >> b;
    vector<int> vec;
    vec.push_back(a+b);
    vec.push_back(a-b);
    vec.push_back(a*b);

    int max = *max_element(vec.begin(), vec.end());

    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A_k = list(map(int, input().split()))
B_k = list(map(int, input().split()))
C_k = list(map(int, input().split()))

amount = 0
mae = -1
for A in A_k:
    amount += B_k[A-1]
    if A == mae + 1:
        amount += C_k[A-2]
    mae = A    

print(amount)

Measured memory_bytes: 3064
n = gets.to_i
a = gets.split.map(&:to_i).sort_by{|x| x}

f = 0
a.length.times do |i|
  if a[i] == a[i+1]
    print 'NO'
    f = 1
    break
  end
end

print 'YES' if f == 0

Measured memory_bytes: 22144
//**************************
//*** writer  :  Alan Hu **
//************************
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include<cstring>
#include<cmath>

using namespace std;
     
#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
     
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

vector<string> v;

int main()
{
	string s1,s2,s3;
	cin>>s1>>s2;
	s3=s1;
	rept(i,0,s1.size())
	{
		string cnt=s1.substr(1,s1.size()-1);
		v.pb(cnt+s1[0]);	
		s1=cnt+s1[0];
	}
	rept(i,0,v.size())
	{
		if (s2==v[i])
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

int main(){
  int64_t N;
  cin >> N;
  int A = (int)sqrt(N);
  int answer = 11;
  for(int64_t i=1;i<=A;i++){
    if(N%i==0){
      int M = to_string(N/i).size();
      answer = min(answer,M);
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int INF=(1<<21);
int main(){

  int n;
  
  while(cin>> n,n){
    int town[11][11];
    int a,b,c;
    int min_total=INF;
    int min_town=0;
    int s[11]={0};
    for(int i=0;i<11;i++){
      for(int j=0;j<11;j++){
	town[i][j]=(i==j)?0:INF;
      }
    }
 
    int v=0;
    for(int i=0;i<n;i++){
    cin>> a>> b>> c;
    town[a][b]=c;
    town[b][a]=c;
    v=max(max(v,a),b);
  }

    for(int i=0;i<=v;i++){
      for(int j=0;j<=v;j++){
	for(int k=0;k<=v;k++){
	  town[j][k]=min(town[j][k],town[j][i]+town[i][k]);
	}
      }
    }

    for(int i=0;i<=v;i++){
      int total=0;
      for(int j=0;j<=v;j++){
	total+=town[i][j];
      }
      s[i]=total;
      min_total=min(min_total,total);
    }
    for(int i=0;i<=v;i++){
      if(s[i]==min_total){
	cout<< i<< ' ';
	cout<< min_total<< endl;
	break;
      }
    }
  }
}

Measured memory_bytes: 1160
X, Y, A, B, C = tuple(int(v) for v in input().split())
p_list = sorted((int(v) for v in input().split()), reverse=True)
q_list = sorted((int(v) for v in input().split()), reverse=True)
r_list = sorted((int(v) for v in input().split()), reverse=True)

p_list = p_list[:X]
q_list = q_list[:Y]
all_apple = sorted(p_list + q_list + r_list, reverse=True)

yummy = sum(all_apple[:X+Y])
# # 赤リンゴを食べる
# for _ in range(X):
#     if p_list[-1] >= r_list[-1]:
#         yummy += p_list.pop()
#         if len(p_list) == 0:
#             p_list = [0]
#     else:
#         yummy += r_list.pop()
#         if len(r_list) == 0:
#             r_list = [0]
# # 緑リンゴを食べる
# for _ in range(Y):
#     if q_list[-1] >= r_list[-1]:
#         yummy += q_list.pop()
#         if len(q_list) == 0:
#             q_list = [0]
#     else:
#         yummy += r_list.pop()
#         if len(r_list) == 0:
#             r_list = [0]

print(yummy)


Measured memory_bytes: 23328
class PotentialUnionFind
  def initialize(n)
    @size = Array.new(n, 1)
    @rank = Array.new(n, 0)
    @diff_weight = Array.new(n + 1, 0)
    @parent = []

    (0..n).each do |i|
      @parent[i] = i
    end
  end

  def find(x)
    if @parent[x] == x
      x
    else
      root = find(@parent[x])
      @diff_weight[x] += @diff_weight[@parent[x]]
      @parent[x] = root
    end
  end

  def unite(x, y, w)
    w += weight(x)
    w -= weight(y)
    x = find(x)
    y = find(y)

    return false if x == y

    if @rank[x] < @rank[y]
      @diff_weight[x] = -w
      @parent[x] = y
      @size[y] += @size[x]
    else
      @parent[y] = x
      @diff_weight[y] = w
      @size[x] += @size[y]

      @rank[x] += 1 if @rank[x] == @rank[y]
    end
  end

  def weight(x)
    find(x)
    @diff_weight[x]
  end

  def diff(x, y)
    weight(y) - weight(x)
  end

  def same?(x, y)
    find(x) == find(y)
  end

  def size(x)
    @size[find(x)]
  end
end

N, Q = gets.split.map(&:to_i)
puf = PotentialUnionFind.new(N + 1)

Q.times do
  query = gets.split.map(&:to_i)

  if query.first == 0
    _, x, y, z = query

    puf.unite(x, y, z)
  else
    _, x, y = query

    if puf.same?(x, y)
      puts puf.diff(x, y)
    else
      puts '?'
    end
  end
end



Measured memory_bytes: 10248
i=gets
W=i.split[0].to_i
H=i.split[1].to_i
x=i.split[2].to_i
y=i.split[3].to_i
r=i.split[4].to_i
if (x>=r && x<=W-r && y>=r && y<=H-r)
    print "Yes\n"
else
    print "No\n"
end


Measured memory_bytes: 6872
#include<iostream>
using namespace std;
int main()
{
  int num,rem;
  cin>>num;
  int ar=0;
  int br=0;
  while(num!=0)
  {
    rem=num%10;
    if(rem==7)
    {
      ar+=1;
    }
    else
    {
      br+=1;
    }
    num=num/10;
  }
  if(ar>=1)
    cout<<"Yes";
  else
    cout<<"No";
      
  return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n;
    cin>>n;
    int l[2020];
    for(int i=0; i<n; i++) cin>>l[i];
    sort(l, l+n);
    ll ans=0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n-1; j++){
            int k=lower_bound(l+j+1, l+n, l[i]+l[j])-l;
            ans+=k-j-1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    a_list.sort(reverse=True)

    ans = 0
    for i  in range(n):
        ans += a_list[2 * i + 1]
    print(ans)

    
if __name__ == '__main__':
    main()

Measured memory_bytes: 39492
'''
問題：
    水を入れる容器が 2つあります。
    容器 1には水を A ミリリットルまで入れることができ、
    水が B ミリリットル入っています。
    容器 2 には水が C ミリリットル入っています。
    容器 2 から容器 1 に入るだけ水を移します。
    容器 2 の中には何ミリリットルの水が残るでしょうか。
'''

'''
制約：
    入力は全て整数である。
    1 ≤ B ≤ A ≤ 20
    1 ≤ C ≤ 20
'''

# 標準入力から A, B, C の値を取得する
a, b, c = map(int, input().split())

# 容器2の水の量を計算して出力する
result = c - (a - b)

if result > 0:
    print(result)
else:
    print(0)    # 水は残ってないので、0 を出力する


Measured memory_bytes: 8992
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
ll K;
ll ds(ll x)
{
        ll ret = 0;
        while(x)
        {
                ret += x%10;
                x = x / 10;
        }
        return ret;
}
ld gets(ll x)
{
        ld ay = ds(x);
        ay = ((ld)(1.0*x) / (ay));
        return ay;
}
vector<ll> v , X;
int main()
{
        //cout<<setprecision(12) << fixed;
        cin >> K;
        v.pb(999999999999999LL);
        ll rm = 1;
        for(ll i=0;i<=16;i++){
                X.pb(rm);
                rm = rm*10LL;
        }
        ll cur = v.back();
        while(cur != 1) {

                ll nxt = 0;
                for(auto i : X) {
                        nxt = cur - i;
                        if(nxt <= 0) break;
                        if(gets(nxt) > gets(cur)) {
                                continue;
                        }
                        v.pb(nxt);
                                cur = nxt;
                                break;
                }
        }
        reverse(v.begin() , v.end());
        for(ll i=0;i<K;i++) cout << v[i] << "\n";
        return 0;
}


Measured memory_bytes: 256