akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<pll, ll> > 
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define all(v)  (v).begin(), (v).end()
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
// #define MOD 998244353
#define endl "\n"
#define INF (ll)1e18
#define s(v) (ll)v.size()
#define e(v) v.empty()
#define bscount(x) __builtin_popcountll(x)
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
// using namespace __gnu_pbds;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);} 
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        ll n, k;
        cin>>n>>k;
        vl vec(n);
        rep(i, n)   cin>>vec[i];
        sort(all(vec));
        ll sum =0 ;
        rep(i, k)   sum += vec[i];
        cout<<sum;
    }
}

Measured memory_bytes: 3660
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------
int n,m;
vector<int>graph[100001];
int dp[100005];
bool V[100001];
int indeg[100001];
vector<int>out;
void bfs(int s){
    queue<int>q;
    q.push(s);
    V[s]=1;
    while(!q.empty()){
        int u=q.front();q.pop();
        out.pb(u);
        for(int i=0;i<graph[u].size();i++){
            int v=graph[u][i];
            indeg[v]--;
            if(indeg[v]==0&&!V[v]){
                V[v]=1;
                q.push(v);
            }
        }
    }
}
void tsort(){
    for(int i=0;i<n;i++){
        indeg[i]=0;
        
    }
    for(int u=0;u<n;u++){
        for(int i=0;i<graph[u].size();i++){
            int v=graph[u][i];
            indeg[v]++;
        }
    }
    for(int u=0;u<n;u++){
        if(indeg[u]==0&&!V[u]){
            bfs(u);
        }
    }
}
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    cin>>n>>m;
    memset(dp,0,sizeof(dp));
    int ans=0;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--;y--;
        graph[x].pb(y);
    }
    tsort();
    for(auto it=out.begin();it!=out.end();it++){
        for(int j=0;j<siz(graph[*it]);j++){
            chmax(dp[graph[*it][j]],dp[*it]+1);
        }
    }
    for(int i=0;i<n;i++){
        chmax(ans,dp[i]);
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------



Measured memory_bytes: 7292
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define mod 1000000007
 
string solve() {
	int n; cin >> n;
	string s,y="Yes",no="No";
	cin >> s;
	if(n&1) {
		return no;
	}
	string ans="",res="";
	for(int i = 0;i<n/2;++i) res+=s[i];
	for(int i=n/2;i<n;++i) ans +=s[i];
 
	return (ans==res ? y: no);
}
 
 
int main() {
	ios_base::sync_with_stdio(false);
 
	cout << solve() << "\n";
 
	return 0;
} 

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int INF = INT_MAX;

int main(){
    int n, a, ki=0;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a;
        if(a%2==1) ki++;
    }
    if(ki%2==0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String o;
        String x=sc.next();
        String y=sc.next();
        if(y.length()-1==x.length()&&y.substring(0,y.length()-1).equals(x))o="Yes";
      	else o="No";
      	System.out.println(o);
    }
    
}

Measured memory_bytes: 35504
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;

typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    cin >> s;

    if(s.back()=='s')
        cout << s + "es";
    else
        cout << s + "s";
    return 0;
}


Measured memory_bytes: 3660
#include<iostream>
     
    int main(){
    	int a, b;
    	std::cin >> a >> b;
     
    	if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)std::cout << "Possible" << std::endl;
    	else std::cout << "Impossible" << std::endl; 
    }

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;
static const long long mod = 1000000007;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
 
  ll n;
  cin >> n;

  vll as(n);
  map<ll, ll> imai;
  rep(i, n){
    cin >> as[i];
    imai[i - as[i]]++;
  }

  ll ans = 0;
  rep(i, n){
    imai[i - as[i]]--;
    ans += imai[i + as[i]];
  }

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


Measured memory_bytes: 27408
#include<iostream>
#include<algorithm>
#include<memory.h>
#include<string> 
#include<vector>
#include<map>
using namespace std;
typedef long long ll;

int main()
{
	string s;cin>>s;
	ll x=0;
	for(int i=0;i<s.size();i++) x+=(s[i]-'0');
	if(x%9) cout<<"No";
	else cout<<"Yes"; 
	return 0;	
} 

Measured memory_bytes: 3256
#include <iostream>
using namespace std;
int main(){
	int b1, b2, b3;
	cin >> b1 >> b2 >> b3;
	if(b1 == 1 && b2 == 0 && b3 == 0){
		cout << "Close" << endl;
	}
	else if(b1 == 0 && b2 == 1 && b3 == 0){
		cout << "Close" << endl;
	}
	else if(b1 == 1 && b2 == 1 && b3 == 0){
		cout << "Open" << endl;
	}
	else if(b1 == 0 && b2 == 0 && b3 == 1){
		cout << "Open" << endl;
	}
	else if(b1 == 0 && b2 == 0 && b3 == 0){
		cout << "Close" << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
N = int(input())
A = list(map(int, input().split()))
abss = [abs(A[i]) for i in range(N)]
minus = [A[i] for i in range(N) if A[i] < 0]
if len(minus) % 2 == 0:
    ans = sum([abs(A[i]) for i in range(N)])
    print(ans)
else:
    abss.sort()
    ans = -abss[0] + sum(abss[1:])
    print(ans)
    

Measured memory_bytes: 95704
n, a, b = map(int, input().split())
sum = 0
for i in range(n+1):
    i_str = list(str(i))
    # print(i_str)
    num_sum = 0
    for num_str in i_str:
        num_sum += int(num_str)
    if num_sum >= a and num_sum <= b:
        sum += i
print(sum)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976

#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976
#define MAX_N 100010

int main(){
	lint a,b,k;cin>>a>>b>>k;
	if(b-a+1>2*k){
		rep(i,k)cout<<a+i<<endl;
		rep(i,k)cout<<b-k+i+1<<endl;
	} else{
		rep(i,b-a+1)cout<<a+i<<endl;
	}
}

//sub-EOF


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

int N, Q;

struct SegmentTree {
private:
    int n;
    vector<int> node;
public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1;
        // 2の累乗の大きさにする
        while (n < sz) n *= 2;
        // 余りを0で埋める
        node.resize(2*n-1, 0);
        // 葉を構築
        for (int i = 0; i < sz; i++) {
            node[i+n-1] = v[i];
        }
        // 親を構築
        for (int i = n - 2; i >= 0; i--) {
            node[i] = node[2*i+1] + node[2*i+2];
        }
    }

    void add(int x, int val) {
        x += (n - 1);
        node[x] += val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = node[2*x+1] + node[2*x+2];
        }
    }

    int getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return node[k];
        int vl = getsum(a, b, 2*k+1, l, (l+r) / 2);
        int vr = getsum(a, b, 2*k+2, (l+r) / 2, r);
        return vl + vr;
    }
};

int main() {
    cin >> N >> Q;
    SegmentTree seg( vector<int>(N, 0) );
    for (int i = 0; i < Q; i++) {
        int c, x, y; cin >> c >> x >> y;
        if (c == 0) seg.add(x-1, y);
        else cout << seg.getsum(x-1, y) << endl;
    }
}


Measured memory_bytes: 4136
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define mt make_tuple
#define pb push_back
const int N = 3010;
double dp[N][N],p[N];

int main(){
    int n;
    double ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)   cin>>p[i];
    for(int i=0;i<=n;i++)   dp[0][i] = 0;
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(j==0)    dp[i][j] = dp[i-1][j]*(1-p[i]);
            else    dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*(p[i]); 
        }
    }
    for(int i=(n/2)+1;i<=n;i++) ans += dp[n][i];
    cout.precision(12);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 70784
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c,e,f;
    while(~scanf("%d%d",&a,&b))
    {
        if(a==0&&b==0)
        {
           printf("0\n");
        }
        else
        {
        c=a+b;
        e=a-b;
        f=a*b;
        if(c>=e&&c>=f)
        {
            printf("%d\n",c);
        }
        else if(e>=c&&e>=f)
        {
            printf("%d\n",e);
        }
        else if(f>=c&&f>=e)
        {
            printf("%d\n",f);
        }
        }
    }

}

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main(){
    int st,e;
    string s;
    cin>>s;
    int l=s.length();
    for(int i=0;i<l;i++)
    {
        if(s[i]=='A')
        {
            st=i+1;
            break;
        }
    }
    for(int i=0;i<l;i++)
    {
        if(s[i]=='Z')
        {
            e=i+1;
        }
    }
    cout<<e-st+1<<endl;
    return 0;
}


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

using namespace std;

int main(){
    int a1,a2,a3;
    cin >> a1 >> a2 >> a3;
    if(a1+a2+a3 >= 22){
        cout << "bust" << '\n';
    }else{
        cout << "win" << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int S,h,m,s,temp;
    cin >> S;
    h = S/3600;
    temp = S%3600;
    m = temp/60;
    s = temp%60;
    
    cout << h << ":" << m << ":" << s << endl;
    
}

Measured memory_bytes: 3092
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,x,m,a[200005],k=0,ans=0;
map<ll,ll>viz;
int32_t main(){
CODE_START;
cin>>n>>x>>m;
if(n==1){
cout<<x;
return 0;
}
ans+=x;
x%=m;
viz[x]=1;
a[++k]=x;
for(ll i=2;i<=n;i++)
{
    x*=x;
    x%=m;
        if(viz[x]!=0){
               // cout<<i<<endl;
            vector<ll>v;
            for(ll j=viz[x];j<i;j++)
            {
                v.pb(a[j]);
            }
            n-=i;
        n++;
            ll nr=n/int(v.size());
            ll sum=0;
            for(ll j=0;j<v.size();j++)
            {
                sum+=v[j];
            }
            ans+=sum*nr;
            ll pos=n%int(v.size());
            sum=0;
            for(ll j=0;j<pos;j++)
            {
                sum+=v[j];
            }
            ans+=sum;

        break;
    }
    ans+=x;
    viz[x]=i;
    a[++k]=x;
}
cout<<ans<<endl;
}


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

using namespace std;

int main()
{
  vector<string> c(3);
  for (int i = 0; i < 3; ++i) {
    cin >> c[i];
  }

  cout << string(1, c[0][0]) + string(1, c[1][1]) + string(1, c[2][2]);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int g;
void dfs(ll i,vector<ll>a[],ll vi[])
{
    if(vi[i]==1)
        return;

    vi[i]=1;
    g++;
    for(int j=0;j<a[i].size();j++)
    {
        if(vi[a[i][j]]==0)
        {
            dfs(a[i][j],a,vi);
        }
    }
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
int n,m;
cin>>n>>m;
vector<ll>v[n+1];
set <pair <int,int> >in;
while(m--)
{
    int a,b;
    cin>>a>>b;
    in.insert({a,b});
}
for(auto x:in)
{
 int a=x.first;
  int b=x.second;
  v[a].push_back(b);
  v[b].push_back(a);
}
int mx=0;
ll vi[n+1];
memset(vi,0,sizeof(vi));
for(int i=1;i<=n;i++)
{
    g=0;
    dfs(i,v,vi);
    mx=max(mx,g);
}
cout<<mx;
}


Measured memory_bytes: 34744
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int n;
string s;

int main() {

	cin >> n >> s;

	rep(i, s.size()) {
		s[i] += n;
		if (s[i] > 'A' + 25) {
			s[i] -= 26;
		}
	}

	cout << s << endl;

	return 0;
}

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

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

    if(D == 0) {
        if(N == 100) {
            cout << 101;
        }
        else {
            cout << N;
        }
    }
    else if(D == 1) {
        if(N == 100) {
            cout << 10100;
        }
        else {
            cout << 100*N;
        }
    }
    else {
        if(N == 100) {
            cout << 1010000;
        }
        else {
            cout << 10000*N;
        }
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
s = [0] * N
p = [0] * N

list_ = [0]*N
for i in range(N):
    s[i],p[i] = (input()).split()

for i in range(N):
    list_[i] = "{} {} {:03d}".format(i+1,s[i],int(p[i])).split()

for i in range(N):
    list_[i][2] = int(list_[i][2])
list_.sort(key=lambda x:(x[1],-x[2]))


for i in list_:
    print(i[0])

Measured memory_bytes: 38384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


bool check(vint s, int n)
{
	rep(i, n) if(s[i] != count(ALL(s), s[i]))
		return false;

	return true;
}


int main()
{
	int n;
	while(cin >> n && n)
	{
		vint s(n);
		int res = 0;

		rep(i, n)
			cin >> s[i];

		while(!check(s, n))
		{
			vint prv = s;

			rep(i, n)
				s[i] = count(ALL(prv), s[i]);

			res++;
		}

		cout << res << endl;
		rep(i, n)
			cout << s[i] << (i + 1 == n ? "\n" : " ");
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main(){
#define int long long
	int n;
	string s;
	cin >> n >> s;
	long long r = 0, g = 0, b = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') {
			r++;
		}
		else if (s[i] == 'G') {
			g++;
		}
		else {
			b++;
		}
	}
	long long co = 0;
	for (int j = 0; j < n; j++) {
		for (int k = j + 1; k < n; k++) {
			if (k + k - j >= n) {
				continue;
			}
			else {
				if (s[j] != s[k] && s[j] != s[k + k - j] && s[k] != s[k + k - j]) {
					co++;
				}
			}
		}
	}
	long long ans = r * g * b - co;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main(){

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

    int ct =1;
   int minno=a[0];
    for(int i=1;i<n;i++){
    if(a[i]<minno){
      ct++;
      minno=a[i];
    }
    }

    cout<<ct;
return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;
typedef long long LL;

int main(void) {

	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];

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

	if (a[0] != a[1]) {
		cout << a[0] << endl;
	} else {
		cout << a[2] << endl;
	}



	return 0;
}

Measured memory_bytes: 256
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for k in range(W):
            if (i+k)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()
 
    print() #データセットの区切り


Measured memory_bytes: 7004
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  for(int i=0; i<10; ++i){
    c*=a;
    c-=b;
    cout<<c<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (!(a % 2) && a % 3 && a % 5) {
      puts("DENIED");
      return 0;
    }
  }
  puts("APPROVED");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


ll tentou = 0;

void mergesort(int* A, int N0) {
	if (N0 > 2) {
		int N1 = N0 / 2;
		int N2 = N0 - N1;
		mergesort(A, N1);
		mergesort(A + N0 / 2, N2);

		int itr1 = 0;
		int itr2 = 0;
		vector<int> V;
		rep(i, N0) {
			if (N1 > itr1 && N2 > itr2) {
				if (A[itr1] > A[N1 + itr2]) {
					V.push_back(A[N1 + itr2]);
					itr2++;
					tentou += N1 - itr1;
				}
				else {
					V.push_back(A[itr1]);
					itr1++;
				}
			}
			else if (itr1 == N1) { V.push_back(A[N1 + itr2]); itr2++; }
			else { V.push_back(A[itr1]); itr1++; }
		}
		rep(i, N0) A[i] = V[i];
	}
	else if (N0 == 2) {
		if (A[0] > A[1]) {swap(A[0], A[1]);	tentou++;}
	}
}

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


	//当時は若く、パクリが必要でした

	int N;
	cin >> N;
	int A[100000];
	rep(i, N) cin >> A[i];

	
	int L = 1;
	int R = 1000000000;

	while (L != R) {
		int half = (L + R) / 2 + 1;
		int B[100001] = {};
		rep(i, N) {
			B[i + 1] = B[i];
			if (A[i] >= half) B[i + 1] += 1;
			else B[i + 1] -= 1;
		}
		tentou = 0;
		mergesort(B, N + 1);
		if(1ll * N * (N + 1) / 4 >= tentou) L = half;
		else R = half - 1;

	}

	co(L);

	Would you please return 0;
}

Measured memory_bytes: 2012
#include <stdio.h>

int main(void) {
    int a,b,c,i;
    int count;
    scanf("%d %d %d\n", &a, &b, &c);
    for(i=a,count=0;i<=b;i++) {
        if(c%i==0) count ++;
    }
    printf("%d\n", count);
    
    return 0;
}

Measured memory_bytes: 600
N, Q = list(map(int, input().split()))
S = input()

counts = [0]*N

count = 0
for i, (a, b) in enumerate(zip(S, S[1:])):
    if a == 'A' and b == 'C':
        count += 1
        counts[i+1] = count
    else:
        counts[i+1] = count

for i in range(Q):
    l, r = list(map(int, input().split()))
    print(counts[r-1] - counts[l-1])


Measured memory_bytes: 6084
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	s := readLine()
	Loop(0, len(s), func(i int) {
		c := string(s[i])
		i++
		if (i % 2) == 0 {
			switch c {
			case "L", "U", "D":
			default:
				goto Fail
			}
		} else {
			switch c {
			case "R", "U", "D":
			default:
				goto Fail
			}
		}

		return
	Fail:
		fmt.Println("No")
		os.Exit(0)
	})

	fmt.Println("Yes")
}

/////////////////////////////////////////
var scanner = bufio.NewScanner(os.Stdin)

func init() {
	//scanner.Split(bufio.ScanWords)
}
func readLine() string {
	scanner.Scan()
	return scanner.Text()
}

func Loop(start, end int, f func(i int)) {
	for i := start; i < end; i++ {
		f(i)
	}
}


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

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

    if ((a == 7 && b == 5 && c == 5)
        || (a == 5 && b == 7 && c == 5)
        || (a == 5 && b == 5 && c == 7)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
 
using namespace std ;
int main()
{
    int d;
    cin>>d;
    
    if(d==25){
        cout<<"Christmas"<<endl;
    }
    else if(d==24){
        cout<<"Christmas Eve"<<endl;
    }
    else if(d==23){
        cout<<"Christmas Eve Eve"<<endl;
    }
    else if(d==22){
        cout<<"Christmas Eve Eve Eve"<<endl;
    }
        
 
    return 0;
}

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

int main() {
  int x;
  cin >> x;
  if (x == 1) cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
map<int,int> mp;
long long t[40];
int cnt=0;
int n,a[200000];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
	}
	sort(a,a+n);
	long long last=1;
	while(1)
	{
		if(last>a[n-1]*2)
		break;
		t[cnt++]=last;
		last*=2;
	}
	int ans=0;
	for(int i=n-1;i>=0;i--)
	{
		int tmp=lower_bound(t,t+cnt,(long long)(a[i]))-t;
		if(mp[a[i]]>=2&&(long long)(a[i])==t[tmp]&&a[i-1]==a[i])
		{
			mp[a[i]]-=2;
			ans++;
		}
		if(mp[a[i]]>=1&&(long long)(a[i])!=t[tmp]&&mp[t[tmp]-a[i]])
		{
			mp[a[i]]--;
			mp[t[tmp]-a[i]]--;
			ans++;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 19712
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n;
    cin>>n;
    vector<ll> v(n);
    rep(i, n){
        cin>>v[i];
    }
    vector<vector<int> > table(n, vector<int>(30));
    rep(i, n){
        ll x = v[i];
        rep(j, 30){
            table[i][j] = x%2;
            x = (x-x%2)/2;
        }
    }
    rep(i, 30){
        bool change = false;
        int now = 0;
        for(int j = 1;j<=n-1;j++){
            now += table[j][i];
        }
        if(now%2 != table[0][i]){
            rep(j, n){
                if(table[j][i] == 1) table[j][i] = 0;
                else table[j][i] = 1;
            }
        }
    }
    rep(i, n){
        ll beki = 1;
        ll ans = 0;
        rep(j, 30){
            ans += beki*(ll)table[i][j];
            beki *= 2;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 34360
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  ll a,b,c=0,d=0,e,n,m,ans=0;
  string s,t;
  cin>>s;
  if(s[0]=='7'||s[1]=='7'||s[2]=='7') co("Yes");
  else co("No");
  
  return 0;
}

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

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

    int f = 1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        if (a == f)
            f++;
    }

    if (f == 1)
        cout << -1 << endl;
    else
        cout << (n - (--f)) << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n, m,k; string s; string sp;
char maze[60][60];
int dis[60][60];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main() {
	cin >> s; string res="Yes"; int alp[26] = { 0 };
	rep(i,s.size()){
		rep(j, 26) {
			if (s[i] == 'a' + j) {
				alp[j]++;
				break;
			}
		}
	}
	rep(i, 26) {
		if (alp[i] % 2 != 0) {
			res = "No";
		}
	}
	cout << res << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    long long sum = 0;
    long long S = 0;
    for(int i = 0;i <N; i++){
        cin >> A[i];
        S += A[i];
        if(i%2 == 1)
            sum += A[i];
    }
    vector<long long> ans(N);
    ans[0] = S - 2 * (sum);
    cout << ans[0] << " ";
    for (int i = 1; i < N;i++){
        ans[i] = 2*A[i - 1] - ans[i - 1];
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    map<string,int> mp;
    string s;
    rep(i,n){
        cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }

    ll ans;
    ans=0;
    int s2;
    for(auto& p: mp){
        s2=p.second;
        ans+=(ll)s2*(s2-1)/2;
    }

    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ar array
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll a;
  long double b;
  cin >> a >> b;
  a*=b;
  cout << a << '\n';
  return 0;
}


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

int n;

int main() {
    int n;
    cin >> n;
    int x[n], y[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &x[i]);
        y[i] = x[i];
    }
    sort(y, y + n);
    int ans1 = y[n/2-1], ans2=y[n/2];
    for (int i = 0; i < n; i++) {
        if (x[i] <= ans1) cout << ans2 << endl;
        else cout << ans1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,count=0,i=0;
    scanf("%d",&n);
    getchar();
    char s[n+1];
    scanf("%s",s);
    //printf("%s",s);

    for(i=0;i<n;i++)
    {
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
            count++;
    }
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


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

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

ll dp[1000005][4];

int main(){
  string S;
  cin >> S;
  
  dp[0][0] = 1;
  
  for(int i = 0; i < S.size(); i++){
    for(int j = 0; j < 4; j++){
      if(S[i] == '?') dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * 3) % mod;
      else dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod;
    }
    if(S[i] == 'A' || S[i] == '?') dp[i + 1][1] = (dp[i + 1][1] + dp[i][0]) % mod;
    if(S[i] == 'B' || S[i] == '?') dp[i + 1][2] = (dp[i + 1][2] + dp[i][1]) % mod;
    if(S[i] == 'C' || S[i] == '?') dp[i + 1][3] = (dp[i + 1][3] + dp[i][2]) % mod;
  }
  cout << dp[S.size()][3] << endl;
  return 0;
}


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

using namespace std;

int main(){
    long int n;

    cin >> n;

    long int sum = 0;

    for(int i = 1;i<=n;i++){
        if(i%15==0)continue;
        else if(i%3==0)continue;
        else if(i%5==0)continue;
        else sum+=i;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define v vector
#define len length()
#define fi first
#define se second
#define mt make_tuple
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9+7;
int ll_max=1e6;
v<ll> fact;
//factorial
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <=n; i++)
    {
        fact[i] = i * fact[i - 1];
        fact[i] %= M;
    }
}
// modular exponentiation 
ll binpow(ll val, ll deg)
{
    if (!deg)
        return 1 % M;
    if (deg & 1)
        return binpow(val, deg - 1) * val % M;
    ll res = binpow(val, deg >> 1);
    return (res * res) % M;
}
//combination
ll combination(ll n, ll i)
{
    ll res = fact[n]; 
    ll div = fact[n - i] * fact[i];
    div %= M;
    // using fermat little theorum
    div = binpow(div, M - 2); // modular inverse  
    return (res * div) % M; 
}

int main() {
	// your code goes here
	IOS;
	ll n,m,i;
	ll j,t,x,y,z,k,d;
	cin>>n>>m>>k;
	ll a[n+1],b[m+1],s1[n+1]={0};
	v<ll> s2(m+1,0);
	rep(i,n+1) {
	if(i>0){      
	cin>>a[i];
	s1[i]+=s1[i-1]+a[i];
	}
	//cout<<s1[i]<<" ";
	}
	//cout<<endl;
	rep(i,m+1) {
	
	if(i>0){
	cin>>b[i];
	s2[i]+=s2[i-1]+b[i];
	}
	//cout<<s2[i]<<" ";
	}
	ll maxi=0;
	ll count;
	for(i=0;i<=n;i++){
	      count=0;
	      if(s1[i]>k)
	      break;
	      ll rem=k-s1[i];
	      //cout<<i<<"\n";
	      count+=i;
	      ll ans=upper_bound(s2.begin(),s2.end(),rem)-s2.begin();
	      if(s2[ans]!=rem)
	      ans--;
	      count+=ans;
	      if(count>maxi)
	      maxi=count;
	}
	cout<<maxi;
	return 0;
}

Measured memory_bytes: 9520
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

"""

N, K = map(int, input().split())
S = input()
def main():
    now = 1
    cnt = 0
    nums = []
    for i in range(N):
        if S[i] == str(now):
            cnt += 1
        else:
            nums.append(cnt);
            now = 1-now
            cnt = 1
    if cnt != 0:
        nums.append(cnt)
    if len(nums)%2 ==0:
        nums.append(0)
    add = 2*K + 1
    res = 0
    # ループの外にleft , right
    left = 0
    right = 0
    tmp= 0 # [left, right) のsum
    for i in range(0, len(nums), 2):
        # 次のleft, right を計算
        nextLeft = i
        nextRight = min(i+add, len(nums))
        # 左端を計算
        while (nextLeft > left):
            tmp -= nums[left]
            left += 1
        
        # 右端を計算
        while (nextRight > right):
            tmp += nums[right]
            right +=1
        res = max(tmp, res)
    print(res)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 14676
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define LL long long
#define MAXN 200000
#define MOD 1000000007
int n,q,pre[MAXN+5],ecnt,BLK,pcnt;
int F[MAXN+5][20];
int dfn[MAXN+5],ed[MAXN+5],ct,fd[MAXN+5],dep[MAXN+5];
int col[MAXN+5],val[MAXN+5],flag[MAXN+5],ans[MAXN+5],cnt[MAXN+5];
int sum[MAXN+5];
struct edge{
	int to,nxt,col,dis;
}e[MAXN*2+5];
struct Query{
	int l,r,id,x,y;
}Q[MAXN+5];
bool cmp(Query s1,Query s2){
	if(s1.l/BLK==s2.l/BLK)return s1.r<s2.r;
	else return s1.l<s2.l;
}
void add(int u,int v,int a,int b){
	e[++ecnt]=(edge){v,pre[u],a,b};
	pre[u]=ecnt;
	e[++ecnt]=(edge){u,pre[v],a,b};
	pre[v]=ecnt;
}
void dfs(int x,int fa){
	dfn[x]=++ct,fd[ct]=x;
	F[x][0]=fa,dep[x]=dep[fa]+1;
	for(int k=1;k<20;k++)
	F[x][k]=F[F[x][k-1]][k-1];
	for(int i=pre[x];i!=-1;i=e[i].nxt){
		int xnt=e[i].to;
		if(xnt==fa)continue;
		dfs(xnt,x);
		col[xnt]=e[i].col,val[xnt]=e[i].dis;
	}
	ed[x]=++ct,fd[ct]=x;
}
int LCA(int a,int b)
{
	if(dep[b]>dep[a])swap(a,b);
	for(int i=19;i>=0;i--)
	if(dep[F[a][i]]>=dep[b])a=F[a][i];
	if(a==b)return a;
	for(int i=19;i>=0;i--)
	if(F[a][i]!=F[b][i])
	a=F[a][i],b=F[b][i];
	return F[a][0];
}
void upd(int x){
    int y=fd[x];
    if(flag[y])cnt[col[y]]--,sum[col[y]]-=val[y],pcnt-=val[y];
    else cnt[col[y]]++,sum[col[y]]+=val[y],pcnt+=val[y];
    flag[y]^=1;
}
int main(){
	scanf("%d%d",&n,&q);
	BLK=floor(sqrt(n));
	memset(pre,-1,sizeof(pre));
	for(int i=1;i<n;i++){
		int u,v,a,b;
		scanf("%d%d%d%d",&u,&v,&a,&b);
		add(u,v,a,b);
	}
	dfs(1,0);
	for(int i=1;i<=q;i++){
		int x,y,u,v;
		scanf("%d%d%d%d",&x,&y,&u,&v);
		int p=LCA(u,v);
		if(u==p||v==p){
			if(dep[v]<dep[u])swap(u,v);
			Q[i]=(Query){dfn[u]+1,dfn[v],i,x,y};
		}
		else{
			if(dfn[v]<dfn[u])swap(u,v);
			Q[i]=(Query){ed[u],dfn[v],i,x,y};
		}
	}
	sort(Q+1,Q+q+1,cmp);
	int L=1,R=0;
	for(int i=1;i<=q;i++){
		while(L<Q[i].l)upd(L++);
		while(L>Q[i].l)upd(--L);
		while(R>Q[i].r)upd(R--);
		while(R<Q[i].r)upd(++R);
		ans[Q[i].id]=pcnt-sum[Q[i].x]+cnt[Q[i].x]*Q[i].y;
	}
	for(int i=1;i<=q;i++)
	printf("%d\n",ans[i]);
}

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

int main(void){
    int n, m;
    long long sum = 0;
    
    cin >> n >> m;
    
    int tmp;
    priority_queue<long long> que;
    
    rep(i, n){
        cin >> tmp;
        que.push(tmp);
    }
    
    rep(i, m){
        tmp = que.top();
        que.pop();
        que.push(tmp/2);
    }
    
    rep(i, n){
        sum += que.top();
        que.pop();
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 1400
//default
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
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 int MOD=1e9+7;
const long long INF = 1LL << 60;

class Edge {
public:
  int to;     // 辺の行き先
  int weight; // 辺の重み
  Edge(int t, int w) : to(t), weight(w) { }
};

using Graph = vector<vector<Edge>>;

signed main(){
  // 頂点数と辺数
  int N, M, r; cin >> N >> M >> r;

  // グラフ
  Graph G(N);
  for (int i = 0; i < M; ++i) {
    int a, b, d;
    cin >> a >> b >> d;
    G[a].push_back(Edge(b,d));

    // 無向グラフの場合は以下を追加
    // G[b].push_back(a);
  }

  vector<int> D(N,INF);
  D[r]=0;
  rep(i,N){
    rep(j,N){
      if(D[j]>=INF/2) continue;
      for(auto v : G[j]){
        if(D[v.to]>D[j]+v.weight){
          D[v.to]=D[j]+v.weight;

          if(i==N-1){
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
          }
        }
      }
    }
  }
  rep(i,N){
    if(D[i]>=INF/2) cout << "INF" << endl;
    else cout << D[i] << endl;
  }


  return 0;
}



Measured memory_bytes: 3156
function Main(input){
    input = input.split("\n");
    var n = parseInt(input[0],10);
    var q = parseInt(input[2],10);
    input[1] = input[1].split(" ");
    input[3] = input[3].split(" ");
    var s = Array(n),t = Array(q);
    for(var i = 0;i < n;i++){
        s[i] = parseInt(input[1][i],10);
    }
    for(var i = 0;i < q;i++){
        t[i] = parseInt(input[3][i],10);
    }
    var count = 0;

    for(var i = 0;i < q;i++){
        var left = 0,right = n;
        while(left <= right){
            var mid = Math.floor((left + right) / 2);
            if(s[mid] === t[i]){
                count++;break;
            }else if(s[mid] < t[i])
                left = mid + 1;
            else
                right = mid - 1;
        }
    }
    console.log(count);
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 29972
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

template<typename T> bool chmax( T &a, T b ) { if ( a < b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, T b ) { if ( a > b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp( a, b ) make_pair( a, b )
#define mt( ... ) make_tuple( __VA_ARGS__ )

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()

#define MOD ( (ll)( 1e9 + 7 ) )


int main()
{
	int A, B;
	cin >> A >> B;

	int result = A > B ? A-- : B--;
	result += A > B ? A : B;

	cout << result << endl;

	return ( 0 );
}


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


int main()
{
    int N;
    cin >> N;
    if ((N % 10 == 7) || (N / 10 % 10 == 7) || (N / 100 == 7))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N, H, W, ans = 0;
    cin >> N >> H >> W;
    int A[1000], B[1000];
    for(int i=0;i<N;i++)
        cin >> A[i] >> B[i];
    
    for(int i=0;i<N;i++){
        if(H <= A[i] && W <= B[i])
            ans++;
    }

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

Measured memory_bytes: 256