akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long n;
  cin>>n;
  long long a[n],b[n]={0},c[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
    b[a[i]-1]++;
  }
  
  long long ans=0;
  for(int i=0;i<n;i++){
  	ans+=b[i]*(b[i]-1)/2;
  }
  
  for(int i=0;i<n;i++){
  	c[i]=ans-b[a[i]-1]*(b[a[i]-1]-1)/2+(b[a[i]-1]-1)*(b[a[i]-1]-2)/2;
  }
   for(int i=0;i<n;i++){
   	cout<<c[i]<<endl;
   }
}

Measured memory_bytes: 7296
#include<stdio.h>
int main(void){
  int a,b;
  int x,y,z,t;
  scanf("%d%d",&a,&b);
  x=a+b;y=a-b;z=a*b;
  if(x<y){
    t=x;x=y;y=t;
  }
  if(y<z){
    t=y;y=z;z=t;
  }
  if(x<y){
    t=x;x=y;y=t;
  }
  printf("%d",x); 
 
  return 0;
}

Measured memory_bytes: 128
using System;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine();

        var odd = "RUD";
        var even = "LUD";

        for (int i = 0; i < s.Length; i++)
        {
            if (i % 2 == 0)
            {
                if (!odd.Contains(s.Substring(i, 1)))
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            else
            {
                if (!even.Contains(s.Substring(i, 1)))
                {
                    Console.WriteLine("No");
                    return;
                }
            }
        }

        Console.WriteLine("Yes");
    }
}


Measured memory_bytes: 13140
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))

# セグ木

def segfunc(a,b):
    return a+b

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res


n, M, Q = mi()

#####単位元######
ide_ele = 0
#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

L = [0]*n
init(L)

lrpq = dp2(0, 3, M+Q)

for i in range(M):
    l, r = mi()
    lrpq[i][1] = l-1
    lrpq[i][2] = r-1

for i in range(M, M+Q):
    p, q = mi()
    lrpq[i][0] = i
    lrpq[i][1] = p-1
    lrpq[i][2] = q-1

lrpq = sorted(lrpq, key=lambda x:(x[2], x[0]))

ans = [0]*(Q)

for i in range(M+Q):
    if lrpq[i][0] == 0:
        #L[lrpq[i][1]] += 1
        update(lrpq[i][1], seg[lrpq[i][1]+num-1]+1)
    else:
        ans[lrpq[i][0]-M] = query(lrpq[i][1], lrpq[i][2]+1)

for num in ans:
    print(num)

Measured memory_bytes: 107936
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }

int main () {
  int k;
  cin >> k;
  vi a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a[k-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const int N = 1 << 18;

ll t[2*N], lazy[2*N];
void push(int i) {
  if (lazy[i]) {
    lazy[2*i] += lazy[i];
    lazy[2*i+1] += lazy[i];
    t[2*i] += lazy[i];
    t[2*i+1] += lazy[i];
    lazy[i] = 0;
  }
}

void pull(int i) {
  t[i] = max(t[2*i], t[2*i+1]);
}

void update(int x, int y, ll v, int i=1, int l=0, int r=N-1) {
  if (r < x || y < l) return;
  if (x <= l && r <= y) {
    t[i] += v;
    lazy[i] += v;
    return;
  }
  push(i);
  int m = (l+r)/2;
  update(x, y, v, 2*i, l, m);
  update(x, y, v, 2*i+1, m+1, r);
  pull(i);
}

ll query(int x, int y, int i=1, int l=0, int r=N-1) {
  if (r < x || y < l) return -INF;
  if (x <= l && r <= y) return t[i];
  push(i);
  int m = (l+r)/2;
  return max(query(x, y, 2*i, l, m), query(x, y, 2*i+1, m+1, r));
}

int n, m;
struct qry {
  int x, d;
};
vector<qry> open[N], close[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int l, r, d; cin >> l >> r >> d;
    open[l].push_back({l, d});
    close[r].push_back({l, d});
  }
  // dp[i] = max score of [0..i] with a 1 at i
  //       = max_{j<i} (dp[j] + sum_k d_k where i in k, j not in k)
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    for (const qry& q : open[i]) {
      update(0, q.x-1, q.d);
    }
    ll dp = query(0, i-1);
    //cerr << i << " " << dp << nl;
    update(i, i, dp);
    ans = max(ans, dp);
    for (const qry& q : close[i]) {
      update(0, q.x-1, -q.d);
    }
  }
  cout << ans << nl;
  return 0;
}


Measured memory_bytes: 33280
# https://atcoder.jp/contests/abc097/tasks/abc097_a



a, b, c, d = gets.split.map(&:to_i)
cond=false
if (a-c).abs<=d || ((a-b).abs<=d && (c-b).abs<=d)
    cond=true
end

puts cond ? 'Yes' : 'No'


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
ll INF = (1LL<<31)-1;

vector<int> seg;
int N;

void update(int i, int x){
    i += N-1;
    seg[i] = x;
    while(i > 0){
        i = (i-1)/2;
        seg[i] = min(seg[i*2+1],seg[i*2+2]);
    }
}

int query(int a, int b, int k, int l, int r){
    if(r <= a || b <= l) return INF; //区間が全く被らない
    if(a <= l && r <= b){ //区間が完全に含まれる
        return seg[k];
    }else{
        int c1 = query(a,b,2*k+1,l,(l+r)/2);
        int c2 = query(a,b,2*k+2,(l+r)/2,r);
        return min(c1,c2);
    }

}

int main(){
    int n,q;
    cin >> n >> q;
    N = 1;
    while(N < n){
        N *= 2;
    }
    seg = vector<int>(2 * N - 1, INF);
    rep(i,q){
        int c,x,y; cin >> c;
        if(c){
            int x,y;cin >> x >> y;
            cout << query(x,y+1,0,0,N) << endl;
        }else{
            int x,y;
            cin >> x >> y;
            update(x,y);
        }
    }
    return 0;
}


Measured memory_bytes: 4912
import Data.List

split' [] = []
split' (',':xs) = split' xs
split' x =
  let w = takeWhile (/= ',') x
      z = dropWhile (/= ',') x
  in
    w:(split' z)

numbering :: Int -> Int -> [(Int,Int)] -> [(Int,Int,Int)]
numbering _ _ [] = []
numbering n p ((i,s):xs) =
  if p == s
  then (i,s,n):(numbering n p xs)
  else (i,s,n+1):(numbering (n+1) s xs)

mkdb x =
  let s = sortBy (\(x0,x1) (y0,y1) -> compare y1 x1) x
      (_,p) = s!!0
      n = numbering 1 p s
  in
    n

lookup' :: Int -> [(Int,Int,Int)] -> Int
lookup' n ((i,s,o):xs) =
  if n == i
  then o
  else lookup' n xs

main = do
  c <- getContents
  let l = lines c
      t = map (map read) $ map split' $ takeWhile (/= "0,0") l :: [[Int]]
      t'= map (\ [x,y] -> (x,y)) t :: [(Int,Int)]
      q = map read $ drop 1 $ dropWhile (/= "0,0") l :: [Int]
      d = mkdb t'
      o = map (\ i -> lookup' i d) q
--  print t'
--  print q
--  print d
  mapM_ print o

Measured memory_bytes: 3908
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, char** argv) {
    int n, m;
    cin >> n >> m;

    int id_min{1}, id_max = n;

    for (int i = 0; i < m; ++i) {
        int l, r;
        cin >> l >> r;
        id_min = max(id_min, l);
        id_max = min(id_max, r);
    }
    if (id_max-id_min < 0) cout << '0' << endl;
    else cout << (id_max-id_min+1) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = (long)Math.sqrt((double)n);
        long b = 0;
        long c = 0;
        
        for (long i = a; i > 0; i--) {
            if (n % i == 0) {
                b = n / i;
                c = i;
                break;
            }
        }
        System.out.println(b + c - 2);
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

template <class T> T up(T a, T div) { return (a + div - 1) / div; }

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

    int D, G;
    scan(D, G);
    vector<int> p(D), c(D);
    REP(i, D) scan(p[i], c[i]);

    int ans    = INF32;
    auto check = [&](int sum) { return G <= sum ? true : false; };
    REP(bit, (1 << D)) {
        int sum = 0;
        int cnt = 0;
        REP(i, D) {
            if (bit & (1 << i)) {
                sum += (i + 1) * 100 * p[i] + c[i];
                cnt += p[i];
            }
        }
        if (!check(sum)) {
            RREP(i, D) {
                if (!(bit & (1 << i))) {
                    int diff = G - sum;
                    int add  = min(p[i] - 1, up(diff, ((i + 1) * 100)));
                    sum += 100 * (i + 1) * add;
                    cnt += add;
                    if (check(sum))
                        break;
                }
            }
        }
        if (check(sum))
            chmin(ans, cnt);
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;

int main()
{
    int N,M;
    cin >> N >> M;
    vector< vector<int> > card(M, vector <int>(2));
    for(int i=0; i<M; i++){
        cin >> card[i][0] >> card[i][1];
    }
    int L=card[0][0], R=card[0][1];
    for(int i=1; i<M; i++){
        L=max(L, card[i][0]);
        R=min(R, card[i][1]);
    }
    cout << max(R-L+1, 0) << endl;

    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    int n;
    cin >> n;
    map<ll, int> m;
    rep(i, n) {
        ll a;
        cin >> a;
        m[a]++;
    }

    vll a;
    for(auto t : m) {
        for(int i = 0; i < t.second / 2; i++) a.push_back(t.first); 
    }

    int i = a.size();
    ll ans = 0;
    if(i >= 2) ans = a[i-1]*a[i-2];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
//Powered by caibiCH2 at 2020/04/24,19:58:15
#include<bits/stdc++.h>
#define elif else if
using namespace std;
typedef long long ll;
const ll INF=0x3f3f3f3f;
ll f[2010][2010];
struct msp{
	ll num,data;
}a[2010];
inline ll cal(int cx,int wz){
	return abs(wz-a[cx].num)*a[cx].data;
}
signed main(){
	ios::sync_with_stdio(0);
	//cin.tie(0);
	int n;cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i].data;a[i].num=i;
	}
	sort(a+1,a+n+1,[](const msp&x,const msp&y){
		return x.data>y.data;
	});
	for(int i=0;i<=n;++i){
		for(int j=0;j<=n-i;++j){
			int now=i+j;
			if(i==0&&j==0)continue;
			elif(i==0){
				f[i][j]=f[i][j-1]+cal(now,n-j+1);
			}
			elif(j==0){
				f[i][j]=f[i-1][j]+cal(now,i);
			}
			else{
				f[i][j]=max(f[i][j-1]+cal(now,n-j+1),f[i-1][j]+cal(now,i));
			}
		}
	}
	ll ans=0;
	for(int i=0;i<=n;++i){
		ans=max(ans,f[i][n-i]);
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 26300
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N; cin >> N;
  int p = -1;
  for (int i = 0; i < N; ++i) {
    int H; cin >> H;
    if (H > p) --H;
    if (p > H) {
      cout << "No" << endl;
      return 0;
    }
    p = H;
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3580
import sys
import heapq

def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    C = list(input())

    Wcount=0
    Rcount =0
    rr =C.count("R")
    ww =C.count("W")


    for j in range(rr):
        if C[j]=="W":
            Rcount+=1

    for i in range(ww):
        if C[-1-i]=="R":
            Wcount+=1

    print(min(Rcount,Wcount))






if __name__ == "__main__":
    main()


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e2+23;

int x[N], y[N], h[N];

void solve() {
  int n; scanf("%d", &n);
  int remember = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d%d", x+i, y+i, h+i);
    if (h[i]) remember = i;
  }
  for (int cx = 0; cx <= 100; ++cx) {
    for (int cy = 0; cy <= 100; ++cy) {
      int H = h[remember] + abs(x[remember]-cx) + abs(y[remember]-cy);
      bool good = true;
      for (int i = 0; i < n; ++i) {
	if (max(H - abs(x[i]-cx) - abs(y[i]-cy), 0) == h[i]) continue;
	good = false;
	break;
      }
      if (good) {
	printf("%d %d %d", cx, cy, H);
	return;
      }
    }
  }
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3824
N, M = map(int, input().split())
if N % 2 == 1:
    for a, b in zip(range(1, M+1), range(2*M, M, -1)):
        print(a, b)
else:
    for a, b in zip(range(1, M+1), range(M+1, 0, -1)):
        if a < b:
            print(a, b)
        else:
            break

    for a, b in zip(range(M+3, 2*M+2), range(2*M+2, M, -1)):
        if a < b:
            print(a, b)
        else:
            break
        

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  string s,t; cin >> s >> t;

  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  
  bool ok = false;
  if(s<t) ok = true;
  /*rep(i,s.size()){
    if(t.size()>i){
      if(s[i]<t[i]) ok = true;
      break;
    }
  }
  if(s.size()<t.size()){
    rep(i,s.size())
      if(s[i]==t[i]) ok = true;
  }
  */
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3592
n,m= map(int,input().split())
c= list(map(int,input().split()))
inf=60000
dp=[inf]*50010
dp[0]=0
dp[1]=1
for i in range(2,n+1):
    for j in c:
        if i-j>=0:
            dp[i]=min(dp[i-j]+1, dp[i])
print(dp[n])


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

int main(){
  int n,k;
  cin >> n >> k;
  int a[n];
  rep(i,n)cin >> a[i];
  map<int,int> mp;
  rep(i,n)mp[a[i]]++;
  vector<int> t;
  for(auto p:mp){
    t.push_back(p.second);
  }
  int ans = 0;
  if(mp.size()>k){
    sort(t.begin(),t.end());
    rep(i,mp.size()-k)ans += t[i];
    //cout << ans << endl;
  }
  //rep(i,t.size())cout << t[i] << endl;
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 11516
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

 ll dp[100005][3];
int main() {
    ll N;
    cin >> N;

    ll a[100005];
    ll b[100005];
    ll c[100005];


    bool ca = false, cb = false, cc = false;

    for(int i = 0; i < N; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    
    ll max_dp = 0;

    for(int i = 1; i < N; i++) {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }

    cout << max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])) << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<int, int> P;

int main() {
    cin>>N>>A>>B;
    ll ans = (N / (A + B)) * A;
    cout<<ans + min(N % (A + B), A)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = 240000;
LL tree[maxn << 4], lazy[maxn << 4];
struct node{int l, a;node(int l = 0, int a = 0): l(l), a(a){}};
vector<node> s[maxn];
void pushdown(int o){
	lazy[o * 2] += lazy[o];
	tree[o * 2] += lazy[o];
	lazy[o * 2 + 1] += lazy[o];
	tree[o * 2 + 1] += lazy[o];
	lazy[o] = 0;
}
void update(int o, int l, int r, int L, int R, LL v){
	if(l >= L and r <= R){
		tree[o] += v;
		lazy[o] += v;
	}
	else{
		int m = (l + r) >> 1;
		pushdown(o);
		if(L <= m) update(o * 2, l, m, L, R, v);
		if(R > m) update(o * 2 + 1, m + 1, r, L, R, v);
		tree[o] = max(tree[o * 2], tree[o * 2 + 1]);
	}
}
int main(){
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	while(M --){
		int l, r, a;
		cin >> l >> r >> a;
		s[r].push_back(node(l, a));
	}
	for(int i = 1; i <= N; i += 1){
		update(1, 1, N, i, i, tree[1]);
		for(node p: s[i]) update(1, 1, N, p.l, i, p.a);
	}
	cout << max(0LL, tree[1]);
}

Measured memory_bytes: 22912
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(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 F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int n;
    int ans=INF;
    cin >>n;
    string s;
    cin>>s;
    vector<int>sum(n+2,0);
    sum[0]=0;
  //  clog<<"0 ";
    rep(i,n){
        sum[i+1]+=sum[i];
        if(s[i]=='.'){
            sum[i+1]++;
           
        }
     //   clog << sum[i + 1] << " ";
    }
  //  clog<<endl;
    for(int i=0;i<n;i++){
        chmin(ans,i-sum[i]+sum[0]+sum[n]-sum[i+1]);
     //  clog<<(sum[i]-sum[0])<<" "<<(sum[n]-sum[i+1])<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1412
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    ll h,n;
    while(cin>>h>>n)
    {
        ll ans=0;
        for(int i=1;i<=n;i++)
        {
            ll a;cin>>a;ans+=a;
        }
        if(ans>=h)cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 256
use std::cmp;
use std::collections::*;
use std::i32;
use std::io::{self, Read};
use std::mem;

const MOD: usize = 1000000007;

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock());

    let n: usize = sc.read().unwrap();
    let i: usize = sc.read().unwrap();

    println!("{}", n - i + 1);
}

struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse()
            .ok()
    }

    fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Option<Vec<T>> {
        (0..n).map(|_| self.read()).collect()
    }

    fn read_vec2d<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Option<Vec<Vec<T>>> {
        (0..m).map(|_| self.read_vec(n)).collect()
    }

    fn read_board(&mut self, n: usize) -> Option<Vec<Vec<char>>> {
        (0..n)
            .map(|_| {
                self.read::<String>()
                    .map(|s| s.chars().collect::<Vec<char>>())
            })
            .collect()
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    string st;
    cin>>st;
    int n=st.size();
    int a=0;
    REP(i,n){
        if(i%2){
            if(st[i]=='0'){
                a++;
            }
        }else{
            if(st[i]=='1'){
                a++;
            }
        } 
    }
    int b=0;
    REP(i,n){
        if(i%2==0){
            if(st[i]=='0'){
                b++;
            }
        }else{
            if(st[i]=='1'){
                b++;
            }
        } 
    }
    cout<<min(a,b)<<endl;
    return 0;
}

Measured memory_bytes: 512
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    k=int(readline())

    a=np.arange(1,k+1,dtype=np.int64)
    b=np.gcd.outer(np.gcd.outer(a,a),a)
    print(b.sum())

if __name__=="__main__":
    main()

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

using namespace std;

bool check(int i) {
  auto s = to_string(i);
  unordered_set<char> t;
  for (auto& e : s) {
    t.insert(e);
  }
  return t.size() == 1;
}

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

  int n;
  cin >> n;
  for (int i = n; ; ++i) {
    if (check(i)) {
      cout << i << "\n";
      break;
    }
  }
}


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

vector<ll>multiple(1001);
void prime(ll v){
  multiple[0]=-1;
  multiple[1]=-1;
  for(int i=2; i<=v; i++){
    if(multiple[i]!=0)continue;
    for(int j=i*2; j<=v; j+=i){
     multiple[j]=i;
    }
  }
}

int main(){
  ll n;
  cin >> n;
  vector<ll>a(n);
  queue<ll>que;
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  prime(1000);
  vector<ll>lcm(1000005);
  vector<vector<ll>>alcm(n,vector<ll>(1001));
  for(int j=0; j<n; j++){
    for(int i=2; i<=1000; i++){
      ll count=0;
      if(multiple[i]!=0)continue;
      while(a[j]%i==0){
        a[j]/=i;
        count++;
      }
      alcm[j][i]=count;
      lcm[i]=max(lcm[i],count);
    }
    if(lcm[a[j]]==0 && a[j]!=1) que.push(a[j]);
    lcm[a[j]]=1;
  }
  ll sum=0;
  for(int i=0; i<n ;i++){
    ll res=1;
   for(int j=2; j<=1000; j++){
     if(lcm[j]==0) continue;
     res*=pow(j,lcm[j]-alcm[i][j]);
     res%=mod;
   }
    for(int j=0; j<que.size(); j++){
      ll kari=que.front();
      que.pop();
      que.push(kari);
      if(kari==a[i])continue;
      res*=kari;
      res%=mod;

    }
    sum+=res;
    sum%=mod;
  }
  cout << sum << endl;
}
  
  
  


Measured memory_bytes: 86784
import java.io.*;
import java.util.Arrays;
 
public class Main{
    public static void main(String[] args) throws IOException{ 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while(true){
            String line = br.readLine();
            String[] spl = line.split(" ");
            int m = Integer.parseInt(spl[0]);
            int f = Integer.parseInt(spl[1]);
            int r = Integer.parseInt(spl[2]);
            if ( m == -1  && f == -1 && r == -1) {break;}
            if ( m == -1 || f == -1) {
                System.out.println("F");
            }else if( m + f >= 80){
                System.out.println("A");
            }else if( m + f >= 65){
                System.out.println("B");
            }else if( m + f >= 50 || ( m + f >=30) && r >= 50){
                System.out.println("C");
            }else if( m + f >= 30){
                System.out.println("D");
            }else{
                System.out.println("F");
            }
        }
    }
}

Measured memory_bytes: 24444
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

s64 mypow(s64 x, s64 n)
{
    s64 ret = 1;
    while (n > 0)
    {
        if (n & 1) ret = (ret * x) % MOD;
        x = (x * x) % MOD;
        n >>= 1;
    }
    return ret;
}

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

    s64 N;
    cin >> N;
    vs64 c(N);
    rep (i, N)
    {
        cin >> c[i];
    }
    sort(c.begin(), c.end());

    s64 ans = 0;
    for (s64 i = 1; i <= N; ++i)
    {
        ans += (c[N - i] * (i + 1)) % MOD;
        ans %= MOD;
    }

    cout << (mypow(4, N - 1) * ans) % MOD << "\n";
    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
using namespace std;
main()
{
	long long int n, i, ans = 0;
	cin >> n;
	long long int ima = 100;
 while(ima<n)
 {
 	long long int x = ima/100;
 	ima+=x;
 	ans++;
 }
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = _in[0] # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    TF = 'Yes' if '7' in N else 'No'
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(TF)


Measured memory_bytes: 61868
#include<bits/stdc++.h>
#define wa puts("Impossible"),exit(0)

using namespace std;

int n,a[105],m;

int main(){
	scanf("%d",&n);
	for(int i=1,x;i<=n;i++)scanf("%d",&x),a[x]++,m=max(m,x);
	if(m==1&&n!=2)wa;
	int p=(m+1)/2;
	for(int i=1;i<p;i++)if(a[i])wa;
	if(a[p++]!=1+(m&1))wa;
	while(p<=m)if(a[p++]<2)wa;
	puts("Possible");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>



int GreatestCommonDivisor(int x, int y)
{
    if (x < y) {
        int tmp = x;
        x = y;
        y = tmp;
    }
    while (x % y != 0) {
        int tmp = x % y;
        x = y;
        y = tmp;
    }
    return y;
}

int main(int argc, int *argv[])
{
    int x, y;

    scanf("%d %d", &x, &y);
    printf("%d\n", GreatestCommonDivisor(x, y));

    return 0;
}

Measured memory_bytes: 592
n = int(input())
p = list(map(int, input().split()))
num_list = [0] * (n + 1)

for i in range(n):
    if p[i] == i + 1:
        num_list[p[i] - 1] = 1

counter = 0
res = 0
for i in range(n + 1):
    if num_list[i] == 1:
        counter += 1
    else:
        res += (counter + 2 - 1) // 2
        counter = 0

print(res)


Measured memory_bytes: 20552
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, M;
ll D[200010];
std::vector<P> G[200010];
ll C[200010];
ll col[200010];
ll U[200010], V[200010];
std::vector<ll> nG[200010];
bool used[200010];

void dfs( ll v, ll c ) {
  used[v] = true;
  col[v] = c;

  for( auto u : nG[v] ) if( !used[u] ) {
    dfs( u, c^1 );
  }

  return;
}

int main()
{
  std::cin >> N >> M;

  rep( i, N )
    std::cin >> D[i];

  rep( i, M ) {
    std::cin >> U[i] >> V[i];
    --U[i]; --V[i];

    G[U[i]].emplace_back( V[i], i );
    G[V[i]].emplace_back( U[i], i );
  }

  rep( i, M )
    C[i] = 1e9;

  rep( i, N ) {
    bool fl = true;

    ll mi = INF, idx;

    for( auto up : G[i] ) {
      fl &= D[i] < D[up.first];
      
      if( chmin( mi, D[up.first] ) )
        idx = up.second;
    }

    if( fl ) {
      std::cout << -1 << std::endl;

      return 0;
    }

    C[idx] = D[i];

    nG[U[idx]].emplace_back( V[idx] );
    nG[V[idx]].emplace_back( U[idx] );
  }

  rep( i, N ) if( !used[i] )
    dfs( i, 0 );

  std::string S;

  rep( i, N )
    S += (col[i] ? 'W' : 'B');

  std::cout << S << std::endl;

  rep( i, M )
    std::cout << C[i] << std::endl;

  return 0;
}

Measured memory_bytes: 32384
#include <stdio.h>
int main(void)
{
  char str[4];
  fgets(str,4,stdin);
  if ((str[0] == 'a') || (str[0] == 'i') || (str[0] == 'u') || (str[0] == 'e') || (str[0] == 'o'))
  {
    printf("vowel\n");
  }
  else
  {
    printf("consonant\n");
  }
  return 0;
}


Measured memory_bytes: 128
def main():
    N = int(input())
    an = list(map(int, input().split()))
    ans = 0
    for a in an:
        if a % 2 != 0:
            continue
        while True:
            if a % 2 != 0:
                break
            a //= 2
            ans += 1
    print(ans)


main()


Measured memory_bytes: 4152
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

yakusu = make_divisors(n)

answers = []
for i in range(len(yakusu)):
    answers.append(yakusu[i] + yakusu[-(i+1)] - 2)

print(min(answers))


Measured memory_bytes: 3552
n,k=map(int,input().split())
#0-indexed
p=[i-1 for i in list(map(int,input().split()))]
c=list(map(int,input().split()))
#1回以上K回以下
ansF=-1000000000000000000
for i in range(n):
    #すでに辿ったもの
    check=[False]*n
    #辿った順番
    turns=[]
    #今
    now=i
    while check[now]==False:
        check[now]=True
        turns.append(now)
        now=p[now]
    #答え(今の)
    ans=0
    #kのうち何回分
    #更新を毎回行う
    spare=turns.index(now)
    if spare>=k:
        for j in range(k):
            ans+=c[turns[j]]
            ansF=max(ans,ansF)
        continue
    for j in range(spare):
        ans+=c[turns[j]]
        ansF=max(ans,ansF)
    turns=turns[spare:]
    spare=k-spare
    #サイクルの長さ
    l=len(turns)
    #サイクルの和(あまりも)
    #サイクルどこで止めるか
    x=0
    for j in range(l):
        x+=c[turns[j]]
    #そもそもサイクル回らない場合
    if spare<=l:
        for j in range(spare):
            ans+=c[turns[j]]
            ansF=max(ans,ansF)
        continue
    #サイクル回した方が良い場合
    #最後のサイクルは回さない方が良いパターンも
    if x>=0:
        ans+=(x*(spare//l-1))
        ansF=max(ans,ansF)
        for j in range(l):
            ans+=c[turns[j]]
            ansF=max(ans,ansF)
        for j in range(spare%l):
            ans+=c[turns[j]]
            ansF=max(ans,ansF)
    #サイクル回さない方がいい場合
    else:
        for j in range(l):
            ans+=c[turns[j]]
            ansF=max(ans,ansF)
print(ansF)

Measured memory_bytes: 87300
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int64_t> x(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> x[i];
    }
    
    auto center = lower_bound(begin(x), end(x), 0);
    
    int rest = k;
    int64_t ans = 10e9;

    if(center + (k - 1) < end(x))
        ans = min(ans, abs(*(center + (k - 1))));
        
    if(begin(x) <= center - k)
        ans = min(ans, abs(*(center - k)));

    for(auto i = center - 1; begin(x) <= i; --i)
    {
        rest--;
        auto e = center + (rest - 1);
        if(e < end(x))
        {
            int64_t cost = abs(*i * 2) + abs(*e);
            ans = min(ans, cost);
        }
        if(rest == 0) break;
    }
    
    rest = k;
    for(auto i = center; i < end(x); ++i)
    {
        rest--;
        auto e = center - rest;
        if(begin(x) <= e)
        {
            int64_t cost = abs(*i * 2) + abs(*e);
            ans = min(ans, cost);
        }
        if(rest == 0) break;
    }
    
    cout << ans << '\n';
    
    
    return 0;
}

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

/*
int Swap[3][2] = {
{0, 1},
{0, 2},
{1, 2}
};
*/

int main() {
    int N;
    long long A[3];
    cin >> N >> A[0] >> A[1] >> A[2];
    vector<vector<long long*>> In(N,vector<long long*>(2));
    string s;
    for(int i = 0; i < N; ++i) {
        cin >> s;
        if(s == "AB") {
            In[i][0] = &A[0], In[i][1] = &A[1];
        }
        else if(s == "AC") {
            In[i][0] = &A[0], In[i][1] = &A[2];
        }
        else {
            In[i][0] = &A[1], In[i][1] = &A[2];
        }
    }

    if(A[0] + A[1] + A[2] == 0) {
        cout << "No" << endl;
        return 0;
    }

    vector<int> res(N);
    if(A[0] + A[1] + A[2] == 1) {
        for(int i = 0; i < N; ++i) 
        {
            assert(A[0] >= 0 && A[1] >= 0 && A[2] >= 0);
            auto &p = In[i];
            if(*p[0] == 0 && *p[1] == 0) 
            {
                cout << "No" << endl;
                return 0;
            }
            if(*p[0] == 0) 
            {
                res[i] = p[0] - A;
                ++(*p[0]), --(*p[1]);
            }
            else 
            {
                res[i] = p[1] - A;
                ++(*p[1]), --(*p[0]);
            }
        }
    }
    else {
        for(int i = 0; i < N; ++i)
        {
            assert(A[0] >= 0 && A[1] >= 0 && A[2] >= 0);
            auto &p = In[i];
            if(*p[0] == 0 && *p[1] == 0) 
            {
                cout << "No" << endl;
                return 0;
            }
            else if(*p[0] == 0) 
            {
                res[i] = p[0] - A;
                ++(*p[0]), --(*p[1]);
            }
            else if(*p[1] == 0)
            {
                res[i] = p[1] - A;
                ++(*p[1]), --(*p[0]);
            }
            else 
            {// *p[0] != 0 かつ *p[1] != 0 のとき
                if(A[0] + A[1] + A[2] == 2 && i+1 < N) {
                    auto &q = In[i+1];
                    bool flg = false;
                    for(int j = 0; j < 2; ++j) {
                        for(int k = 0; k < 2; ++k) {
                            if(p[j] == q[k]) {
                                res[i] = p[j] - A;
                                ++(*p[j]), --(*p[j == 1 ? 0 : 1]);
                                flg = true; break;
                            }
                        }
                        if(flg) break;
                    }
                }
                else {
                    auto q = (*p[0] > *p[1]) ? p[1] : p[0];
                    auto r = (*p[0] > *p[1]) ? p[0] : p[1];
                    res[i] = q - A;
                    ++(*q), --(*r);
                }
            }
        }
    }

    cout << "Yes" << endl;
    for(int i = 0; i < N; ++i) {
        cout << (char)(res[i] + 'A') << endl;
    }
    return 0;
}

Measured memory_bytes: 9004
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    string S;
    int K;
    cin >> S >> K;
    int cnt1 = 0,sum1 = 0;
    for(int i = 0; i < (int)S.size()-1; i++) {
        if(S[i] == S[i+1]) {
            sum1++;
        }
        else {
            cnt1+=(sum1+1)/2;
            sum1 = 0;
        }
    }
    bool ok = false;
    if(sum1 == S.size()-1) ok = true;
    cnt1+=(sum1+1)/2;
    int cnt2 = 0,sum2 = 0;
    string T = S;
    T+=S;
    for(int i = 0; i < (int)T.size()-1; i++) {
        if(T[i] == T[i+1]) {
            sum2++;
        }
        else {
            cnt2+=(sum2+1)/2;
            sum2 = 0;
        }
    }
    cnt2+=(sum2+1)/2;
    if(ok) {
        cout << ((int)S.size()*K)/2 << endl;
        return 0;
    }
    cout << cnt1+(K-1)*(cnt2-cnt1) << endl;
}


Measured memory_bytes: 3616
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val AB = Array.fill(2)(sc.nextInt)

    (6 - AB.sum).toString
  }
}


Measured memory_bytes: 25416
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);

       		String inputString = scanner.nextLine();

		String[] strStdIn = inputString.split(" ", 0);

		long start = Long.parseLong(strStdIn[0]);
		long end = Long.parseLong(strStdIn[1]);
		long divide = Long.parseLong(strStdIn[2]);

		long result = (end / divide) - (start / divide);

		if (start % divide == 0) {
			result++;
		}

		System.out.println(result);
	}
}

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

int main()
{
    int n, k;
    std::cin >> n;
    std::cin >> k;
    std::vector<int> h(n);
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }

    int c = 0;
    for (int i = 0; i < n; i++) {
        if (h[i] >= k)
            c++;
    }
    std::cout << c << std::endl;

    return 0;
}


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

int main() {
    int k, t, ans = 0;
    cin >> k >> t;
    int a;
    priority_queue<int> pq;
    for(int i = 0; i < t; ++i) {
        cin >> a;
        pq.push(a);
    }
    pq.push(0);
    while(pq.size() != 1) {
        int x = pq.top();
        pq.pop();
        int y = pq.top();
        pq.pop();
        x -= y;
        pq.push(x);
    }
    cout << max(pq.top() - 1, 0) << '\n';

    return 0;
}


Measured memory_bytes: 256
c1=list(map(int,input().split()))
c2=list(map(int,input().split()))
c3=list(map(int,input().split()))

c1_m=c1[0]
c2_m=c2[1]
c3_m=c3[2]

for a_1 in range(c1_m+1):
    b_1=c1_m-a_1
    
    for a_2 in range(c2_m+1):
        b_2 = c2_m-a_2

        for a_3 in range(c3_m+1):
            b_3 = c3_m-a_3

            flg=0

            if c1[0]!=(a_1+b_1):
                flg+=1
            if c1[1]!=(a_1+b_2):
                flg+=1
            if c1[2]!=(a_1+b_3):
                flg+=1
            if c2[0]!=(a_2+b_1):
                flg+=1
            if c2[1]!=(a_2+b_2):
                flg+=1
            if c2[2]!=(a_2+b_3):
                flg+=1
            if c3[0]!=(a_3+b_1):
                flg+=1
            if c3[1]!=(a_3+b_2):
                flg+=1
            if c3[2]!=(a_3+b_3):
                flg+=1
            
            if flg==0:
                print('Yes')
                exit(0)

print('No')
            




Measured memory_bytes: 9268
//     . .. ... .... ..... be name khoda ..... .... ... .. .     \\

#include <bits/stdc++.h>
using namespace std;

inline int in() { int x; scanf("%d", &x); return x; }
const int N = 20002;

int a[N], b[N];

int main()
{
	int n = in();
	for(int i = 0; i < n; i++)
		a[i] = in();
	for(int i = 0; i < n; i++)
		b[i] = in();
	long long aSum = 0, bSum = 0;
	bool bad = false;
	for(int i = 0; i < n; i++)
	{
		if(a[i] < b[i])
			aSum += (b[i] - a[i])/2;
		else
			bSum += a[i] - b[i];
	}
	cout << (aSum >= bSum ? "Yes\n" : "No\n");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int a[N], b, c;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  b = min_element(a,a+N)-a;
  c = max_element(a,a+N)-a;
  cout << 2*N << endl;
  if (-a[b] > a[c]) {
    cout << b+1 << ' ' << N << endl << b+1 << ' ' << N << endl;
    for (int i = N-1; i; i--) {
      cout << i+1 << ' ' << i << endl << i+1 << ' ' << i << endl;
    }
  } else {
    cout << c+1 << " 1\n" << c+1 << " 1\n";
    for (int i = 1; i < N; i++) {
      cout << i << ' ' << i+1 << endl << i << ' ' << i+1 << endl;
    }
  }
}

Measured memory_bytes: 3636
package main

import (
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := readInt()
	type station struct{ c, s, f int }
	st := make([]station, n-1)
	for i := range st {
		c, s, f := readInt(), readInt(), readInt()
		st[i] = station{c, s, f}
	}

	var wr = bufio.NewWriter(os.Stdout)
	for i := range st {
		ans := 0
		for _, s := range st[i:] {
			if ans <= s.s {
				ans = s.s
			} else {
				d := (ans - s.s + s.f - 1) / s.f
				ans = d*s.f + s.s
			}
			ans += s.c
		}
		wr.WriteString(strconv.Itoa(ans) + "\n")
	}
	wr.WriteString(strconv.Itoa(0) + "\n")
	wr.Flush()
}


Measured memory_bytes: 640