akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>
#include<bitset>


using namespace std;

#define rep(i,n) for(int i=0;i<n;i++) //0から
#define REP(i,n) for(int j=i;j<n;j++) //iから

typedef long long ll;



//英字ならture、数字ならfalse
bool isalpha(char s){
    if(('A'<=s&&s<='Z')||('a'<=s&&s<='z')){
        return 1;
    }else{
        return 0;
    }
}
//全ての文字が英字ならture、数字ならfalse
bool Isalpha(string s){
    ll n;
    bool tmp = true;
    rep(i,n){
        if(isalpha(s[i])){
            tmp = false;
        }
    }
    return tmp;
}




using Graph = vector<vector<ll>>;



//cout<<fixed<<setprecision(10);

ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

#define MOD 1000000007

ll INFLL =  pow(10,9)+1;




string periodic_table[104] = {
    "None","H(1)","He(2)", //2
    "Li(3)","Be(4)","B(5)","C(6)","N(7)","O(8)","F(9)","Ne(10)", //10
    "Na(11)","Mg(12)","Al(13)","Si(14)","P(15)","S(16)","Cl(17)","Ar(18)", //18
    "K(19)","Ca(20)","Sc(21)","Ti(22)","V(23)","Cr(24)","Mn(25)","Fe(26)","Co(27)","Ni(28)","Cu(29)","Zn(30)","Ga(31)","Ge(32)","As(33)","Se(34)","Br(35)","Kr(36)", //36
    "Rb(37)","Sr(38)","Y(39)","Zr(40)","Nb(41)","Mo(42)","Tc(43)","Ru(44)","Rh(45)","Pd(46)","Ag(47)","Cd(48)","In(49)","Sn(50)","Sb(51)","Te(52)","I(53)","Xe(54)", //54
    "Cs(55)","Ba(56)","La(57)","Ce(58)","Pr(59)","Nd(60)","Pm(61)","Sm(62)","Eu(63)","Gd(64)","Tb(65)","Dy(66)","Ho(67)","Er(68)","Tm(69)","Yb(70)","Lu(71)","Hf(72)","Ta(73)","W(74)","Re(75)","Os(76)","Ir(77)","Pt(78)","Au(79)","Hg(80)","Tl(81)","Pb(82)","Bi(83)","Po(84)","At(85)","Rn(86)", //86
    "Fr(87)","Ra(88)","Ac(89)","Th(90)","Pa(91)","U(92)","Np(93)","Pu(94)","Am(95)","Cm(96)","Bk(97)","Cf(98)","Es(99)","Fm(100)","Md(101)","No(102)" //102
};

int main(){
    string s;
    cin>>s;
    int ans;
    if(s=="RRR"){
        ans = 3;
    }
    else if(s=="RRS"||s=="SRR"){
        ans=2;
    }
    else{
        ans=1;
    }
    if(s=="SSS"){
        ans=0;
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n,m;cin >> n >> m;
    int a[n];
    rep(i,n)cin >> a[i];
    sort(a,a+n);
    vector<int> s(n+1);
    rep(i,n)s[i+1] = s[i] + a[i];
    int bot = 0,top = 220000;
    while(top - bot > 1){
        int mid = (top + bot )/2;
        //mid:一回の握手の最小値
        int cnt = 0;
        rep(i,n){
            //i:migi
            int num = lower_bound(a,a+n,mid - a[i]) - a;
            cnt += n-num;
        }
        if(cnt >= m)bot = mid;
        else top = mid;

    }
    //bot:
    int tot = 0;
    int cnt = 0;
    
        
    rep(i,n){
        //i:migi
        int num = lower_bound(a,a+n,bot - a[i]) - a;
        tot += a[i]*(n-num);
        tot += s[n] - s[num];
        cnt += n- num;

    }

    
    tot -= bot*(cnt - m);
    cout <<tot << endl;
    
    return 0;
}

Measured memory_bytes: 4808
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    double dg;
    ll ig;
    bool answerd = false;
    for (ll i=1;i<3501;i++) {
        if (answerd) break;
        for (ll j=1;j<3501;j++) {
            dg = double(n*i*j) / double(4*i*j - n * (i+j));
            ig = ll(dg);
            if (dg==ig and ig>0) {
                cout << i << " ";
                cout << j << " ";
                cout << ig << endl;

                answerd = true;
                break;
            }
        }    
    }
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}
namespace IO{
    char nc(){ static char bf[100000],*p1=bf,*p2=bf; return p1==p2&&(p2=(p1=bf)+ fread(bf,1,100000,stdin),p1==p2)?EOF:*p1++; }
    int rd(){ int res=0; char c=getchar(); while(!isdigit(c))c=getchar(); while(isdigit(c))res=res*10+c-'0',c=getchar(); return res; }
}/*}}}*/
/******************heading******************/
const int N=2e5+5,M=1e6+6,P=998244353,X=1e6;

int n,maxa;
int c[M];

bool bp[M];
int pn[N],lp;
int mu[M],ans;

int pw(int a,int m,int p){
    int res=1;
    while(m)m&1?res=1ll*res*a%p:0,a=1ll*a*a%p,m>>=1;
    return res;
}
void sieve(int k){
    bp[0]=bp[1]=1,mu[1]=1;
    FOR(i,2,k){
        if(!bp[i])pn[++lp]=i,mu[i]=-1;
        FOR(j,1,lp){
            int pj=pn[j];
            if(i*pj>k)break;
            bp[i*pj]=1;
            if(i%pj==0){
                mu[i*pj]=0;
                break;
            }
            mu[i*pj]=-mu[i];
        }
    }
}
int F(int d){
    int lim=maxa/d;
    int s=0,ss=0;
    FOR(i,1,lim){
        int lj=c[i*d],x=i*d;
        FOR(j,1,lj){
            ss=(ss+1ll*s*x)%P;
            s=(s+x)%P;
        }
    }
    //if(ss)printf("F(%d)=%d\n",d,ss);
    return ss;
}
int f(int d){
    int res=0,lim=maxa/d;
    FOR(i,1,lim){
        res=(res+1ll*mu[i]*F(i*d))%P;
    }
    res=(res+P)%P;
    //if(res)printf("\033[32mf(%d)=%d\033[0m\n",d,res);
    return res;
}
void calc(int d){
    int fd=f(d);
    ans=(ans+1ll*fd*pw(d,P-2,P))%P;
}
int main(){
    scanf("%d",&n);
    sieve(X);
    FOR(i,1,n){
        int x;
        scanf("%d",&x);
        c[x]++;
        maxa=max(maxa,x);
    }
    FOR(d,1,maxa) calc(d);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 9856
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val n = readLine.trim.toInt
  val p = readLine.trim.split(' ').map(_.toInt)
  var min = Int.MaxValue
  for (r ← 0 to p.head){
    val arr = p.clone()
    var sum = r
    arr(0) -= r
    for (i ← arr.indices){
      if (arr(i) > 0){
        sum += arr(i)
        if (i + 1 < arr.length) {
          sum += arr(i)
          arr(i + 1) -= arr(i)
        }
      }
    }
    if (sum < min) min = sum
  }
  println(
    min
  )
  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
/*


 */


Measured memory_bytes: 44740
import java.util.*;
public class Main {
    public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            String w = sc.nextLine();
            
            boolean[] alphabets = new boolean[26];
            for(int i = 0;i<26;i++){
                alphabets[i] = true;
            }
            
            for(int i = 0;i<w.length();i++){
                alphabets[(int)w.charAt(i) - 97] = !alphabets[(int)w.charAt(i) - 97];
            }
            
            for(boolean evenChar : alphabets){
                if(!evenChar){
                    System.out.println("No");
                    System.exit(0);
                }
            }
            System.out.println("Yes");
            
    }
}

Measured memory_bytes: 8660
K=int(input())

N=[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]

print(N[K-1])

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

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

	vector<int>V;
	for (int i = 0; i < N; i++) V.push_back(L + i);

	sort(V.begin(), V.end());

	int ans = 0;

	auto result = find(V.begin(), V.end(), 0);
	
	if (result != V.end()) {
		for (int i = 0; i < N; i++) ans += V[i];
		cout << ans << endl;
		return 0;
	}
	else {
		int A = V.front();
		int B = V.back();

		if (abs(A) < abs(B)||abs(A)==abs(B)) {
			for (int i = 1; i < N; i++) ans += V[i];
			cout << ans << endl;
			return 0;
		}
		else if(abs(A) > abs(B)) {
			for (int i = 0; i < N - 1; i++) ans += V[i];
			cout << ans << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3636
import std.stdio;
import std.algorithm;
import std.string;
import std.functional;
import std.array;
import std.conv;
import std.math;
import std.typecons;
import std.regex;
import std.range;

void main(){

    while(true){
	auto temp = readln();
	if(stdin.eof()) break;
	auto s = split(temp).to!(int[]);
	writeln(s[0]-s[1]);
    }

}

Measured memory_bytes: 2500
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

struct Edge{
    ll to;
    ll cost;
    Edge(ll to, ll cost): to(to), cost(cost) {}
    Edge(){}
};

const int N_MAX = 100010;
vector<vector<Edge> > G;
bool visited[N_MAX];
ll x[N_MAX] = {};
bool is_consistent = true;

void print_x(){
    FOR(i, 0, 10){
        cout << x[i] << " ";
    }
    cout << endl;
}

// 矛盾チェック
void dfs(ll current, ll prev, ll position){
    
    visited[current] = true;
    x[current] = position;

    // cout << "dfs " << current << " " << prev << endl;
    // print_x();

    for(auto edge : G[current]){
        ll next_x = x[current] + edge.cost;
        if(visited[edge.to]){
            // 距離の整合性チェック
            if(x[edge.to]!=next_x){
                is_consistent = false;
            }
            continue;
        }else{
            dfs(edge.to, current, next_x);
        }
    }
    return;
}

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

    // input
    ll N, M;
    cin >> N >> M;

    FOR(i, 0, N_MAX){
        visited[i] = false;
        x[i] = 0;
    }

    G.resize(N+1);

    FOR(i, 0, M){
        ll l, r, d;
        cin >> l >> r >> d;
        
        G[l].push_back(Edge(r, d));
        G[r].push_back(Edge(l, -d));
    }

    FOR(i, 1, N+1){
        if(!visited[i]){
            dfs(i, -1, 0);
        }
    }

    if(is_consistent){
        p_yes();
    }else{
        p_no();
    }
    
    return 0;
}

Measured memory_bytes: 15616
input = gets.chomp.split(' ')
k = input[0].to_i
s = input[1].to_i

x = k + 1
y = k + 1

count = 0

x.times do |x_a|
  y.times do |y_a|
    z = s - x_a - y_a
    if 0 <= z && z <= k
      count += 1
    end
  end
end

p count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 998244353
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<ll> d(100000);
    int m = -1;

    ll ans = 1;

    rep(i,n){
        int tmp;
        cin >> tmp;

        d[tmp]++;

        m = max(m,tmp);

        if(i == 0){
            if(tmp != 0) ans = 0;
        }else{
            if(tmp == 0) ans = 0;
        }
    }

    

    for(int i = m - 1; i >= 1; i--){
        ll tmp = 1;

        rep(j,d[i + 1]){
            tmp = (tmp * d[i]) % MODN;
        }
        ans = (ans * tmp) % MODN;

        if(d[i] == 0) ans = 0;
    }

    cout << ans << endl;




    return 0;

}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

ll mod = 1000000007;

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

  int h, w, n;
  cin >> h >> w >> n;
  vector<int> a(n);
  vector<vector<int>> ans(h, vector<int>(w));
  rep(i, n) cin >> a[i];

  int posh = 0, posw = 0;
  bool inc = true;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < a[i]; j++) {  // i+1 で塗る
      ans[posh][posw] = i + 1;
      if (inc) {
        posw++;
        if (posw == w) {
          posh++;
          posw--;
          inc = false;
        }
      } else {
        posw--;
        if (posw < 0) {
          posh++;
          posw++;
          inc = true;
        }
      }
    }
  }

  rep(i, h) {
    rep(j, w) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <iterator>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd long long
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
using namespace std;
char a[300005];
ll mod=1e9+7;
ll modpow(ll a,ll n){
	ll res=1;
	while(n){
		if(n%2)res=(res*a)%mod;
		a=(a*a)%mod;
		n/=2;
	}
	return res;
}
int main(){
   
   ll n;
   cin>>n;
   ll ans=modpow(10,n);
   ans=(ans-modpow(9,n)+mod)%mod;
   ans=(ans-modpow(9,n)+mod)%mod;
   ans=(ans+modpow(8,n)+mod)%mod;
   cout<<ans;
   
}
    
   
   

  
   
 

Measured memory_bytes: 3632
#include <iostream>
#include <string.h>
using namespace std;

long long n, t = 0, m = 1, v = 0;
long long a[300];
long long dp[90001];
const long long M = 998244353;

int main()
{
	memset(dp, 0, sizeof(dp));

	cin >> n;

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

	dp[0] = 1;

	for (int i = 1; i <= n; i++) {
		for (int j = t; j >= 0; j--) {
			if (j < a[i - 1])
				dp[j] = dp[j] * 2 % M;
			else
				dp[j] = (dp[j] * 2 + dp[j - a[i - 1]]) % M;
		}
	}

	for (int i = 0; i < n; i++)
		(m *= 3) %= M;

	for (int i = (t + 1) / 2; i <= t; i++)
		((m += M) -= dp[i] * 3 % M) %= M;

	if (t % 2 == 0) {
		memset(dp, 0, sizeof(dp));
		dp[0] = 1;

		for (int i = 1; i <= n; i++) {
			for (int j = t; j >= 0; j--) {
				if (j < a[i - 1])
					dp[j] = dp[j];
				else
					dp[j] = (dp[j] + dp[j - a[i - 1]]) % M;
			}
		}

		(m += dp[t / 2] * 3) %= M;
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n, k;
    cin >> n >> k;
    
    vector<bool> snuke(n, false);

    for(int i = 0; i < k; i++) {
        int d;
        cin >> d;
        for(int j = 0; j < d; j++) {
            int A;
            cin >> A;
            snuke[A-1] = true;
        }
    }

    int res = 0;
    for(int i = 0; i < n; i++) {
        if (snuke[i] == false) res++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <complex>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
	ll n;
	cin >> n;
	for (int i = 0; i <= 25; i++) {
		if (n - i * 4 < 0)break;
		if ((n - i * 4) % 7 == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
  ll n;
  scanf("%lld", &n);
  vector<ll> x(n);
  for(int i=0; i<n; i++) scanf("%lld", &x[i]);
  
  ll m = n/2 - 1;
  vector<ll> o(n);
  for(int i=0; i<n; i++) o[i] = x[i];
  sort(o.begin(), o.end());

  for(int i=0; i<n; i++) {
    if(x[i] <= o[m]) {
      printf("%lld\n", o[m+1]);
    } else {
      printf("%lld\n", o[m]);
    }
  }

  return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}

class BIT{
private:
    //[1,n]
    vector<int> bit;
    int n;

public:
    BIT(){}
    BIT(int size){
        n = size;
        bit = vector<int>(n+2,0);
    }
    //[0,i)のsum（内部実装は[1,i]）
    int sum(int i){
        int s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int x){
        i++;
        while(i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }
    void show(){
        for(int i = 1; i <= n; i++){
            cout << " " << bit[i];
        }
        cout << endl;
    }
};

signed main(void) {
    int n,d,a;
    cin >> n >> d >> a;
    vp in(n);
    rep(i,n)cin >> in[i].first >> in[i].second;
    sort(all(in));
    vi x(n);
    rep(i,n)x[i] = in[i].first;
    BIT bit(n+1);//何回攻撃を受けたか？
    int ans = 0;
    rep(i,n){
        int left = in[i].second - bit.sum(i+1)*a;
        if(left <= 0)continue;
        int num = (left + a-1)/a;
        int ind = upper_bound(all(x), x[i] + 2*d) - x.begin()-1;
        bit.add(i,num);
        bit.add(ind+1,-num);
        ans += num;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6528
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

template<typename T>
T absi(T x) {
    if (x < static_cast<T>(0)) {
        x *= static_cast<T>(-1);
    }
    return x;
}

int main()
{
    int64_t x, y;
    std::cin >> x >> y;

    auto xx = absi(x);
    auto yy = absi(y);

    if (x < y) {
        if (0 <= x || y <= 0) {
            // 0 <= x < y, x < y <= 0
            std::cout << y - x << std::endl;
        }
        else {
            // x < 0 < y
            auto p = y - x;
            if (xx <= yy) {
                // 符号反転してから追いつくパターン
                p = std::min(p, yy - xx + 1);
            }
            if (xx >= yy) {
                // 同じ位置に到達してから反転するパターン
                p = std::min(p, xx - yy + 1);
            }
            std::cout << p << std::endl;
        }
    }
    else {
        // y < x
        if (0 <= y) {
            // 0 <= y < x  反転してそのまま+, 反転して足して反転, 
            auto p = xx + y + 1;
            auto p2 = 1 + absi(xx - yy) + 1;
            std::cout << std::min(p, p2) << std::endl;
        }
        else if (x <= 0) {
            // y < x <= 0 反転して足して反転, たして反転
            auto p = absi(xx - yy) + 2;
            auto p2 = yy + xx + 1;
            std::cout << std::min(p, p2) << std::endl;
        }
        else {
            // y < 0 < x 反転してそのままたす or 足して反転する
            auto p = absi(xx - yy) + 1;
            std::cout << p << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define endl "\n"
#define ciosup cin.tie(0);ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int main()
{
    ciosup;
    int n, k;
    cin >> n >> k;
    if (k > (n-1)*(n-2)/2){
        cout << -1 << endl;
    }else{
        vector<pint> vert;
        int now = (n - 1) * (n - 2) / 2 - k;
        REP(i, n - 1)
        {
            vert.eb(make_pair(1, i + 2));
        }
        int st = 2, en = 3;
        while(now > 0){
            vert.eb(make_pair(st, en));
            en++;
            if (en > n){
                st++;
                en = st + 1;
            }
            now--;
        }
        cout << vert.size() << endl;
        for (auto ite = vert.begin(); ite != vert.end(); ++ite)
        {
            cout << (*ite).FI << " " << (*ite).SE << endl;
        }
    }
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(a%b==0){
            a=b;
        }else{
            a=a%b;
        }
        cout<<a<<endl;
    }
    return 0;
}


Measured memory_bytes: 3100
def solve(h, w, c, a):
    n = 10
    dp = c.copy()
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
    ans = 0
    for i in range(h):
        for j in range(w):
            x = a[i][j]
            if x == -1:
                continue
            ans += dp[x][1]
    return ans

h, w = map(int, input().split())
c = [list(map(int, input().split())) for i in range(10)]
a = [list(map(int, input().split())) for i in range(h)]
print(solve(h, w, c, a))

Measured memory_bytes: 3444
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;
int main(void)
{
	int n,x;
	int a[100100];
	a[0]=0;
	long long s = 0;
	scanf("%d %d", &n, &x);
	for (int i = 1; i<=n; i++)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 1; i<=n; i++)
	{
		if (a[i]+a[i-1]>x)
		{
			int p = a[i]+a[i-1]-x;
			if (a[i]>=p)
			{
				s+=p;
				a[i]-=p;
			}
		}
	}
	printf("%lld\n", s);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 
   
int main(){
    int n=0;
    int w=0;
    int ss=0;
    int e=0;
    string s;
    cin >> s;
    int m=s.size();
    rep(i,m){
        if(s.at(i)=='N')n++;
        else if(s.at(i)=='W')w++;
        else if(s.at(i)=='S')ss++;
        else if(s.at(i)=='E')e++;
    }
    if((n>0 && ss==0)||(n==0 && ss>0)){
        cout << "No" << endl;
    }
    else if((w>0 && e==0)||(w==0 && e>0)){
        cout << "No" << endl;
    }
    else cout << "Yes" << endl;
} 

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

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

    vector<int> cnt(n + 1);
    for (int i = 1; i * i <= n; ++i) {
        for (int j = 1; j * j <= n; ++j) {
            for (int k = 1; k * k <= n; ++k) {
                int now = i * i + j * j + k * k + i * j + j * k + k * i;
                if (now <= n)
                    cnt[now]++;
            }
        }
    }
    rep(i, n) {
        cout << cnt[i + 1] << "\n";
    }

    return 0;
}

Measured memory_bytes: 3560
#include <stdio.h>

int parent(int);
int left(int);
int right(int);


int main(){
  int n,i,A[250],j;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  for(j=1;j<=n;j++){
    printf("node %d: ",j);
    printf("key = %d, ",A[j]);
    if(parent(j)>=1)
      printf("parent key = %d, ",A[parent(j)]);
    if(left(j)<=n)
      printf("left key = %d, ",A[left(j)]);
    if(right(j)<=n)
      printf("right key = %d, ",A[right(j)]);
    printf("\n");
  }
  return 0;
}
int parent(int j){
  return j/2;
}
int left (int j){
  return 2*j;
}
int right(int j){
  return 2*j+1;
}
	     
      



Measured memory_bytes: 2052
#include<algorithm>
#include<bits/allocator.h>
#include<bits/basic_ios.h>
#include<bits/basic_string.h>
#include<bits/basic_string.tcc>
#include<bits/c++config.h>
#include<bits/char_traits.h>
#include<bits/cpp_type_traits.h>
#include<bits/cxxabi_forced.h>
#include<bits/ios_base.h>
#include<bits/locale_classes.h>
#include<bits/localefwd.h>
#include<bits/ostream_insert.h>
#include<bits/postypes.h>
#include<bits/range_access.h>
#include<bits/stl_algobase.h>
#include<bits/stl_function.h>
#include<bits/stl_iterator.h>
#include<bits/stl_iterator_base_funcs.h>
#include<bits/stl_iterator_base_types.h>
#include<bits/stringfwd.h>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwchar>
#include<cwctype>
#include<debug/debug.h>
#include<deque>
#include<exception>
#include<ext/atomicity.h>
#include<ext/numeric_traits.h>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<math.h>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
int main()
{
	long long n,m,ans=0;
	cin>>n>>m;
	for (int i=m+1;i<=n;i++)
		for (int j=0;i*j+m<=n;j++)
			ans+=min(i-m,n-(i*j+m)+1);
	if (m==0) ans-=n;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int N = in.nextInt();
		LinkedList<Long[]> list = new LinkedList<>();
		for (int i = 0; i < N; i++) {
			long A = in.nextLong();
			long B = in.nextLong();
			list.add(new Long[] {A, B, 0L});
		}
		LinkedList<Long[]>list2 = new LinkedList<>(list);
		list.sort((a, b)->{
			int compare = Long.compare( (b[1] + b[0]), (a[1] + a[0]));
			if (compare != 0) {
				return compare;
			}
			return Long.compare(b[1], a[1]);
		});
		list2.sort((a, b)->{
			int compare = Long.compare( (b[1] + b[0]), (a[1] + a[0]));
			if (compare != 0) {
				return compare;
			}
			return Long.compare(b[0], a[0]);
		});

		long happy = 0;
		while (!list.isEmpty()) {
			Long[] ls = list.pollFirst();
			while (ls != null && ls[2] != 0) {
				ls = list.pollFirst();
			}
			if (ls == null) {
				break;
			}
			happy += ls[0];
			ls[2] = 1L;

			ls = list2.pollFirst();
			while (ls != null && ls[2] != 0) {
				ls = list.pollFirst();
			}
			if (ls == null) {
				break;
			}
			happy -= ls[1];
			ls[2] = 1L;
		}
		System.out.println(happy);
	}
}


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

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  vector<ll> c(1, a[0]);
  for (int i = 1; i < n; i++) {
    c.emplace_back(a[i]);
    c.emplace_back(a[i]);
  }
  ll ans = 0;
  rep(i, n - 1) {
    ans += c[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 8216
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int n,y;
	cin>>n>>y;
	rep(i,n+1)rep(j,n+1)if(i+j<=n){
	    if(i*10000+j*5000+(n-i-j)*1000==y){
	        cout<<i<<" "<<j<<" "<<n-i-j;
	        return 0;
	    }
	}
	cout<<"-1 -1 -1";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int D;
  cin>>D;
  vector<int> c(26);
  for(int &i:c)
    cin>>i;
  vector<vector<int>> s(D,vector<int>(26));
  for(vector<int> &v:s)
    for(int &i:v)
      cin>>i;
  vector<int> t(D);
  vector<int> A(26,0);
  int mzint=0;
  for(int i=0;i<D;i++){
    int mzi=mzint,mzin=0,k;
    for(int j=0;j<26;j++)
      mzi-=(i+1-A[j])*c[j];
    for(int j=0;j<26;j++){
      int l=mzi+s[i][j]-(i+1-A[j])*c[j];
      if(l>mzin){
        k=j;
        mzin=l;
      }
    }
    A[k]=i+1;
    mzint=mzin;
    t[i]=k+1;
  }
  int M=7500000,ans=mzint;
  while(M--){
    vector<pair<int,int>> AAA={make_pair(rand()%D,rand()%26),make_pair(rand()%D,rand()%26)};
    vector<int> BBB={t[AAA[0].first],t[AAA[1].first]};
    int ans2=ans;
    for(int aaa=0;aaa<2;aaa++){
    int d=AAA[aaa].first,q=AAA[aaa].second;
    ans+=s[d][q]-s[d][t[d]-1];
    int mae=-1,ato=D;
    for(int i=d-1;i>=0;i--){
      if(t[i]==t[d]){
        mae=i;
        break;
      }
    }
    for(int i=d+1;i<D;i++){
      if(t[i]==t[d]){
        ato=i;
        break;
      }
    }
    ans-=(ato-d)*(d-mae)*c[t[d]-1];
    mae=-1,ato=D;
    for(int i=d;i>=0;i--){
      if(t[i]==q+1){
        mae=i;
        break;
      }
    }
    for(int i=d;i<D;i++){
      if(t[i]==q+1){
        ato=i;
        break;
      }
    }
    ans+=(ato-d)*(d-mae)*c[q];
    t[d]=q+1;
    }
    if(ans2>ans){
      ans=ans2;
      t[AAA[0].first]=BBB[0];
      t[AAA[1].first]=BBB[1];
    }
  }
  for(int i:t)
    cout<<i<<endl;
}

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


int main() {
  int N, A, B; cin >> N >> A >> B;
  int sum;
  int ans = 0;

  for(int i=1; i<=N; i++){
    sum=0;
    if(i<10){
      sum=i;
    }
    else if(i<100){
      sum+=i%10;
      sum+=i/10%10;
    }
    else if(i<1000){
      sum+=i%10;
      sum+=i/10%10;
      sum+=i/100%10;
    }
    else if(i<10000){
      sum+=i%10;
      sum+=i/10%10;
      sum+=i/100%10;
      sum+=i/1000%10;
    }
    else{
      sum+=i%10;
      sum+=i/10%10;
      sum+=i/100%10;
      sum+=i/1000%10;
      sum+=i/10000%10;
    }
    if(sum>=A&&sum<=B) ans+=i;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import math
for _ in range(int(input())):
    x1,y1,x2,y2,x3,y3=map(float,input().split())
    a,b,c=2*(x2-x1),2*(y2-y1),x1**2-x2**2+y1**2-y2**2
    aa,bb,cc=2*(x3-x1),2*(y3-y1),x1**2-x3**2+y1**2-y3**2
    x,y=(b*cc-bb*c)/(a*bb-aa*b),(c*aa-cc*a)/(a*bb-aa*b)
    print('%.3f %.3f %.3f'%(x,y,math.hypot(x1-x,y1-y)))


Measured memory_bytes: 5680
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
    string s; cin >> s;
    int x, y; cin >> x >> y;
    int n = s.size();
    x += n;
    y += n;
    vector<int> xv, yv;
    bool mode_x = true;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'F') {
            cnt++;
        }
        else {
            if (mode_x) {
                xv.push_back(cnt);
            }
            else {
                yv.push_back(cnt);
            }
            mode_x ^= true;
            cnt = 0;
        }
    }
    if (mode_x) {
        xv.push_back(cnt);
    }
    else {
        yv.push_back(cnt);
    }
    vector<vector<bool>> dpx(xv.size() + 1, vector<bool>(2 * n + 1, false)), dpy(yv.size() + 1, vector<bool>(2 * n + 1, false));
    dpx[1][xv[0] + n] = true;
    dpy[0][n] = true;
    for (int i = 1; i < xv.size(); i++) {
        for (int j = 0; j < 2 * n + 1; j++) {
            if (j + xv[i] <= 2 * n) dpx[i + 1][j + xv[i]] = dpx[i + 1][j + xv[i]] | dpx[i][j];
            if (j - xv[i] >= 0) dpx[i + 1][j - xv[i]] = dpx[i + 1][j - xv[i]] | dpx[i][j];
        }
    }
    for (int i = 0; i < yv.size(); i++) {
        for (int j = 0; j < 2 * n + 1; j++) {
            if (j + yv[i] <= 2 * n) dpy[i + 1][j + yv[i]] = dpy[i + 1][j + yv[i]] | dpy[i][j];
            if (j - yv[i] >= 0) dpy[i + 1][j - yv[i]] = dpy[i + 1][j - yv[i]] | dpy[i][j];
        }
    }
    if (dpx[xv.size()][x] && dpy[yv.size()][y]) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 16128
def main():
    S = input()

    ans = 0
    if S == 'RRR':
        ans = 3
    elif 'RR' in S:
        ans = 2
    elif 'R' in S:
        ans = 1
    else:
        ans = 0
    print(f'{ans}')


if __name__ == '__main__':
    main()

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

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

  // count W numbers or R numbers
  int Wnum = 0;
  int Rnum = 0;
  for (int i = 0; i < n; i++) {
    if (c[i] == 'W') {
      Wnum++;
    } else {
      Rnum++;
    }
  }

  int count = 0;
  for (int i = 0; i < Rnum; i++) {
    if (c[i] == 'W') {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#include <random>
#include <atcoder/all>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
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; }
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };
typedef pair<lint, char> pa;

using namespace atcoder;
lint N, Q, arr[500000];
lint q, u, v;
int main() {
	cin >> N >> Q;
	fenwick_tree<lint> tree(N);
	REP(i, N) {
		cin >> v;
		tree.add(i, v);
	}
	REP(i, Q) {
		cin >> q >> u >> v;
		if (q == 0) tree.add(u, v);
		else cout << tree.sum(u, v) << endk;
	}
}

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

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

    if(c == "a" || c == "e" || c == "i" || c == "o" || c == "u"){
        cout << "vowel" << endl;
    }
    else{
        cout << "consonant" << endl;
    }
}

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


int main(){
  int s[2]; REP(i,2){cin >> s[i];}
  int t[2]; REP(i,2){cin >> t[i];}
  int w = t[0]-s[0];
  int h = t[1]-s[1];
  
  //1周目
  REP(i,h){printf("U");}
  REP(i,w){printf("R");}
  REP(i,h){printf("D");}
  REP(i,w){printf("L");}
  //2週目
  printf("L");
  REP(i,h+1){printf("U");}
  REP(i,w+1){printf("R");}
  printf("D");
  printf("R");
  REP(i,h+1){printf("D");}
  REP(i,w+1){printf("L");}
  printf("U\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    vector<pair<ll,int>>jewels(n);
    vector<ll>colors[k+1];
    for (int i = 0; i < n; i++) {
        long long c, v;
        cin >> c >> v;
        colors[c].push_back(v * 2);
    }

    multiset<long long> top_one;
    multiset<long long> top_two;
    multiset<long long> top_three;
    for (int color = 1; color <= k; color++) {
        sort(colors[color].begin(), colors[color].end(), greater<long long>());
        int nc = colors[color].size();
        top_two.emplace(colors[color][0] + colors[color][1]);
        if (nc > 2) {
            top_three.emplace(colors[color][0] + colors[color][1] + colors[color][2]);
        }
        long long avg = (colors[color][0] + colors[color][1]) / 2;
        jewels.emplace_back(avg, color);
        jewels.emplace_back(avg, color);
        for (int i = 2; i < nc; i++) {
            jewels.emplace_back(colors[color][i], color);
        }
    }

    sort(jewels.begin(), jewels.end(), greater<pair<long long, int>>());


    long long sum = 0;
    vector<int> cnts(k + 1, 0);
    long long min_pair = 1LL<<60;
    long long min_one = 1LL<<60;
    for (int i = 0; i < n; i++) {
        long long color = jewels[i].second;
        long long value = jewels[i].first;
        long long ans = -2;
        if (cnts[color] == 0) {
            if (!top_one.empty()) {
                ans = max(ans, sum + *top_one.rbegin());
            }

            if (!top_two.empty()) {
                ans = max(ans, sum - min_one + *top_two.rbegin());
            }

            if (!top_three.empty()) {
                ans = max(ans, sum - min_pair + *top_three.rbegin());
            }


            // erase from top two and three
            top_two.erase(top_two.find(colors[color][0] + colors[color][1]));
            if (colors[color].size() > 2) {
                top_three.erase(top_three.find(colors[color][0] + colors[color][1] + colors[color][2]));
            }
        }
        else {
            ans = sum + value;
            if (cnts[color] == 1) {

                for (int i = 2; i < colors[color].size(); i++) {
                    top_one.emplace(colors[color][i]);
                }
                min_pair = min(min_pair, colors[color][0] + colors[color][1]);
            }
            else {
                top_one.erase(top_one.find(value));
                min_one = min(min_one, value);
            }
        }
        cnts[color]++;
        sum += value;
        cout << ans / 2 << endl;
    }
}


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

public class Main {

    public static void main(String[] args) throws Exception {
        String line = readLine();
        StringTokenizer st = new StringTokenizer(line, " ");
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int x = Integer.parseInt(st.nextToken());
        int sum = a + b;
        if (x > sum) {
            System.out.println("NO");
            return;
        }
        if (x < a) {
            System.out.println("NO");
            return;
        }
        System.out.println("YES");
        return;
    }

    private static String readLine() throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        return br.readLine();
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  double ans = 0;
  for (int i = 1; i <= n; i++) {
    int tmp = i, cnt = 0;
    while (tmp < k) {
      tmp *= 2;
      cnt++;
    }
    ans += 1 / (double) n * (double) pow(0.5, cnt);
  }
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
typedef pair<LL, LL> P;
typedef pair<P, P> PP;

int main() {
	string s;
	cin >> s;
	if (s[0] == s[1]&& s[1]== s[2]) {
		cout << "Yes" << endl;
		return 0;
	}
	if (s[1] == s[2]&&s[2] == s[3]) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  double a,b,c,d,e,f,x,y;
  int i,j;
  while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f) != EOF)
    {
      x=(c*e-b*f)/(a*e-b*d);
      y=(a*f-c*d)/(a*e-b*d);
      i=x*1000;
      j=y*1000;
      x=(double)i/1000;
      y=(double)j/1000;
      printf("%.3f %.3f\n",x,y);
    }
  return 0;
}

Measured memory_bytes: 652
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;

struct Stu
{
	int pos;
	int val;
};

Stu a[100010];

bool compare(const Stu &a, const Stu &b)
{
	return a.val < b.val;
}

int main()
{
	scanf("%d", &n);
	
	for (int i = 0 ; i < n ; i++)
	{
		a[i].pos = i + 1;
		scanf("%d", &(a[i].val));
	}
	
	sort(a, a + n, compare);
		
	printf("%d", a[0].pos);
	for (int i = 1 ; i < n ; i++)
		printf(" %d", a[i].pos);
	printf("\n");
	
	return 0;
}


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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

int edge_color[100000];

vector<pair<int, int>> nodes[100000];

void dfs(int p, int s, int avoid){
    int color = 1;
    rep(i, nodes[s].size()){
        int e_num = nodes[s][i].first;
        int to = nodes[s][i].second;
        if(to == p) continue;
        if(color == avoid) color++;
        edge_color[e_num] = color;
        dfs(s, to, color);
        color++;
    }
}

int main(void){
    int N; cin >> N;
    rep(i, N-1){
        int a, b; cin >> a >> b;
        nodes[a-1].push_back(make_pair(i, b-1));
        nodes[b-1].push_back(make_pair(i, a-1));
    }
    int has_max_child = 0;
    rep(i, N){
        if(nodes[has_max_child].size() < nodes[i].size()) has_max_child = i;
    }
    dfs(-1, has_max_child, -1);
    cout << nodes[has_max_child].size() << endl;
    rep(i, N-1){
        cout << edge_color[i] << endl;
    }
}

Measured memory_bytes: 9344
#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;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(All(A));
    ll l = -LINF, r = LINF;
    while(r - l > 1) {
        ll mid = (l + r) / 2;
        ll s = 0, t = 0;
        for(int i = 0; i < N; i++) {
            if(A[i] > 0) {
                int ll = -1, rr = N;
                while(rr - ll > 1) {
                    int m = (ll + rr) / 2;
                    if(A[i] * A[m] <= mid) {
                        ll = m;
                    } else {
                        rr = m;
                    }
                }
                s += rr;
            } else if(A[i] < 0) {
                int ll = -1, rr = N;
                while(rr - ll > 1) {
                    int m = (ll + rr) / 2;
                    if(A[i] * A[m] <= mid) {
                        rr = m;
                    } else {
                        ll = m;
                    }
                }
                s += N - rr;
            } else {
                if(mid >= 0)
                    s += N;
            }
            if(A[i] * A[i] <= mid)
                s--;
        }
        ll k = s / 2;
        if(k >= K) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 4836
#include<iostream>
using namespace std;
int main()
{
	int W;
	while(cin>>W)
	{
		bool flag=0;
		for(int i=1;i<=W;i*=2)
		{
			if(W/i%2>0)
			{
				if(flag)
				{
					cout<<' ';
				}
				cout<<i;
				flag=1;
				W-=i;
			}
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3060