akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int K;
ll dp[2][501][2][2];
ll sum[2][501][2][2];
vector<vector<int> > nxtst;

ll solve(string S){
  int N=S.size();
  memset(dp,0,sizeof(dp));
  memset(sum,0,sizeof(sum));

  int crtd=0,nxtd=1;
  rep(i,N){
    memset(dp[nxtd],0,sizeof(dp[nxtd]));
    memset(sum[nxtd],0,sizeof(sum[nxtd]));
    if(i==0) dp[crtd][0][0][0]=1;
    else dp[crtd][0][1][0]=1;
    rep(j,K){
      rep(f1,2){
        rep(f2,2){
          int mn=(f2==0?1:0);
          int mx=(f1==0?S[i]-'0':9);
          repl(nxt,mn,mx+1){
            int nxtj=nxtst[j][nxt];
            (dp[nxtd][nxtj][(f1==0&&nxt==mx?0:1)][1]+=dp[crtd][j][f1][f2])%=mod;
            (sum[nxtd][nxtj][(f1==0&&nxt==mx?0:1)][1]+=sum[crtd][j][f1][f2])%=mod;
            if(nxtj==K-1){
              (sum[nxtd][nxtj][(f1==0&&nxt==mx?0:1)][1]+=dp[crtd][j][f1][f2])%=mod;
            }
          }
        }
      }
    }
    swap(crtd,nxtd);
  }

  ll res=0;
  rep(j,K){
    rep(f1,2){
      (res+=sum[crtd][j][f1][1])%=mod;
    }
  }

  return res;
}

string decrement(string A) {
  for(int i = A.size() - 1; i >= 0; --i) {
    if(A[i] > '0') {
      A[i]--;
      break;
    } else {
      A[i] = '9';
    }
  }
  if(A[0] == '0' && A.size() > 1) {
    return A.substr(1);
  } else {
    return A;
  }
}

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

  int N=s.size();
  vector<string> pfx;
  rep(i,N+1){
    pfx.push_back(s.substr(0,i));
  }
  sort(all(pfx));
  uni(pfx);
  K=pfx.size();
  nxtst=vector<vector<int> >(K,vector<int>(10,-1));
  rep(i,K){
    rep(nxt,10){
      string t=pfx[i];
      t+='0'+nxt;
      int idx=0;
      while(1){
        idx=lower_bound(all(pfx),t)-pfx.begin();
        if(idx<K&&pfx[idx]==t)break;
        t=t.substr(1);
      }
      nxtst[i][nxt]=idx;
    }
  }

  if(A!="0")cout<<(solve(B)-solve(decrement(A))+mod)%mod<<endl;
  else cout<<solve(B)+(s=="0"?1:0)%mod<<endl;

  return 0;
}



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

const int H=4,W=4;
const int SIZE=H*W;

class State
{
 public:
    string str;
    int space,distFromS,distToG;
    State(string str,int space,int dist):str(str),space(space),distFromS(dist),distToG(0){
        for(int i=0;i<SIZE;i++) if(i!=space){
            int y=i/W,x=i%W;
            int gy=(str[i]-'a')/W,gx=(str[i]-'a')%W;
            distToG+=abs(y-gy)+abs(x-gx);
        }
    }
    bool operator<(const State& s) const{
        return distFromS+distToG>s.distFromS+s.distToG;
    }
};

int d[4]={W,1,-1,-W};

int main()
{  
    string s(SIZE,' '),goal(SIZE,' ');
    for(int i=0;i<SIZE;i++) goal[i]=(char)('a'+i);
    for(int i=0;i<SIZE;i++){
        int t; cin>>t;
        if(t==0) s[i]=goal[SIZE-1];
        else s[i]=goal[t-1];
    }

    State start(s,s.find(goal[SIZE-1]),0);
    priority_queue<State> Q; Q.push(start);
    set<string> visited; visited.insert(s);
    while(!Q.empty()){
        auto cur=Q.top(); Q.pop();
        if(cur.str==goal){
            cout<<cur.distFromS<<endl;
            return 0;
        }
        for(int i=0;i<4;i++){
            int nxtspace=cur.space+d[i];
            if(nxtspace<0 or nxtspace>=SIZE) continue;
            if(d[i]==1 and nxtspace%W==0) continue;
            if(d[i]==-1 and nxtspace%W==W-1) continue;
            string nxtstr=cur.str;
            swap(nxtstr[cur.space],nxtstr[nxtspace]);
            if(!visited.count(nxtstr)){
                visited.insert(nxtstr);
                State nxt(nxtstr,nxtspace,cur.distFromS+1);
                Q.push(nxt);
            }
        }
    }
    return 0;
}


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

int main(void)
{
	int N,M,i;

	cin >> N >> M;

	long long A[N+10];

	for(i=0;i<N;i++)
	{
		cin >> A[i];

	}
	priority_queue< long long > B;

	long long tmp;

	for(i=0;i<N;i++)
	{

		tmp=A[i];

		B.push(tmp);
	}

	long long bfr,aft;

	for(i=0;i<M;i++)
	{
		bfr=B.top();
		B.pop();
		aft=bfr/2;
		B.push(aft);
	}

	long long ans=0;

	for(i=0;i<N;i++)
	{
		ans=ans+B.top();
		B.pop();

	}

	cout << ans << endl;

}



Measured memory_bytes: 2168
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  string s;
  cin >> s;

  if(s[2] == s[3] && s[4] == s[5]) Yes;
  else No;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int x,a,b;
    cin>>x>>a>>b;
    if(b<=a)
    {
       cout<<"delicious"<<NL;
    }
    else if(b-a<=x)
    {
        cout<<"safe"<<NL;
    }
    else
    {
        cout<<"dangerous"<<NL;
    }
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var used [10]int
	var a, b, c int
	fmt.Scanf("%d%d%d", &a, &b, &c)
	used[a]++
	used[b]++
	used[c]++

	if used[5] == 2 && used[7] == 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
from functools import reduce

def main():
    N,X = [int(a) for a in input().split()]
    L = [int(a) for a in input().split()]

    D = 0
    Ds=[D]
    for Li in L:
        D += Li
        Ds.append(D)

    print(len([a for a in Ds if a<=X]))




if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	ll N,A,B;
	cin >> N >> A >> B;
	ll ans = 0;
	vector<ll> X(N);
	for (int i = 0; i < N; i++)cin >> X[i];
	for (int i = 0; i < N - 1; i++) {
		ans += min((X[i + 1] - X[i]) * A, B);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define _ ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL);
#define inp(a) for(auto& i : a) cin >> i;
#define out(a) for(auto i : a){cout << i << ' ';}cout << endl;
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
#define LOCAL
const int N = 2e5+7 ;
const int INF = 1e9 ;
const int MOD = INF + 7 ;
string s ;
//#define int long long

int32_t main(){_
	int n,k ;
	cin >> n ;
	vi a(n) ;
	inp(a) ;
	int cnt = 0 ;
	for(int i = 1 ; i < n-1 ; i++){
		if((a[i] > a[i-1] && a[i] < a[i+1]) || (a[i-1] > a[i] && a[i+1] < a[i]))
			cnt++ ;
	}	
	cout << cnt << endl;
		
}


Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n;
    cin >> n;
    set<char> st;
    for(int i = 0; i < n; i++){
        char a;
        cin >> a;
        st.insert(a);
    }

    if(st.size() == 3){
        cout << "Three" << endl;
    } else {
        cout << "Four" << endl;
    }
}   

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

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


    bool ispoor = false;
    if(a==b && b!=c) ispoor = true;
    else if(b==c && c!=a) ispoor = true;
    else if(c==a && a!=b) ispoor = true;

    if(ispoor) cout << "Yes" <<endl;
    else cout << "No" <<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

int d[100010];
typedef pair<int, int> P;
vector<P> G[100010];
void dfs(int v, int dist) {
    //cout << v << " " << dist << endl;
    d[v] = dist;
    for(auto u: G[v]) {
        if (d[u.first] >= 0) continue;
        dfs(u.first, d[v] + u.second);
    }

}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    rep(i, N - 1) {
        int s, t, c;
        cin >> s >> t >> c;
        s--; t--;
        G[s].push_back({t, c});
        G[t].push_back({s, c});
    }
    int Q, K;
    cin >> Q >> K;
    K--;
    rep(i, 100010) d[i] = -1;
    dfs(K, 0);
    while(Q--) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        cout << d[s] + d[t] << endl;
    }

    return 0;
}


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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; const ll MOD = 1000000007;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

//---------------------------------------------------------------------------------------------------
void _main() {
    ll N, W; cin >> N >> W;
    vector<vector<ll>> dp(N+2, vector<ll>(W+2, 0));
    rep(i, 0, N) {
        ll v, w; cin >> v >> w;
        rep(j, 0, W + 1) {
            if (j >= w) dp[i+1][j] = max(dp[i][j], max(dp[i][j-w] + v, dp[i+1][j-w] + v));
            else dp[i+1][j] = dp[i][j];
        }
    }
    cout << dp[N][W] << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  vector <ll> a(n-1, 0);
  rep(i, n-1) {
    if ((s.at(i) == 'A') && (s.at(i+1) == 'C')) {
      a.at(i)++;
    }
  }
  vector <ll> b(n, 0);
  rep(i, n-1) b.at(i+1) += b.at(i) + a.at(i);
  rep(i, m) {
    ll l, r;
    cin >> l >> r;
    cout << b.at(r-1) - b.at(l-1) << endl;
  }
}

Measured memory_bytes: 2688
#include <iostream>

int main()
{
	int N, K, D[10];

	std::cin >> N >> K;
	for (int i = 0; i < K; i++)
		std::cin >> D[i];

	int temp;
	bool check = true;
	while (true) {
		temp = N;
		while (temp != 0) {
			for (int i = 0; i < K; i++)
				if (temp % 10 == D[i])
					check = false;
			temp /= 10;
		}
		if (check)
			break;
		else {
			++N;
			check = true;
		}
	}

	std::cout << N << '\n';

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
#import bisect
#import numpy as np
# from collections import deque
from collections import deque
# map(int, sys.stdin.read().split())
import itertools
import heapq

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


def main():
    N = int(input())
    A = list(map(lambda x: -1*int(x),input().split()))
    heapq.heapify(A)
    l = deque()
 #   print(A)
    score =0
    c = heapq.heappop(A)
    l.append(c)
    for i in range(N-1):
        c = heapq.heappop(A)
        l.append(c)
        l.append(c)
        current =l.popleft()
        score +=current

    print(-score)


if __name__ == "__main__":
    main()


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

int main(){
  int r;
  cin >>r;
  if(r<1200) cout << "ABC" << endl;
  if(r>=1200 && r<2800) cout << "ARC" << endl;
  if(r>=2800) cout << "AGC" << endl;
  return 0;
}


Measured memory_bytes: 256
s = input().split()
N = int(s[0])
K=int(s[1])
MOD = 1000000007
res=0
M = N+1
L = K-1
res = M*(M*M+5)/6 + L*(L*L*2+L*3-5-M*(L+1)*3)/6
print(int(res%MOD))

Measured memory_bytes: 9184
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    int k, n;
    scan(k, n);

    int[] ans;

    if ((k & 1) == 0) {
        ans = [k / 2] ~ repeat(k, n - 1).array;
    } else {
        ans = repeat((k + 1) / 2, n).array;
        int last = n - 1;

        foreach (i ; 0 .. n / 2) {
            if (ans[last] == 1) {
                ans[last--] = 0;
            }
            else {
                ans[last]--;

                foreach (j ; last + 1 .. n) {
                    ans[j] = k;
                }

                last = n - 1;
            }
        }
    }

    writefln("%(%s %)", ans.filter!"a > 0");
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	int a[n], b[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	sort(a, a + n);
	sort(b, b + n);
	if (n % 2 == 0) {
		int min2 = (a[n/2-1] + a[n/2]);
		int max2 = (b[n/2-1] + b[n/2]);
		cout << max2 - min2 +1 << endl;
	} else {
		int min = a[n/2];
		int max = b[n/2];
		cout << max-min+1 << endl;
	}

	return 0;
}


Measured memory_bytes: 5188
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll inf = 1e18;

using namespace std;



void solve()
{
  ll n,w,x=0,y,ans=0;
  cin>>n>>w;
  std::vector<ll> weight(n),value(n);
  //dp[i] = the minimum total weight of items with total value i resp
  for (int i = 0; i < n; ++i)
  {
    cin>>weight[i]>>value[i];
  }
  for(ll i=0;i<n;i++)
  {
    x+=value[i];
  }
  std::vector<ll> dp(x+1,inf);
  dp[0] = 0;
  for (int i = 0; i < n; ++i)
  {
   for(ll j=x-value[i];j>=0;j-- )
    {
    dp[j+value[i]] = min(dp[j+value[i]],dp[j] + weight[i]);
    }
  }

  for (ll i = 1; i <=x; ++i)
  {
    if(dp[i]<=w)
    ans = max(i,ans);
    //c(dp[i]);
  }
c(ans);
}

signed main(){
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 1024
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc124/tasks/abc124_b

n = int(input())
h = [0] + [int(x) for x in input().split()]
cnt = 0
for i in range(1, len(h)):
    if len([j - h[i] for j in h[:i + 1] if j - h[i] > 0]) == 0:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
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=1LL<<60;
//set<int>::iterator it;



int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int a,b,c;
	cin>>a>>b>>c;
	if(b>=a*c)cout<<c<<endl;
	else cout<<b/a<<endl;
	
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	int n;
	cin >> n;
	vi a(n),b;
	rep(i,n) cin >> a[i];
	b = a;
	sort(all(b));
	for(int i = 0; i < n; i++){
		if((b[n-1] != b[n-2]) && a[i] == b[n-1]){
			cout << b[n-2] << endl;
		}else{
			cout << b[n-1] << endl;
		}
	}
	return 0;
}

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


public class Main{

	class E implements Comparable<E>{
		int t, p;
		public E(int t, int p) {
			this.t = t;
			this.p = p;
		}
		public int compareTo(E o) {
			return t!=o.t?t-o.t:p-o.p;
		}
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			E[] e = new E[n*2];
			for(int i=0;i<n;i++){
				String[] r = sc.next().split(":"), v = sc.next().split(":");
				int s = Integer.parseInt(r[0])*3600+Integer.parseInt(r[1])*60+Integer.parseInt(r[2]);
				int t = Integer.parseInt(v[0])*3600+Integer.parseInt(v[1])*60+Integer.parseInt(v[2]);
				e[i] = new E(s, 0); e[i+n] = new E(t, -1);
			}
			Arrays.sort(e);
			int res = 0, c = 0;
			for(E v:e){
				if(v.p==0)c++;else c--;
				res = Math.max(res, c);
			}
			System.out.println(res);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 100010;

int N;
set<int> es[2][MN];
vi g_i[MN];

int main() {
	cin >> N;

	rep(t, 2) {
		rep(i, N-1) {
			int a, b;
			cin >> a >> b;
			--a; --b;
			es[t][a].insert(b);
			es[t][b].insert(a);
		}
	}

	vi i_g(N);

	rep(i, N) i_g[i] = i;
	rep(i, N) g_i[i].pb(i);

	queue<pii> que;

	rep(i, N) {
		for (int to : es[0][i]) {
			if (es[1][i].count(to)) {
				que.push(mp(i, to));
			}
		}
	}

	int c = 0;

	while (!que.empty()) {
		pii p = que.front(); que.pop();
		int u = p.fi, v = p.se;
		int gu = i_g[u], gv = i_g[v];
		if (gu == gv) continue;
		++c;

		if (es[0][gu].size() + es[1][gu].size() > es[0][gv].size() + es[1][gv].size()) {
			swap(gu, gv);
		}

		rep(t, 2) {
			for (int to : es[t][gu]) {
				int tt = i_g[to];
				if (tt == gv) continue;
				es[t][tt].erase(gu);
				es[t][tt].insert(gv);
			}
		}

		rep(t, 2) {
			for (int to : es[t][gu]) {
				int tt = i_g[to];
				if (tt == gv) continue;
				if (es[t^1][gv].count(tt)) {
					que.push(mp(gv, tt));
				}
			}
		}

		rep(t, 2) {
			for (int to : es[t][gu]) {
				int tt = i_g[to];
				if (tt == gv) continue;
				es[t][gv].insert(tt);
			}
		}

		es[0][gu].clear();es[1][gu].clear();

		for (int id : g_i[gu]) i_g[id] = gv;
		g_i[gv].insert(g_i[gv].end(), ALL(g_i[gu]));
		g_i[gu].clear();
	}

	puts(c == N-1 ? "YES" : "NO");

	return 0;
}

Measured memory_bytes: 35904
#include<iostream>
#include<math.h>

using namespace std;

int main(){
    int N;
    cin >> N;
    int a[N];
    int cnt=0;
    long int min=1000000000;
    int tmp;
    for(int i=0;i<N;i++){
        cin >> tmp;
        if(tmp<0) cnt++;
        a[i] = abs(tmp);
        if(abs(tmp)<min) min = abs(tmp);
    }
    long long int sum=0;
    for(int i=0;i<N;i++){
        sum = sum + a[i];
    }
    if(cnt%2==0) cout << sum << endl;
    else cout << sum - 2*min << endl;
}

Measured memory_bytes: 640
n=int(input())
a=list(map(int, input().split()))
ans=0

cnt=[0]*1000000
for i in a:
    cnt[i]+=1
for i in cnt:
    ans+=i*(i-1)/2
for i in a:
    
    print(int(ans-cnt[i]*(cnt[i]-1)/2+(cnt[i]-1)*(cnt[i]-2)/2))


Measured memory_bytes: 26268
#include <iostream>

using namespace std;


signed main()
{
	int n;
	cin >> n;
	int ans = 0;
	int nh = 0;
	for (int i=1; i <= n; i++)
	{
		int a;
		cin >> a;
		if(nh < a)
			ans += a-nh;
		
		nh = a;
	}
	cout << ans << endl;
}
 

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

using namespace std;

#define ll long long
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)

const ll INF=1e9+7;
ll n,a[100000],mountain[100000],k,h,g,cha;
int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n;
	rep(i,n){
		cin>>a[i];
		g+=a[i];
		if(i&1){
			h+=a[i];
		}
	}
	mountain[1]=h*2-g;
	k=3;
	while(k!=1){
		if(k==2){
			mountain[2]=mountain[n]+(a[1]-a[n])*2;
		}
		else{
			mountain[k]=mountain[k-2]+(a[k-1]-a[k-2])*2;
		}
		k+=2;
		if(k>n){
			k%=n;
		}
	}
	rep(i,n){
		cout<<mountain[i]+cha<<' ';
	}
	return 0;
}

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

int main(){
    int a , b , c ;
    cin >> a >> b >> c ;
    if ( a - b >= c)
    {
        cout << "0" << endl ;
    }
    else
    {
        cout << c - a + b << endl ;
    }
    
    
}

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

int p[1010];
int sum[1002010];

int main(void){
	int n,m;

	while(scanf("%d%d",&n,&m) && (n||m)){
		for(int i=0;i<n;i++){
			scanf("%d",&p[i]);
		}
		p[n++] = 0; //0ツ点ツづ個スツコツアツづーツ催ャツづゥ

		int size=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				sum[size++] = p[i] + p[j];
			}
		}
		sort(sum,sum+size);

		int ans = 0;

		for(int i=0;i<size;i++){
			int rem = m - sum[i];
			if(rem < 0) continue;
			int left = 0, right = size;

			while(left < right){
				int center = (left + right) / 2;
				if(rem > sum[center]){
					left = center + 1;
				}
				else if(rem < sum[center]){
					right = center;
				}
				else {
					break;
				}
			}

			ans = max(ans, sum[i] + sum[right-1]);
		}

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

	return 0;
}

Measured memory_bytes: 4672
n = int(input())
if n ==1:
    print(0)
    exit()
a = [int(input()) for _ in range(n)]
a.sort()
na = [0]*n
c = n//2
if n%2 == 1:
    if a[c]-a[c-1] < a[c+1]-a[c]:
        lst1 = a[:c+1]
        lst2 = a[c+1:]
        na[0] = lst1[-1]
        na[-1] = lst1[-2]
    else:
        lst1 = a[c:][::-1]
        lst2 = a[:c]
        na[0] = lst1[-1]
        na[-1] = lst1[-2]
else:
    lst1 = a[:c]
    lst2 = a[c:][::-1]
    na[0] = lst1[-1]
    na[-1] = lst2[-1]
i1 = i2 = 0
for i in range(1,n-1):
    if i%2 == 0:
        na[i] = lst1[i1]
        i1 += 1
    else:
        na[i] = lst2[i2]
        i2 += 1
# print(na)
ans = 0
for i in range(1,n): ans += abs(na[i]-na[i-1])
print(ans)

Measured memory_bytes: 14676
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll x = c-a, y = d-b;
    string ans;
        for(ll i = 0; i < x; i++) ans += 'R';
        for(ll i = 0; i < y; i++) ans += 'U';
        for(ll i = 0; i < x; i++) ans += 'L';
        for(ll i = 0; i < y; i++) ans += 'D';
        ans += 'D';
        for(ll i = 0; i < x+1; i++) ans += 'R';
        for(ll i = 0; i < y+1; i++) ans += 'U';
        ans += 'L';  ans += 'U';
        for(ll i = 0; i < x+1; i++) ans += 'L';
        for(ll i = 0; i < y+1; i++) ans += 'D';
        ans += 'R';


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


Measured memory_bytes: 256
#include <cstdio>
int chr[10000],N;
int solve(int n) {
	int count=1,check=chr[n];
	int i,j;
	for(i=n-1;i>=0;i--)
		if(chr[i]!=check)break;else count++;
	for(j=n+1;j<N;j++)
		if(chr[j]!=check)break;else count++;
	if(count>=4) {
		if(i==-1||j==N)return count;
		if(chr[i]!=chr[j])return count;
		int add;
		while(i>=0&&j<N) {
			add=0;
			check=chr[i];
			for(i;i>=0;i--)
				if(chr[i]!=check)break;else add++;
			for(j;j<N;j++)
				if(chr[j]!=check)break;else add++;
			if(add>=4)count+=add;else break;
		}
		return count;
	}else return 0;
}
int main() {
	while(scanf("%d",&N),N) {
		for(int i=0;i<N;i++)
			scanf("%d",&chr[i]);
		int res=0,ret,tmp;
		for(int i=0;i<N;i++) {
			tmp=chr[i];
			for(int j=1;j<=3;j++) {
				if(tmp==j)continue;
				chr[i]=j;
				ret=solve(i);
				if(res<ret)res=ret;
			}
			chr[i]=tmp;
		}
		printf("%d\n",N-res);
	}
}

Measured memory_bytes: 1064
/*input
6 9
3 4
6 1
2 4
5 3
4 6
1 5
6 2
4 5
5 6
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	ll n,m;
	cin>>n>>m;
	ll x,y;
	vll adj[n+1];
	rep(i,0,m)cin>>x>>y,adj[x].pb(y),adj[y].pb(x);
	ll vis[n+1]={0};
	ll a[n+1];
	init(a,n+1,-1);
	list<ll> queue;
	queue.pb(1);
	vis[1]=0;
	while(!queue.empty()){
		ll z=queue.front();
		queue.pop_front();
		rep(i,0,adj[z].size()){
			if(!vis[adj[z][i]]){
				vis[adj[z][i]]=1;
				a[adj[z][i]]=z;
				queue.pb(adj[z][i]);
			}
		}
	}
	rep(i,2,n+1){
		if(a[i]==-1){
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	rep(i,2,n+1)cout<<a[i]<<endl;
	return 0;
}




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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	map<int, int> num;
  ll n;
  cin >> n;
  ll a;
  rep(i, n) {
    cin >> a;
    num[a]++;
  }
  ll result = 0;
  vector<int> men;
  for (auto i : num) {
    while (i.second > 0) {
      i.second /= 2;
      if (i.second > 0) men.pb(i.first);
    }
  }
  sort(men.begin(), men.end());
  reverse(men.begin(), men.end());

  if (men.size() >= 2) {
    result = men[0] * men[1];
    cout << result << endl;
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 6528
a, b, k = map(int, input().split())
aup = min(a+k-1, b)
bdn = max(b-k+1, aup+1)
l1 = list(map(str,range(a, aup+1)))
l2 = list(map(str,range(bdn, b+1)))
print("\n".join(l1 + l2))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(5);
  for(int i=0;i<5;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  int k;
  cin>>k;
  if((a.at(4)-a.at(0))<=k){
    cout<<"Yay!"<<endl;
  }
  else{
    cout<<":("<<endl;
  }
}
    


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(void){

  vector<int>v(3);
  for(int i=0;i<3;i++)
    cin >> v[i];

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

  int ans=0;
  for(int i=1;i<3;i++)
    ans += v[i] - v[i-1];

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


Measured memory_bytes: 888
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
#======================================================#

def main():
    n, m, q = MII()
    query = [MII() for _ in range(q)]

    def calc_point(lst):
        sumv = 0
        for a, b, c, d in query:
            if lst[b-1] - lst[a-1] == c:
                sumv += d
        return sumv

    def dfs(lst):
        if len(lst) == n:
            return calc_point(lst)
        point = 0
        last_elm = lst[-1] if lst else 1
        for i in range(last_elm, m+1):
            point = max(point, dfs(lst+[i]))
        return point

    print(dfs([]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 9136
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vdewansa
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FLCS solver = new FLCS();
        solver.solve(1, in, out);
        out.close();
    }

    static class FLCS {
        final int SKIP_S = 1;
        final int SKIP_T = 2;
        final int MATCH = 3;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String S = in.next();
            String T = in.next();
            int[][] lcs = new int[S.length() + 1][T.length() + 1];
            int[][] dir = new int[S.length() + 1][T.length() + 1];
            for (int t = 1; t <= T.length(); t++) {
                for (int s = 1; s <= S.length(); s++) {
                    int skipS = lcs[s - 1][t];
                    int skipT = lcs[s][t - 1];
                    int match = lcs[s - 1][t - 1] + (S.charAt(s - 1) == T.charAt(t - 1) ? 1 : 0);
                    if (skipS >= skipT && skipS >= match) {
                        lcs[s][t] = skipS;
                        dir[s][t] = SKIP_S;
                    } else if (skipT >= skipS && skipT >= match) {
                        lcs[s][t] = skipT;
                        dir[s][t] = SKIP_T;
                    } else {
                        lcs[s][t] = match;
                        dir[s][t] = MATCH;
                    }
                }
            }
            int s = S.length();
            int t = T.length();
            StringBuilder res = new StringBuilder();
            while (s > 0 && t > 0) {
                switch (dir[s][t]) {
                    case SKIP_S:
                        s--;
                        break;
                    case SKIP_T:
                        t--;
                        break;
                    case MATCH:
                        if (S.charAt(s - 1) != T.charAt(t - 1)) {
                            throw new RuntimeException("mismatch");
                        }
                        res.append(S.charAt(s - 1));
                        s--;
                        t--;
                }
            }
            out.println(res.reverse().toString());
        }

    }
}



Measured memory_bytes: 129100
X, Y, Z, K = map(int, input().split())

A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))[::-1]

A_B = []
for a in A:
    for b in B:
        A_B.append(a + b)

A_B = sorted(A_B)

def bin_search(mid):
    res = 0
    idx = 0
    ans = [] 
    for c in C:
        while idx < len(A_B):
            if c + A_B[idx] >= mid:
                res += len(A_B) - idx
                ans.append((c, idx))
                break
            else:
                idx += 1

    return res, ans

ok = 0
ng = pow(10, 10) * 3 + 1

while ok + 1 < ng:
    mid = (ok + ng) // 2
    res, ans = bin_search(mid)
    if res >= K:
        ok = mid
    else:
        ng = mid

res, ans = bin_search(ok)

tmp_ans = []
for c, idx in ans:
    for i in range(idx, len(A_B)):
        tmp_ans.append(A_B[i] + c)
for ans in sorted(tmp_ans)[::-1][:K]:
    print(ans)

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

long long N,cost[100000][3],dp[100000][3];

int main()
{
    cin>>N;
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            cin>>cost[i][j];
        }
    }
    dp[0][0]=cost[0][0];
    dp[0][1]=cost[0][1];
    dp[0][2]=cost[0][2];
    for(int i=1;i<N;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+cost[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+cost[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+cost[i][2];
    }
    long long k=0;
    for(int i=0;i<3;i++){
        k=max(dp[N-1][i],k);
    }
    cout<<k;
    return 0;
}



Measured memory_bytes: 4992
use proconio::input;

#[allow(unused_imports)]
use std::collections::HashSet;

use std::cmp;


fn main() {
    input! {
        n: usize,
        k: usize,
    }
    solve(n, k);
}

fn prepare(m: usize, k: usize, p :u64) -> Vec<Vec<u64>> {
    let mut v : Vec<Vec<u64>> = Vec::<Vec<u64>>::with_capacity(m + 1);
    let v0 : Vec<u64> = vec![1; 1];
    v.push(v0);
    for i in 1..m+1 {
        let mut vi : Vec<u64>;
        if i <= k {
            vi = vec![0; i+1];
            vi[0] = 1;
            vi[i] = 1;
            for j in 1..i/2+1 {
                vi[j] = (v[i-1][j-1] + v[i-1][j]) % p;
                vi[i-j] = vi[j];
            }
        }
        else {
            vi = vec![0; k+1];
            vi[0] = 1;
            if i < 2 * k {
                for j in 1..i/2+1 {
                    vi[j] = (v[i-1][j-1] + v[i-1][j]) % p;
                    let jx = i - j;
                    if jx <= k {
                        vi[jx] = vi[j];
                    }
                }
            } else {
                for j in 1..k+1 {
                    vi[j] = (v[i-1][j-1] + v[i-1][j]) % p;
                }
            } 
        }
        v.push(vi);
    }
    return v;
}

fn solve(n: usize, k: usize) {
    let p : u64 = (10u32.pow(9u32) + 7) as u64;

    // 1. Calculate values of combinations
    let m = cmp::max(k-1, n-k+1);
    let c = prepare(m, k, p);

    // 2. Calculate possible ways
    for i in 1..k+1 {
        let b = c[k-1][i-1];
        let r = if i > n-k+1 { 
            0
        } else {
            c[n-k+1][i]
        };
        let t = b * r % p;
        println!("{}", t);
    }
}


Measured memory_bytes: 17804
#!/usr/bin/perl
#A - Christmas Eve Eve Eve - AtCoder Beginner Contest 115

use strict;
use warnings;

# データ取得
my ($data_num);
my ($price);
my ($sum);
my ($max);

    {
        $data_num = <STDIN>;
        chomp($data_num);
    }

    my ($i);
    $max = 0;
    $sum = 0;
    for ($i = 0 ; $i < $data_num ; $i++) {

        $price = <STDIN>;
        $sum += $price;
        $max = ($max < $price) ? $price : $max;
    }

    $sum = $sum - ($max >> 1);

print("$sum\n");

exit(0);


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

struct second_order {
    bool operator()(const pair<int,int>& x, const pair<int,int>& y) const {
        return x.second > y.second;
    }
};

int main() {
    int n,k; cin >> n >> k;
    map<int,int> mp;
    rep(i, n) {
        int t; cin >> t;
        mp[t]++;
    }
    vector<pair<int,int>> v;
    auto begin = mp.begin(); auto end = mp.end();
    for (auto itr=begin; itr != end; itr++) {
        v.push_back(make_pair(itr->second, itr->first));
    }

    int now = mp.size();
    int ans = 0;
    sort(v.begin(),v.end());
    rep(i, v.size()) {
        if(now <= k) break;
        ans += v[i].first;
        now--;
    }

    cout << ans << endl;

    return 0;
}

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  string s;cin>>s;
  vector<ll>a(n-1);
  rep(i,0,n-1)a[i]=abs(s[i+1]-s[i]);
  bool one=false;
  ll ret=1;
  rep(i,0,n-1){
    if(a[i]==1)one=true;
  }
  if(!one){
    ret=2;  
  }
  ll sum=0;
  ll now=1;
  //debug(a,n-1);
  rep(i,0,n-1){
    bool sw=false;
    sw=(n-2==(n-2|i));
    //if(sw)cout<<i<<endl;
    if(a[i]!=ret)continue;
    ll d=n-2-i;
    
    if(sw){
      sum^=ret;
    }
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 9116
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next());
    String s = sc.next();

    if(a>=3200){
      System.out.println(s);
    }
    else{
      System.out.println("red");
    }
  }
} 

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N,K; cin>>N>>K;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  sort(ALL(A));
  int ans=0;
  rep(i,0,K){
    ans+=A[N-1-i];
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;

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

int main() {
    ll N;
    cin >> N;
    ll a[N];
    ll XOR = 0;
    rep(i,N){
        cin >> a[i];
        if(i==0) XOR = a[i];
        else XOR = XOR^a[i];
    }
    rep(i,N){
        ll out = a[i]^XOR;
        cout << out << endl;
    }
    return 0;
}



Measured memory_bytes: 5164
n = int(input())
a = list(map(int, input().split())) 
s = 0
ans = [0]*n
for i in range(0,n):
    s = s ^ a[i]
for i in range(0,n):
    ans[i] = s ^ a[i]
for  item in ans:
    print(item,end=' ')

Measured memory_bytes: 31664
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

pts = [0 for _ in range(n)]
for i in range(q):
    pts[a[i] - 1] += 1

for i in range(n):
    if k - (q - pts[i]) > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 13720
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String s[]=new String[n];
        for(int i=0;i<n;i++){
            s[i]=sc.next();
        }
        int acount=0;
        int bcount=0;
        int count=0;
        int both=0;
        for(int i=0;i<n;i++){
            if(s[i].charAt(0)=='B') bcount++;
            if(s[i].charAt(s[i].length()-1)=='A') acount++;
            if(s[i].charAt(0)=='B' &&s[i].charAt(s[i].length()-1)=='A') both++;
            for(int k=0;k<s[i].length()-1;k++){
                if(s[i].charAt(k)=='A' && s[i].charAt(k+1)=='B') count++;
            }
        }
        int min=Math.min(acount,bcount);
        if(both==0 ||acount+bcount-both*2>0) System.out.println(count+min);
        else  System.out.println(both+count-1);
        
        
    }
}

Measured memory_bytes: 32148
n, q = map(int, input().split())
d = {1: [0, 0]}
for i in range(n-1):
    a, b = map(int, input().split())
    d[b] = [a, 0]

for i in range(q):
    p, x = map(int, input().split())
    d[p][1] += x

for i in range(2, n+1):
    d[i][1] += d[d[i][0]][1]

l = []
for i in sorted(d.keys()):
    l.append(d[i][1])
    
print(" ".join(map(str, l)))

Measured memory_bytes: 72840
s = input()
t = input()
m = 0
ans = 0
for i in range(len(s)-len(t)+1):
    c = 0
    for j in range(len(t)):
        if s[i+j] == t[j]:
            c += 1
    if c >= m:
        m = c
        ans = len(t) - c

print(ans)

Measured memory_bytes: 67736
#include <algorithm>
#include <iostream>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n /= 2LL;
  }
  return res;
}

int main() {
  ll n, ans = 0LL;
  cin >> n;
  vector<ll> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  sort(c.begin(), c.end());
  for (ll i = 0; i < n; i++) {
    ans += c[n - 1 - i] * (i + 2LL);
    ans %= MOD;
  }
  ans *= mod_pow(2LL, 2LL * n - 2LL, MOD);
  ans %= MOD;
  cout << ans << endl;
}

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

int main(){
  string S;
  cin>>S;
  int n=S.size();
  vector<ll> s(n);
  for(int i=0;i<n;i++){
    s.at(i)=S.at(n-1-i)-'0';
  }

  ll ans=0;
  for(int i=0;i<(1<<(n-1));i++){
    vector<ll> op(n,0);
    int res=i;
    for(int i=0;i<n-1;i++){
      op.at(i)=res%2;
      res/=2;
    }
    ll dig=1;
    for(int i=0;i<n;i++){
      ans+=s.at(i)*dig;
      if(op.at(i)==1){
        dig=1;
      }else{
        dig*=10;
      }
    }
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
typedef pair <int, int> P;

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

    int n;
    cin >> n;

    vector <P> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec[i].first;
        vec[i].second = i + 1;
    }

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

    for (P p : vec) {
        cout << p.second << ' ';
    }

    cout << "\n";
    return 0;
}

Measured memory_bytes: 1664