akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }

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

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    vector<ll> b(N);
    rep(i, N) b[i] = a[i] / 2;
    ll m1 = a[0], m2 = b[0], g = b[0];
    rep(i, N) {
        m1 = lcm(m1, a[i]);
        if(m1 > M) {
            m1 = INF;
            break;
        }
    }
    rep(i, N) {
        m2 = lcm(m2, b[i]);
        g = gcd(g, b[i]);
        if(m2 > M) {
            m2 = INF;
            break;
        }
    }

    rep(i, N) {
        if(b[i] / g % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    cout << M / m2 - M / m1 << endl;
    return 0;
}

Measured memory_bytes: 1792
n,m,k=map(int,input().split())
g=998244353
r=1
p=pow(m-1,n-1,g)
for i in range(1,k+1):
    r=(r*(n-i)*pow(i,g-2,g))%g
    p=(p+r*pow(m-1,n-1-i,g))%g
print((m*p)%g)

Measured memory_bytes: 9096
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  int n;
  double d;
  cin>>n>>d;
  double ans=0;
  for(int i=0;i<n;i++){
    double x,h;
    cin>>x>>h;
    ans=max(ans,h/x*d);
  }
  printf("%.6f\n",ans);
  return 0;
}

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

struct Edge {
  int to, w;
  Edge(int t, int w) :to(t), w(w) {}
};

struct Tree {
  int N;
  vector<vector<Edge>> edges;

  void addEdge(int a, int b) { addEdge(a, b, 1); }
  void addEdge(int a, int b, int w) { edges[a].emplace_back(b, w); }

  Tree(int N) :N(N), edges(N) {}

  long long diam(){
    setDist(0);
    int start;
    long long maxd = -1;
    rep(i, N) {
      if (dist[i] > maxd) {
        maxd = dist[i];
        start = i;
      }
    }
    setDist(start);
    rep(i, N) maxd = max(maxd, dist[i]);
    return maxd;
  }

  vector<long long> dist;
  void setDist(int s) {
    dist = vector<long long>(N, -1);
    dist[s] = 0;
    queue<int> q;
    q.push(s);
    while (!q.empty()) {
      int x = q.front(); q.pop();
      for (Edge e : edges[x]) {
        if (dist[e.to] != -1) continue;
        dist[e.to] = dist[x] + e.w;
        q.push(e.to);
      }
    }
  }
};

int main(){
  int N; cin >> N;
  Tree G(N);
  rep(i, N - 1) {
    int x, y; cin >> x >> y;
    x--; y--;
    G.addEdge(x, y);
    G.addEdge(y, x);
  }

  long long diam = G.diam();

  if ((diam + 1) % 3 == 2) cout << "Second" << endl;
	else cout << "First" << endl;
}


Measured memory_bytes: 16752
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#include<numeric>
#define rep(a,b) for(ll a=0;a<b;++a)
#define REP(a,b,c,d) for(ll a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_ll = pair<ll, ll>;
int main() {
	int N, M; cin >> N >> M;
	ll ans = 0;
	vector<p_ll> AB(N);
	rep(i, N)cin >> AB[i].first >> AB[i].second;
	sort(AB.begin(), AB.end());
	rep(i, N) {
		if (AB[i].second >= M) {
			ans += AB[i].first * M;
			break;
		}
		else {
			ans += AB[i].first * AB[i].second;
			M -= AB[i].second;
		}
	}
	cout << ans << endl;
	cin >> N;
}

Measured memory_bytes: 1792
#include<stdio.h>

#define MAX 100000

int partition(int p, int r);

int A[MAX],n;

int main(){
  int i,q;

  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d",&A[i]);

  q = partition(0, n - 1);
  
  for(i = 0; i < n; i++){

    if(i > 0) printf(" ");
  
    if(i == q) printf("[");

    printf("%d",A[i]);

    if(i == q) printf("]");
  }
  
  printf("\n");
  
  return 0;
}

int partition(int p, int r){
  int x, i, j, temp;
  x = A[r];
  i = p - 1;
  for(j = p; j < r; j++){
    if(A[j] <= x){
      i++;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  return  i+1;
}



Measured memory_bytes: 2128
#include <cstdio>
#include <utility>
#include <vector>
#include <complex>
#include <cmath>
#include <algorithm>
#include <functional>

using namespace std;

static const double EPS=1e-12;
static const double INF=1e24;

using Point=complex<double>;
using Plane=vector<Point>;
using Polygon=vector<Point>;

bool operator<(const Point &a, const Point &b) {
    return real(a)!=real(b)? real(a)<real(b) : imag(a)<imag(b);
}

double cross_prod(const Point &a, const Point &b) {
    return imag(conj(a)*b);
}

double dot_prod(const Point &a, const Point &b) {
    return real(conj(a)*b);
}

enum {
    ONLINE_FRONT=-2,
    CLOCKWISE,
    ON_SEGMENT,
    COUNTER_CLOCKWISE,
    ONLINE_BACK,
};

int ccwise(Point a, Point b, Point c) {
    b -= a; c -= a;

    if (cross_prod(b, c) > 0) {
        return COUNTER_CLOCKWISE;
    } else if (cross_prod(b, c) < 0) {
        return CLOCKWISE;
    } else if (dot_prod(b, c) < 0) {
        return ONLINE_BACK;
    } else if (norm(b) < norm(c)) {
        return ONLINE_FRONT;
    } else {
        return ON_SEGMENT;
    }
}

template <class LineType>
int ccwise(LineType l, Point p) {
    return ccwise(l.first, l.second, p);
}

struct Line: public pair<Point, Point> {
    Line() {}
    Line(const Point &a, const Point &b) {
        first = a;
        second = b;
    }
};

struct LineSeg: public pair<Point, Point> {
    LineSeg() {}
    LineSeg(const Point &a, const Point &b) {
        first = a;
        second = b;
    }
};

template <class RandomIt=Polygon::iterator>
pair<Point, Point> closest_pair(RandomIt first, RandomIt last) {
    size_t n=last-first;
    if (n < 2)
        return make_pair(Point(-INF, -INF), Point(INF, INF));

    RandomIt mid=first+n/2;
    double x=real(*mid);
    pair<Point, Point> p1=closest_pair(first, mid);
    pair<Point, Point> p2=closest_pair(mid, last);
    inplace_merge(first, mid, last, [](const Point &lhs, const Point &rhs) {
        return imag(lhs) < imag(rhs);
    });

    double d1=norm(p1.first-p1.second), d2=norm(p2.first-p2.second);
    double d=(d1<d2? d1:d2);
    pair<Point, Point> res=(d1<d2? p1:p2);

    vector<Point> b;
    for (RandomIt it=first; it<last; ++it) {
        if (norm(real(*it)-x) >= d) continue;

        for (size_t j=0; j<b.size(); ++j) {
            Point e=*it-b[b.size()-j-1];
            if (imag(e) >= sqrt(d)) break;

            if (d > norm(e)) {
                d = norm(e);
                res = make_pair(*it, b[b.size()-j-1]);
            }
        }
        b.push_back(*it);
    }

    return res;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    Polygon g(n);
    for (size_t i=0; i<n; ++i) {
        double x, y;
        scanf("%lf %lf", &x, &y);
        g[i] = Point(x, y);
    }

    sort(g.begin(), g.end(), [](const Point &lhs, const Point &rhs) {
        return real(lhs)!=real(rhs)? real(lhs)<real(rhs) : imag(lhs)<imag(rhs);
    });

    pair<Point, Point> p=closest_pair(g.begin(), g.end());
    printf("%.9f\n", abs(p.first-p.second));
    return 0;
}

Measured memory_bytes: 7228
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer k = Integer.parseInt(scanner.next());
        Integer total = Integer.parseInt(scanner.next());
        Integer gohyakuen = 500;

        if (gohyakuen*k >= total) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23252
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<math.h>
#define N 1002

int main() {
	double x1, x2, y1, y2;
	scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
	printf("%.8lf\n", sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)));

	return 0;
}

Measured memory_bytes: 656
import numpy as np
from itertools import combinations
n,m,x = list(map(int, input().split()))
pa = [[] for _ in range(n)]
for i in range(n):
  pa[i] = list(map(int, input().split()))
  
pa = np.array(pa)
ans = 10**5 * n + 1

for i in range(1,n+1):
  for cs in list(combinations(range(n),i)):
    p = np.array([0]*(m+1))
    for j in cs:
      p += pa[j]
    if min(p[1:]) >= x:
      ans = min(ans, p[0])

if ans == 10**5 * n + 1:
  print(-1)
else:
  print(ans)


Measured memory_bytes: 27444
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

double d[31][1<<8];
vector<pair<int,int>> g[31];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m,p,a,b;
	while(cin >> n >> m >> p >> a >> b,n){
		a--; b--;
		for(int i=0;i<m;i++){
			for(int j=0;j<(1<<n);j++){
				d[i][j]=1e18;
			}
			g[i].clear();
		}
		vector<int> t(n);
		for(int i=0;i<n;i++){
			cin >> t[i];
		}
		while(p--){
			int x,y,z; cin >> x >> y >> z;
			x--; y--;
			g[x].push_back(make_pair(y,z));
			g[y].push_back(make_pair(x,z));
		}
		d[a][0]=0;
		priority_queue<pair<double,pair<int,int>>> q;
		q.push(make_pair(0.0,make_pair(a,0)));
		while(q.size()){
			auto p=q.top(); q.pop();
			int s=p.second.first;
			int now=p.second.second;
			if(p.first!=-d[s][now])continue;
			for(int i=0;i<n;i++){
				if((1<<i)&now)continue;
				for(auto to:g[s]){
					double cost=(double)(to.second)/t[i];
					if(d[to.first][now|(1<<i)]>d[s][now]+cost){
						d[to.first][now|(1<<i)]=d[s][now]+cost;
						q.push(make_pair(-d[to.first][now|(1<<i)],make_pair(to.first,now|(1<<i))));
					}
				}
			}
		}
		double res=1e18;
		for(int i=0;i<(1<<n);i++){
			res=min(res,d[b][i]);
		}
		if(res==1e18){
			printf("Impossible\n");
		}
		else{
			printf("%.3f\n",res);
		}
	}
}


Measured memory_bytes: 4472
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

N = int(readline())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))

class BinaryIndexedTree():
    def __init__(self, seq):
        self.size = len(seq)
        self.depth = self.size.bit_length()
        self.build(seq)
        
    def build(self,seq):
        data = seq
        size = self.size
        for i,x in enumerate(data):
            j = i+(i&(-i))
            if j < size:
                data[j] += data[i]
        self.data = data
        
    def __repr__(self):
        return self.data.__repr__()
        
    def get_sum(self,i):
        data = self.data
        s = 0
        while i:
            s += data[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        data = self.data
        size = self.size
        while i < size:
            data[i] += x
            i += i & -i
    
    def find_kth_element(self,k):
        data = self.data; size = self.size
        x,sx = 0,0
        dx = 1 << (self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= size:
                continue
            y = x + dx
            sy = sx + data[y]
            if sy < k:
                x,sx = y,sy
        return x + 1

def Inversion(seq):
    # seqは、1,2,...,Nの順列
    N = len(seq)
    bit = BinaryIndexedTree([0] * (N+1))
    inv = N*(N-1)//2
    for x in seq:
        inv -= bit.get_sum(x)
        bit.add(x,1)
    return inv

INF = 10 ** 9
answer = INF
for I in itertools.combinations(range(N),(N+1)//2):
    J = [j for j in range(N) if j not in I]
    ODD = [(B[i] if i&1 else A[i],i) for i in I]
    EV = [(A[i] if i&1 else B[i],i) for i in J]
    ODD.sort()
    EV.sort()
    ind = [0] * N
    seq = [0] * N
    for i in range(0,N,2):
        seq[i], ind[i] = ODD[i//2]
    for i in range(1,N,2):
        seq[i], ind[i] = EV[i//2]
    if not all(x<= y for x,y in zip(seq,seq[1:])):
        continue
    ind = [x+1 for x in ind]
    n = Inversion(ind)
    if answer > n:
        answer = n

if answer == INF:
    answer = -1
print(answer)

Measured memory_bytes: 58716
n = int(input())
a = [[0]*n for i in range(n)]
 
for i in range(n):
    v = list(map(int, input().split()))
    u = v[0]
    k = v[1]
    for j in range(k):
        a[u - 1][v[2 + j] - 1] = 1

for i in range(n):
    print(*a[i])

Measured memory_bytes: 6380
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue> 
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;
const int maxn=1e5+7;
const int mod=1e9+7;
int a[maxn];
int vis[maxn]={0};
long long f[maxn];
inline long long qpow(long long a,long long b){long long r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline long long inv(long long b){return qpow(b,mod-2);}
void init(){f[0] = 1;for (int i=1;i<=maxn;i++)f[i] = (f[i-1]*i) % mod;}
long long c(int x,int y){return f[x]*inv(f[y])%mod*inv(f[x-y])%mod;}
int main()
{
	init();
	int n;
	cin>>n;
	int p1,p2;
	for (int i=1;i<=n+1;i++)
	{
		cin>>a[i];
		if (vis[a[i]])
		{
			p1=vis[a[i]]-1;
			p2=i;
		}
		vis[a[i]]=i;
	}
	for (int i=1;i<=n+1;i++)
	{
		long long ans=c(n+1,i)%mod;
		if (n+1-p2+p1>=i-1) ans=(ans-c(n+1-p2+p1,i-1)+mod)%mod;
		while (ans<0) ans=(ans+mod)%mod;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[9] = {0, 1, 0, -1, 0, 1, 1, -1, -1};
int dy[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
T intceil(T a, T b) {
    return (a + (b - 1)) / b;
}

signed main() {
    INIT;
    cin >> H >> W >> N;
    vi a(N), b(N);
    map<pair<int, int>, int> mp;
    REP(i, N) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        mp[{a[i], b[i]}] = 1;
    }
    vector<ll> v(10);
    set<pair<int, int>> st;
    REP(i, N) {
        REP(j, 9) {
            int h = a[i] + dx[j];
            int w = b[i] + dy[j];
            if (0 < h && h < H - 1 && 0 < w && w < W - 1 && st.count({h, w}) == 0) {
                st.insert({h, w});
                int tmp = 0;
                REP(k, 9)
                tmp += mp[{h + dx[k], w + dy[k]}];
                v[tmp]++;
            }
        }
    }
    v[0] = (H - 2) * (W - 2) - st.size();
    dump(v);
    REP(i, v.size())
        cout << v[i] << endl;
}

Measured memory_bytes: 202480
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define all(s) s.begin(),s.end()
#define INT_MAX 2147483647
#define debug(x) cout<<#x<<": "<<x<<endl;
#define PI 2*acos(0,0)
#define inin(x) int x; cin>>x;
#define ll long long

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

int main()
{
	int h, w;
	int m[200][200];
	memset(m, -1, sizeof(m));
	cin >> h >> w;
	for (int i = 1; i <= h; i++)
	{
		for (int l = 1; l <= w; l++)
		{
			char x;
			cin >> x;
			m[i][l] = (x == 'c') ? 0 : -1;
		}
	}
	for (int i = 1; i <= h; i++)
	{
		for (int l = 1; l <= w; l++)
		{
			if (m[i][l]!=0&&m[i][l - 1] != -1)m[i][l] = m[i][l - 1] + 1;
			cout << m[i][l];
			if (l != w)cout << " ";
		}cout << endl;
	}





}

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

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

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

void solve()
{
    int n;
    cin>>n;
    vi a{2,4,5,7,9},b{0,1,6,8},c{3};
    int rem = n%10;
    for(int i=0;i<5;i++) {
        if(a[i]==rem) {
            cout<<"hon";
            return;
        }
    }
    for(int i=0;i<4;i++) {
        if(b[i]==rem) {
            cout<<"pon";
            return;
        }
    }

    cout<<"bon";

}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

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

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

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

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


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

bool dfs(int i, VI& xs, string& s, int sum){
  if(i == 3){
	return sum == 7;
  }

  s += "+";
  if(dfs(i+1, xs, s, sum+xs[i+1]))
	return true;
  
  s.back() = '-';
  if(dfs(i+1, xs, s, sum-xs[i+1]))
	return true;

  s.pop_back();
  return false;
}

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

  VI xs(4);
  REP(i,4){
	char c;
	cin >> c;
	xs[i] = c - '0';
  }
  string ans;
  dfs(0, xs, ans, xs[0]);
  cout << xs[0];
  REP(i,3)
	cout << ans[i] << xs[i+1];
  cout << "=7" << endl;

  return 0;
}


Measured memory_bytes: 256
// Author : Mohamed Sameh
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<stack>
#include<deque>
#include <cstring>
#include <iomanip>    
using namespace std ;
typedef long long ll ;

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define PI  3.141592 
#define SZ(a) (int)a.size()
void READ (string INPUT = "NO" , string OUTPUT = "NO" )
{
    if (INPUT != "NO")
    freopen(INPUT.c_str() , "r" , stdin );
    if (OUTPUT!="NO")
    freopen ( OUTPUT.c_str() , "w" , stdout);
} 
int n ,k ; 
int a[100001]; 
int dp[100001]; 
int solve (int i)
{
    if (i==n-1)
        return 0 ; 
    if (i >= n)
        return 2e9 ; 
    if (dp[i]!=-1)return dp[i]; 
    int &ret = dp[i];ret = 2e9 ;  
    for (int j = 1; i+j < n && j <= k ; j++)
    ret = min( abs (a[i] - a[i+j]) + solve(j+i) , ret );  
    
    return ret ; 
}
int main ()
{
    memset (dp,-1,sizeof dp );
    scanf ("%d%d" , &n , &k ); 
    for (int i =0 ; i < n ;i++)
        scanf ("%d" , a+i); 
    printf ("%d\n" , solve(0)); 
    return 0 ; 
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
using namespace std;
int x[100010],y[100010];
signed main(){
	int a;
	cin>>a;
	x[0]=0;
	f(i,a){
		cin>>y[i];
		if(i>=2)
		x[i]=min(x[i-2]+abs(y[i-2]-y[i]),x[i-1]+abs(y[i-1]-y[i]));
		else if(i){
			x[i]=abs(y[i-1]-y[i]);
		}
	}
	cout<<x[a-1]<<endl;
	return 0;
}


Measured memory_bytes: 1792
class dsu:
    def __init__(self, N):
        self.root = [-1 for _ in range(N)]
        self.size = [1 for _ in range(N)]

    def merge(self, x, y):
        x = self.leader(x)
        y = self.leader(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            self.root[x] = y
            self.size[y] += self.size[x]
        else:
            self.root[y] = x
            self.size[x] += self.size[y]
    
    def leader(self, x):
        while self.root[x] >= 0:
            x = self.root[x]
        return x

    def same(self, x, y):
        return self.leader(x) == self.leader(y)

N, M = [int(_) for _ in input().split()]
uf = dsu(N)

for i in range(M):
    A, B = [int(_) - 1 for _ in input().split()]
    uf.merge(A, B)

leader = set()
for i in range(N):
    leader.add(uf.leader(i))
    
print(len(leader) - 1)


Measured memory_bytes: 18864
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, d;
    cin >> n >> d;
    long long p[n][2];
    for(int i=0; i<n; i++){
        cin >> p[i][0] >> p[i][1];
    }
    long long s = d*d;
    int count = 0;
    for(int i=0; i<n; i++){
        if(s>= (p[i][0]*p[i][0] + p[i][1]*p[i][1]))count++;
    }
    cout << count << endl;
    return 0;
}

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

int main()
{
    int d;

    cin>>d;

    if(d == 25)
        cout<<"Christmas";
    else if(d == 24)
        cout<<"Christmas Eve";
    else if(d == 23)
        cout<<"Christmas Eve Eve";
    else if(d == 22)
        cout<<"Christmas Eve Eve Eve";

    return 0;

}


Measured memory_bytes: 256
n = gets.chomp.to_i
x = gets.chomp.split().map(&:to_i)

sorted = x.sort

median1 = sorted[n/2-1]
median2 = sorted[n/2]

n.times do |i|
  if x[i] <= median1
    puts median2
  else
    puts median1
  end
end

Measured memory_bytes: 25316
#include<stdio.h>

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

scanf("%d", &N);
  
  if(N == 1)
  {
    printf("Hello World");
  }
  if(N == 2)
  {
    scanf("%d", &A);
    scanf("%d", &B);
    printf("%d", A+B);
  }
  
return 0;
}

Measured memory_bytes: 128
number = input().split(" ")
N = int(number[0])
M = int(number[1])
ans = ["○"]*N
a = 0
b = 0
for i in range(M):
    sc = input().split(" ")
    s = int(sc[0])
    c = int(sc[1])
    if ans[s-1] == "○":
        ans[s-1] = c
    elif ans[s-1] == c:
        pass
    else:
        a += 1
    if s == 1:
        b += 1
    else:
        pass

for i in ans:
    if i == "○":
        x = ans.index("○")
        ans[x] = 0

if N > 1:
    if b == 0:
        ans[0] = 1
    else:
        pass

if N > 1:
    if ans[0] == 0:
        a += 1
    else:
        pass

if a > 0:
    print(-1)
else:
    for i in ans:
        print(i,end="")

Measured memory_bytes: 3064
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = 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; }

int main()
{
    int N = 3;
    std::map<int, int> m;
    rep (i, N)
    {
        int tmp; cin >> tmp;
        m[tmp] = 0;
    }

    cout << m.size() << "\n";

    return 0;
}


Measured memory_bytes: 256
#F
import sys
from collections import Counter as cc

N,A,B,C = list(map(int, input().split()))
abc = []
ans = []

for i in range(N):
    abc.append(input())
abc.append("")

a = abc.count("AB")+abc.count("AC")
b = abc.count("AB")+abc.count("BC")
c = abc.count("AC")+abc.count("BC")


for i, (s, ns) in enumerate(zip(abc,abc[1:])):
    if s == "AB":
        if A > B or (A == B and i != N-1 and ("AB" in ns or "BC" in ns)):
            A -= 1
            B += 1
            ans.append("B")
        else:
            A += 1
            B -= 1
            ans.append("A")
    elif s == "AC":
        a -= 1
        c -= 1
        if A > C or (A == C and i != N-1 and ("AC" in ns or "BC" in ns)):
            A -= 1
            C += 1
            ans.append("C")
        else:
            A += 1
            C -= 1
            ans.append("A")
    else:
        c -= 1
        b -= 1
        if B > C or (B == C and i != N-1 and ("AC" in ns or "BC" in ns)):
            C += 1
            B -= 1
            ans.append("C")
        else:
            C -= 1
            B += 1
            ans.append("B")
    if A < 0 or B < 0 or C < 0:
        print("No")
        sys.exit()

print("Yes")
for i in range(N):
    print(str(ans[i]))

Measured memory_bytes: 17932
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;

int main() {
	ll a, b, c, x, y; cin >> a >> b >> c >> x >> y;

	//1
	ll P1 = x * a + y * b;
	ll P2, P3;

	//2
	if (x >= y) {
		P2 = c * 2 * x;
		P3 = c * 2 * y + (x - y)* a;
	}
	else {
		P2 = c * 2 * y;
		P3 = c * 2 * x + (y - x)* b;
	}

	cout << min(P1, min(P2, P3)) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int i = 0;i < (n);++i)
using ll = long long;
using namespace std;

int main() {
	int n;
	cin >> n;
	ll V = 0,E = 0;
	for(int i = 1; i<=n;++i)V+=ll(i)*(n-i+1);
	rep(i,n-1){
		int a,b;
		cin >>a >> b;
		if(a > b)swap(a,b);
		E += ll(a)*(n-b+1);
	}
	ll ans = V -E;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int n;
string str;
int main()
{
	cin>>n>>str;
	for(int i=0;i<(int)str.size();i++) str[i]=(str[i]-'A'+n)%26+'A';
	cout<<str<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define f first
#define s second
#define pb push_back
#define pp push
#define RETURN exit(0)
#define pow(x,y) (int)(pow(x,y))
#define ceil(x) (int)(ceil(x))
#ifndef ONLINE_JUDGE
#define debug(x) cout<<x<<endl;
#else
#define debug(x) 42
#endif
const int MAX=1e4;
const int MOD=1e9+7;
const int MAAX=1e15;
const long double EPS=1e-6;
const int N=1e6;
int power(int x,int y)
{
    if (y == 0)
        return 1;
    int a=power(x,y/2)%MOD;
    if (y % 2 == 0)
        return a * a % MOD;
    else
        return x * a % MOD * a % MOD;
}
long double sq(int x){
    long double s=0,e=x,mid;
    while(e-s>=EPS){
        mid=(s+e)/2;
        if(mid*mid<=x){
            s=mid;
        }
        else{
            e=mid-EPS;
        }
    }
    return s;
}
vector<int> primes;
bool visted[N+5];
void sieve(){
    visted[0]=visted[1]=1;
    for(int i=2;i*i<=N;i++){
        if(visted[i]==0){
            primes.pb(i);
            for(int j=i*i;j<=N;j+=i){
                visted[j]=1;
            }
        }
    }
    for(int i=sqrt(N)+1;i<=N;i++){
        if(visted[i]==0)
            primes.pb(i);
    }
    return;
}

int n;
vector<pair<int,int>> v[100010];
int freq[100010],cl[100010];
void bfs(int idx){
    cl[idx]=0;
    queue<pair<int,int>> q;
    q.pp({idx,0});
    while(!q.empty()){
        queue<pair<int,int>> q2;
        while(!q.empty()){
            q2.pp(q.front());
            cl[q.front().f]=q.front().s;
            q.pop();
        }
        while(q2.size()){
            pair<int,int> x=q2.front();
            q2.pop();
            for(int i=0;i<v[x.f].size();i++){
                if(cl[v[x.f][i].f]==-1)
                    q.pp({v[x.f][i].f,(x.s+v[x.f][i].s)%2});
            }
        }
    }
}

in main()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    int tc=1;
    //sieve();
    //scanf("%lld",&tc);
    while(tc--)
    {
        memset(cl,-1,sizeof cl);
        cin>>n;
        for(int i=0;i<n-1;i++){
            int x,y,c;
            cin>>x>>y>>c;
            v[x].pb({y,c%2});
            v[y].pb({x,c%2});
        }
        bfs(1);
        for(int i=0;i<n;i++)
            cout<<cl[i+1]<<endl;
    }
    RETURN;
}


Measured memory_bytes: 8832
k, n = map(int, input().split())
A = list(map(int, input().split()))
T = [0] * n

A.sort()

for i in range(n):
    if abs(A[i] - A[i - 1]) <= k / 2:
        T[i] = abs(A[i] - A[i - 1])
    else:
        T[i] = k - abs(A[i] - A[i - 1])

print(k - max(T))

Measured memory_bytes: 26420
from itertools import combinations

while True:
    N, X = map(int, input().split())
    if N==0 and X==0:
        exit()
    A = list(range(1, N+1))
    Comb = combinations(A, 3)
    ans = 0
    for a, b, c in Comb:
        if (a+b+c) == X:
            ans += 1
    print(ans)


Measured memory_bytes: 5640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n; cin >> n;
    bool ok = false;
    rep(i, n) {
        int x; cin >> x;
        if (x%2!=0) ok = true;
    }
    if (ok) puts("first");
    else puts("second");
}

Measured memory_bytes: 256
A=[]
for _ in range(3):
    A.append(list(map(int,input().split())))

n=int(input())

for _ in range(n):
    x=int(input())
    for i in range(3):
        for j in range(3):
            if x==A[i][j]:
                A[i][j]=0
ans='No'
if A[1][1]==0:
    if A[0][0]==0 and A[2][2]==0:
        ans='Yes'
    if A[0][2]==0 and A[2][0]==0:
        ans='Yes'

for i in range(3):
    if A[i][0]==0 and A[i][1]==0 and A[i][2]==0:
        ans='Yes'
    if A[0][i]==0 and A[1][i]==0 and A[2][i]==0:
        ans='Yes'
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
 
#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>
 
#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll solve(ll a, ll b) {
  if (!a) return -b;
  return solve(b % a, a) + b / a * 2 * a;
}

int main() {
  ll n, x;
  scanf("%lld%lld", &n, &x);
  printf("%lld\n", n + solve(x, n - x));
  return 0;
}


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

#define ll long long

ll n;
int len = 0;
std::deque <int> dq;

void solve(ll n){
	if (n == 1){
		return;
	}
	solve(n >> 1);
	dq.push_back(++ len);
	if (n & 1){
		dq.push_front(++ len);
	}
}

int main(){
	scanf("%lld", &n);
	++ n;
	solve(n);
	printf("%d\n", len << 1);
	while ((int) dq.size()){
		printf("%d ", dq.front());
		dq.pop_front();
	}
	for (int i = 1; i <= len; ++ i){
		printf("%d ", i);
	}
	return printf("\n"), 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  string text;
  int s=0,n=0;
  while(cin>>text){
    for(int i=0;i<text.size();i++){
      if('0'<=text[i]&&text[i]<='9'){
	n*=10;
	n+=(text[i]-'0');
      }
      else{
	s+=n;
	n=0;
      }
    }
    s+=n;
    n=0;
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
  
#define SIZE 250
  
int main(){
  int i,n;
  int x[SIZE];
  
  scanf("%d",&n);
  
  for(i = 1; i <= n; i++){
    scanf("%d",&x[i]);
  }
  
  for(i = 1; i <= n; i++){
    printf("node %d: key = %d,",i ,x[i]);
    if(i != 1){
      printf(" parent key = %d,",x[i/2]);
    }
    
    
 if(2*i <= n){
      printf(" left key = %d,",x[2*i]);
    }
 if(2*i+1 <= n){
      printf(" right key = %d,",x[2*i+1]);
    }
    printf(" \n");
  }
  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#define int long long
#define int32 int32_t

using namespace std;



int32 main() {
    ios_base::sync_with_stdio(false);
    int k;
    string s;
    cin >> k >> s;
    if(k >= s.size()) {
        cout << s;
        return 0;
    }
    else {
        cout << s.substr(0, k) + "...";
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define M 100005
#define ll long long
int a[M],b[M],c[M],res[M<<3];
int main(){
	int X,Y,A,B,C,num=0;ll ans=0;
	scanf("%d %d %d %d %d",&X,&Y,&A,&B,&C);
	for(int i=1;i<=A;i++)scanf("%d",&a[i]);
	for(int i=1;i<=B;i++)scanf("%d",&b[i]);
	for(int i=1;i<=C;i++)scanf("%d",&c[i]); 
	sort(a+1,a+A+1);
	sort(b+1,b+B+1);
	sort(c+1,c+C+1);
	for(int i=1;i<=X;i++)res[++num]=a[A-i+1]; 
	for(int i=1;i<=Y;i++)res[++num]=b[B-i+1];
	for(int i=1;i<=X+Y&&i<=C;i++)res[++num]=c[C-i+1];
	sort(res+1,res+num+1);
	for(int i=1;i<=X+Y;i++)ans+=res[num-i+1];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include<map>
#include <utility>
#include <math.h>
using namespace std;
int a = 0, b = 0, c = 0, d = 0, e[1050] = {}, f[100010] , counto = 0, counto1 = 0;
double syo = 0, su = 0;
char mado[105];
string rik;
bool mazi[110], gi[110];
pair<int, int>n[110];
vector<int> r;
map<int, int>kazu;
int main() 
{
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> b;
		f[i] = b;
		kazu[b]++;
	}
	for (int i = 0; i < a; i++) {
		if (kazu[f[i]] % 2 != 0) {
			counto++;
			kazu[f[i]] = 0;
		}
		//cout << f[i] << endl;
		//cout << counto << endl;
	}
	cout << counto << endl;
	return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define N 500001
#define M 1000001
int fa[N], d[N], f[N], su, sv;
int hd[N], nx[M], e[M], num;
int n, m, ans;
void dfs(int x, int dep) {
    d[x] = dep, f[x] = dep & 1 ? 1 : -1;
    for (int i = hd[x]; i; i = nx[i]) {
        if (e[i] == fa[x]) continue;
        if (d[e[i]]) {
            su = x, sv = e[i];
            continue;
        }
        fa[e[i]] = x;
        dfs(e[i], dep + 1);
        f[x] += f[e[i]];
    }
}
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1, x, y; i <= m; i++) {
        scanf("%d%d", &x, &y);
        nx[++num] = hd[x], hd[x] = num, e[num] = y;
        nx[++num] = hd[y], hd[y] = num, e[num] = x;
    }
    dfs(1, 1);
    if (m == n - 1) {
        if (f[1]) return (puts("-1"), 0);
        for (int i = 1; i <= n; i++) ans += abs(f[i]);
    } else if ((d[sv] - d[su]) & 1) {
        if (f[1]) return (puts("-1"), 0);
        vector<int> vec;
        while (sv != su) vec.push_back(f[sv]), d[sv] = 0, sv = fa[sv];
        sort(vec.begin(), vec.end());
        int mid = vec[vec.size() / 2];
        ans = abs(mid);
        for (int i = 1; i <= n; i++)
            if (d[i]) ans += abs(f[i]);
        for (auto i : vec) ans += abs(i - mid);
    } else {
        if (f[1] & 1) return (puts("-1"), 0);
        int del = -f[1] / 2;
        ans = abs(del);
        while (su) f[su] += del, su = fa[su];
        while (sv) f[sv] += del, sv = fa[sv];
        for (int i = 1; i <= n; i++) ans += abs(f[i]);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 18684
//waz
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
 
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;
 
#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))
 
int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}
 
const int N = 1e5 + 10;
 
int n, a[N];
 
int main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) gi(a[i]);
	sort(a + 1, a + n + 1);
	if (a[n] - a[1] > 1)
	{
		puts("No");
		return 0;
	}
	reverse(a + 1, a + n + 1);
	int j = 0;
	while (a[j + 1] == a[1]) ++j;
	a[1] -= n - j;
	if (a[1] <= 0)
	{
		puts("No");
		return 0;
	}
	if (a[1] == j - 1 && (n == j))
	{
		puts("Yes");
		return 0;
	}
	if (j / a[1] >= 2) 
	{
		puts("Yes");
		return 0;
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n = 0, max = 0;
	string s;
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'R') {
			n += 1;
		} else {
			if (n > max) {
				max = n;
			}
			n = 0;
		}
	}
	if (n > max) {
		max = n;
	}
	cout << max;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
constexpr int P = 1'000'000'007, INV2 = 500'000'004;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vector<vector<int>> f(n, vector<int>(n));
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            f[i][j] = a[i] > a[j];
    for (int i = 0; i < q; ++i) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        for (int j = 0; j < n; ++j) {
            if (j != x && j != y) {
                int v = 1LL * (f[x][j] + f[y][j]) * INV2 % P;
                f[x][j] = f[y][j] = v;
                v = 1LL * (f[j][x] + f[j][y]) * INV2 % P;
                f[j][x] = f[j][y] = v;
            }
        }
        int v = 1LL * (f[x][y] + f[y][x]) * INV2 % P;
        f[x][y] = f[y][x] = v;
    }
    int ans = 0;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < i; ++j)
            ans = (ans + f[j][i]) % P;
    for (int i = 0; i < q; ++i)
        ans = 2 * ans % P;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 37632
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }
// 桁和
LL Ketawa_s(string s) { LL a=0; FOR(i,0,s.length())a += s[i] - '0'; return a; }


//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p%i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

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

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL N;
	cin >> N;
	LL sn = Ketawa_s(to_string(N));
	if (N%sn == 0) { O("Yes"); }
	else O("No");

	return 0;
}

Measured memory_bytes: 256
n, k, q = gets.chomp.split(' ').map(&:to_i)
a=[]
while gets; a << $_.to_i; end
b=[0]*n
total = 0
a.each do |n|
  b[n-1] = 0 unless b[n-1]
  b[n-1] += 1
  total += 1
end

b.map{|x| q - x}.each do |n|
  puts n < k ? 'Yes' : 'No'
end



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

// definitions
#define __Imperial_Lord__ ONLINE_JUDGE
#define _cps CLOCKS_PER_SEC
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c <<endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d <<endl
#define exec cerr<<"Time taken : "<<(ld)(clock())/_cps<<"s"<<endl
#define mod1 998244353
#define mod 1000000007
#define pi 3.1415926535897932384

using namespace std;

// alias name for common data types
typedef vector<long long> vl;
typedef vector<long double> vld;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const ll INF=1e18;

// cin and cout overloaded for vectors
template<typename T>    istream& operator>>(istream& is,  vector<T>& v)
{
    for (auto& i : v) 
        is >> i;        
    return is;
}
template<typename T>             
ostream& operator<<(ostream& os,  vector<T>& v)
{
    for (auto& i : v) 
        os << i << ' '; 
        return os;
}


// code beigns in main
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    while(t--)
    {
    	ll a,b;
    	cin >> a >>b;
    	ll d=a*500;
    	if(d>=b) cout << "Yes" << endl;
    	else cout << "No" << endl;
    }	
    exec;
}


Measured memory_bytes: 3660
n = int(input())
m = n
cnt = 0
while(n>=1):
    n = n/10
    cnt += 1
ans = 0
i = 1
while( i < cnt):
    ans += 9 * 10**(i-1)
    i += 2
    

if cnt%2 == 1:
    ans += m-10**(i-1) + 1
    
print(ans)

Measured memory_bytes: 38384
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
int main(){
    std::stack<int> stack;
    int x;
    char s[100];
    while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
        int b = stack.top();
        stack.pop();
        int a = stack.top();
        stack.pop();
        stack.push(a+b);
    } else if ( s[0] == '-' ){
        int b = stack.top();
        stack.pop();
        int a = stack.top();
        stack.pop();
        stack.push(a-b);
    } else if ( s[0] == '*' ){
        int b = stack.top();
        stack.pop();
        int a = stack.top();
        stack.pop();
        stack.push(a*b);
    } else {
        x = atoi(s);
        stack.push(x);
    }
  }

    
    cout << stack.top() << endl; 
    return 0;
}
    




Measured memory_bytes: 3248
# 押しだしながらDPする場合
N = int(input())
h = list(map(int, input().split()))
h.extend([0,0]) # 要らない足場
dp = [float("inf")]*(N+2)
dp[0] = 0 # 初期足場のコストは0
for i in range(N):
    dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1] - h[i]))
    dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2] - h[i]))
    
print(dp[N-1])

Measured memory_bytes: 13928