akhauriyash/Code-Regression huggingface dataset:
//***Blessed are the curious for they shall have adventures********

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[21],b[21],c[21];
int main()
{
    ll n,s=0,p=-2;
    cin>>n;

    forn(i,n) cin>>a[i];
    forn(i,n) cin>>b[i];
    forn(i,n-1) cin>>c[i];
    s+=b[a[0]-1];
    p=a[0];
    for(ll i=1;i<n;i++){
        s+=b[a[i]-1];
        if(p==(a[i]-1))
        s+=c[p-1];
        p=a[i];
    }
    cout<<s;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
  int len,i;
  char m;

  while((m=getchar())!=EOF){

    if(isupper(m)){
        printf("%c",tolower(m));
      }
    else {
        printf("%c",toupper(m));
      }
  }
      
  return 0;
}

Measured memory_bytes: 908
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
    ll h, n; cin >> h >> n;
    rep(i, n) {
        int a; cin >> a;
        h -= a;
        if(h <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

P = sorted(P, key=lambda p: - p[0] - p[1])

ret = 0

for i, p in enumerate(P):
    if i % 2 == 0:
        ret += p[0]
    else:
        ret -= p[1]

print(ret)


Measured memory_bytes: 33064
using System;
using System.Collections.Generic;
using System.Text;

namespace AtCoder02
{
    class ABC112_A
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            if(n == 1)
            {
                Console.WriteLine("Hello World");
            }
            else
            {
                int x = int.Parse(Console.ReadLine());
                int y = int.Parse(Console.ReadLine());
                Console.WriteLine(x + y);
            }
        }
    }
}

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

using namespace std;

int FastPower(int a, int pow, int m) {
    int res = 1;

    while (pow > 0) {
        if (pow % 2 == 1) {
            res = (int)(((int64_t)res * a) % m);
        }
        a = (int)(((int64_t)a * a) % m);
        pow /= 2;
    }
    return res;
}

int Divide(int a, int b, int m) {
    // b^(-1) = b^(\pi(m) - 1) = b^(m - 2)

    int inv_b = FastPower(b, m - 2, m);
    int res = (int)(((int64_t)a * inv_b) % m);
    return res;
}

int main() {
#ifdef LOCAL
    freopen("atcoder/3/input.txt", "r", stdin);
#endif

    int h, w, a, b;
    cin >> h >> w >> a >> b;

    int m = (int)1e9 + 7;

    vector<int> facts(h + w + 1);
    facts[0] = 1;
    for (int i = 1; i < facts.size(); ++i) {
        facts[i] = ((int64_t)facts[i - 1] * i) % m;
    }

    int total_count = Divide(Divide(facts[h + w - 2], facts[h - 1], m), facts[w - 1], m);
//    cout << "init_count: " << total_count << "\n";

    int row = h - a;
    int col = b - 1;

    int prohibited_count = 0;

    while (row < h && col >= 0) {
        int current_left = Divide(Divide(facts[row + col], facts[row], m), facts[col], m);
        int current_right = Divide(Divide(facts[h - row + w - col - 2], facts[h - row - 1], m), facts[w - col - 1], m);
//        total_count = (int)(total_count - ((int64_t)current_left * current_right) % m) % m;
        prohibited_count = (int)((prohibited_count + (int64_t)current_left * current_right) % m);
        ++row;
        --col;
    }

    total_count = (int)(((int64_t)total_count + m - prohibited_count) % m);

//    cout << "prohibited_count: " << prohibited_count << "\n";
    cout << total_count << "\n";

    return 0;
}











Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b;
    cin >> a >> b;

    if(a < b){
        cout << "a < b" << endl;
    }
    else if(a == b){
        cout << "a == b" << endl;
    }
    else{
        cout << "a > b" << endl;       
    }
}


Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <numeric>

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

using namespace std;


int main(){
    int n;
    cin >> n;
    long ans = 0;
    for(int i=n-1; i>0; i--){
        ans += i;
    }

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

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

using namespace std;

using ll = long long;

const int N = 105, W = 1e9 + 5, V = 1e3 + 5, INF = 1e9 + 5;

ll dp[N][N * V];

int main(){
	ios_base::sync_with_stdio(0); cin.tie();
	int n, w;	cin >> n >> w;
	fill(dp[0], dp[0] + N * V, INF);
	dp[0][0] = 0; 
	for(int i = 1; i <= n; i++){
		int wi, vi;	cin >> wi >> vi;
		for(int j = 0; j < vi; j++)	dp[i][j] = dp[i - 1][j];
		for(int j = vi; j < N * V; j++) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - vi] + wi);
	}
	for(int i = N * V - 1; i >= 0; i--)	if(dp[n][i] <= w){
		cout << i << "\n";
		return 0;
	}
}


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


int main() {
    ll x; cin >> x;

    ll y = 100;
    int i = 0;
    while (true) {
        if (y >= x) {
            break;
        }
        y *= 1.01;
        i++;
    }
    cout << i << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int A, B, C, D; cin >> A >> B >> C >> D;
  
  cout << max(0, min(B,D)-max(A,C)) << endl; 
}

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

class Point {
   public:
    long double x, y;
    constexpr Point(long double x = 0, long double y = 0) : x(x), y(y) {}

    constexpr Point operator+(const Point p) { return Point(*this) += p; }
    constexpr Point operator-(const Point p) { return Point(*this) -= p; }
    constexpr Point operator*(const long double a) { return Point(*this) *= a; }
    constexpr Point operator/(const long double a) { return Point(*this) /= a; }
    constexpr Point &operator+=(const Point p) {
        x += p.x;
        y += p.y;
        return *this;
    }
    constexpr Point &operator-=(const Point p) {
        x -= p.x;
        y -= p.y;
        return *this;
    }
    constexpr Point &operator*=(const long double a) {
        x *= a;
        y *= a;
        return *this;
    }
    constexpr Point &operator/=(const long double a) {
        x /= a;
        y /= a;
        return *this;
    }

    constexpr Point e() { return Point(*this) / dist(); }
    constexpr long double dist(const Point &p = Point(0, 0)) { return hypot(x - p.x, y - p.y); }
    constexpr long double arg() { return atan2(x, y); }

    friend std::istream &operator>>(std::istream &in, Point &m) {
        long double a, b;
        in >> a >> b;
        m.x = a, m.y = b;
        return in;
    }
};

vector<Point> p;
vector<char> d;
int N;

double f(double t) {
    long double x0 = 1e18, x1 = -1e18, y0 = 1e18, y1 = -1e18;
    unordered_map<char, Point> mp;
    mp['L'] = Point(-1, 0);
    mp['R'] = Point(1, 0);
    mp['D'] = Point(0, -1);
    mp['U'] = Point(0, 1);
    for (int i = 0; i < N; i++) {
        Point pi;
        pi = p[i] + mp[d[i]] * t;
        x0 = min(x0, pi.x);
        x1 = max(x1, pi.x);
        y0 = min(y0, pi.y);
        y1 = max(y1, pi.y);
    }
    return (x1 - x0) * (y1 - y0);
}

double ternary_search(double l, double r) {
    double t1, t2;
    t1 = (r - l) / 3 + l;
    t2 = (r - l) / 3 * 2 + l;

    if (t2 - t1 < 1e-12) return t1;

    if (f(t1) <= f(t2))
        return ternary_search(l, t2);
    else
        return ternary_search(t1, r);
}

int main() {
    cin >> N;
    p.resize(N);
    d.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i] >> d[i];
    }
    double t = ternary_search(0, 1e10);
    cout << setprecision(12) << f(t) << endl;
    return 0;
}

Measured memory_bytes: 3456
n = input()
N = int(n)
A = input()
B = input()
C = input()

count = 0
for i in range(N):
    if A[i] == B[i] and A[i] != C[i]:
        count += 1
    elif B[i] == C[i] and B[i] != A[i]:
        count += 1
    elif C[i] == A[i] and C[i] != B[i]:
        count += 1
    elif B[i] != C[i] and B[i] != A[i]:
        if A[i] != C[i]:
            count += 2
    else:
        count += 0
print(str(count))



Measured memory_bytes: 3064
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const N = parseInt(args[0][0], 10)
	let ans = false

	for (let i = 1; i <= 9; i++) {
		for (let j = 1; j <= 9; j++) {
			if ((i * j) === N) ans = true
		}
	}

	if (ans) console.log('Yes')
	else console.log('No')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
a =  int(input())
b =  int(input())
c =  int(input())
d =  int(input())
e =  int(input())
k =  int(input())
f = 0
if abs(a-b) > k:
  f = 1
if abs(a-c) > k:
  f = 1
if abs(a-d) > k:
  f = 1
if abs(a-e) > k:
  f = 1
if abs(b-c) > k:
  f = 1
if abs(b-d) > k:
  f = 1
if abs(b-e) > k:
  f = 1
if abs(c-d) > k:
  f = 1
if abs(c-e) > k:
  f = 1
if abs(d-e) > k:
  f = 1


if f > 0:
  print(':(')
else:
  print('Yay!')

Measured memory_bytes: 3064
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  string a, b;
  cin >> a >> b;
  a += b;
  int N = stoi(a);
  for (int i = 1; i * i <= N; i++) {
    if (i * i == N) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int l[10],v[2];
	int sv,sl,i;
	double n;
	while(~scanf("%d",l)){
		sv=0;sl=l[0];
		for(i=1;i<=9;i++){
			scanf(",%d",l+i);
			sl+=l[i];
		}
		for(i=0;i<2;i++){
			scanf(",%d",v+i);
			sv+=v[i];
		}
		n=sl/(double)sv;
		n*=v[0];
		for(i=0;n>0;i++)n-=l[i];
		printf("%d\n",i);
	}
	return 0;
}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;


int main() {
    int n;
    ll z, w;
    cin >> n >> z >> w;
    vector<ll> cards(n);
    rep(i, n) cin >> cards[i];

    if (n == 1) {
        cout << abs(cards.back() - w) << endl;
        ret();
    }

    ll a1 = abs(cards.back() - w);
    ll a2 = abs(cards[n - 1] - cards[n - 2]);

    cout << max(a1, a2) << endl;

}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int i, j, k, n, q, c, x, y;
  scanf("%d%d", &n, &q);
  int u[n];
  for(i = 0; i < n; ++i) u[i] = i;
  for(i = 0; i < q; ++i) {
    scanf("%d%d%d", &c, &x, &y);
    if(c) {
      while(u[x] != x) x = u[x];
      while(u[y] != y) y = u[y];
      if(x == y) printf("1\n");
      else printf("0\n");
    } else {
      while(u[x] != x) x = u[x];
      while(u[y] != y) y = u[y];
      u[y] = x;
    }
  }
  return 0;
}


Measured memory_bytes: 2716
number=list(map(int,input().split()))
count_l=number[0]
count_t=number[1]
luggage=[int(input()) for i in range(count_l)]

min_P=max(max(luggage),sum(luggage)//count_t)
max_P=sum(luggage)
left=min_P
right=max_P

while left<right:
    mid=(left+right)//2
    count_track=1
    flag=1
    load=0
    for i in range(count_l):
        load+=luggage[i]
        if load>mid:
            count_track+=1
            load=luggage[i]

        if count_track>count_t:
            flag=0
            break

    if flag:
        right=mid

    else:
        left=mid+1

print(left)



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

using namespace std;

const int MAXN = 100010;
const int INF = 1000000010;

int n, t;

int v[MAXN];

int main()
{
	scanf("%d %d",&n,&t);

	for(int i = 1 ; i <= n ; i++)
		scanf("%d",&v[i]);

	int mn = INF;
	int profit = -INF;

	for(int i = 1 ; i <= n ; i++)
	{
		profit = max( profit , v[i] - mn );
		mn = min( mn , v[i] );
	}

	int ans = 0;

	mn = INF;

	for(int i = 1 ; i <= n ; i++)
	{
		int s = 0;

		if( v[i] - mn == profit )
		{
			s = 1;
			ans++;
		}

		mn = min( mn , v[i] ) + s;
	}

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

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = 10000000;
const long long INFL = (1LL<<50);
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}


int n,a,b;
vector<int>h;


bool ok(int m){
    vector<int> temp(h);
    ll c = 0;
    rep(i,n){
        temp[i]-=m*b;
        if(temp[i]>0){
            c+= temp[i]/(a-b);
            if(temp[i]%(a-b)!=0) c++;
        }
    }
    return c<=m;
}

int main() {
    cin>>n>>a>>b;
    h.resize(n);cin>>h;
    sort(all(h));
    
    int l=0;
    int r=h[n-1]/b +1;
    int m=r/2;
    while(l<r){
        m=(l+r)/2;
        if(ok(m)){
            r = m;
        }else{
            l=m+1;
        }
    }
    cout<<l<<endl;
    
    return 0;
}












Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#define MAX_N 101
#define MAX_W 10001
using namespace std;

int v[MAX_N], w[MAX_N];
int dp[MAX_N][MAX_W];

void solve(int N, int W) {
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= W; j++) {
      if (j - w[i] < 0) dp[i][j] = dp[i - 1][j];
      else dp[i][j] = max(dp[i - 1][j], dp[i][j - w[i]] + v[i]);
    }
  }
  cout << dp[N][W] << endl;
}

void init() {
  for (int  i = 0; i < MAX_N; i++) {
    for (int j = 0; j < MAX_W; j++)
      dp[i][j] = 0;
  }
}

int main() {
  int N, W;
  cin >> N >> W;
  init();

  for (int i = 1; i <= N; i++) {
    cin >> v[i] >> w[i];
  }

  solve(N, W);

  return 0;
}

Measured memory_bytes: 7032
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned long;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

    void Solve() {
        UL ans[26] = {};
        while (true) {
            string S; getline(cin, S);
            if (cin.eof()) break;
            for (char c : S) {
                if ('a' <= c && c <= 'z') ans[c - 'a']++;
                else if ('A' <= c && c <= 'Z') ans[c - 'A']++;
            }
        }
        rep(i, 26) {
            cout << char('a' + i) << " : " << ans[i] << endl;
        }
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}



Measured memory_bytes: 3152
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n,a,b; cin>>n>>a>>b;
  long long ans = 0;
  FOR(i, 1, n+1) {
    int temp = i, sum = 0;
    while (temp > 0) {
      sum += temp % 10;
      temp /= 10;
    }
    if (a <= sum && sum <= b) ans += i;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
// #define DEBUG

#include <bits/stdc++.h>
#define x first
#define y second
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define out(t, a) copy(all(a), ostream_iterator<t>(cout, " ")); cout << "\n";
#define int long long

using namespace std;

void set_program() {
	#ifdef DEBUG
		freopen ("test.in", "r", stdin);
		freopen ("test.out", "w", stdout);
		// freopen ("test.in", "w", stdout);
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pt;

const int ALF = 26;
const int LOGN = 20;
const int MOD = 998244353;
const int INF = 1e9;
const int MAXN = 1e5;

void solve() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector <int> p(a), q(b), r(c);
	for (int& i : p) {
		cin >> i;
	}
	for (int& i : q) {
		cin >> i;
	}
	for (int& i : r) {
		cin >> i;
	}
	sort(rall(p));
	sort(rall(q));
	sort(rall(r));
	multiset <int> s;
	for (int i = 0; i < x; ++i) {
		s.insert(p[i]);
	} 
	for (int i = 0; i < y; ++i) {
		s.insert(q[i]);
	}
	for (int i = 0; i < c; ++i) {
		if (*s.begin() < r[i]) {
			s.erase(s.begin());
			s.insert(r[i]);
		}
	}
	int ans = 0;
	for (int i : s) {
		ans += i;
	}
	cout << ans << "\n";
}

signed main() {
	set_program();
	int t;
	#ifdef DEBUG
		// cin >> t;
		t = 3;
	#else
		// cin >> t;
		t = 1;
	#endif
	for (int num_test = 1; num_test <= t; ++num_test) {
		solve();
		cout << "\n";
	}
 	return 0;
}

Measured memory_bytes: 11008
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <chrono>
#include <random>
#include <functional>
using namespace std;
typedef long long ll;

const ll OPEN = 0, CLOSE = 1;

signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }

    ll n, x, d;
    cin >> n >> x >> d;
    if (d == 0) {
        if (x != 0)
            cout << n + 1;
        else
            cout << 1;
        return 0;
    }
    if (d < 0) {
        x *= -1;
        d *= -1;
    }
    map<ll, vector<pair<ll, ll>>> a;
    ll minn = 0, maxx = 0;
    a[0].push_back({ 0, OPEN });
    a[0].push_back({ 0, CLOSE });
    for (ll k = 1; k <= n; ++k) {
        ll m = x * k % d;
        if (m < 0)
            m += d;
        long long j = (x * k - m) / d;
        minn += k - 1;
        maxx += n - k;
        a[m].push_back({ j + minn, OPEN });
        a[m].push_back({ j + maxx, CLOSE });
    }
    ll ans = 0;
    for (auto& p : a) {
        auto& v = p.second;
        sort(v.begin(), v.end());
        ll w = 0, prev;
        for (auto e : v)
            if (e.second == OPEN) {
                if (w == 0)
                    prev = e.first;
                ++w;
            }
            else if (e.second == CLOSE) {
                --w;
                if (w == 0)
                    ans += e.first - prev + 1;
            }
    }
    cout << ans;
    return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9
ll mod = 1e9+7;


int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> cnt(61, 0);
  REP(i, N){
    cin >> A[i];
    REP(j, 60){
      cnt[j] += (A[i] >> j) & 1;
    }
  }
  ll ans = 0;
  ll beki = 1;
  REP(j, 60){
    ll c = cnt[j] *(N-cnt[j]);
    c %= mod;
    ans += c * beki;
    ans %= mod;
    beki *= 2;
    beki %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main(){
	int N, M, C, B[20];
	cin >> N >> M >> C;
	for (int i = 0; i < M; i++){
		cin >> B[i];
	}

	int counter = 0;
	for (int i = 0; i < N; i++){
		int sum = 0;
		for (int j = 0; j < M; j++){
			int temp;
			cin >> temp;

			sum += B[j] * temp;
		}
		if(sum + C > 0){
			counter++;
		}
	}

	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int main() {
    int N;
    cin >> N;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    vector<ll> d(N - 1);
    for(int i = 0;i < N - 1;i++) {
        d.at(i) = vec.at(i + 1) - vec.at(i);
    }
    reverse(d.begin(),d.end());
    ll cnt = 3;
    ll as = 2;
    for(ll i = 3;i <= N - 1;i++) {
        cnt = cnt * i + as;
        cnt %= MOD;
        as = as * i % MOD;
    }
    ll a = 1;
    for(int i = 1;i <= N - 2;i++) {
        a = (a * i) % MOD;
    }
    ll b = N - 2;
    ll ret = 0;
    for(int i = 0;i < N - 1;i++) {
        ret += d.at(i) * cnt;
        ret %= MOD;
        if(cnt <= a) {
            cnt = (cnt + MOD) - a;
        }
        else {
            cnt -= a;
        }
        if(i == N - 2) {
            break;
        }
        a = (a * (b + 1)) % MOD * modinv(b,MOD) % MOD;
        b--;
    }
    cout << ret << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

char func(ll n){
  ll tmp = ((n%26) == 0 ? 25 : (n%26)-1);
  return (char)('a'+tmp);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  string ans;
  while(N > 0){
    ans.push_back(func(N));
    int tmp = N%26;
    N /= 26;
    if(tmp == 0) N--;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}

Measured memory_bytes: 3576
n = int(input())
a = list(map(int, input().split()))

a = sorted(a)

l = 0
r = n

while l < r:
    mid = (l+r)//2

    size = sum(a[:mid+1])
    ptr = mid+1
    ans = True

    while ptr < n:
        if 2*size >= a[ptr]:
            size += a[ptr]
            ptr += 1
        else:
            ans = False
            break

    if ans:
        r = mid
    else:
        l = mid+1

print(n-l)

Measured memory_bytes: 20392
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    int n = nextInt();
    int k = nextInt();
    int s = nextInt();


    for(int i=0;i<n;i++){
      if(i<k){ //i=0～(k-1)のk回表示する
        System.out.print((s)+" ");
      }
      else{
        int ans = 2*s;
        ans = ans%1000000000;
        ans ++;
        System.out.print(ans+" ");
      }
    }


    //System.out.println();

  }
  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 43508
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	int a,b;
	cin >> a >> b;
	if(a+b==15) cout << "+\n";
	else if(a*b==15) cout << "*\n";
	else cout << "x\n";
	return 0;
}

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

using ll = long long;
const ll INF = 1LL << 50;


 int main(void) {
 int N, M;
 cin >> N >> M;

 const int NMAX = 1000;
 const int MMAX = 2000;
 int a[MMAX], b[MMAX];
 ll c[MMAX];

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

 ll dist[NMAX];

 for (int i = 0; i < N; ++i) {
 dist[i] = INF;
 }

 dist[0] = 0;


for (int loop = 0; loop < N - 1; ++ loop) {
for (int i = 0; i < M; ++i) {

 if (dist[a[i] - 1] == INF) continue;

 if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
 dist[b[i] - 1] = dist[a[i] - 1] + c[i];
 }
 }
 }

 ll ans = dist[N - 1];


 bool negative[NMAX];

 for (int i = 0; i < N; ++i) {
 negative[i] = false;
 }

 for (int loop = 0; loop < N ; ++ loop) {
 for (int i = 0; i < M; ++i) {
 if (dist[a[i] - 1] == INF) continue;

 if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
 dist[b[i] - 1] = dist[a[i] - 1] + c[i];
 negative[b[i] - 1] = true;
 }

 if (negative[a[i] - 1] == true) {
 negative[b[i] - 1] = true;
 }
 }
 }


 if (negative[N - 1])
 cout << "inf" << endl;
 else
 cout << -ans << endl;

 return 0;
 }


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

int main() {
  int n;cin>>n;
  rep(i,26)rep(j,15){
    if(i*4+j*7==n){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int euclid(int a, int b);

int main(void) {
  int i, N, A[100010], min;
  scanf("%d", &N);
  for (i=0;i<N;i++) {
    scanf("%d", &A[i]);
  }
  min = A[0];
  for (i=1;i<N;i++) {
    if (min > A[i]) min = A[i];
  }
  for (i=0;i<N;i++) {
    A[i] = euclid(min,A[i]);
  }
  min = A[0];
  for (i=1;i<N;i++) {
    if (min > A[i]) min = A[i];
  }
  printf("%d\n", min);
  return 0;
}

int euclid(int a, int b) {
  int r;
  if (a>b) {
    while (b) {
      r = b;
      b = a%b;
      a = r;
    }
    return a;
  } else {
    while (a) {
      r = a;
      a = b%a;
      b = r;
    }
    return b;
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	ll a, b;
	cin >> a >> b;
	map<ll, ll> m;
	ll g = __gcd(a, b), p = g;
	repl(i, 2, sqrt(g) + 1) {
		while (p % i == 0) {
			m[i]++;
			p /= i;
		}
	}
	if (p != 1) m[p]++;
	cout << m.size() + 1 << endl;
	return 0;
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };



int main() {
	string s;
	cin >> s;
	int i;
	vi cnt(3, 0);
	for (i = 0; i < s.size(); i++) {
		cnt[s[i] - 'a']++;
	}
	sort(cnt.begin(), cnt.end());
	if (cnt[1] - cnt[0] <= 1 && cnt[2] - cnt[1] <= 1 && cnt[2] - cnt[0] <= 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int inf=1<<30;
const int maxn=200100;
int n,x,y,mx1=-inf,mx2=-inf,mn1=inf,mn2=inf,ans=-inf,sum[maxn]={},diff[maxn]={};
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&x,&y),sum[i]=x+y,diff[i]=x-y;
	for(int i=1;i<=n;i++)mx1=max(mx1,sum[i]),mx2=max(mx2,diff[i]),mn1=min(mn1,sum[i]),mn2=min(mn2,diff[i]),ans=max(ans,max(mx1-mn1,mx2-mn2));
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 5348
#include <bits/stdc++.h> 
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define per(i,n) for(long long i = (long long)(n-1);i >= 0;--i)
#define REP(i,s,t) for(long long i=s;i<t;i++)
#define PER(i,s,t) for(long long i=s;i>t;--i)
#define all(x) x.begin(),x.end()
#define sp(n) setprecision(n)
typedef long long ll;
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<ll> a(100000+10);
  rep(i,n){
    cin>>a[i];
  }
  ll x=1;
  bool ans=true;
  rep(i,n){
    if(a[i]==0){
      ans=false;
      x=0;
    }
  }
  if(ans){
    rep(i,n){
      if((1000000000000000000/x)<a[i]){
         x=-1;
         ans=false;
      }
    if(ans){
      x*=a[i];
    }
  }
  }
  cout<<x<<endl;
}

Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <map>
using namespace std;
 
void search(int node, vector<vector<pair<int,long>>> &path,vector<long> &route, vector<int> &s, vector<int> v){
    static int isSearch=1;
    vector<int> next;
    for(auto n : v){
        for(auto p : path[n]){
            if(s[p.first]==0){
                s[p.first]=1;
                isSearch++;
                next.push_back(p.first);
                route[p.first]=route[n]+p.second;
            }
        }
    }
    if(isSearch!=node){
        search(node,path,route,s,next);
    }
}
 
int main(void){
    int n,q,k;
    cin>>n;
    vector<vector<pair<int,long>>> path(n+1);
    vector<long> route(n+1,0);
    for(int i=0;i<n-1;i++){
        int a,b;
        long c;
        cin>>a>>b>>c;
        path[a].push_back(pair<int,long>(b,c));
        path[b].push_back(pair<int,long>(a,c));
    }
    //for(auto a:path){for(auto p:a)cout<<p.first<<",";cout<<endl;}
    cin>>q>>k;
    vector<int> s(n+1,0);
    s[k]=1;
    search(n,path,route,s,vector<int>(1,k));
    for(int i=0;i<q;i++){
        int a,b;
        cin>>a>>b;
        cout<<route[a]+route[b]<<endl;
    }
}

Measured memory_bytes: 33408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
const int N = 2e5+10;

int a[N], n;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cin >> n;
	for(int i=0;i<n;++i){
		cin >> a[i];
		a[i] -= i+1;
	}
	sort(a, a+n);
	ll ans = 0;
	int m = a[n/2];
	for(int i=0;i<n;++i) ans += abs(a[i] - m);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll a, b, c;
	cin >> a >> b >> c;
	if (a + b + c >= 22)cout << "bust\n";
	else cout << "win\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int N = 100000;
const int oo = 0x3f3f3f3f;
 
template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int n;
int st[N + 5], nxt[(N << 1) + 5], to[(N << 1) + 5], e = 1;

void addedge(int u, int v) {
    to[++ e] = v; nxt[e] = st[u]; st[u] = e;
    to[++ e] = u; nxt[e] = st[v]; st[v] = e;
}

int id[N + 5], ans;
bool vis[N + 5][30];

void dfs(int u, int f = 0) {
    id[u] = 1;

    for(int i = st[u]; i; i = nxt[i]) {
        int v = to[i];
        if(v == f) continue;

        dfs(v, u);

        for(int j = 1; j <= 25; ++j) if(vis[v][j]) {
            if(vis[u][j]) 
                chkmax(id[u], j + 1);
            else vis[u][j] = true;
        }
    }

    while(vis[u][id[u]]) ++ id[u];
    chkmax(ans, id[u]);

    vis[u][id[u]] = true;
    for(int i = 1; i < id[u]; ++i) vis[u][i] = false;
}

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif 

    scanf("%d", &n);
    for(int i = 1; i < n; ++i) {
        static int u, v;
        scanf("%d%d", &u, &v); addedge(u, v);
    }

    dfs(1);
    printf("%d\n", ans - 1);

    return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}


int main(){
  string s;
  cin>>s;
  int k[s.length()];
  int ans[s.length()];
  for(int i = 0; i < s.length(); i++){
    ans[i]=0;
  }
  for(int i = 0; i < s.length(); i++){
    if(s[i]=='R'){
      if(i!=0&&s[i-1]=='R'){
        k[i]=k[i-1]-1;
      }
      else{
        for(int j = i+1; j < s.length(); j++){
          if(s[j]=='L') {
            k[i]=j-i;
            break;
          }
        }
      }
      if(k[i]%2!=0){
        ans[k[i]+i-1]++;
      }
      else{
        ans[k[i]+i]++;
      }
    }
    if(s[i]=='L'){
      if(i!=0&&s[i-1]=='L'){
        k[i]=k[i-1]+1;
      }
      else{
        for(int j = i-1; ; j--){
          if(s[j]=='R') {
            k[i]=i-j;
            break;
          }
        }
      }
      if(k[i]%2!=0){
        ans[i-k[i]+1]++;
      }
      else{
        ans[i-k[i]]++;
      }
    }
  }
  for(int i = 0; i < s.length(); i++){
    cout<<ans[i]<<" ";
  }
  return 0;
}

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

int main(){
	string str[]={"lunch","dinner","midnight"};
int a;
while(scanf("%d",&a),a){
	int b[3][2]{};
	for(int c=0;c<a;c++){
		int d,e,f;
		scanf("%d%*c%d%d",&d,&e,&f);
		if(f<e)f+=60;
		if(f-e<9){
			if(d>=11&&d<=14){b[0][0]++;b[0][1]++;}
			else if(d>=18&&d<=20){b[1][0]++;b[1][1]++;}
			else if(d>=21||d<=1){b[2][0]++;b[2][1]++;}
		}
		else{
			if(d>=11&&d<=14){b[0][1]++;}
			else if(d>=18&&d<=20){b[1][1]++;}
			else if(d>=21||d<=1){b[2][1]++;}
		}
	}
    for(int q=0;q<3;q++){
    	cout<<str[q]<<" ";
    	if(b[q][1]){
    		printf("%d\n",b[q][0]*100/b[q][1]);
    	}
    	else{
    		puts("no guest");
    	}
    }
}
}

Measured memory_bytes: 3144
#include <iostream>
#include <cmath>
#include <set>
#include <string>

using namespace std;
using LLONG = long long;

int main()
{
    int N, A;
    cin >> N >> A;
    for (int i = 0; i <= A; ++i)
    {
        if ((N - i) % 500 == 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[100005],b[100005];
long long ans;
int main(){
    cin>>n;
    for(int i=0;i<n+1;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=n-1;i>=0;i--){
        if(a[i+1]>=b[i])a[i+1]-=b[i],ans+=b[i];
        else{
            ans+=a[i+1],b[i]-=a[i+1];
            if(a[i]>=b[i])a[i]-=b[i],ans+=b[i];
            else ans+=a[i],a[i]=0;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(input.readLine());
        int a = Integer.parseInt(tokenizer.nextToken()) + Integer.parseInt(tokenizer.nextToken());
        System.out.println(a%24);
    }
}


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

int main() {
    int n; cin >> n;
    vector<int> a(n, 0), b(n, 0);

    for(int i = 0; i < n; i += 1)
        cin >> a[i];
    
    priority_queue<pair<int, int>> pq;

    for(int i = 0; i < n; i += 1) {
        cin >> b[i];
        if(a[i] != b[i])
            pq.push(make_pair(b[i], i));
    }

    int64_t sum_a = accumulate(a.begin(), a.end(), 0LL);
    int64_t sum_b = accumulate(b.begin(), b.end(), 0LL);
    
    int64_t steps = 0;

    while(sum_b > sum_a) {
        auto maxx = pq.top();
        pq.pop();

        int where = maxx.second;
        int value = maxx.first;
        
        int left = b[(where - 1 + n) % n];
        int right = b[(where + 1) % n];
        
        int diff = left + right;
        int many = (value - max(a[where], max(left, right))) / diff;
        
        if(b[where] - 1LL * (many + 1) * diff >= a[where]) {
            many += 1;
        }

        b[where] -= many * diff;
        sum_b -= many * diff;
        steps += many;
            
        if(a[where] != b[where])
            pq.push(make_pair(b[where], where));

        if(many == 0)
            break;
    } 

    if(a != b) {
        cout << "-1\n";
    } else {
        cout << steps << "\n";
    }
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    
    int cnt = 0;
    for ( int i = 0; i < N; i++ ) {
        int minj = i;
        for ( int j = i; j < N; j++ ) {
            if (A[minj] > A[j]) {
                minj = j;
            }
        }
        if ( minj != i ) {
            int t = A[i];
            A[i] = A[minj];
            A[minj] = t;
            cnt++;
        }
    }

    for ( int i = 0; i < N; i++ ) {
        cout << (i==0 ? "" : " ") << A[i];
    }
    cout << '\n';
    cout << cnt << '\n';
    return 0;
}


Measured memory_bytes: 3072
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [s,c] <- getIntList
    let ans | c `div` 2 <= s = c `div` 2
            | otherwise = s + ((c-s*2) `div` 4)
    print ans

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

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W, N;
	cin >> H >> W >> N;
	vector< vector<int> > ans(H, vector<int>(W, 0));
	int h = 0, w = 0;
	for (int i = 1; i <= N; i++) {
		int a;
		cin >> a;
		for (int j = 0; j < a; j++) {
			ans[h][w] = i;
			if (h % 2 == 0) {
				if (w == W - 1) h++;
				else w++; 
			} else {
				if (w == 0) h++;
				else w--;
			}
		}
	}

	for (int i = 0; i < H; i++) {
		cout << ans[i][0];
		for (int j = 1; j < W; j++) {
			cout << " " << ans[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int l = s.length;
		long countB = 0;
		long ans = 0;
		for(int i = 0; i < l; i++) {
			if(s[i]=='W') {
				ans+=countB;
			}
			else {
				countB++;
			}
		}
		System.out.println(ans);
	 }
}

Measured memory_bytes: 26556
import sys

alphas = {alpha: 0 for alpha in "abcdefghijklmnopqrstuvwxyz"}

for char in sys.stdin.read().lower():
    if char not in alphas.keys():
        continue
    alphas[char] += 1
    
for alpha, val in alphas.items():
    print("{} : {}".format(alpha, val))


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

int main()
{
    int k, x;
    cin >> k >> x;

    if(k*500>=x){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


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

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(int i = a ; i < b ; ++i)

typedef long long ll ; 
typedef long double ld ; 
typedef pair<int,int> pii ; 
typedef pair<ll,ll> pll ;

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int MOD = 1e9+9 ;
const ll inf = 1e18 ;  
const ll mod = 1e9+7 ;  

ll nCr(ll n,ll r){ll t=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){t*=(n-i);t/=(i+1);}return t;}
ll power(ll a, ll n) { ll r=1;while(n){if(n&1)r=(r*a)%MOD;n>>=1;a=(a*a)%MOD;}return r%MOD;}
ll sq(int x) { ll ans = x*x ; return ans ; }
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
void read(vt<int> &a) {
	rep(i,0,a.size()) 
	cin >> a[i] ; 
}

// ==========Start Here==============

struct cmp{
	bool operator()(pii a, pii b) {
		return a.ff >= b.ff ; 
	}
};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
 	
 	int n , m ; 
 	cin >> n >> m ; 
 	vt<int> a(n) ; 
 	read(a) ; 
 	set< pii> s ; 
 	rep(i,0,n) {
 		s.insert({a[i],i+1}) ; 
 	}
 	//cout << s.size() << endl ;
 	while(m--) {
 		//cout << 1 << endl ;
 		pii tmp = *s.rbegin() ; 
 		s.erase(tmp) ; 
 		s.insert(mp(tmp.ff/2 , tmp.ss)) ; 
 	}
 	ll ans = 0 ; 
 	for(pii x : s) {
 		ans += x.ff ; 
 		//cout << ans << endl ;
 	}
 	cout << ans ; 


 	return 0 ; 
 	
}

Measured memory_bytes: 8312