akhauriyash/Code-Regression huggingface dataset:
MOD = 10**9 + 7
S = input()
res = 0
dp0 = 1 # ''
dp1 = 0 # 'a'
dp2 = 0 # 'ab'
dp3 = 0 # 'abc'

for c in S:
    if c == 'A':
        dp1 += dp0
    elif c == 'B':
        dp2 += dp1
    elif c == 'C':
        dp3 += dp2
    else:
        dp0,dp1,dp2,dp3 = dp0*3,dp1*3+dp0,dp2*3+dp1,dp3*3+dp2
    dp0 %= MOD
    dp1 %= MOD
    dp2 %= MOD
    dp3 %= MOD
print(dp3)


Measured memory_bytes: 9148
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#define loop(i,a,b) for(int i=a; i<b; i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

using namespace std;

typedef vector<int> vi;

int main(){
    int n;
    while (cin >> n && n){
        vi v(n);
        int c = 0;
        rep(i, n) cin >> v[i];
        while(1){
            vi next(n);
            map<int, int> m;
            rep(i, n) m[v[i]]++;
            rep(i, n) next[i] = m[v[i]];
            if (next == v) break;
            c++;
            v = next;
        }

        cout << c << endl;
        rep(i, n - 1){
            cout << v[i] << " ";
        }
        cout << v.back() << endl;
    }
}

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

int main(){
    int n;
    cin >> n;
    string ans;
    while(true){
        if (n%(-2) == 0) {
            ans = "0" + ans;
            n = n/(-2);
        }
        else
        {
            n = (n-1)/(-2);
            ans = "1" + ans;
        }

        if (n == 0) {
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma region template
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define vint vector<int>
#define vll vector<ll>
#define vstr vector<string>
#define vbl vector<bool>
#define pb push_back
using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {x++;}
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> inline T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> inline T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> inline T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}template<class T> inline T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> inline T sum(vector<T>v){return reduce(all(v),0LL);}
#pragma endregion template

void solve(ll N, vector<ll> B) {
  ll ans = B.at(0);
  rep2(i, 1, N - 2) ans += min(B.at(i - 1), B.at(i));
  cout << ans + B.at((int)B.size() - 1) << endl;
}

int main() {
  ll N;
  ignore_ret(scanf("%lld",&N));
  vector<ll> B(N-1);
  for(int i = 0 ; i < N-1 ; i++){
    ignore_ret(scanf("%lld",&B[i]));
  }
  solve(N, move(B));
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
  int n;
  int a[100000], b[100000];

  scanf("%d", &n);
  int t = -1, num;
  for(int i = 0; i < n; i++){
    scanf("%d %d", &a[i], &b[i]);
    if(a[i] > t){
      t = a[i];
      num = i;
    }
  }

  long long res = a[num] + b[num];
  printf("%lld\n", res);

  return 0;
}


Measured memory_bytes: 1656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll int n;
    cin>>n;
    string t;
    set<string>s;
    for(ll int i=0;i<n;i++)
    {
        cin>>t;
        s.insert(t);
    }
    cout<<s.size();
    return 0;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int a, p;
    cin >> a >> p;
    cout << (3 * a + p) / 2 << endl;

    return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

  int n, m, u, v;
  cin >> n >> m;
  vector<vector<int>> g(n);
  vector<int> deg(n);
  for (int i = 0; i < n - 1 + m; i++) {
    cin >> u >> v;
    u--; v--;
    g[u].push_back(v);
    deg[v]++;
  }

  vector<int> par(n, -1);
  vector<int> q;
  for (int i = 0; i < n; i++) {
    if (deg[i] == 0) {
      q.push_back(i);
    }
  }
  assert(q.size() == 1);

  while (q.size()) {
    u = q.back(); q.pop_back();
    for (auto v : g[u]) {
      deg[v]--;
      if (deg[v] == 0) {
        q.push_back(v);
        par[v] = u;
      }
    }
  }

  for (auto i : par) {
    cout << i + 1 << '\n';
  }

  return 0;
}


Measured memory_bytes: 9516
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long n,m;

int main(){
	cin>>n>>m;
	if(n==1&&m==1){
		cout<<1<<endl;
	}else if(n==1||m==1){
		cout<<max(n,m)-2<<endl;
	}else{
		cout<<(n-2)*(m-2)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, K, A[112345];
std::set<LL>dif, dic;

int main()
{
	in >> N >> K;
	rep(i, N) { in >> A[i]; }

	std::sort(A, A + N);
	rep(i, N)
	{
		if (i < N - 1) { dif.insert(A[i] - A[i + 1]); }
		if (A[i] > K) { dic.insert(A[i] - K); }
		if (A[i] == K)
		{
			out << "POSSIBLE" << std::endl;
			return 0;
		}
	}
	for (auto i : dif)
	{
		for (auto j : dic)
		{
			if (i == 0) { continue; }
			if (j%i == 0)
			{
				out << "POSSIBLE" << std::endl;
				return 0;
			}
		}
	}
	out << "IMPOSSIBLE" << std::endl;
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  string s; cin >> s;
  ll N = s.length();
  ll r = 0;
  ll c = 0;
  vector<ll> v (N);
  for(ll i = 0; i < N; i++) v[i] = s[i] - '0';
  vector<vector<ll>> dp (N, vector<ll> (10, INT_MAX));
  for(ll i = 0; i < 10; i++){
    ll r = (v[0] + i) / 10;
    ll val = (v[0] + i) % 10;
    dp[0][i] = min(val, 10 - val + 1) + r;
  }
  for(ll i = 1; i < N; i++){
    for(ll j = 0; j <= 9; j++){
      ll r = (v[i] + j) / 10;
      ll val = (v[i] + j) % 10;
      dp[i][j] = min(
        val + dp[i-1][r],
        10 - val + dp[i-1][r+1]
      );
    }
  }
  cout << dp[N-1][0] << endl;
}


Measured memory_bytes: 126212
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void yn(bool ok){if(ok) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1e18;
const int mx=200005;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int cnt=0;
    rep(i,s.size()) cnt+=s[i]-'0';
    yn(cnt%9==0);
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep (i,n) cin >> a[i];
  vector<int> ans(n);
  //気分的にはans[a[i]]=iにしたいけどindexとかの関係で
  rep (i,n) ans[a[i]-1]=i+1;
  rep (i,n) {
     cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>

static const int N =100;

int min(int a,int b){
  if(a<b) return a;
  else return b;
}

int main(){
  int l,i,j,k,n,p[N+1],m[N+1][N+1];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  for(i=1;i<=n;i++) m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=(1<<21);
      for(k=i;k<=j-1;k++){
	m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

struct BIT{
private:
    vector<ll> a;
    int n;
public:
    BIT(int sz){
        n=sz;
        a.resize(sz+1);
    }
    ll sum(int i){
        ll res=0;
        while(i>0){
            res+=a[i];
            i-=i&-i;
        }
        return res;
    }
    ll sum(int i,int j){
        return sum(j)-sum(i-1);
    }
    void add(int i,ll x){
        while(i<=n){
            a[i]+=x;
            i+=i&-i;
        }
    }
};

int main(){
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    ll ans=LINF;
    int p[n]={};
    for(int i=0;i<(n+1)/2;i++){
        p[n-1-i]=1;
    }
    do{
        bool flag=true;
        vector<pair<int,int>> ev;
        vector<pair<int,int>> od;
        for(int i=0;i<n;i++){
            if(p[i]){
                if(i%2==0)ev.push_back({a[i],i});
                else ev.push_back({b[i],i});
            }
            else{
                if(i%2==0)od.push_back({b[i],i});
                else od.push_back({a[i],i});
            }
        }
        sort(ev.begin(),ev.end());
        sort(od.begin(),od.end());
        int t=-1;
        ll sum=0;
        BIT bit(n);
        for(int i=0;i<(n/2)*2;i++){
            if(i%2==0){
                if(t>ev[i/2].first){
                    flag=false;
                }
                t=ev[i/2].first;
                sum+=abs(ev[i/2].second+bit.sum(ev[i/2].second+1,n)-i);
                bit.add(ev[i/2].second+1,1);
            }
            else{
                if(t>od[i/2].first){
                    flag=false;
                }
                t=od[i/2].first;
                sum+=abs(od[i/2].second+bit.sum(od[i/2].second+1,n)-i);
                bit.add(od[i/2].second+1,1);
            }
        }
        if(n&1){
            if(t>ev.back().first){
                flag=false;
            }
        }
        if(flag){
            ans=min(ans,sum);
        }
    }while(next_permutation(p,p+n));
    if(ans==LINF)cout<<-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 256
S = input()

check = ('dream','dreamer','erase','eraser')

index = len(S) + 1
flag = True

while True:
    if len(S) == 0:
        break
    for c in check:
        if S[-len(c):] in check:
            S = S[:-len(c)]
            break
    else:
        flag = False
        break

print('YES' if flag else 'NO')

Measured memory_bytes: 9228
# -*- coding: utf-8 -*-
"""
https://abc060.contest.atcoder.jp/tasks/abc060_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(A, B, C):
    ans = 'NO'
    if A[-1] == B[0] and B[-1] == C[0]:
        ans = 'YES'
    return ans


def main(args):
    A, B, C = input().strip().split()
    ans = solve(A, B, C)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
#include<stdio.h>

typedef struct TREE{
	int id;
	struct TREE *parent;
	struct TREE *child[2];
	int depth;
	int height;
}Tree;

Tree tree[100];

int setDepthHeight(Tree *nt, int depth){
	if( nt == NULL ){ return -1; }
	nt->depth = depth;
	int lh = setDepthHeight(nt->child[0], depth+1);
	int rh = setDepthHeight(nt->child[1], depth+1);
	nt->height = (lh>rh?lh:rh) + 1;
	return nt->height;
}

void output(Tree *tr){
	char *nodetype[3] = {"root", "internal node", "leaf"};
	int pid, sibling = -1, degree = 0, ni;
	if( tr->child[0] != NULL ){ degree++; }
	if( tr->child[1] != NULL ){ degree++; }
	if( tr->parent != NULL ){
		if( tr->parent->child[0] != NULL && tr->parent->child[0]->id != tr->id ){
			sibling = tr->parent->child[0]->id;
		}else if( tr->parent->child[1] != NULL && tr->parent->child[1]->id != tr->id ){
			sibling = tr->parent->child[1]->id;
		}
		if( degree == 0 ){
			ni = 2;
		}else{
			ni = 1;
		}
		pid = tr->parent->id;
	}else{
		ni = 0;
		pid = -1;
	}
	printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", 
		tr->id, pid, sibling, degree, tr->depth, tr->height, nodetype[ni]
	);
	return;
}

int main(){
	int n, id, id2, i, j;
	Tree *root = NULL;
	scanf("%d", &n);
	for( i = 0; i < n; i++ ){
		tree[i].id = -1;
		tree[i].parent = NULL;
		tree[i].child[0] = NULL;
		tree[i].child[1] = NULL;
		tree[i].depth = -1;
		tree[i].height = -1;
	}
	for( i = 0; i < n; i++ ){
		scanf("%d", &id);
		tree[id].id = id;
		scanf("%d", &id2);
		if( 0 <= id2 && id2 < n ){
			tree[id].child[0] = &tree[id2];
			tree[id2].parent = &tree[id];
		}
		scanf("%d", &id2);
		if( 0 <= id2 && id2 < n ){
			tree[id].child[1] = &tree[id2];
			tree[id2].parent = &tree[id];
		}
	}
	for( i = 0; i < n; i++ ){
		if( tree[i].parent == NULL ){
			root = &tree[i];
			break;
		}
	}
	setDepthHeight(root, 0);
	for( i = 0; i < n; i++ ){ output(&tree[i]); }
	return 0;
}

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

int n, x;
int a[100005];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> x;
	for (int i = 1; i <= n; ++i) cin >> a[i];

	long long ans;
	for (int i = 2; i <= n; ++i) {
		if (a[i-1] + a[i] > x) {
			int s = a[i] + a[i-1] - x;
			a[i] -= s;
			ans += s;
			if (a[i] < 0) a[i] = 0;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  int cur = 1, ans = 0, found = false;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a == cur) {
      found = true;
      cur++;
    } else {
      ans++;
    }
  }

  cout << (found ? ans : -1) << '\n';

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
const int M = 305;
const int N = 305;
int main()
{
	int m, n;
	while(scanf("%d %d", &n, &m))
    {
    	bool ok = true, go = false;
    	if(n == 0 && m == n)
    	{
    		break;
		}
		for(int i = 0; i <n; i++)
		{
			if(ok)
			{
				go = true;
				for(int j = 0; j < m; j++)
				{
					if(go)
					{
					printf("#");
					go = false;
					}
					else
					{
						printf(".");
						go = true;
					}
				} 
				printf("\n");
				ok = false;
				}
			else
			{
				go = true;
				for(int j = 0; j < m; j++)
				{
					if(go)
					{
					printf(".");
					go = false;
					}
					else
					{
						printf("#");
						go = true;
					}
					
				} 
				printf("\n");
				ok = true;
			}
								
		}
		printf("\n");
		
	}
	
	return 0;
} 


Measured memory_bytes: 2620
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD 1000000007
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
ll ncr[2005][2005];
ll compute(int n, int r)
{
    if(n < 0 || r < 0) return 0;
    if(ncr[n][r] != -1) return ncr[n][r];
    if( n < r) return ncr[n][r] = 0;
    if( r == 0) return ncr[n][r] = 1;
    return ncr[n][r] = (compute(n-1, r)%MOD + compute(n-1, r-1)%MOD)%MOD;
}
int main()
{
    she_told_me_dont_worry
    ll n, k;
    memset(ncr, -1, sizeof ncr);
    cin>>n>>k;
    ll dp[n+5] = {};
    int i;
    dp[i] = 0;
    FOR(i, 1, k+1)
    {
        dp[i] = (compute(n-k+1, i)%MOD*compute(k-1, i-1)%MOD)%MOD;
        cout<<dp[i]<<endl;
    }
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

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

using namespace std;

typedef long long ll;

int getfa(int x, vector<int> &fa) {
	return fa[x] == x ? x : (fa[x] = getfa(fa[x], fa));
}

int main() {
	int n, m = 0, x, y;
	scanf("%d", &n);
	vector<pair<int, int>> p;
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &x, &y);
		m = max(m, max(x, y));
		p.push_back(make_pair(x, y));
	}
	sort(p.begin(), p.end());
	vector<int> fa(m + 1, 0);
	vector<int> li(m + 1, 0);
	vector<int> po(m + 1, 0);
	for (int i = 1; i <= m; i++) {
		fa[i] = i;
		li[i] = 0;
		po[i] = 1;
	}
	ll ans = 0;
	for (int i = 0, j = 0; i < n; i = j) {
		while (j < n && p[i].first == p[j].first) j++;
		// cout << i << " " << j << endl;
		int f1 = getfa(p[i].second, fa), f2;
		ll tt = 1LL * li[f1] * po[f1];
		// cout << "=" << li[f1] << " " << po[f1] << " " << tt << endl;
		for (int k = i + 1; k < j; k++) {
			f2 = getfa(p[k].second, fa);
			if (f2 != f1) {
				fa[f2] = f1;
				li[f1] += li[f2];
				po[f1] += po[f2];
				tt += 1LL * li[f2] * po[f2];
			}
		}
		li[f1]++;
		tt += j - i;
		// cout << "=" << li[f1] << " " << po[f1] << " " << tt << endl;
		ans += 1LL * li[f1] * po[f1] - tt;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
  int A,B,C ;
  cin>>A>>B>>C ;
  
  if(A==B&&A==C) cout<<"No"<<endl ;
  else if(A!=B&&A!=C&&B!=C) cout<<"No"<<endl ;
  else cout<<"Yes"<<endl ;
  
  return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x,r;
    cin>>x;
    r=x%10;
    if(r==2||r==4||r==5||r==7||r==9)
        cout<<"hon"<<endl;
    else if(r==0||r==1||r==6||r==8)
        cout<<"pon"<<endl;
    else if(r==3)
        cout<<"bon"<<endl;

}


Measured memory_bytes: 3588
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;

int n, a[100005], ans, flag, t, q;

bool chack(int p) {
	if(a[p + 1] == a[p]) {p++;chack(p);}
	else if(a[p + 1] > a[p]) {q = p;flag = 1;}
	else if(a[p + 1] < a[p]) {q = p;flag = 0;}
}

int main()
{
	t = 0;
	ans = 1;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
	}
	if(a[t + 2] > a[t + 1]) {
		flag = 1;
	}
	else if(a[t + 2] < a[t + 1]) {
		flag = 0;
	}
	for(int i = 1; i <= n - 1; i++)
	{
		if(a[i + 1] > a[i] && flag == 1 || a[i + 1] < a[i] && flag == 0 || a[i + 1] == a[i])  t++;
		else {
			ans++;
			chack(i + 1);
			i = q - 1;
			t = 0;
		}
	}
	if(a[n] == a[n - 1]) ans--;
	printf("%d\n", ans);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,m,c,count=0;
	cin>>n>>m>>c;
	vector<int> b(m),a(m);

	for(auto& i:b)
		cin>>i;

	long long int dot_product;

	for(int i=0;i<n;i++){
		for(auto& i:a)
			cin>>i;

		dot_product=0;
		for(int i=0;i<m;i++)
			dot_product+=a[i]*b[i];

		if(dot_product + c > 0)
			count++;
	}
	cout<<count;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
// const ll INF = 1LL << 60;
const ll INF = 1000000000;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

// rep(i, 0, sz(v)) cout << v[i] << " \n"[i==sz(v)-1];

////////////////////////////////////////////////////////

int main() {
    ll n, q; 
    string s;
    cin >> n >> s >> q;

    vector<set<ll>> st(26);
    rep(i, 0, 26) st[i].insert(500001);

    rep(i, 0, n) st[s[i]-'a'].insert(i);

    Vl answ;
    rep(i, 0, q){
        ll qu; cin >> qu;
        if(qu == 1){
            ll i; char c;
            cin >> i >> c;
            i--;
            ll bf = s[i] - 'a';
            s[i] = c;
            st[bf].erase(i);
            ll af = c - 'a';
            st[af].insert(i);
        }
        if(qu == 2){
            ll x, y; cin >> x >> y;
            ll ans = 0;
            x--, y--;
            rep(i, 0, 26){
                ll r;
                r = *st[i].lower_bound(x);
                if(r <= y) ans++; 
            }
            answ.push_back(ans);
        }   
    }

    rep(i, 0, sz(answ)) co(answ[i]);

    return 0;
}
 
 


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



int main(){
    //input
    /*
    int A = 5;
    int B = 4;
    */
    int A,B;
    cin >> A >> B;
    if (A == B){
        cout << 2*A << endl;
    }
    else{
        cout << 2*max(A,B) - 1 << endl;
    }
    return 0;
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i, n) for(int i = 0; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}

int main() {
    int H, W; cin >>H>>W;
    vvi c(10, vi(10)); cin >> c;
    vvi A(H, vi(W)); cin >> A;

    rep(k, 10) rep(i, 10) rep(j, 10) chmin(c[i][j], c[i][k] + c[k][j]);    

    int ans = 0;
    rep(h, H) rep(w, W) if (A[h][w] != -1) ans += c[A[h][w]][1];
    cout << ans << endl;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  vector<int> sum(N + 1, 0);
  for (int i = 0; i < N; ++i) {
    cin >> W[i];
    sum[i + 1] += sum[i] + W[i];
  }
  int min_diff = 100000;
  for (int i = 0; i < N; ++i) {
    int s1 = sum[i];
    int s2 = sum[N] - s1;
    int diff = abs(s1 - s2);
    if (diff < min_diff) min_diff = diff;
  }
  cout << min_diff << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

unordered_map<long long, int, custom_hash> safe_map;

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    char ch;
    cin>>ch;
    cout<<(char)(ch+1),nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 256
item = gets.chomp.split(/\s+/).map { |e| e.to_i }

n = item[0]
k = item[1]

h = gets.chomp.split(/\s+/).map { |e| e.to_i }.sort

if n <= k
  puts "0"
else
  puts h[0..h.size-k-1].inject(:+)
end


Measured memory_bytes: 21352
while True:
    list = input().split()
    a = int(list[0])
    b = int(list[2])
    op = list[1]
    if op == "?": break
    elif op == "+": print(int(a+b))
    elif op == "-": print(int(a-b))
    elif op == "*": print(int(a*b))
    elif op == "/": print(int(a/b))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> lP;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    int n; cin>>n;
    vector<P> red;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        P v=P(a,b);
        red.push_back(v);
    }
    vector<P> blue;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        P v=P(a,b);
        blue.push_back(v);
    }

    sort(red.begin(),red.end());
    sort(blue.begin(),blue.end());
    vector<bool> id(n,true);

    rep(i,n){
        P v=blue[i];
        int maxy=-1;
        int maxj=-1;
        rep(j,n){
            P w=red[j];
            if(v.first>w.first&&v.second>w.second&&id[j]){
                if(maxy<w.second){
                    maxy=w.second;
                    maxj=j;
                }
            }
        }
        if(maxy==-1) continue;
        else id[maxj]=false;
    }
    int ans=0;
    rep(i,n){
        if(!id[i]) ans++;
    }
    cout<<ans<<endl;

}

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

int main(){
    int R, C, N;
    cin >> R >> C >> N;
    map<int, int> mp[4];

    auto onside = [&](int x, int y){ return (x==0 || x==R || y==0 || y==C); };
    for(int i=0; i<N; i++){
        int x[2], y[2];
        cin >> x[0] >> y[0] >> x[1] >> y[1];
        if(onside(x[0], y[0]) && onside(x[1], y[1])) for(int k=0; k<2; k++){
            if(x[k] == 0){
                mp[0][y[k]] = i;
            }else if(y[k] == C){
                mp[1][x[k]] = i;
            }else if(x[k] == R){
                mp[2][-y[k]] = i;
            }else if(y[k] == 0){
                mp[3][-x[k]] = i;
            }
        }
    }

    vector<int> order;
    for(int k=0; k<4; k++) for(auto& p : mp[k]) order.push_back(p.second);

    stack<int> stk;
    for(int a : order){
        if(stk.size() && stk.top() == a){
            stk.pop();
        }else{
            stk.push(a);
        }
    }
    cout << (stk.size() ? "NO" : "YES") << endl;
}

Measured memory_bytes: 10748
var
    n,m,i,j,x,cnt:longint;
    a:array[0..501,0..501] of longint;
    x1,y1,x2,y2:array[0..250001] of longint;
begin
    readln(n,m);
    cnt:=0;
    for i:=1 to n do
        begin 
            for j:=1 to m-1 do
                begin
                    read(x);inc(a[i,j],x);
                    if odd(a[i,j]) then 
                        begin
                            inc(cnt);
                            x1[cnt]:=i;x2[cnt]:=i;y1[cnt]:=j;y2[cnt]:=j+1;
                            inc(a[i,j+1]);
                        end;
                end;
            read(x);inc(a[i,m],x);
            if odd(a[i,m]) then 
                begin
                    inc(cnt);
                    x1[cnt]:=i;x2[cnt]:=i+1;y1[cnt]:=m;y2[cnt]:=m;
                    inc(a[i+1,m]);
                end;
        end;
    if odd(a[n,m]) then dec(cnt);
    writeln(cnt);
    for i:=1 to cnt do
        writeln(x1[i],' ',y1[i],' ',x2[i],' ',y2[i]);
end.

Measured memory_bytes: 5888
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};
int N,M,ope[33],dist[33];
bool field[33][33];

void input(){
    int i;
    rep(i,N){
        int x,y; cin >> x >> y;
        field[y][x] = true;
    }
    cin >> M;
    rep(i,M){
        char dir; cin >> dir >> dist[i];
        if( dir == 'S' ) ope[i] = 1;
        if( dir == 'N' ) ope[i] = 0;
        if( dir == 'E' ) ope[i] = 2;
        if( dir == 'W' ) ope[i] = 3;
        //cout << "dir=" << dir << " , dist=" << dist[i] << endl;
    }
}

int main(){
    int i;

    while( cin >> N, N ){
        memset(field, false, sizeof(field));
        input();

        int cnt = 0;
        int sx = 10, sy = 10;

        rep(i,M){
            int tx = sx + dx[ope[i]] * dist[i];
            int ty = sy + dy[ope[i]] * dist[i];
            for(;;){
                //printf("(%d,%d)\n",sx,sy);
                if( field[sy][sx] ){
                    field[sy][sx] = false;
                    cnt++;
                }
                if( tx == sx && ty == sy ) break;
                sx += dx[ope[i]];
                sy += dy[ope[i]];
            }
        }
        puts(cnt == N ? "Yes" : "No");
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int 	     	  long long   // [9,223,372,036,854,775,807 to -9.....808] 19 digits
#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define mp                make_pair
#define vi                vector<int>
#define vpi               vector<pair<int,int>>
#define mii               map<int,int>
#define x                 first
#define y                 second
#define mem(a,x)          memset(a,x,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define sz(x)             (int)((x).size())
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order()  // order_of_key
 
//const int32_t hellhsh = 444440583533; const double pi=2*acos(0.0);
const int32_t mod = 1e9+7;
const int32_t maxn=3e5+5;
int inf=1e18;
 
int n,m,k;
int r[maxn],c[maxn];
set<pair<int,int>> s;
 
void solve(){
    cin>>n>>m>>k;
    rep(i,0,k){
        int x,y;cin>>x>>y;
        r[x]++;
        c[y]++;
        s.insert({x,y});
    }
    int ans=0;
    int rmx=max_element(r,r+maxn)-r;
    int cmx=max_element(c,c+maxn)-c;
 
    rep(i,0,maxn){
        int res1=r[i]+c[cmx]-s.count({i,cmx});
        int res2=c[i]+r[rmx]-s.count({rmx,i});
        ans=max({ans,res1,res2});
    }
    cout<<ans;
 
}
 
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc=1,k=1;
    //cin>>tc;
    while(tc--){
        //cout<<"Case #"<<k++<<": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 27076
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = 998244353;
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}

const int N = 100100;
int a[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int n;
	scanf("%d", &n);
	int x;
	scanf("%d", &x);
	if (x != 0) {
		printf("0\n");
		return 0;
	}
	a[0] = 1;
	for (int i = 1; i < n; i++) {
		scanf("%d", &x);
		a[x]++;
	}
	if (a[0] != 1) {
		printf("0\n");
		return 0;
	}
	while(a[n] == 0) n--;
	ll ans = 1;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < a[i + 1]; j++)
			ans = mult(ans, a[i]);
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    NLIST = list(lines.pop(0))
    zero = 0
    one = 0
    for i in NLIST:
        if i == '1':
            one += 1
        else:
            zero += 1
    print(min(one,zero) * 2)
    
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 4084
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <ll> v;

ll fep(ll x, ll y, ll mod)
{ll res=1;while(y>0){if(y&1)res=(res*x)%mod;
    y=y>>1;x=(x*x)%mod;}return res%mod;}

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

	ll n,i,m,j,k,x,y,a=0,b,t,c;
	string s;
	
	cin >> n >> k;
	a=(n/k)*k;
	b=(1+n/k)*k;
	cout << min(n-a,b-n);
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int>>
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long>>
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
string an="";
void check(string S,string T,int st){
    REP(i,SZ(S)){
        if(i<st||i>=st+SZ(T)){
            if(S[i]=='?')S[i]='a';
        }
        else{
            if(S[i]=='?')S[i]=T[i-st];
            if(S[i]!=T[i-st])return;
        }
    }
    if(an==""||an>S)an=S;
}
int main(){
    string S,T;
    cin>>S>>T;
    REP(i,SZ(S)-SZ(T)+1){
        check(S,T,i);
    }
    if(an=="")cout<<"UNRESTORABLE";
    else cout<<an;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
S = [list(map(int, input().split())) for _ in range(N)]

dpA = [0]*N
dpB = [0]*N
dpC = [0]*N
dpA[0] = S[0][0]
dpB[0] = S[0][1]
dpC[0] = S[0][2]

for i in range(1, N):
    dpA[i] = max(dpB[i-1], dpC[i-1]) + S[i][0]
    dpB[i] = max(dpC[i-1], dpA[i-1]) + S[i][1]
    dpC[i] = max(dpA[i-1], dpB[i-1]) + S[i][2]

print(max(dpA[N-1],dpB[N-1],dpC[N-1]))

Measured memory_bytes: 61148
import Control.Monad
import Data.List

main = do
    [n, m] <- fmap read <$> words <$> getLine
    x      <- fmap read <$> words <$> getLine
    putStrLn $ show $ solve n m x

solve :: Int -> Int -> [Int] -> Int
solve n m x = sum $ take (m - n) dx
  where
    dx = sort $ map (\(a, b) -> b - a) $ zip sx $ drop 1 sx
    sx = sort x

Measured memory_bytes: 32764
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  string S;
  cin >> S;
  
  int zero = 0, one = 0;
  for(int i = 0;i < S.size(); i++){
    if(S[i]=='0')zero++;
    else one++;
  }
  
  cout << min(zero,one) * 2 << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] abt = sc.nextLine().split(" ");
        int A = Integer.parseInt(abt[0]);
        int B = Integer.parseInt(abt[1]);

        int max = Math.max(A, B) * 2;
        if (A == B) {
            System.out.println(max);
        } else {
            System.out.println(max - 1);
        }
    }

}


Measured memory_bytes: 22612
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
int f[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    r(n); r(m);
    LL ans=0;
    FOR(i,1,n){
        r(f[i]);
    }
    sort(f+1,f+n+1);
    FOR(i,1,n-m){
        ans+=f[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val (row, col) = readLine()!!.split(" ").map { it.toInt() }
    val m = ArrayList<String>(row)
    repeat(row) {
        m.add(readLine()!!)
    }

    var best = 0
    (0 until row).forEach { r ->
        (0 until col).forEach { c ->
            if (m[r][c] == '.') {
                val temp = dijkstra(r, c, row, col, m)
                best = Math.max(best, temp)
            }
        }
    }
    println(best)
}

data class T(val cost: Int, val r: Int, val c: Int) : Comparable<T> {
    override fun compareTo(other: T): Int {
        return cost.compareTo(other.cost)
    }
}

fun dijkstra(r: Int, c: Int, row: Int, col: Int, m: List<String>): Int {
    val visit = ArrayList<BooleanArray>(row)
    repeat(row) { visit.add(BooleanArray(col) { false }) }
    val q = PriorityQueue<T>()
    q.add(T(0, r, c))
    visit[r][c] = true

    var best = 0
    while (q.isNotEmpty()) {
        val now = q.poll()
        best = Math.max(best, now.cost)
        if (now.r > 0 && m[now.r - 1][now.c] == '.' && !visit[now.r - 1][now.c]) { // LEFT
            visit[now.r-1][now.c] = true
            q.add(T(now.cost + 1, now.r - 1, now.c))
        }
        if (now.r < row - 1 && m[now.r + 1][now.c] == '.' && !visit[now.r + 1][now.c]) { // RIGHT
            visit[now.r+1][now.c] = true
            q.add(T(now.cost + 1, now.r + 1, now.c))
        }
        if (now.c > 0 && m[now.r][now.c - 1] == '.' && !visit[now.r][now.c - 1]) { // UP
            visit[now.r][now.c-1] = true
            q.add(T(now.cost + 1, now.r, now.c - 1))
        }
        if (now.c < col - 1 && m[now.r][now.c + 1] == '.' && !visit[now.r][now.c + 1]) { // DOWN
            visit[now.r][now.c+1] = true
            q.add(T(now.cost + 1, now.r, now.c + 1))
        }
    }
    return best
}

/*
20 20
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
 */


Measured memory_bytes: 42912
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <map>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr int MOD = 998244353;

ll N, K;


int main() {
  cin >> N;

  ll ans = INF;
  for(ll i = 1; i*i <= N; ++i) {
    if(N % i == 0) {
      ans = min(ans, i + N / i);
    }
  }
  cout << ans - 2;;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
 
 
 
int N;
vector<int> E[101010];
//---------------------------------------------------------------------------------------------------
int cnt[101010];
int dfs(int cu, int pa = -1) {
    cnt[cu] = 1;
    int g = 0;
    for (int to : E[cu]) if (to != pa) {
        g ^= dfs(to, cu);
        cnt[cu] += cnt[to];
    }

    if (cnt[cu] == 1) return 1;
    else return g + 1;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    while (cin >> N) {
        rep(i, 0, N + 1) E[i].clear();

        rep(i, 0, N - 1) {
            int a, b; cin >> a >> b;
            E[a].push_back(b);
            E[b].push_back(a);
        }

        int g = 0;
        for (int to : E[1]) g ^= dfs(to, 1);

        if (g == 0) printf("Bob\n");
        else printf("Alice\n");
    }
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
void print() {
    cout << endl;
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
using ll = long long;
const int INF = 1001001001;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    bool flag = false;
    rep(k1, K+1) {
        rep(k2, K+1) {
            rep(k3, K+1) {
                if(k1+k2+k3<=K) {
                    int red = A*1<<k1;
                    int green = B*1<<k2;
                    int blue = C*1<<k3;
                    if(red<green && green<blue) {
                        flag = true;
                    }
                }
            }
        }
    }
    if(flag) {
        print("Yes");
    } else {
        print("No");
    }
    
    return 0;
}

Measured memory_bytes: 3588
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    std::string s, ans;
    std::cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'B') { ans = ans.substr(0, ans.length() - 1); }
        else if (s[i] == '0')
        {
            ans += '0';
        }
        else
        {
            ans += '1';
        }
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

#define MAX 1000002
typedef unsigned char byte;   // ???????????§????????????0??¨1???????????????????????±????????????
byte mask[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};

int Lv[MAX];
int n, k;

bool cmp_Lv(const int i, const int j){ return Lv[i] < Lv[j]; }

bool cmp(const int i, const int j){
    if(Lv[i] != Lv[j]){ return Lv[i] < Lv[j]; }
    int L_i = (i + k >= n ? -1 : Lv[i + k]);
    int L_j = (j + k >= n ? -1 : Lv[j + k]);

    return L_i < L_j;
}

int main()
{
    int A[MAX];
    //std::string T;
	char c[MAX];
    //std::cin >> T;
	scanf("%s", c);
	std::string T = std::string(c);
    n = T.size();
    byte *t;
    t = new byte [(n >> 3) + 1];  // ??¬???????????´??°???1??¨0???????????°?????\????????¨????????´?°??????????????????§???????????§??????

    int i;
    for(i = 0; i < n; i++){ A[i] = i; }
    for(i = 0; i < n; i++){ Lv[i] = T[i]; }
    std::sort(A, A + n, cmp_Lv);

    for(i = 1; i < n; i++){
        t[i >> 3] = (Lv[A[i]] != Lv[A[i - 1]] ? t[i >> 3] | mask[i & 7] : t[i >> 3] & ~mask[i & 7]);
    }  // ????????±??????????????????8?????????????????????0??¨1???????´??????????????????????

    Lv[A[0]] = 0;
    for(i = 1; i < n; i++){
        Lv[A[i]] = Lv[A[i - 1]] + !!(mask[i & 7] & t[i >> 3]); 
    } // 0???1????????????????????????0???0??§??????????????????????????¢??°!!????????????

    k = 1;
    while(1){
        if(k > n) break;

        std::sort(A, A + n, cmp);
 
        for(i = 1; i < n; i++){
            t[i >> 3] = (cmp(A[i - 1], A[i]) ? t[i >> 3] | mask[i & 7] : t[i >> 3] & ~mask[i & 7]);
        }
        Lv[A[0]] = 0;
        for(i = 1; i < n; i++){
            Lv[A[i]] = Lv[A[i - 1]] + !!(mask[i & 7] & t[i >> 3]);
        }

        if(Lv[A[n - 1]] == n - 1) break;
        k <<= 1;
    };

    char p[1000];  // ????????§char??????????????¢???????¢????????????????
    int q, left, right, mid, crit;
    bool exist;
    scanf("%d", &q);

    A[n] = n;

    while(q){
        scanf("%s", p);
        std::string P = std::string(p);
        left = 0, right = n, exist = false;
        while(left < right){

            if(n < P.size()){ exist = false; break; }

            mid = (left + right) / 2;
            crit = T.compare(A[mid], P.size(), P);

            if(crit > 0){ right = mid; }
            else if(crit < 0){ left = mid + 1; }
            else{ exist = true; break; }
        };
        if(T.compare(A[right], P.size(), P) == 0) exist = true;
        if(exist){ printf("1\n"); }else{ printf("0\n"); }
        q--;
    }
    return 0;
}

Measured memory_bytes: 11044