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

int main(void)
{
    int64_t n;
    int a[4];
    pair <int, int> b[4];
    for (int i = 0; i < 4; i++) {
        scanf("%d", &a[i]);
        b[i].first = a[i] << (3 - i);
        b[i].second = i;
    }
    sort(b, b + 4);
    scanf("%lld", &n);
    n *= 4;
    int64_t ans = 0;
    while (n) {
        if (n <= 4 && b[0].second == 3) {
            ans += a[b[1].second];
            n -= 1 << b[1].second;
        }
        else {
            int div = 1 << b[0].second;
            ans += n / div * a[b[0].second];
            n %= div;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 262144
long long can_do[200000] = {};
int main() {
#define double long double
	long long a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	double ans = 0.0;
	can_do[0] = true;
	for (int i = 0;i < 4000;++i) {
		if (can_do[i] == true) {
			can_do[i + d] = true;
			can_do[i + c] = true;
		}
	}
	long long bunsi = 0;
	long long bunbo = 0;
	for (int q = 0;q <= 40;++q) {
		for (int j = 0;j <= 40;++j) {
			if ((q*a + j*b) * 100 <= f) {
				for (int t = min((q*a+j*b)*e,f - (q*a+j*b)*100);t >= 0;--t) {
					if (can_do[t] == true) {
						double up = t;
						double bot = (q*a + j*b) * 100 + t;
						if (up / bot >= ans) {
							ans = up / bot;
							bunsi = t;
							bunbo = (q*a+j*b)*100+t;
						}
					}
				}
			}
		}
	}
	cout << bunbo << " " << bunsi << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
	Scanner stdIn=new Scanner(System.in);
		int h,w,i,j;
		for(;;){
			h=stdIn.nextInt();
			w=stdIn.nextInt();
			if(h<1&&w<1)break;
			for(i=0;i<h;i++){
				for(j=0;j<w;j++){
					if(i!=0&&i!=h-1&&j!=0&&j!=w-1)System.out.print(".");
					else System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}


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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

int N;
int A[100050], B[100050];

bool comp(pair<int, int> a, pair<int, int> b) {
    if(a.first - a.second > b.first - b.second){
        return true;
    }else{
        return false;
    }
}

int main(){
    cin >> N;
    FOR(i,1,N+1)cin >> A[i];
    FOR(i,1,N+1)cin >> B[i];
    pair<int, int> p[N];
    FOR(i,1,N+1)
    {
      p[i-1] = make_pair(A[i],B[i]);
    }
    sort(p,p+N,comp);
    pair<int, int> tmp[N];
    REP(i,N)tmp[i] = p[i];
    if(p[0].first < p[0].second){cout << -1 << endl; return 0;}
    REPR(i,N-1){
      if(p[i].first < p[i].second)
      {
        int j=0;
        while(p[i].first < p[i].second && j < N)
        {
          if(p[j].first <= p[j].second){true;}
          else if(p[j].first - (p[i].second - p[i].first) < p[j].second){
            p[i].first += p[j].first-p[j].second;
            p[j].first = p[j].second;
          }else{
            p[j].first -= (p[i].second - p[i].first);
            p[i].first = p[i].second;
          }
          j++;
        }
      }
      else break;
    }
    REP(i,N)
    {
      if(p[i].first < p[i].second)
      {
        cout << -1 << endl;
        return 0;
      }
    }
    int cnt=0;
    REP(i,N)
    {
      if(p[i].first != tmp[i].first)cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MAX_N 5001
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;
typedef vector<ll> V;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;


int co = 1;
char k;
int W, N, v[1010], w[1010];

ll dp[1010][1010];//i???????????§???????????§?????????j??\?????¨?????????????????????????????§???

int main(){
	while (cin >> W&&W){
		REP(i, N + 1)REP(j, W + 1)dp[i][j] = 0;
		cin >> N;
		REP(i, N)cin >> v[i] >> k >> w[i];
		REP(i, N){
			REP(j, W + 1){
				if (j >= w[i]){
					dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
				}
				else{
					dp[i + 1][j] = dp[i][j];
				}
			}
		}
		int max = -1, ans = -1;
		REP(i, W + 1){
			if (max < dp[N][i]){
				max = dp[N][i];
				ans = i;
			}
		}
		printf("Case %d:\n", co++);
		cout << max << endl;
		cout << ans << endl;
	}
}

Measured memory_bytes: 9100
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, K = read_int()

def solve():
    ans = N % K
    return min(ans, abs(ans - K))

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 4016
import itertools
import math

def dfs(N,E,start):
    d = [-1] * (N + 1)
    d[start] = 0
    q = [start]
    while q:
        now = q.pop()
        vertexes = E[now]
        for to in vertexes:
            if d[to] == -1:
                d[to] = d[now] + E[now][to]
                q.append(to)
    return d
N = int(input())
E = [{} for _ in range(N + 1)]
for _ in range(N-1):
    a,b,c = map(int, input().split(" "))
    E[a][b] = c
    E[b][a] = c

Q, K = map(int, input().split(" "))
d = dfs(N,E,K)
AB = [list(map(int, input().split(" "))) for _ in range(Q)]
for a,b in AB:
    print(d[a] + d[b])

Measured memory_bytes: 113000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n,k;
  cin >> n >> k;
  vi h(n);
  rep(i,n) cin >> h[i];
  int ans=0;
  rep(i,n){
    if(k<=h[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
def main():
    N = int(input())
    ans = 0
    for i in range(N):
        ans += (i+1) * (N-i)
    for _ in range(N-1):
        u, v = map(int, input().split())
        l, r = min(u, v)-1, max(u, v)-1
        ans -= (l+1) * (N-r)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 74412
n = int(input())
a = list(map(int, input().split()))
ans = right = tmp = 0

for left in range(n):
  while(right < n):
    if(tmp & a[right]):
      break
    tmp += a[right]
    right += 1
  ans += (right - left)
  tmp -= a[left]
  
print(ans)
  
  

Measured memory_bytes: 24840
#include <cstdio>
#include <vector>
#include <cstring>
#include <cmath>
#include <algorithm>
#define INF 1e12
using namespace std;
typedef long long ll;
struct P{
	ll x,y,id;
	double dir;
	P(){}
	P(ll xx,ll yy,ll pp){
		x=xx;
		y=yy;
		id=pp;
		dir=atan2((double)yy,(double)xx);
		if(dir<0)dir=M_PI*2.0+dir;
	}
	P operator -(P p2){
		return P(x-p2.x,y-p2.y,id);
	}
	bool operator<(const P& p1)const{
		if(dir==p1.dir){
			if(p1.x==x)return y<p1.y;
			return x<p1.x;
		}else return dir<p1.dir;
	}
};
P p[55];
bool used[55];
P pp[55];
ll n,q;
//dp[????????°][??????-1][??????]
ll dp[41][41][41];
ll poll[41][41][41][41];
ll res[41];
ll resp[41][41];

int main(void){
	scanf("%lld",&n);
	for(ll i=0;i<n;i++){
		ll x,y;
		scanf("%lld %lld",&x,&y);
		p[i]=P(x,y,i+1);
		res[i+1]=INF;
	}
	for(ll turn=0;turn<n-2;turn++){
		ll nec=-1;
		for(ll i=0;i<n;i++){
			if(used[i])continue;
			if(nec==-1)nec=i;
			else if(p[i].y<p[nec].y || (p[i].y==p[nec].y && p[i].x<p[nec].x))nec=i;
		}
		P ch=p[nec];
		ll cnt=0;
		for(ll i=0;i<n;i++){
			if(used[i])continue;
			pp[cnt++]=p[i]-ch;
		}
		sort(pp,pp+n-turn);
		for(ll i=3;i<=cnt;i++){
			for(ll j=0;j<=cnt;j++){
				for(ll k=0;k<=cnt;k++){
					dp[i][j][k]=INF;
				}
			}
		}
		for(ll i=1;i<cnt;i++){
			for(ll j=i+1;j<cnt;j++){
				ll cross=pp[i].x*pp[j].y-pp[j].x*pp[i].y;
				if(cross<0)cross=-cross;
				dp[3][i][j]=cross;
				poll[3][i][j][0]=pp[0].id;
				poll[3][i][j][1]=pp[i].id;
				poll[3][i][j][2]=pp[j].id;
				if(dp[3][i][j]<res[3]){
					res[3]=dp[3][i][j];
					resp[3][0]=pp[0].id;
					resp[3][1]=pp[i].id;
					resp[3][2]=pp[j].id;
				}
			}
		}
		for(ll i=3;i<cnt;i++){
			for(ll j=1;j<cnt;j++){
				for(ll k=j+1;k<cnt;k++){
					for(ll l=k+1;l<cnt;l++){
						ll cross=pp[k].x*pp[l].y-pp[k].y*pp[l].x;
						ll cross2=(pp[j].x-pp[k].x)*(pp[l].y-pp[k].y)-(pp[j].y-pp[k].y)*(pp[l].x-pp[k].x);
						if(cross<0)cross=-cross;
						if(cross2<0 && cross+dp[i][j][k]<dp[i+1][k][l]){
							dp[i+1][k][l]=cross+dp[i][j][k];
							for(int m=0;m<i;m++){
								poll[i+1][k][l][m]=poll[i][j][k][m];
							}
							poll[i+1][k][l][i]=pp[l].id;
							if(dp[i+1][k][l]<res[i+1]){
								res[i+1]=dp[i+1][k][l];
								for(int m=0;m<i+1;m++){
									resp[i+1][m]=poll[i+1][k][l][m];
								}
							}
						}
					}
				}
			}
		}
		used[nec]=true;
	}
	scanf("%d",&q);
	for(ll i=0;i<q;i++){
		ll que;
		scanf("%lld",&que);
		if(res[que]==INF)printf("NA\n");
		else{
			for(ll i=0;i<que;i++){
				printf("%lld%c",resp[que][i],i==que-1?'\n':' ');
			}
		}
	}
	return 0;
}

Measured memory_bytes: 11816
import sys
input=sys.stdin.readline
s=input()
n=len(s)
n=n-1
INF=10**9+7
dp=[[0]*13 for i in range(n+1)]
dp[0][0]=1
for i in range(n):
    if s[i]=='?':
        for k in range(10):
            for j in range(13):
                dp[i+1][(10*j+k)%13]=(dp[i+1][(10*j+k)%13]+dp[i][j])%INF
    else:
        num=int(s[i])
        for j in range(13):
            dp[i+1][(10*j+num)%13]=dp[i][j]%INF
print(dp[n][5])


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

#define reint register int
#define coint const int

using namespace std;

int main(void) {
    int n, d;
    scanf("%d%d", &n, &d);
    coint len = d * 2 + 1;
    printf("%d\n", (n + len - 1) / len);
    return 0;
}



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

using namespace std;
int k, n;
int ar[100], ans;
int main() {
    scanf("%d %d", &n, &k);

    for (int i = 0; i < n; i++)
        scanf("%d", ar + i);
    sort(ar, ar+n);

    for (int i = n-1, j=0; j <k; i--) {
        ans += ar[i];
        j++;
    }

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

    return 0;
}

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

using namespace std;

const int nax = 3e5+5;

struct pair_hash {
    inline long long operator()(const std::pair<int,int> & v) const {
        return (long long)v.first*nax+v.second;
    }
};

int main() {
  int h, w, m, x, y;
  unordered_set<pair<int, int>, pair_hash> set;
  cin >> h >> w >> m;
 	vector<int> r(h, 0), c(w, 0);
  while(m--) {
    cin >> x >> y;
    x--, y--;
    r[x]++, c[y]++;
    set.insert({x,y});
  }
  int mh = -1, mw = -1;
  vector<int> mvh, mvw;
  for(int i = 0; i < h; i++) {
  	if(mh < r[i]) mh = r[i];
  }
  for(int i = 0; i < h; i++) {
  	if(r[i] == mh) {
      mvh.push_back(i);
    }
  }
  for(int i = 0; i < w; i++) {
  	if(mw < c[i]) mw = c[i];
  }
  for(int i = 0; i < w; i++) {
  	if(c[i] == mw) {
      mvw.push_back(i);
    }
  }
  for(auto x : mvh) {
  	for(auto y : mvw) {
  	    //cout << x << ' ' << y << endl;
    	if(set.find({x,y}) == set.end()) {
        	cout << r[x]+c[y];
          	return 0;;
        }
    }
  }
  cout << r[mvh[0]] + c[mvw[0]] - 1;
	return 0;
}

Measured memory_bytes: 23368
#include<bits/stdc++.h> 
using namespace std;
int main(){
	int h,n,s=0;
	cin>>h>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		s+=a[i];
	}
	if(s<h) cout<<"No";
	else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int k,n;
  cin >> n >> k;
  int a[n+k];
  LOOP(i,k){
    a[i] = 0;
  }
  int np = 0;
  int ma = -1;
  LOOP(i,n){
    cin >> a[i+k];
    np += a[i+k];
    np -= a[i];
    ma = max(ma, np);
  }
  // cout << ((double)ma+k)/2 << endl;
  printf("%.10f\n", (double)(ma+k)/2);
}

/*
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  string n;
  int k;
  cin >> n >> k;
  int a[n.length()];
  LOOP(i,n.length()){
    a[i] = n[i]-'0';
  }

}
*/


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

using namespace std;

const int N = 2e5 + 5;
long long n, a[N], arr[N];

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    cout << n + n * n + n * n * n << endl;
    return 0;
}

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

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

int main(){
  int X;
  cin >>X;
  
  vector<int> prime_list;
  
  prime_list.push_back(2);
  
  for(int i=3;i<200000;i += 2){
    if(is_prime(i)) prime_list.push_back(i);
  }
  
  for(int i=0;i<prime_list.size();i++){
    if(X <= prime_list[i]){
      cout << prime_list[i] << endl;
      break;
    }
  }
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val (a, b, k) = readLine()!!.split(" ").map { it.toInt() }

    var cnt = 0
    for (i in 100 downTo 1) {
        if (a%i ==0 && b%i == 0){
            cnt += 1
            if(cnt == k){
                print(i)
                break
            }
        }
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> t;
  rep(i, n) {
    int c;
    cin >> c;
    t.push_back(c);
  }
  int m;
  cin >> m;
  vector<pair<int, int>> px;
  rep(i, m) {
    int p, x;
    cin >> p >> x;
    px.push_back(make_pair(p, x));
  }

  for (pair<int, int> change: px) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (i + 1 == get<0>(change)) {
        ans += get<1>(change);
      }
      else {
        ans += t[i];
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
natural = list(map(int,input().split()))
Q = int(input())
number = [0]*(10**5+1)
for i in range(N):
    number[natural[i]] += 1
Nsum = sum(natural)
ans = []
for i in range(Q):
    B,C = map(int,input().split())
    count = number[B]
    diff = C-B
    number[C] += count
    number[B] = 0
    Nsum += diff * count
    ans.append(Nsum)

for i in range(Q):
    print(ans[i])

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int ans[100005];
bool visited[100005];

int dfs(int n){
  if(visited[n]){
    return ans[n];
  }
  if(n==1) return 1;
  if(n==0) return 0;

  ans[n] = dfs(n-1) + 1;
  int x = 6;
  while(x <= n) {
    ans[n] = min(ans[n], dfs(n-x)+1);
    x *= 6;
  }
  x = 9;
  while(x <= n) {
    ans[n] = min(ans[n], dfs(n-x)+1);
    x *= 9;
  }

  visited[n] = true;
  return ans[n];
}


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

  fill(visited, visited+n+3, false);

  cout << dfs(n) << endl;

  return 0;
}


Measured memory_bytes: 3840
#include<stdio.h>

int main(void) {
   int N;
   int T, A;

   scanf("%d" ,&N);
   scanf("%d %d", &T, &A);

   int H[N];
   float t[N];
   float diff[N];

   for(int i = 0; i < N; i++) {
      scanf("%d", &H[i]);
      t[i] = T - H[i] * 0.006;
      diff[i] = A - t[i];
      if(diff[i] < 0) {
         diff[i] *= -1;
      }
   }

   float min = diff[0];
   int answer = 1;

   for(int i = 0; i < N; i++) {
      if(min > diff[i]) {
         min = diff[i];
         answer = i+1;
      }
   }

   printf("%d\n", answer);
   return 0;
}


Measured memory_bytes: 1696
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e10;
const ll MOD = 100000000;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 100;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    ll n,a,b;
    cin >> n >> a >> b;
    vector<ll> v(n),u(a);
    vector<vector<ll>> dp(51,vector<ll>(51,0));
    dp[0][0] = 1;
    rep(i,1,51){
        for(ll j = 0;j <= i;j++){
            dp[i][j] += dp[i-1][j];
            if (j > 0) dp[i][j] += dp[i-1][j-1];
        }
    }
    cins(all(v));
    RSORT(v);
    bool f = 1;
    long double avg = 0;
    rep(i,a){
        u[i] = v[i];
        avg += v[i];
        if (u[i] != u[0]) f = 0;
    }
    ll ans = 0;
    if (f){
        ll c = 0;
        rep(i,n) if (v[i] == u[0]) c++;
        ll k = min(c,b);
        rep(i,a,k+1) ans += dp[c][i];
    }
    else{
        ll c1 = 0,c2 = 0;
        rep(i,a) if (u[i] == u[a-1]) c1++;
        rep(i,n) if (v[i] == u[a-1]) c2++;
        ans = dp[c2][c1];
    }
    long double s = avg/a;
    cout << setprecision(20) << s << endl;
    PRINT(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const i64 mod = 1e9 + 7;
i64 fact_memo[200001];
i64 fact(i64 x) {
  if (x == 0) return 1;
  if (fact_memo[x]) return fact_memo[x];
  return fact_memo[x] = x * fact(x - 1) % mod;
}
i64 ipow(i64 a, i64 b) {
  return (b & 1 ? a : 1) * (b > 1 ? ipow(a * a % mod, b >> 1) : 1) % mod;
}
i64 inv(i64 x) {
  return ipow(x, mod - 2);
}
i64 fact_inv(i64 x) {
  return inv(fact(x));
}
i64 perm(i64 a, i64 b) {
  return fact(a) * fact_inv(a - b) % mod;
}
i64 conb(i64 a, i64 b) {
  return fact(a) * fact_inv(b) % mod * fact_inv(a - b) % mod;
}

i64 n, m;
int main() {
  cin >> n >> m;
  map<i64, i64> fs;
  for (i64 x = 2; x <= min(n, i64(40000)); ++x) {
    while (m % x == 0) {
      cerr << x << endl;
      fs[x]++;
      m /= x;
    }
  }
  if (m > 1) fs[m]++;
  i64 ans = 1;
  for (auto p : fs) {
    i64 k = p.second;
    ans = ans * conb(k + n - 1, k) % mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
#define P pair<int,int>
using namespace std;
const int M = 120000;
typedef long long ll;
int n,m,k;
struct node{
    int a,b;
    bool operator < (const node & to){
        return a<to.a;
    }
}nd[M];
int f[M];
int fd(int x){return f[x]==x?x:f[x]=fd(f[x]);}
vector<P> g[M];
bool join(int a,int b){
    int fa=fd(a),fb=fd(b);
    if(fa==fb) return 0;
    f[fa]=fb;
    return 1;
}
int pos[M];
bool ans[M*2]={0};
bool vs[M]={0};
void dfs(int u,int v,int id){
    if(vs[u]) return;
    vs[u]=1;
    for(P to:g[u]){
        if(v==to.first) continue;
        dfs(to.first,u,to.second);
    }
    if(u==v)return;
    if(nd[u].b==1){
        ans[id]=1;
        nd[v].b^=1;
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin>>n>>m;
    fo(i,0,n) f[i]=i;
    nd[0].a=nd[0].b=0;
    fo(i,1,n) cin>>nd[i].a>>nd[i].b;
    sort(nd+1,nd+1+n);
    int pre=0;
    rv(i,n,0){
        pos[i]=nd[i].a;
        nd[i].b^=pre;
        pre^=nd[i].b;
    }
    int l,r;
    fo(i,1,m) {
        cin>>l>>r;
        l=lower_bound(pos+1,pos+n+1,l)-pos-1;
        r=lower_bound(pos+1,pos+n+1,r+1)-pos-1;
        if(l>=r) continue;
        if(join(l,r)){
            g[l].push_back({r,i});
            g[r].push_back({l,i});
        }
    }
    bool fg=0;
    fo(i,0,n){
        if(vs[i]) continue;
        dfs(i,i,i);
        if(nd[i].b==1) fg=1;
    }
    if(fg){
        cout<<-1<<endl;
    }
    else{
        int cnt=0;
        fo(i,1,m)
            if(ans[i])
                ++cnt;
        cout<<cnt<<endl;
        fo(i,1,m)
            if(ans[i])
                cout<<i<<' ';
        cout<<endl;
    }
    return 0;
}

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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new MyInputStream(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(MyInputStream cin)
        {
            var s = cin.Read();
            WriteLine(s.Where(x => x == '1').Count());
        }
    }

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

Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int main(void){
  string s;
  cin >> s;
  int n = s.length();
  int count = 0,m = 0;
  rep(i,n){
    char k = s[i];
    if(k == 'A' || k == 'C' || k == 'G' || k == 'T'){
      count++;
      m = max(count,m);
    }else {
      count = 0;
    }
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;

int f[maxn],nxt[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n,m;
  string s;
  cin>>n>>m>>s;
  memset(f,-1,sizeof(f));
  set<pair<int,int>>st;
  st.insert(make_pair(0,n));
  f[n] = 0;
  int r = n;
  for(int i=n-1;i>=0;i--){
    if(s[i]=='1')continue;
    while(r-i>m){
      if(f[r]!=-1)
      st.erase(make_pair(f[r],r));
      r--;
    }
    if(st.size()==0)break;
    auto pr = *st.begin();
    f[i] = pr.first + 1;
    nxt[i] = pr.second;
    st.insert(make_pair(f[i],i));
  }
  if(f[0]==-1){
    cout<<-1<<endl;
    return 0;
  }
  int cur = 0;
  while(cur != n){
    if(cur)cout<<" ";
    cout<<nxt[cur] - cur;
    cur = nxt[cur];
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3840
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        _n: i64,
        m: i64,
        x: i64,
        a: [i64; m],
    }
    for i in 0..a.len() {
        if a[i] > x {
            if i + 1 > a.len() - (i + 1) {
                println!("{}", a.len()-i);
                return;
            } else {
                println!("{}", i);
                return;
            }
        }
    }
}

Measured memory_bytes: 4352
// #pragma GCC optimize(3)
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cstring>
#include <iostream>
#include <algorithm>
#define maxn 100010
// #define int long long
using namespace std;
void write(int x){if(x<0){putchar('-');x=-x;}if(x>9) write(x/10);putchar(x%10+'0');}
int read(){int d=0,w=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')
w=-1;for(;c>='0'&&c<='9';c=getchar())d=(d<<1)+(d<<3)+c-48;return d*w;}
void wln(int x){write(x);putchar('\n');}
void wrs(int x){write(x);putchar(' ');}
int n,l,t,w[maxn],x[maxn],cnt,ans[maxn],anss[maxn];
signed main()
{
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	n=read();
	l=read();
	t=read();
	for(int i=1;i<=n;i++)
	{
		x[i]=read();
		w[i]=read()==1?1:-1;
		ans[i]=((x[i]+w[i]*t)%l+l)%l;
	}
	sort(ans+1,ans+n+1);
	// wrs(w[1]);
	// wrs(n-x[4]+x[1]);
	// if(w[1]==1)
	// {
	// cnt=1;
	for(int i=2;i<=n;i++)
		if(w[i]!=w[1]&&2*t>=(w[1]==1?x[i]-x[1]:l-x[i]+x[1])) cnt=(cnt+w[1]*((2*t-(w[1]==1?x[i]-x[1]:l-x[i]+x[1]))/l+1));
	cnt+=1;
	// int llk=lower_bound(ans+1,ans+n+1,((x[1]+w[1]*t)%l+l)%l)-ans;
	int llk;
	if(w[1]==1) llk=upper_bound(ans+1,ans+n+1,((x[1]+w[1]*t)%l+l)%l)-ans-1;
		else llk=lower_bound(ans+1,ans+n+1,((x[1]+w[1]*t)%l+l)%l)-ans;
	// wrs(llk);
	// wln(cnt);
	for(int i=1;i<=n;i++)
		anss[i]=ans[((llk-cnt+i)%n+n-1)%n+1];
	for(int i=1;i<=n;i++)
		wln(anss[i]);
		// ans[cnt]=(x[1]+t)%l;
		// for(int i=1;i<=n;i++)
		// 	if(w[((1-cnt+i)%n+n-1)%n+1]==1) ans[i]=(x[((1-cnt+i)%n+n-1)%n+1]+t)%l;
		// for(int i=1;i<=n;i++)
		// 	wrs(ans[i]);
	// }
	return 0;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

// 羊=0, 狼=1
string solve()
{
    int n;
    string s;
    cin >>n >>s;

    rep(mask,4)
    {
        vector<int> a(n);
        a[0] = mask&1;
        a[1] = mask>>1&1;

        for(int i=2; i<n; ++i)
        {
            if(s[i-1]=='o')
            {
                if(a[i-1]==0) a[i]=a[i-2];
                else a[i]=!a[i-2];
            }
            else
            {
                if(a[i-1]==0) a[i]=!a[i-2];
                else a[i]=a[i-2];
            }
        }

        bool ok=true;
        rep(i,n)
        {
            if(a[i]==0)
            {
                if(s[i]=='o') ok &= (a[(i+1)%n]==a[(i-1+n)%n]);
                else ok &= (a[(i+1)%n]!=a[(i-1+n)%n]);
            }
            else
            {
                if(s[i]=='o') ok &= (a[(i+1)%n]!=a[(i-1+n)%n]);
                else ok &= (a[(i+1)%n]==a[(i-1+n)%n]);
            }
        }

        if(ok)
        {
            string ret="";
            rep(i,n) ret += a[i]?'W':'S';
            return ret;
        }
    }

    return "-1";
}

int main()
{
    cout << solve() << endl;
    return 0;
}


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

int main()
{
	int N, D, X, i, j, A[100] = { 0 };

	cin >> N;
	cin >> D;
	cin >> X;
	for(i=0; i<N; i++)
		cin >> A[i];

	for (i = 0; i < N; i++)
		for (j = 0; j*A[i] + 1 <= D; j++)
				X++;

	cout << X << endl;

    return 0;
}


Measured memory_bytes: 256
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        k: usize1,
        aa: [usize1;n]
    }
    let mut m = HashMap::new();
    let mut v = Vec::new();
    let mut i = 0;
    loop {
        let t = (i, aa[i]);
        if let Some(i) = m.get(&t) {
            if *i == 2 { break; }
        }
        v.push(i);
        *m.entry(t).or_insert(0) += 1;
        i = t.1;
    }
    let k = k+1;
    if k < v.len() {
        println!("{}", v[k] + 1);
    } else {
        let l = m.iter().filter(|t| *t.1 == 1).count();
        let r = m.iter().filter(|t| *t.1 == 2).count();
        let v = &v[l..(v.len()-r)];
        println!("{}", v[(k-l) % v.len()] + 1);
    }
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 16132
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef ONLINE_JUDGE
const int N = 1e6+50;
#else
const int N = 1e2+10;
#endif


int n;
string s;
map<pair<string,string>,int> a;

int main() {
	cin>>n>>s;
	int mx = (1<<n)-1;
	REP(i,0,mx) {
		string L, R;
		REP(j,0,n-1) {
			if (i>>j&1) L.pb(s[j]);
			else R.pb(s[j]);
		}
		++a[{L,R}];
	}
	ll ans = 0;
	REP(i,0,mx) {
		string L, R;
		REP(j,0,n-1) {
			if (i>>j&1) L.pb(s[2*n-1-j]);
			else R.pb(s[2*n-1-j]);
		}
		ans += a[{L,R}];
	}
	printf("%lld\n", ans);
}








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

int main(){
  int X1,Y1,X2,Y2;
  cin >> X1 >> Y1 >> X2 >> Y2;
  int dx=X2-X1;
  int dy=Y2-Y1;
  int X=X2;
  int Y=Y2;
  for(int i=0;i<2;i++){
    swap(dx,dy);
    dx=-dx;
    X+=dx;
    Y+=dy;
    cout << X << " " << Y;
    if(i==0){
      cout << " ";
    }
    else{
      cout << endl;
    }
  }
}

Measured memory_bytes: 3676
#include <stdio.h>

int main(void)
{
    int a,b,c,ans;
    scanf("%d%d%d", &a,&b,&c);

    if(a==b&&b==c) ans=1;
    else if(a!=b&&b!=c&&c!=a) ans=3;
    else ans=2;

    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
import sys
from collections import deque
from copy import deepcopy

input = sys.stdin.readline
h, w = [int(x) for x in input().strip().split()]
m = [['#' for _ in range(w+2)] for _ in range(h+2)]
hs = []
ws = []
for hi in range(1, h+1):
    for wi, s in enumerate(input().strip(), start=1):
        m[hi][wi] = s
        if s == '.':
            hs.append(hi)
            ws.append(wi)

def bfs(hs, ws, m):
    cost = 0
    q = deque([])
    m[hs][ws] = '#'
    for offset in [(0, 1), (-1, 0), (0, -1), (1, 0)]:
        if m[hs+offset[0]][ws+offset[1]] == '.':
            q.append((hs+offset[0], ws+offset[1]))
    while q:
        cost += 1
        q_ = deque(q)
        q = deque([])
        for h, w in q_:
            m[h][w] = '#'
            for offset in [(0, 1), (-1, 0), (0, -1), (1, 0)]:
                if m[h+offset[0]][w+offset[1]] == '.':
                    m[h+offset[0]][w+offset[1]] = '#'
                    q.append((h+offset[0], w+offset[1]))

    return cost, h, w

maxi = -1
for hss, wss in zip(hs, ws):
    maxi_, hh, ww = bfs(hss, wss, deepcopy(m[:]))
    maxi = max(maxi, maxi_)

print(maxi)

Measured memory_bytes: 3436
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    string x;
    cin>>x;
    map<char, int> data;
    for(auto i : x){
        data[i]++;
    }
    int c = 0 , d = 0;
    if(data.size() == 2){
        auto it = data.begin();
        c = it->second;
        it++;
        d = it->second;
        if(c == d)
            cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }else cout<<"No"<<endl;


}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    int n;
    cin >> n;
    cout << n/3 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;

    rep(i, n) ans += a[i] - 1;

    cout << ans << endl;
}


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

using namespace std;

int main(){
	double r;
	scanf("%lf", &r);
	double area = r * r * M_PI;
	double circumference = 2 * r * M_PI;
	printf("%.6lf %.6lf\n", area, circumference);

	return 0;
}

Measured memory_bytes: 1080
#![allow(dead_code)]
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};
#[fastout]
fn main() {
    input!(n: usize, x: usize, m: usize);

    let mut ans = Vec::with_capacity(1000);
    ans.push(x);
    let mut set = std::collections::HashSet::new();

    for i in 1..n {
        let buff = (ans[i - 1] * ans[i - 1]) % m;
        if set.contains(&buff) {
            let pos = ans.iter().position(|x| *x == buff).unwrap();
            let ans_len = ans.len();
            let wa = ans_len - pos;

            let count = (n - ans_len) / wa;
            let count_m = (n - ans_len) % wa;

            let mut sum = ans.iter().take(ans_len - wa + count_m).sum::<usize>();

            sum += ans.iter().skip(ans_len - wa).sum::<usize>() * (count + 1);
            println!("{}", sum);
            return;
        }
        set.insert(buff);
        ans.push(buff);
    }

    println!("{}", ans.iter().sum::<usize>());
}


Measured memory_bytes: 3320
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

#[allow(unused)]
use std::cmp::{max, min};
#[allow(unused)]
use std::collections::HashMap;

#[allow(unused)]
fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}

#[allow(unused)]
fn lcm(x: i64, y: i64) -> i64 {
    x * y / gcd(x, y)
}

fn main() {
    input! {
        // usize
        // n: usize,
        // vec
        // v: [i64; n],
        w: f64,
        h: f64,
        x: f64,
        y: f64,
    }

    let ans1 = w * h / 2.0;
    let ans2 = if 2.0 * x == w && 2.0 * y == h { 1 } else { 0 };

    println!("{} {}", ans1, ans2);
}


Measured memory_bytes: 4352
#include "algorithm"
#include "iomanip"
#include "iostream"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define all(vec) vec.begin(), vec.end()
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;

int main() {
  ll h, w;
  cin >> h >> w;
  
  if (h == 1 || w == 1) {
    cout << 1 << endl;
  } else if (h & w & 1) {
    cout << h*w / 2 + 1 << endl;
  } else {
    cout << h*w / 2 << endl;
  }
}


Measured memory_bytes: 256
use std::cmp;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        a: [usize;n+1],
        b: [usize;n]
    }

    let mut ans = 0;

    let mut rest = 0;
    for i in 0..n {
        let total = a[i] + a[i + 1] - rest;
        if b[i] >= total {
            ans += total;
            rest = a[i + 1];
        } else {
            ans += b[i];

            if b[i] >= (a[i] - rest) {
                rest = b[i] - (a[i] - rest);
            } else {
                rest = 0;
            }
        }
    }

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

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 10620