akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<complex>

using namespace std;


//union find木(グループわけができる)
int par[200010];
int unifind(int n) {
             for (int i = 0; i < n; i++) {
                           par[i] = i;
             }
             return 0;
}
             //木の根を求める
int unifind_root(int x) {
             if (par[x] == x) {
                           return x;
             }
             else {
                           return par[x] = unifind_root(par[x]);
             }
}
             //同じグループか判定
bool unifind_same(int x, int y) {
             return unifind_root(x) == unifind_root(y);
}
             //グループ併合
int unifind_unite(int x, int y) {
             x = unifind_root(x);
             y = unifind_root(y);
             if (x == y) {
                           return 0;
             }
             par[x] = y;
}
 

const long long int mod=1000000007;
int main(){
	cout << fixed << setprecision(18);
	long long int n,m,h,w,res=0,l,r,memo[200004][2]={};
	string str[500];
	char ch;
	cin>>n;
	for(int i=1;i<20000;i++)
	{
		if((i*i+i)/2>=n)
		{
			res=(i*i+i)/2-n;
			r=i;
			break;
		}
	}
	for(int i=1;i<=r;i++)
	{
		if(i==res)
		{
			continue;
		}
		cout<<i<<endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:1048576")  
using namespace std;

#define mp make_pair  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef tuple <int, int, int> t3;

int IT_MAX = 1 << 17;
const ll MOD = 1000000009;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<(n);i++)

char in1[100] = "CODEFESTIVAL2016";
char in2[100];

int main() {
	scanf("%s", in2);

	int i, ans = 0;
	for (i = 0; in1[i] != 0; i++) if (in1[i] != in2[i]) ans++;
	return !printf("%d\n", ans);
}

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

int main() {
    int N;
    string S,T;
    char temp;
    cin >> N;
    cin >> S >> T;

    for (int i =0; i < N; i++){
        cout << S.at(i) << T.at(i);
    }

    cout << endl;
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
int B[20];
int main() {
	int N, M, C;
	cin >> N >> M >> C;
	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int sum = C;
		for (int j = 0; j < M; j++) {
			int A;
			cin >> A;
			sum += A * B[j];
		}
		if (sum > 0) ans++;
	}
	cout << ans << endl;
 }

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;

int f[5][110];
int n,a[5][110];

int main()
{
   	cin>>n;
   	for(int i=1;i<=2;++i)
   		for(int j=1;j<=n;++j)
   			cin>>a[i][j];
   	f[1][1]=a[1][1];
   	for(int i=1;i<=n;++i)
   		for(int j=1;j<=2;++j)
   			f[j][i]=a[j][i]+max(f[j-1][i],f[j][i-1]);
	cout<<f[2][n]<<endl;
    return 0;	 
}

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

using namespace std;

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

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

ll N, K;
ll a[101010];
ll ans = 0;

void solve() {
    cin >> N >> K;
    rep(i,N) cin >> a[i];
    ll sum[N+1] = {};
    sum[1] = a[0];
    REP(i,1,N) sum[i+1] = sum[i] + a[i];
    ll p[N+1] = {};
    if (a[0] >= 0) p[1] = a[0];
    REP(i,1,N) {
        if (a[i] >= 0) p[i+1] = p[i] + a[i];
        else p[i+1] = p[i];
    }
    REP(i,K,N+1) {
        ans = max({ans, sum[i] - sum[i-K] + p[N] - (p[i] - p[i-K]), p[N] - (p[i] - p[i-K])});
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 2560
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


int main() {
    int N, K;
    cin >> N >> K;
    vint V(N);
    rep(i, N) {
        cin >> V[i];
    }
    ll ans = 0;
    rep(i, K) { // 削除を何回行うか
        int M = min(N, K - i);//取れる個数
        REP(l, 0, M + 1) { // 左から何個取るか
            int r = M - l;
            vint ext(M);
            int u = 0;
            rep(t, l) {
                ext[u] = V[t];
                u++;
            }
            for (int t = N - 1; t >= N - r; t--) {
                ext[u] = V[t];
                u++;
            }
            sort(ext.begin(), ext.end());
            ll s = 0;
            int skip_num = 0;
            rep(t, M) {
                if (ext[t] < 0 && skip_num < i) {
                    skip_num++;
                }
                else{
                    s += ext[t];
                }
            }
            ans = max(ans, s);
            
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> b.at(i);
  }
  
  int ans = b.at(0);
  for (int i = 0; i < n - 1; i++) {
    if (i == n - 2) {
      ans += b.at(i);
    }
    else {
      ans += min(b.at(i), b.at(i + 1));
    }
  }
  cout << ans << endl;
}


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

int main (void){
	int s,i=1;
	cin >> s;
	while(1){
		if(s==4||s==2||s==1) break;
		if(s%2==0) s=s/2;
		else s=3*s+1;
		i++;
	}
	cout << i+3 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

void solve(){
     int x;cin >> x;
     if(x>=1800) cout << 1;
     else if(x>=1600) cout << 2;
     else if(x>=1400) cout << 3;
     else if(x>=1200) cout << 4;
     else if(x>=1000) cout << 5;
     else if(x>=800) cout << 6;
     else if(x>=600) cout << 7;
     else cout << 8;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3636
import Text.Printf

poland :: [String]->[Double]->[Double]
poland [] stack = stack
poland (x:xs) stack
    | x=="+"    = poland xs (((stack!!1)+(stack!!0)):(drop 2 stack))
    | x=="-"    = poland xs (((stack!!1)-(stack!!0)):(drop 2 stack))
    | x=="*"    = poland xs (((stack!!1)*(stack!!0)):(drop 2 stack))
    | x=="/"    = poland xs (((stack!!1)/(stack!!0)):(drop 2 stack))
    | otherwise = poland xs ((read x::Double):stack)

solve :: String->IO ()
solve str = do
    printf "%.6f\n" $ head $ poland (words str) []

main :: IO ()
main = do
    ss <- getContents
    mapM_ solve $ lines ss

Measured memory_bytes: 4396
#include<bits/stdc++.h>
#define ll long long 
#define print(ds) for(auto i:ds){cout<<i<<" ";} cout<<endl;
#define printpair(pairs) cout<<pairs.first<<" "<<pairs.second<<endl;
#define p2v(v) for(int i=0; i<v.size();i++){ for(int j=0; j<v[i].size();j++){ cout<<v[i][j]<<" ";} cout<<endl;}
#define pp pair <ll, ll>
#define mod 1000000007
#define large 1e6
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int32_t main(){
    fastio;
    int n;
    cin>>n;
    int cnt = 0;
    bool ans = false;
    for(int i=0; i<n;i++){
        int a, b;cin>>a>>b;
        if(a==b){
            cnt++;
        }
        else{
            cnt=0;
        }
        if(cnt==3) ans =true;
    }
    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   string S;
   cin >> S;
   int N = int(S.size());
   int low = 1, high = N;
   while (low < high) {
      int mid = (low + high) >> 1;
      bool good = false;
      for (int z = 0; z < 2; ++z) {
         int l = z, r = mid;
         if ((r - l) & 1) --r;
         bool fail = false;
         for (int i = 0; i < N; ++i) {
            if (S[i] == '1') {
               ++l, ++r;
            } else if (S[i] == '0') {
               --l, --r;
            } else {
               --l, ++r;
            }
            if (l < 0) l += 2;
            if (r > mid) r -= 2;
            if (l > r) {
               fail = true;
               break;
            }
         }
         if (!fail) good = true;
      }
      if (good) high = mid;
      else low = mid + 1;
   }
   cout << low << "\n";
   return 0;
}


Measured memory_bytes: 4280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		String S = reader.next();
		char[] arr = S.toCharArray();
		int[] accumulateE = new int[N+2];
		int[] accumulateW = new int[N+2];

		for (int i = 1; i <= N; i++) {
			accumulateW[i] = accumulateW[i-1];
			if (arr[i-1] == 'W') {
				accumulateW[i]++;
			}
		}

		for (int i = N - 1; i >= 0; i--) {
			accumulateE[i] = accumulateE[i+1];
			if (arr[i] == 'E') {
				accumulateE[i]++;
			}
		}

		int min = N;
		for (int i = 0; i < N; i++) {
			int count = accumulateW[i];
			if (i < N - 1) {
				count += accumulateE[i+1];
			}
			if (count < min) {
				min = count;
			}
		}

		reader.close();
		System.out.print(min);
	}
}



Measured memory_bytes: 31968
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int a; cin>>a;
    string s; cin>>s;
    cout << (a >= 3200 ? s : "red") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
const int MAX = 3000;
long long fac[MAX], finv[MAX], inv[MAX];
ll po(ll i){
  ll ret = 1;
  ll pp = 10;
  while(i){
    if(i&1)ret*=pp;
    ret%=2019;
    pp *= pp;
    pp %=2019;
    i /=2;
  }
  return ret;
}
ll sum[200005];
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin >> s;
  ll n = s.size();
  reverse(all(s));
  ll now = 0;
  map<ll,ll> se;
  rep(i,n){
    now = now + (s[i] - '0') *po(i);
    now%=2019;
    se[now]++;
  }
  ll ans = 0;
  for(auto it : se){
    ll ele = it.first;
    ll num = it.second;
    cerr << ele << " " << num << endl;
    if(ele==0){
      ans += (num+1) * num/2;
    }else{
      ans += num * (num-1) / 2;
    }
  }
  cout << ans << endl;


}

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

int main() {
    int L,R,d;
    cin >> L >> R >> d;

    int sum  = 0;
    for(int i = L; R >= i; i++){
        if(i % d == 0){
            sum++;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>

using namespace std;
int main() {
  int h, w, k;
  cin >> h >> w >> k;
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  x1--, y1--, x2--, y2--;
  vector<string> mat(h);
  for (int i = 0; i < h; ++i)
    cin >> mat[i];
  vector<vector<int>> dist(h, vector<int>(w, -1));
  vector<set<int>> row(h), col(w);
  vector<vector<int>> llim(h, vector<int>(w)), rlim(h, vector<int>(w)),
      ulim(h, vector<int>(w)), dlim(h, vector<int>(w));
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j) {
      if (mat[i][j] == '@' || (i == x1 && j == y1))
        continue;
      row[i].insert(j);
      col[j].insert(i);
    }
  for (int i = 0; i < h; ++i) {
    int l = -1;
    for (int j = 0; j < w; ++j) {
      llim[i][j] = l;
      if (mat[i][j] == '@')
        l = j;
    }
    int r = w;
    for (int j = w - 1; j >= 0; --j) {
      rlim[i][j] = r;
      if (mat[i][j] == '@')
        r = j;
    }
  }
  for (int j = 0; j < w; ++j) {
    int u = -1;
    for (int i = 0; i < h; ++i) {
      ulim[i][j] = u;
      if (mat[i][j] == '@')
        u = i;
    }
    int d = h;
    for (int i = h - 1; i >= 0; --i) {
      dlim[i][j] = d;
      if (mat[i][j] == '@')
        d = i;
    }
  }
  queue<pair<int, int>> q;
  q.push({x1, y1});
  dist[x1][y1] = 0;
  while (!q.empty()) {
    auto [i, j] = q.front();
    q.pop();
    vector<pair<int, int>> nxt;

    // row
    if (!row[i].empty()) {
      auto it = row[i].upper_bound(j);
      for (auto it1 = it; it1 != row[i].end(); ++it1) {
        if (*it1 - j > k || *it1 >= rlim[i][j])
          break;
        nxt.emplace_back(i, *it1);
      }
      if (it != row[i].begin()) {
        it--;
        for (auto it2 = it; it2 != row[i].begin(); --it2) {
          if (j - *it2 > k || *it2 <= llim[i][j])
            break;
          nxt.emplace_back(i, *it2);
        }
        if (j - *row[i].begin() <= k && *row[i].begin() > llim[i][j])
          nxt.emplace_back(i, *row[i].begin());
      }
    }

    // col
    if (!col[j].empty()) {
      auto it = col[j].upper_bound(i);
      for (auto it1 = it; it1 != col[j].end(); ++it1) {
        if (*it1 - i > k || *it1 >= dlim[i][j])
          break;
        nxt.emplace_back(*it1, j);
      }
      if (it != col[j].begin()) {
        it--;
        for (auto it2 = it; it2 != col[j].begin(); --it2) {
          if (i - *it2 > k || *it2 <= ulim[i][j])
            break;
          nxt.emplace_back(*it2, j);
        }
        if (i - *col[j].begin() <= k && *col[j].begin() > ulim[i][j])
          nxt.emplace_back(*col[j].begin(), j);
      }
    }

    for (auto [ci, cj] : nxt) {
      dist[ci][cj] = dist[i][j] + 1;
      if (ci == x2 && cj == y2) {
        cout << dist[ci][cj];
        exit(0);
      }
      q.push({ci, cj});
      row[ci].erase(cj);
      col[cj].erase(ci);
    }
  }
  cout << -1;
}

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

int main(){
 int n,tc=0,hc=0;
 string taro,hanako;

 cin >> n ;
 for (int i=0;i<n;i++){
  cin >> taro >> hanako ;
  if(taro>hanako)tc+=3;
  else if(taro<hanako)hc+=3;
  else {
   tc++;
   hc++;
  }
 }

 cout << tc << " " << hc << endl;

 return 0;
}

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

int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int count = 0;
    for (int i = 0; i <= A; i++){
        for (int j = 0; j <= B; j++){
            for (int k = 0; k <= C; k++){
                if (500 * i + 100 * j + 50 * k == X){
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import sys
#import numpy as np
#from collections import defaultdict
import math
#from collections import deque

#input = sys.stdin.readline
import numpy as n



def main():


    S = input()
    T = input()

    ans = 0
    for i in range(len(S)):
        if S[i] == T[i]:
            ans += 1

    print(len(S) - ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 27336
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
bool mp[1000][1000];
int r,c;

queue<pii> bfs(queue<pii> que)
{
	queue<pii> q;
	while(!que.empty())
	{
		pii p=que.front(); que.pop();
		if(p.F<r-1 && !mp[p.F+1][p.S]) {q.emplace(p.F+1,p.S); mp[p.F+1][p.S]=true;}
		if(p.F>0   && !mp[p.F-1][p.S]) {q.emplace(p.F-1,p.S); mp[p.F-1][p.S]=true;}
		if(p.S<c-1 && !mp[p.F][p.S+1]) {q.emplace(p.F,p.S+1); mp[p.F][p.S+1]=true;}
		if(p.S>0   && !mp[p.F][p.S-1]) {q.emplace(p.F,p.S-1); mp[p.F][p.S-1]=true;}
	}
	return q;
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>r>>c;
	queue<pii> que;
	char ch;
	For(i,0,r-1)
	{
		For(j,0,c-1)
		{
			cin>>ch;
			mp[i][j]=(ch=='#'?true:false);
			if(mp[i][j]) que.emplace(i,j);
		}
	}
	//queue<pii> tmp=que;
	//while(!tmp.empty())
	//{
	//	cout<<tmp.front().F<<" "<<tmp.front().S<<"\n";
	//	tmp.pop();
	//}
	//cout<<"\n\n";
	int ans=0;
	while(!que.empty())
	{
		que=bfs(que);
		ans++;
		//queue<pii> tmp=que;
		//while(!tmp.empty())
		//{
		//	cout<<tmp.front().F<<" "<<tmp.front().S<<"\n";
		//	tmp.pop();
		//}
		//cout<<"\n\n";
	}
	cout<<ans-1<<"\n";
	return 0;
}








Measured memory_bytes: 17552
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, k, l, m;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n){
        int inp;
        cin >> inp;
        a[i] = inp;
    }
    m = k - a[n-1] + a[0];
    rep(i,n-1){
        l = a[i+1] - a[i];
        m = max(m,l);
    }
    cout << k-m << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main()
{
    long n, k;
    cin >> n >> k;

    vector<long> vec(n);
    for (long i = 0; i < n; i++)
    {
        long h;
        cin >> h;
        vec[i] = h;
    }

    sort(vec.begin(), vec.end(), greater<long>());

    long sum = 0;
    for (long i = 0; i < n; i++)
    {
        if (k > 0)
        {
            k--;
            continue;
        }
        
        sum += vec[i];
    }
    
    cout << sum << endl;

    return 0;
}

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

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(e, x) for (auto &e : x)
#define dbg(x) #x << ": " << x <<
#define sz(x) ((int)x.size())

const int N = 1e5;
int ac[N + 1], wa[N + 1];

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, m; cin >> n >> m;
	rep(i, 0, m) {
		int p; cin >> p; string s; cin >> s; --p;
		if (s == "AC") ++ac[p];
		else if (ac[p] == 0) ++wa[p];
	}

	int correct = 0, penalty = 0;
	rep(i, 0, n)
		if (ac[i] > 0) {
			++correct;
			penalty += wa[i];
		}
	cout << correct << ' ' << penalty << ' ';
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"strconv"
	"strings"
)

func (p *problem) solve() {
	N := p.NextInt()
	P := p.NextInts()
	end := N - 1
	var cnt int
	for i := 1; i < end; i++ {
		if P[i-1] > P[i] || P[i] < P[i+1] {
			if P[i-1] < P[i] || P[i] > P[i+1] {
				cnt++
			}
		}
	}
	p.PrintInt(cnt)
}

var (
	debug  bool
	output string
)

func main() {
	flag.BoolVar(&debug, "debug", false, "Print debug logs")
	flag.BoolVar(&debug, "d", false, "Print debug logs")
	flag.StringVar(&output, "output", "stdout", "Specify output target (Default: stdout)")
	flag.StringVar(&output, "o", "stdout", "Specify output target (Default: stdout)")
	flag.Parse()

	if debug {
		out := os.Stdout
		if output != "stdout" {
			logfile, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY, 0666)
			if err != nil {
				panic(err)
			}
			defer logfile.Close()
			out = logfile
		}
		log.SetOutput(out)
	} else {
		log.SetOutput(ioutil.Discard)
	}

	p := problem{
		in:  bufio.NewReader(os.Stdin),
		out: bufio.NewWriter(os.Stdout),
	}
	p.solve()

	if err := p.out.Flush(); err != nil {
		panic(err)
	}
}

type problem struct {
	in  *bufio.Reader
	out *bufio.Writer
}

func (p *problem) PrintInt(d int) {
	p.Printf("%d\n", d)
}

func (p *problem) Printf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, format, a...); err != nil {
		panic(err)
	}
}

func (p *problem) Printfln(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(p.out, fmt.Sprintf("%v\n", format), a...); err != nil {
		panic(err)
	}
}

func (p *problem) NextInt() int {
	return stoi(p.Next())
}

func (p *problem) NextInts() []int {
	line := p.NextSSLine()
	ds := make([]int, len(line))
	for i, s := range line {
		ds[i] = stoi(s)
	}
	return ds
}

func (p *problem) NextSSLine() []string {
	return strings.Split(p.Next(), " ")
}

// Next reads line and return string.
func (p *problem) Next() string {
	var b []byte
	for {
		l, pre, err := p.in.ReadLine()
		if err != nil {
			panic(err)
		}
		b = append(b, l...)
		if !pre {
			break
		}
	}
	return string(b)
}

func stoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		fmt.Println(i)
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

ll dp[101010][2];

int main(){
	string s;
	cin >> s;
	int sz = s.size();

	dp[0][0] = 1;
	rep(i, 0, sz) {
		if (s[i] == '0') {
			dp[i+1][0] += dp[i][0];
			dp[i+1][1] += 3*dp[i][1];
			dp[i + 1][0] %= MOD;
			dp[i + 1][1] %= MOD;
		}
		else {
			dp[i + 1][0] += 2*dp[i][0];
			dp[i + 1][1] += dp[i][0]+3*dp[i][1];
			dp[i + 1][0] %= MOD;
			dp[i + 1][1] %= MOD;
		}
	}
	cout << (dp[sz][0] + dp[sz][1])%MOD << endl;

	return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<string>

using namespace std;

int ChangeFromStringToInt(string);
string ChangeFromIntToString(int);
void Atoi(int&, string&, int, char);

int main(){
  int i, n, a, b;
  string s, t, ans;

  cin >> n;

  for(i=0; i<n; ++i){
    cin >> s >> t;

    a = ChangeFromStringToInt(s);
    b = ChangeFromStringToInt(t);
    ans = ChangeFromIntToString(a+b);

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

int ChangeFromStringToInt(string s){
  int i, x, ans;

  for(i=0, x=1, ans=0; i<s.size(); ++i){
    if(s[i] >= '2' && s[i] <= '9'){
      x = s[i] - 48;
    }else{
      if(s[i] == 'm') ans += 1000*x;
      else if(s[i] == 'c') ans += 100*x;
      else if(s[i] == 'x') ans += 10*x;
      else if(s[i] == 'i') ans += x;
      x = 1;
    }
  }
  return ans;
}

string ChangeFromIntToString(int x){
  string s;
  Atoi(x, s, 1000, 'm');
  Atoi(x, s, 100, 'c');
  Atoi(x, s, 10, 'x');
  Atoi(x, s, 1, 'i');
  return s;
}

void Atoi(int& x, string& s, int l, char c){
  char _c;
  _c = x/l + 48;
  if(_c == '1'){
    s.push_back(c);
  }else if(_c >= '2' && _c <= '9'){
    s.push_back(_c);
    s.push_back(c);
  }
  x %= l;
}

Measured memory_bytes: 0
#include <iostream>
#include <climits>

#define ll long long
#define inf LONG_LONG_MAX
ll a[200001];
int lc = 1, rc = 3;

ll abs(ll n) {
    if (n < 0)
        return -n;
    return n;
}

ll getmin(int sc, int n) {
    int newlc, newrc;

    int i = lc;
    while(i < sc && abs(a[sc] - 2 * a[i]) >= abs(a[sc] - 2 * a[i + 1])) {
        i++;
    }
    newlc = i;

    i = rc;
    while(i < n && abs(a[sc] + a[n] - 2 * a[i]) >= abs(a[sc] + a[n] - 2 * a[i + 1])) {
        i++;
    }
    newrc = i;

    lc = newlc;
    rc = newrc;
    ll q[4];
    q[0] = a[lc];
    q[1] = a[sc] - a[lc];
    q[2] = a[rc] - a[sc];
    q[3] = a[n] - a[rc];
    ll min = q[0];
    ll max = q[0];
    for (int i = 1; i < 4; i++) {
        if (min > q[i])
            min = q[i];
        if (max < q[i])
            max = q[i];
    }
    ll ans = max - min;
    return ans;
}

int main()
{
    int n;
    std::cin >> n;
    a[0] = 0;
    for (int i = 1; i <= n; i++) {
        std::cin >> a[i];
        a[i] += a[i - 1];
    }
    ll min = inf;
    for (int i = 2; i <= n - 2; i++) {
        ll ans = getmin (i, n);
        if (ans < min)
            min = ans;
    }
    std::cout << min;
}


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

int main(){

    int N;
    cin >> N;

    vector<int> A(N+1, 0);
    for(int i = 0; i < N+1; i++){
        cin >> A.at(i);
    }

    vector<int> B(N, 0);
    for(int i = 0; i < N; i++){
        cin >> B.at(i);
    }

    long long sum = 0;
    for(int i = 0; i < N; i++){

        if(A.at(i) < B.at(i)){
            B.at(i) = B.at(i) - A.at(i);
            sum += A.at(i);
            A.at(i) = 0;

            if(A.at(i+1) < B.at(i)){
                B.at(i) = B.at(i) - A.at(i+1);
                sum += A.at(i+1);
                A.at(i+1) = 0;
            }else{
                A.at(i+1) = A.at(i+1) - B.at(i);
                sum += B.at(i);
                B.at(i) = 0;
            }

        }else{
            A.at(i) = A.at(i) - B.at(i);
            sum += B.at(i);
            B.at(i) = 0;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;

    vector<int> step;
    int cnt = 0;
    rep(i, (int)s.size()){
        if(s[i] == 'F'){
            cnt++;
            if(i == (int)s.size() - 1) step.push_back(cnt);
        }else{
            step.push_back(cnt);
            cnt = 0;
        }
    }

    set<int> prev_x, prev_y;
    prev_x.insert(step[0]);
    prev_y.insert(0);
    for(int i = 1; i < (int)step.size(); i++){
        set<int> next_x, next_y;
        if(i % 2 == 1){
            for(int yy : prev_y){
                next_y.insert(yy + step[i]);
                next_y.insert(yy - step[i]);
            }
            prev_y = next_y;
        }else{
            for(int xx : prev_x){
                next_x.insert(xx + step[i]);
                next_x.insert(xx - step[i]);
            }
            prev_x = next_x;
        }
    }
    if(prev_x.find(x) != prev_x.end() && prev_y.find(y) != prev_y.end()){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 768
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

d = ["" for i in range(K)]
for i in range(N):
    d[i%K] += T[i]

def score(dd):
    c = 0
    if dd[0] == "r": c += P
    if dd[0] == "s": c += R
    if dd[0] == "p": c += S

    if len(dd) >= 1:
        flag = 0
        for i in range(1,len(dd)):
            if dd[i] == dd[i-1] and flag == 1:
                if dd[i] == "r": c += P
                if dd[i] == "s": c += R
                if dd[i] == "p": c += S
                flag = 0
            elif dd[i] == dd[i-1] and flag == 0:
                flag = 1
            elif dd[i] != dd[i-1]:
                if dd[i] == "r": c += P
                if dd[i] == "s": c += R
                if dd[i] == "p": c += S
                flag = 0

    return c

total = 0
for dd in d:
    total += score(dd)

print(total)


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int a[3300];
int dp[3300][3300];
bool mou[3300][3300];
int dfs(int l, int r, bool taroh) {
    if (l + r == N) { return 0; }
    if (mou[l][r]) { return dp[l][r]; }
    mou[l][r] = true;
    if (taroh) {
        dp[l][r] = dfs(l + 1, r, false) + a[l];
        chmax(dp[l][r], dfs(l, r + 1, false) + a[N - r - 1]);
    } else {
        dp[l][r] = dfs(l + 1, r, true) - a[l];
        chmin(dp[l][r], dfs(l, r + 1, true) - a[N - r - 1]);
    }
    return dp[l][r];
}
signed main() {
    cin >> N;
    rep(i, N) { cin >> a[i]; }
    cout << dfs(0, 0, true) << endl;
}


Measured memory_bytes: 60392
from bisect import bisect_left, bisect_right
from itertools import combinations


if __name__ == "__main__":
    N, K, L, R = map(lambda x: int(x), input().split())
    coins = list(map(lambda x: int(x), input().split()))

    N_half = N // 2
    c1 = [list(map(sum, combinations(coins[:N_half], i))) for i in range(0, N_half + 1)]
    c2 = [list(map(sum, combinations(coins[N_half:], i)))
          for i in range(0, N - N_half + 1)]
    for i in range(0, N - N_half + 1):
        c2[i].sort()

    ans = 0
    for i in range(0, K + 1):
        if K - i < 0 or K - i > N - N_half or i > N_half:
            continue
        for a in c1[i]:
            low = bisect_left(c2[K - i], L - a)  # type: ignore
            high = bisect_right(c2[K - i], R - a)  # type: ignore
            ans += high - low

    print(ans)



Measured memory_bytes: 89588
#include <iostream>

using namespace std;

int main(){

	int data[10000+1];
	for(int i=0;i<=10000;i++){
		data[i]=0;
	}
	data[0] = 1;

	for(int i=1;i<=10000;i++){
		data[i] = data[i-1] + i;
	}

	int num;
	while(cin>>num){
		cout<<data[num]<<endl;
	}

	return 0;

}

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

void main_()
{
    ll N, K;
    vector<ll> As;
    cin >> N >> K;
    copy_n(istream_iterator<ll>(cin), N, back_inserter(As));

    map<ll, ll> balls_map;
    for (auto a : As) {
        balls_map[a]++;
    }
    vector<ll> balls;
    for (auto&& bm : balls_map) {
        balls.push_back(bm.second);
    }

    // 減らさなければいけない番号の数
    auto dec_num = max(static_cast<ll>(balls.size()) - K, 0L);

    // ボールの数が少ない番号から減らさなければならない種類の数だけカウント
    sort(begin(balls), end(balls));
    ll ans = accumulate(begin(balls), begin(balls) + dec_num, 0LL);

    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

int main()
{
	int N, X, i, D, c;
	int L[128];
	D = 0;
	scanf("%d", &N);
	scanf("%d", &X);
	for (i = 1; i < N + 1; i++) 
	{
		scanf("%d", &L[i]);
	}
	for (c = 1; c < N + 1; c++) 
	{
		D += L[c];
		if (D > X) 
		{
			break;
		}
	}
	printf("%d", c);

	
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("Ofast")
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
	
#define int long long
#define double long double 
#define PI 3.141592653589793
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
// Use for file I/O;
#define FIN string _fname = "homework"; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);

using namespace std;
	
int gcd(int a, int b) {
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

const int INF = 4e18 + 10;
const int INF2 = 2e18 + 10;
const int INF3 = 2e10;
const int MAXN = 303;
const int LOGN = 19;
const int MOD = 1e9 + 7;
const int EPS = 1e-9;
const int MULT = 2e5;
const int MCNST = MOD * MOD * 8;

int dp[400][400];
int a[400], p[401];

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

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			dp[i][j] = INF;
		}
	}
	p[0] = 0;
	for (int i = 0; i < n; i++) {
		p[i + 1] = p[i] + a[i];
	}

	for (int i = 0; i < n; i++) {
		dp[i][i] = 0;
	}

	for (int l = 2; l <= n; l++) {
		for (int i = 0; i <= n - l; i++) {
			for (int j = i; j < i + l; j++) {
				dp[i][i + l - 1] = min(dp[i][i + l - 1], dp[i][j] + dp[j + 1][i + l - 1] + p[i + l] - p[i]);
			}
		}
	}
	cout << dp[0][n - 1];
}

Measured memory_bytes: 4868
from math import floor, ceil

H, W = map(int,input().split(" "))


if H == 1 or W == 1:
    ans = 1
elif H%2 == 0:
    ans = (H//2)*W
elif W%2 == 0:
    ans = (W//2)*H
else:
    ans = 0
    ans += floor(H/2) * floor(W/2)
    ans += ceil(H/2) * ceil(W/2)


print(int(ans))



Measured memory_bytes: 3060
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
 
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
 
T lread(T = long)()
{
    return readln.chomp.to!T();
}
 
T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}
 
void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto a = lread();
    (a%2?a*2:a).writeln();
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))

char s[3010],t[3010];
ll sn,tn;
ll dp[3010][3010];
int main(){
	scanf("%s %s",s,t);
	sn=strlen(s);
	tn=strlen(t);
	rep(i,1,sn+1)rep(j,1,tn+1){
		//もらうDP
		if(s[i-1]==t[j-1])dp[i][j]=dp[i-1][j-1]+1;
		else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
	}
	
	char ans[3010]="";
	int len=dp[sn][tn];
	while(len){
		if(dp[sn][tn]==dp[sn-1][tn])sn--;
		else if(dp[sn][tn]==dp[sn][tn-1])tn--;
		else{
			ans[--len]=s[sn-1];
			sn--;
			tn--;
		}
//		printf("%lld %lld\n",sn,tn);
	}
	puts(ans);
	return 0;
}

Measured memory_bytes: 70784
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, D = MAP()
X = [LIST() for _ in range(N)]

def distance(A, B):
	sum = 0
	for i in range(D):
		sum += (A[i]-B[i])**2

	if sqrt(sum)%1 == 0:
		return 1
	else:
		return 0

cnt = 0
for i in range(N-1):
	for j in range(i+1, N):
		cnt += distance(X[i], X[j])

print(cnt)

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

std::vector<string> generateIncNum(std::vector<string> c, int digits)
{
    if(digits == 1)
        return c;
    
    std::vector<string> new_c;
    for(string s : c)
    {
        new_c.push_back("3" + s);
        new_c.push_back("5" + s);
        new_c.push_back("7" + s);
    }
    c = new_c;
    return generateIncNum(new_c, digits - 1);
}

int main()
{
//    string a = "999999999";
  	string a;
    cin >> a;
    int a_num = std::stoi(a);
 
    int ret = 0;
    int digits = a.size();
    if(digits < 3)
    {
        ret = 0;
    }
    else
    {
        for(int i = 3; i < digits; i++)
            ret += pow(3, i) - 3 * pow(2, i) + 3;
        
        std::vector<string> c = {"3", "5", "7"};
        auto cc = generateIncNum(c, digits);
        for(string s : cc)
        {
            int num = std::stoi(s);
            if (num <= a_num)
            {
                if(std::count_if( s.begin(), s.end(), []( char c ){ return c == '3';}) == 0)
                    continue;
                if(std::count_if( s.begin(), s.end(), []( char c ){ return c == '5';}) == 0)
                    continue;
                if(std::count_if( s.begin(), s.end(), []( char c ){ return c == '7';}) == 0)
                    continue;
                ret++;
            }
        }
        
    }
    
    cout << ret;
    return 0;
}


Measured memory_bytes: 2300
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <sstream>
using namespace std;

#define namefile ""
#define inifile freopen(namefile".inp","r",stdin); freopen(namefile".out","w",stdout)
#define fastio ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef unsigned int uint;
typedef unsigned long ulong;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef vector<int> VI;
typedef vector<long> VL;
typedef vector<string> VS;
typedef vector< VI > VVI;
typedef vector< VL > VVL;
typedef vector< PII > VPII;
typedef vector< PLL > VPLL;
typedef set<int> SETI;
typedef set<long> SETL;
typedef map<int,int> MII;
typedef map<long,long> MLL;

const long long MOD = 1e9+7;
const long long INFMAX = 1e9;
const long long INFMIN = -1e9;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const double epsilon = 1e-9;
const double PI = acos(-1.00);

string s,t;

VVI g;
llong res(0);

void Input()
{
    cin >> s;
    cin >> t;
}

void Solve()
{
    g.resize(130);
    for (int i=0; i<s.size(); i++) g[(int)s[i]].pb(i);

    int id(-1);
    for (int i=0; i<t.size(); i++)
    {
        int idt = (int)t[i];
        VI :: iterator it = upper_bound(g[idt].begin(), g[idt].end(), id);
        if (it != g[idt].end()) id = *it; else
        {
            if (g[idt].size() == 0)
            {
                res = -1;
                break;
            }
            else
            {
                res++;
                id = g[idt][0];
            }
        }
    }

    if (res != -1) res = (s.size()*res) + id + 1;
}

void Output()
{
    cout << res;
}

int main()
{
    fastio;
    Input();
    Solve();
    Output();
    return 0;
}


Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
ll n;
cin >> n;
ll a[n];
for (ll i = 0; i < n; i++) cin >> a[i];
map<ll, bool> mp;
for (ll i = 0; i < n;i++){
    if(mp[a[i]]){
        mp[a[i]] = false;
        continue;
    }
    else{
        mp[a[i]] = true;
        continue;
    }
}
ll cnt = 0;
for(auto i:mp)
    if (i.second) cnt++;
cout << cnt << endl;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e5+10;
int main()
{
    FASTINOUT;
    int x,k;
    cin>>x>>k;
    int y[x];
    for (int i=0;i<x;i++)
        cin>>y[i];
    sort(y,y+x);
    ll sum=0;
    for (int i=x-k-1;i>=0;i--)
        sum+=y[i];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll a, b;
	cin >> a >> b;
	if ( a > b )
		swap (a,b);
	if ( a > 0 and b > 0)
		return cout << "Positive",0;
	if ( a <= 0 and b >= 0)
		return cout << "Zero",0;
	ll d = abs (a - b);
	if ( d%2 == 1 )
		return cout << "Positive",0;
	cout << "Negative";
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

const ll MAX_N=1001;

ll lcs(string a,string b){

  ll c[MAX_N][MAX_N];
  ll as=a.size();
  ll bs=b.size();
  a.insert(0," ");
  b.insert(0," ");

  CLR(c,0);
  rep(i,1,as+1){
    rep(j,1,bs+1){
      if(a[i]==b[j])c[i][j]=c[i-1][j-1]+1;
      else chmax(c[i][j],max(c[i-1][j],c[i][j-1]));
    }
  }

  return c[as][bs];
}

int main(){

  ll n;cin>>n;

  while(n--){
    string a,b;cin>>a>>b;
    out(lcs(a,b));
  }

  return 0;
}



Measured memory_bytes: 11036
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
    int n;
    cin >> n;
    int A[n];
    for(int i(0);i<n+1;i++) cin >> A[i];
    int B[n];
    for(int i(0);i<n;i++) cin >> B[i];
    
    long cnt(0);
    
    for(int i(0);i<n;i++){
        
        if(A[i] >= B[i]){
            cnt += B[i];
            A[i] -= B[i];
            //B[i]=0;
        }else if(A[i] < B[i]){
            cnt += A[i];
            int tmp = B[i] - A[i];
            A[i] = 0;
            
            if(A[i+1] <= tmp){
                cnt += A[i+1];
                A[i+1] = 0;
            }else if(A[i+1] > tmp){
                cnt += tmp;
                A[i+1] -= tmp;
            }
        }
    }
    
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 1024