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

#define rep(i,start,n) for(int i=start;i<(int)(n);i++)
#define rrep(i,n,end) for(int i=n-1;i>=end;i--)
#define each(it,v) for(auto it : v)
#define all(v) (v).begin(),(v).end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using vpii = vector<Pii>;
using vpll = vector<Pll>;

const ll mod=1e9+7;
const int intINF=INT_MAX;
const ll  longINF=LONG_LONG_MAX;

int ans[200200];
int cnt[200200];

main()
{
        int N,C; cin>>N>>C;
        vector<vi> v;
        int s,t,c;
        rep(i,0,N)
        {
                cin>>s>>t>>c;
                v.push_back({s,t,c});
        }
        int k=200020;
        rep(i,0,C)
        {
                rep(j,0,k)cnt[j]=0;
                rep(j,0,N)
                {
                        if(v[j][2]!=i+1)continue;

                        cnt[v[j][0]*2-1]++;
                        cnt[v[j][1]*2+1]--;
                }
                rep(j,1,k)cnt[j]+=cnt[j-1];
                rep(j,0,k)ans[j]+=cnt[j]>0;
                //rep(j,0,k)cout<<cnt[j]<<" ";
                //cout<<endl;
        }
        int x=0;
        rep(i,0,k)x=max(x,ans[i]);
        cout<<x<<endl;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i32 n,m; cin >> n >> m;

    /**
     * e,e
     * o,o
     */

    cout << n*(n-1)/2 + m*(m-1)/2 << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

int main(){
  char s[3];
  cin>>s[0]>>s[1]>>s[2];
  for(int i=0;i<3;i++){
    if(s[i]=='1'){
      s[i]='9';
    }else if(s[i]=='9'){
      s[i]='1';
    }
  }
  cout<<s[0]<<s[1]<<s[2]<<endl;
}


Measured memory_bytes: 256
s = input()
N = len(s)
ans = 0
for i in range(N):
    for j in range(i+1, N+1):
        ok = True
        for k in range(i, j):
            if s[k] not in 'ACGT':
                ok = False
        if ok:
            ans = max(ans, j - i)
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long int lli;
int main(void){
  int N,M;
  cin >> N >> M;
  priority_queue<lli> q;
  for(int i=0;i<N;i++){
    lli tmp;
    cin >> tmp;
    q.push(tmp);
  }
  for(int i=0;i<M;i++){
    lli top = q.top();
    if(top > 0){
      q.pop();
      top = top >> 1;
      q.push(top);
    }
  }
  lli sum = 0;
  for(int i=0;i<N;i++){
    lli tmp = q.top();
    q.pop();
    sum = sum + tmp;
  }
  cout << sum << endl;
  return 0;
 } 

Measured memory_bytes: 1400
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int A, B, M;
    cin >> A >> B >> M;

    vector<int> a(A);
    int mini = IINF;
    rep(i, A){
        cin >> a[i];
        chmin(mini, a[i]);
    }

    int ans = mini;

    vector<int> b(B);
    mini = IINF;
    rep(i, B){
        cin >> b[i];
        chmin(mini, b[i]);
    }

    ans += mini;

    rep(i, M){
        int x, y, c;
        cin >> x >> y >> c;
        --x;
        --y;
        chmin(ans, max(a[x] + b[y] - c, 0));
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 1024
N, K = map(int, input().split())
a = list(map(int, input().split()))
s = [0]
for i in range(N):
  s.append(s[i] + a[i])
# print(s)

b = []
for i1 in range(N):
  for i2 in range(i1+1, N+1):
    b.append(s[i2] - s[i1])
# print(b)
b.sort(reverse = True)
# print(b)

for sft in range(48):
  mask = 1 << (47 - sft)
  tmp_b = []
  for i in range(len(b)):
    if (b[i] & mask) != 0:
      tmp_b.append(b[i])
  # print(tmp_b)
  if len(tmp_b) >= K:
    b = tmp_b


ans = b[0]
for i in range(1, K):
  ans &= b[i]

print(ans)


Measured memory_bytes: 24256
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
N = inp.shift() * 1
s = inp.shift()
wc = 0
bc = 0
b = [0]
w = []
w[N+1] = 0
for (i=0;i<N;i++){
    if (s[i] == '#') {
        bc++
    }
    if (s[N-i-1] == '.') {
        wc++
    }
    b[i+1] = bc 
    w[N-i] = wc 
}
min = Infinity
for (i=0; i<=N; i++) {
    m = b[i] + w[i+1]
    if (m < min) {
        min = m
    }
}
console.log(min)

Measured memory_bytes: 21832
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    s = input()
    k = int(input())
    ss = set()
    alp = "abcdefghijklmnopqrstuvwxyz"
    for ai in alp:
        for i,si in enumerate(s):
            if si != ai:
                continue
            nw = ""
            for sj in s[i::]:
                nw += sj
                if len(nw) > 5:
                    break
                ss.add(nw)
        if len(ss) >= k:
            break
    print(sorted(ss)[k-1])



    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 75644
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  COMinit();
  int n,k; cin >> n >> k;
  
  int lim = COM(n-1,2);
  if(k > lim){
    puts("-1");
    return 0;
  }
  queue<pair<int,int>> q;
  //n-1の頂点が最短距離2で繋がるグラフをまず作成する。(限界値)
  for(int i=2;i <= n;i++){
    q.push({1,i});
  }
  
  int cnt = lim - k; //追加で線を引く回数
  
  for(int i=2; i<=n; i++){
    if(cnt == 0) break;
    for(int j=i+1; j<=n;j++){
      if(cnt == 0) break;
      q.push({i,j});
      cnt--;
    }
  }
  
  cout << q.size() << endl;
  while(!q.empty()){
    auto x = q.front(); q.pop();
    cout << x.first << " " << x.second << endl;
  }

  return 0;
}

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

int main() {

  int N;
  cin >> N;

  vector<int> A(N);

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

  bool flg = true;
  int answer = 0;

  while (flg) {
    for (int i = 0; i < N; i++) {
      if (A[i] % 2 != 0) {
        flg = false;
        break;
      }
      A[i] /= 2; 
    }
    if (flg) {
      answer++;
    }
  }
  
  cout << answer << endl;

}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

int main()
{
	IOS;
	int a[3];
	rep(i,3) cin >> a[i];
	sort(a,a+3);
	cout << a[2]-a[0] << endl;
	return 0;
}

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

bool like2017(int num) {
  if(num <= 2) return false;
  for(int i = 2; i * i <= num; ++i){
    if(num % i == 0) return false;
  }
  num = (num + 1) / 2;
  for(int i = 2; i * i <= num; ++i){
    if(num % i == 0) return false;
  }
  return true;
}

int A[100001];
int main(){
  for(int i = 1; i < 100001; ++i) {
    A[i] = A[i - 1] + like2017(i); 
  }
  
  int Q;
  cin >> Q;
  for(int i = 0; i < Q; ++i){
    int a,b;
    cin >> a >> b;
    cout << A[b] - A[a - 1] << endl; 
  }
  return 0;
}


Measured memory_bytes: 1024
n,y=map(int,input().split())

aa=-1
bb=-1
cc=-1

for a in range(n+1):
	for b in range(n+1):
		c=n-a-b
		if (c>=0)&(y==10000*a+5000*b+1000*c):
			aa=a
			bb=b
			cc=c
			break

print('{} {} {}'.format(aa,bb,cc))	

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-9;
const int inf=1e8;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int dp[41][410][410];
int main(){
	int n,ma,mb;
	cin>>n>>ma>>mb;
	vvi in(n,vi(3));
	rep(i,n)rep(j,3)cin>>in[i][j];
	rep(i,41)rep(j,410)rep(k,410)dp[i][j][k]=inf;
	dp[0][0][0]=0;
	rep(i,n)rep(j,410)rep(k,410)if(dp[i][j][k]!=inf){
		dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
		dp[i+1][j+in[i][0]][k+in[i][1]]=min(dp[i][j][k]+in[i][2],dp[i+1][j+in[i][0]][k+in[i][1]]);
	}
	int out=inf;
	loop(i,1,410)rep(j,410)if(ma*j==mb*i)out=min(out,dp[n][i][j]);
	if(out==inf)out=-1;
	cout<<out<<endl;
}











Measured memory_bytes: 27136
#include <bits/stdc++.h>
using namespace std;
#define N (int)2e5
int n,k,memo[N],c[N];

int dp(int curr) {
    if (curr == n) return 0;
    if (curr > n) return 1e9;
    int &sol = memo[curr];
    if (sol != -1) return sol;
    int keep = INT_MAX;
    for (int i = 1 ; i <= k ; i++) {
        keep = min(
            dp(curr + i) + abs(c[curr] - c[curr + i]) ,
            keep
        );
    }
    return sol = keep;
}

int main() {
    scanf("%d%d" , &n , &k);
    for (int i = 1 ; i <= n ; i++)
        scanf("%d" , &c[i]);
    memset (memo , -1 , sizeof memo);
    printf("%d\n" , dp(1));
}


Measured memory_bytes: 12796
/* attention to typo and overflow */
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;
const int INF=1<<25;
void io(){ cin.tie(0);ios::sync_with_stdio(false);} //attention to use of endl
/*printf("%.9Lf\n",cf);*/
vector <int> s;
int solve(vector <int> a){
	if(a.size()!=s.size()) return INF;
	int n=a.size();
	int ret=0;
	for(int i=0;i<n;i++){
		ret+=abs(s[i]-a[i]);
	}
	return ret;
}

int main(){
	io();
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(a==1){
			s.push_back(i);
		}
	}
	vector <int> obj;
	vector <int> obj2;
	int sum=0;
	for(int i=0;i<m;i++){
		if(i%2==0){
			int a;
			cin>>a;
			for(int j=sum;j<sum+a;j++){
				obj.push_back(j);
			}
			sum+=a;
		}else{
			int a;
			cin>>a;
			for(int j=sum;j<sum+a;j++){
				obj2.push_back(j);
			}
			sum+=a;
		}
	}

	/*for(int i=0;i<obj.size();i++){
		cerr<<obj[i]<<' ';
	}
	cerr<<endl;
	for(int i=0;i<obj2.size();i++){
		cerr<<obj2[i]<<' ';
	}
	cerr<<endl;*/

	cout<<min(solve(obj),solve(obj2))<<endl;


	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <queue>
typedef long long ll;
#define rep(i,n) for(int i = 0;i<n;++i)
#define repc(bit,k,n) for (int bit = (1<<k)-1;bit < (1<<n); bit = next_combination(bit))
#define repi(itr,vec) for(auto itr = vec.begin();itr!=vec.end();++itr)
using namespace std;
using Graph = vector<vector<int> >;

/* next combination
 * usage:repc(bit,k,n)
 * */
int next_combination(int sub) {
  int x = sub & -sub, y = sub + x;
  return (((sub & ~y) / x) >> 1) | y;
}

/* uniq
 * usage:uniq(vec)
 * */
void uniq(vector<int> &vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return;
}

/* BinaryIndexedTree
 * usage:update and sum of 1~N
 * */
int N;
int bit[1000010];
void add(int a, int w) {
  for (int x = a; x <= N; x += x & -x) bit[x] += w;
}
int sum(int a) {
  int ret = 0;
  for (int x = a; x > 0; x -= x & -x) ret += bit[x];
  return ret;
}

int main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
  ll m,n;cin >> m >> n;
  n/=m;
  int NO = 60;
  int YES = 0;
  ll hoge = 1;
  while(NO-YES>1){
    int temp = (YES+NO)/2;

    if((hoge<<temp)>n)NO = temp;
    else YES = temp;
  }
  cout << YES +1<< '\n';

        return 0;
}

Measured memory_bytes: 3616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

class Main {
    public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            List<String> input = Arrays.asList(br.readLine().split(""));
            Map<String, Integer> countMap = new HashMap<>();

            for (String str : input) {
                countMap.put(str, 0);
            }

            for (String str : input) {
                countMap.put(str, countMap.get(str).intValue() + 1);
            }

            String ans = "Yes";
            for (Map.Entry<String, Integer> entryMap : countMap.entrySet()) {
                if (!(entryMap.getValue() % 2 == 0)) {
                    ans = "No";
                    break;
                }
            }

            System.out.println(ans);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);  
        }
    }
}

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

using namespace std;

int main() {

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

	int n;
	string s;
	cin >> n >> s;
	int cnt = 1;
	for (int i = 1; i < n; ++i) {
		while (s[i] == s[i - 1] && i < n) {
			++i;
		}
		if(i == n) --i;
		if (s[i] != s[i - 1]) cnt++;
	}
	cout << cnt << '\n';
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n;
long i,j,w,W[200];
long long F[200][100005], v[200];
int main()
{
   cin>>n>>w;
   for (i=1;i<=n;i++)
    cin>>W[i]>>v[i];
    for (i=1;i<= n ;i++)
    for (j=1;j<=w ;j++)
      if (W[i]<=j)
    F[i][j]=max(F[i-1][j],(F[i-1][j-W[i]]+v[i]));
    else
        F[i][j]=F[i-1][j];
   cout<<F[n][w];


}


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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, k;
    cin >> n >> k;
    lint sum = 0;
    for (int i = 0; i < k; ++i) {
    	int x;
    	cin >> x;
    	sum += 1ll*x;
    }
    if (sum >= n) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp34 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int N = st[0];
            int i = st[1];

            Console.WriteLine(N - i + 1);

        }
    }
}


Measured memory_bytes: 13268
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int N = sc.nextInt();
		char[] elems = sc.next().toCharArray();
		int[] acumW = new int[N];
		int[] acumE = new int[N];
		for (int i = 0; i < N; i++) {
			acumW[i] = elems[i] == 'W'? 1 : 0;
			if (i > 0) acumW[i] += acumW[i-1];
		}
		for (int i = N - 1; i >= 0 ; i--) {
			acumE[i] = elems[i] == 'E'? 1 : 0;
			if (i + 1 < N) acumE[i] += acumE[i+1];
		}
		int ans = N;
		for (int i = 0; i < N; i++) {
			int badL = i > 0 ? acumW[i-1] : 0;
			int badR = i + 1 < N ? acumE[i+1] : 0;
			ans = Math.min(ans, badL + badR);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 30848
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i=1; i*i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

void solve(){
    ll N;
    cin >> N;
    auto res = divisor(N);
    int ans = INF;
    for(auto x : res){
        auto y = N / x;
        int xx = 0, yy = 0;
        while(x > 0){
            x /= 10;
            xx++;
        }
        while(y > 0){
            y /= 10;
            yy++;
        }
        chmin(ans, max(xx, yy));
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[200005];
ll B[200005];

int main()
{
    ll N;
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }
    memset(B, 0, sizeof(B));
    REP(i, N)
    {
        int n = N - 1 - i;
        ll m = A[n];
        ll s = 0;
        for (ll j = n; j < N; j += (n + 1))
        {
            s += B[j];
        }

        B[n] = abs(m - (s % 2));
    }
    vector<int> C;
    REP(i, N)
    {
        if (B[i] > 0)
            C.push_back(i + 1);
    }
    cout << C.size() << endl;
    REP(i, C.size())
    {
        cout << C[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    int d; cin >> d;
    mp[d]++;
  }
  int m; cin >> m;
  bool ok = true;
  for(int i = 0; i < m; i++) {
    int t; cin >> t;
    mp[t]--;
    if(mp[t] < 0) ok = false;
  }
  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 12936
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 2e5+5;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	ll n, ans = 0;
	cin >> n;
	ans = (n/500 * 1000);
	n %= 500;
	ans += (n/5 * 5);
	cout << ans;
	return 0;
}


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

int main(){
    int n,k,r,s,p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    int tot = 0;
    //高橋君の手の出し方を格納
    vector<int> a(n);
    //r,s,pで勝った時の獲得点数
    vector<int> pnt(3);
    pnt[0] = r;
    pnt[1] = s;
    pnt[2] = p;
    rep(i,n){
        if(t[i] == 'r'){
            tot += p;
            a[i] = 2;
        }
        if(t[i] == 's'){
            tot += r;
            a[i] = 0;
        }
        if(t[i] == 'p'){
            tot += s;
            a[i] = 1;
        }
    }
    for(int i = 0;i+k < n;i++){
        if(a[i] == a[i+k]){
            tot -= pnt[a[i]];
            a[i+k] = -1;
        }
    }
    cout << tot << endl;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
const int MAX_n=1e5+10;
int n;
int a[MAX_n],b[MAX_n],c[MAX_n];
int dp[MAX_n][3];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)    cin>>a[i]>>b[i]>>c[i];
    dp[1][0]=max(b[1],c[1]);
    dp[1][1]=max(a[1],c[1]);
    dp[1][2]=max(a[1],b[1]);
    for(int i=2;i<=n;i++)
    {
        dp[i][0]=max(dp[i-1][1]+b[i],dp[i-1][2]+c[i]);
        dp[i][1]=max(dp[i-1][0]+a[i],dp[i-1][2]+c[i]);
        dp[i][2]=max(dp[i-1][0]+a[i],dp[i-1][1]+b[i]);
    }
    int ans=max(dp[n][0],dp[n][1]);
    ans=max(ans,dp[n][2]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(){
  int t,n,s,f,sum;
  while(1){
    cin >> t;
    if(t==0) break;
    cin >> n;
    sum=0;
    for(int i=0;i<n;i++){
      cin >> s >> f;
      sum+=f-s;
    }
    if(sum>=t) cout << "OK" << endl;
    else cout << t-sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>


using namespace std;
typedef long long ll;

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; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;


void MakeDFSTree(int cur, int pre, vector<bool> &used, vector<vector<pair<int, int>>>& tree, vector<vector<pair<int, int>>>& g) {
	used[cur] = true;
	for (auto nxt : g[cur]) {
		if (nxt.first == pre) continue;
		if (used[nxt.first]) continue;
		tree[cur].emplace_back(nxt);
		tree[nxt.first].emplace_back(cur, nxt.second);
		MakeDFSTree(nxt.first, cur, used, tree, g);
	}
}
int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n, m; cin >> n >> m;
	vector<pair<int, int>> vp(n); for (int i = 0; i < n; i++) cin >> vp[i].first >> vp[i].second;
	sort(vp.begin(), vp.end());
	vector<int> l(m), r(m);
	for (int i = 0; i < m; i++) {
		cin >> l[i] >> r[i];
		l[i] = lower_bound(vp.begin(), vp.end(), make_pair(l[i], -inf)) - vp.begin();
		r[i] = upper_bound(vp.begin(), vp.end(), make_pair(r[i], inf)) - vp.begin();
	}
	vector<int> sub(n + 1);
	for (int i = 0; i <= n; i++) {
		if (i == 0) sub[i] = vp[i].second;
		else if (i == n) sub[i] = vp[i - 1].second;
		else sub[i] = vp[i - 1].second ^ vp[i].second;
	}

	vector<vector<pair<int, int>>> g(n + 1);
	for (int i = 0; i < m; i++) {
		g[l[i]].emplace_back(r[i], i);
		g[r[i]].emplace_back(l[i], i);
	}
	
	{
		vector<vector<pair<int, int>>> tree(n + 1);
		vector<bool> used(n + 1);
		for (int i = 0; i <= n; i++) {
			if (used[i]) continue;
			MakeDFSTree(i, -1, used, tree, g);
		}
		g = move(tree);
	}
	
	vector<bool> used(n + 1);
	vector<int> res;
	
	auto dfs = [&](auto &&f, int cur, int pre)->void {
		used[cur] = true;
		for (auto nxt : g[cur]) {
			if (nxt.first == pre) continue;
			f(f, nxt.first, cur);
			if (sub[nxt.first]) {
				sub[cur] ^= 1;
				sub[nxt.first] ^= 1;
				res.emplace_back(nxt.second);
			}
		}
	};
	
	for (int i = 0; i <= n; i++) {
		if (used[i]) continue;
		dfs(dfs, i, -1);
		if (sub[i]) {
			cout << -1 << endl;
			return 0;
		}
	}
	for (int i = 0; i <= n; i++) if (sub[i]) {
		cout << -1 << endl;
		return 0;
	}
	sort(res.begin(), res.end());
	cout << res.size() << "\n";
	for (int i = 0; i < res.size(); i++) cout << res[i] + 1 << " \n"[i + 1 == res.size()];
	return 0;
}


Measured memory_bytes: 25988
#include <iostream>
#include <deque>
#include <vector>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int k;
    cin >> k;
    deque<int> q;
    q.push_back(1);
    vector<int> dist(k, k + 2);
    dist[1] = 1;
    while (!q.empty()) {
        int node = q.front();
        q.pop_front();
        if (dist[(node + 1) % k] > 1 + dist[node]) {
            dist[(node + 1) % k] = 1 + dist[node];
            q.push_back((node + 1) % k);
        }
        if (dist[(node * 10) % k] > dist[node]) {
            dist[(node * 10) % k] = dist[node];
            q.push_front((node * 10) % k);
        }
    }
    cout << dist[0] << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int len, dur;
    cin >> len >> dur;
    int a;
    cin >> a;
    long long ans = dur;
    for(int i = 1; i < len; i++) {
        int b;
        cin >> b;
        if(a + dur > b)
            ans -= (a + dur) - b;
        ans += dur;
        a = b;
    }
    cout << ans;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int cnt=0;
    long long sum=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='W')
        {
            sum+=cnt;
        }
        else cnt++;
    }
    printf("%lld\n",sum);
    return 0 ;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

ll dp[2005][2005];

int main() {
  ll N;
  scanf("%lld", &N);

  vector<pair<ll, ll>> list(N);
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    list[i] = make_pair(v, i);
  }
  sort(list.rbegin(), list.rend());

  for (ll i = 0; i < N; i++) {
    for (ll j = 0; i + j < N; j++) {
      ll val = list[i + j].first;
      ll idx = list[i + j].second;

      // 左
      {
        ll next_idx = i;
        ll plus = abs(idx - next_idx) * val;
        ll new_value = max(dp[i + 1][j], dp[i][j] + plus);
        dp[i + 1][j] = new_value;
        // cout << i << "," << j << "," << plus << "," << dp[i][j] << endl;
      }
      // 右
      {
        ll next_idx = N - 1 - j;
        ll plus = abs(idx - next_idx) * val;
        ll new_value = max(dp[i][j + 1], dp[i][j] + plus);
        dp[i][j + 1] = new_value;
        // cout << i << "," << j << "," << plus << "," << dp[i][j] << endl;
      }
    }
  }

  ll ans = 0;
  for (ll i = 0; i <= N; i++) {
    ans = max(ans, dp[i][N - i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 26356
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

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

int main() {
	int n;
	cin >> n;
	
	int ans = 0;

	for (int i = 1; i <= n; i++)
	{
		int t = i;
		int cnt = 0;
		while (t > 0) {
			t /= 10;
			cnt++;
		}
		if (cnt % 2 != 0) ans ++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,b) for(int i=1;i<=b;i++)
#define drep(i,b) for(int i=b;i>=1;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define int long long
#define endl '\n'
using namespace std;
const int N=2e5+5;
const int mod=1e9+7;
int n,m,k,t,x,y,z;
//pr
//
#define mid (l+r)/2
#define ls i<<1
#define rs i<<1|1
//vec
//alg

int a[6000],az;

void solve(int sum=0) {
    int t=lower_bound(a+1,a+az+1,n)-a;
    cout<<t<<endl;
}

#undef int
int main() {
    ios::sync_with_stdio(false);
    //int T;cin>>T;
    x=100;
    rep(i,5000) {
        x+=x/100;
        a[i]=x;
        if(x>1e18) {
            az=i;break;
        }
    }
    while(cin>>n)
    solve();
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  int ans = 0;
    int N; cin >> N;
    int A[N]; rep(i, N) cin >> A[i];
    for(int i = 1; i < N-1; i++){
        int B[] = {A[i-1],A[i], A[i+1]};
        sort(B, B+3);
        if(B[1] == A[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
loop do
  n = gets.to_i
  break if n == 0 
  data = gets.split.map{|e|e.to_i}
  sum = data.inject{|sum,val| sum += val}
  mean = 1.0*sum/n

  variance = 0.0
  for elem in data
    variance += (elem-mean)**2/n
  end

  puts Math.sqrt(variance)
end

Measured memory_bytes: 6168
#include <iostream>
#include <vector>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

const long long inf = 1e18;

struct edge {
	int a, b;
	long long cost;
};

signed main() {
	long long n, m, p; cin >> n >> m >> p;

	vector<edge> e(m);
	REP(i, 0, m) {
		long long a, b, c; cin >> a >> b >> c;
		e[i].a = a - 1;
		e[i].b = b - 1;
		e[i].cost = - c + p;
	}

	vector<long long> d(n, inf);
	d[0] = 0;
	bool x = 0;
	for (int i = 0; i < 2 * n; ++i) {
		for (int j = 0; j < m; ++j)
			if (d[e[j].a] < inf)
				if (d[e[j].b] > d[e[j].a] + e[j].cost) {
					d[e[j].b] = max(-inf, d[e[j].a] + e[j].cost);
					if (i >= n && e[j].b == n - 1) x = 1;
				}
	}

	if (x || d[n - 1] == inf) cout <<  -1;
	else cout << max(0LL, -d[n - 1]);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n,l;
  cin >> n >> l;
  vector<string> a(n);
  rep(i,n){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  rep(i,n){
    cout<<a[i];
  }  
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define isFile 0
#define NAME "taskA"
#define scan 0
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> pii;
typedef pair<short, short> pss;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;

#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define x fr
#define y sc
#define skip continue
#define ins insert
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define _all(v, x, n) v.begin() + x, v.begin() + n + x
#define unique(a) sort(all(a));    a.resize(unique(all(a)) - a.begin())
#define rev(a) reverse(all(a))

#define bit(n, i) (n >> i) & 1
#define bpc(x) __builtin_popcount(x)

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

pair<pii, pii> intersect(pii f1, pii f2, pii s1, pii s2) {    int x5, y5, x6, y6;    x5 = max(min(f1.x, f2.x), min(s1.x, s2.x));    x6 = min(max(f1.x, f2.x), max(s1.x, s2.x));    y5 = max(min(f1.y, f2.y), min(s1.y, s2.y));    y6 = min(max(f1.y, f2.y), max(s1.y, s2.y));    if (x5 >= x6 || y5 >= y6) {        return {{0, 0}, {0, 0}};    }    return {{x5, y5}, {x6, y6}};}

bool isPrime(ll n) {    if (n < 2) return 0;    for(ll i = 2; i * i <= n; i++) {        if (n % i == 0) return 0;    }    return 1;}

void faster() {
    if (isFile) {
        freopen(NAME".in", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    if (scan) {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
}

const ll INF = 1e18;
const int inf = 1e9;
const int MAXN = (int)1e5 + 123;
const int MOD = (int)1e9 + 7;
const ld  PI = acos(-1);
const ld  EPS = 3E-16;

namespace MATH_CAL {
    const int mod = MOD;
    inline ll add(ll a, ll b) { return a + b >= mod ? a + b - mod : a + b; }
    inline ll sub(ll a, ll b) { return a - b < 0 ? a - b + mod : a - b; }
    inline ll mul(ll a, ll b) { return (ll) a * b % mod; }
    inline void Add(ll &a, ll b) { (a += b) >= mod ? a -= mod : 0; }
    inline void Sub(ll &a, ll b) { (a -= b) < 0 ? a += mod : 0; }
    inline ll qpow(ll x, ll n) { ll r = 1; for ( ; n; n /= 2, x = mul(x, x)) if (n & 1) r = mul(r, x); return r; }
    inline ll mod_inv(ll x) { return qpow(x, mod - 2); }
    inline ll gcd(ll a, ll b) {while(b) {a %= b; swap(a, b);} return a;}
} using namespace MATH_CAL;

void solve() {

    int h, w, n;
    cin >> h >> w >> n;

    int ans = 0;
    if (h > w) swap(h, w);

    while(n > 0) {
        n -= w;
        ans++;
    }

    cout << ans << endl;

}

int main() {
    faster();
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    num_list = i_list()

    co_list = Counter(num_list)

    count = 0

    num_list = list(set(num_list))
    num_list.sort(reverse=True)

    ans_list = []

    for i, num in enumerate(num_list):
        num_c = co_list[num]

        for _ in range(num_c*2):
            ans_list.append(num)
        if i == 0:
            ans_list.pop()

    for i in range(n-1):
        count += ans_list[i]
        
    print(count)
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 169176
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200009];
int main()
{
	ll n, i, j, cnt=0;
	cin >> n;
	for(i=0; i<n; i++)
		cin >> a[i];

	for(i=1; i<n; i++){
		if (a[i] < a[i-1]){
			cnt += a[i-1] - a[i];
			a[i] = a[i-1];
		}
	}
	
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 5128
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sz(a) signed(a.size())
using namespace std;

void solve(){
	ll n,i;
	cin >> n;
	ll m = 1e18;
	ll prod = 1;
	bool flag = 0,z=0;
	for(i=1;i<=n;i++){
		ll a;
		cin >> a;
		z += (a==0);
		if (a && prod > m/a){
			//cout << i << " "; 
			flag = 1;
		}
		prod *= a;
	}
	if(z)
	cout <<0;
	else if(!flag)
	cout << prod;
	else
	cout << -1;
}

int main() {
    FAST;
    ll t=1;
    //cin>>t;
    while(t--) solve();	
    return 0;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<int,int>
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define FORR(I,A,B) for(int I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
int gcd(int a,int b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
int lcm(int a,int b){int c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl

int ans = 0;
void merge(int A[],int left,int mid,int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int L[n1+1],R[n2+1];
	for(int i=0;i<n1;i++){
		L[i] = A[left+i];
	}
	for(int i=0;i<n2;i++){
		R[i] = A[mid+i];
	}
	L[n1] = R[n2] = 1000000000;
	int i = 0;
	int j = 0;
	for(int k=left;k<right;k++){
		ans++;
		if(L[i]<=R[j]){
			A[k] = L[i];
			i++;
		}else{
			A[k] = R[j];
			j++;
		}
	}
}
void mergeSort(int A[],int left,int right){
	if(left+1<right){
		int mid = ( left + right )/2;
		mergeSort(A,left,mid);
		mergeSort(A,mid,right);
		merge(A,left,mid,right);
	}
}



int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int a[n];
	FOR(i,0,n)cin>>a[i];
	mergeSort(a,0,n);
	cout << a[0];
	FOR(i,1,n)cout << " " << a[i];
	cout << endl << ans << endl; 
}



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

int cal (int x){
    string c = to_string(x);
    int count = 0;
    for(int i=0;i<c.size();i++){
        count = c[i] - '0' + count;
    }
    return count;
}

int main(){
    int N;
    cin>> N;
    int min = 10000000;
    if(N<=10) cout << N <<"\n";
    else {
        for (int i = N - 10; i > 0; i = i - 10) {
            int p = N - i;
            int q = i;
            int x = cal(p) + cal(q);
            //cout << x << "\n";
            if (min > x) {
                min = x;
            }
        }
        cout << min <<"\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

int n, top;
char s[1000000];
int st[1000000];

int main() {
	scanf("%s", s + 1); n = strlen(s + 1);
	int cnt = 0, last = 1;
	st[++top] = 1;
	for (int i = 2; i <= n; i++) {
		while (top - 1 >= 1 && s[st[top - 1]] != s[i]) top--;
		st[++top] = i;
	}
	if ((n - top) & 1) printf("First\n");
	else printf("Second\n");
	return 0;
}

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

using namespace std;
using ll = long long;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int a, b, c, k;
	cin >> a >> b >> c >> k;

	int cnt = 0;
	while (b <= a) {
		b *= 2;
		cnt++;
	}
	while (c <= b) {
		c *= 2;
		cnt++;
	}

	cout << (cnt <= k ? "Yes\n" : "No\n");
}

Measured memory_bytes: 3608
#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long ll;
ll dp[100009];
int arr[100009];
ll sum = 0;
int k;
long long Frog1(int n){

    if(n==0) return 0;

    else if(dp[n]!=-1) return dp[n];
    else {
            ll sum = INT_MAX;
            for(int i=n-1,j=1;i>=0 && j<=k;i--,j++ ){

                ll x;
                if(dp[i]!=-1) x = dp[i];
                else x = Frog1(i);

                x = abs(arr[i] - arr[n]) + x;
                sum = min(sum,x);
                //cout << n  << " " << i  << " " << j << endl;
            }
            dp[n] = sum;
            return sum;
    }
}


int main()
{
    int n;
    memset(dp,-1,sizeof(dp));
    cin >> n >> k;
    for(int i=0;i<n;i++) cin >> arr[i];
    cout << Frog1(n-1) << endl;
}


Measured memory_bytes: 6144
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a=0,b=0;
    string s;
    cin>>s;
    
    rep(i,s.size()){
        if((i%2&&s[i]=='1')||(i%2==0&&s[i]==('0'))) a++;
        if((i%2&&s[i]=='0')||(i%2==0&&s[i]==('1'))) b++;
    }
    cout1(min(a,b))
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int A, B;
    cin >> A >> B;
    for(int i=0; i<100000; i++) {
        if((int)(i*0.08+0.0000001) == A && (int)(i*0.1+0.0000001) == B) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

int N;
long long int num[2000];
long long int dp[2000][2000];
long long int ans;

long long int Search(int l, int r, int turn) {
	if (dp[l%N][r%N]||r%N==l%N) {
	//	cout << l%N << " " << r%N << " " << dp[l%N][r%N] << endl;
		return dp[l%N][r%N];
	}
	if (turn % 2==0) {
		if (num[l%N] > num[r%N])dp[l%N][r%N] = Search(l + 1, r, turn + 1);
		else dp[l%N][r%N] = Search(l, r - 1, turn + 1);
	}
	else {
		dp[l%N][r%N] = max(dp[l%N][r%N], Search(l + 1, r, turn + 1) + num[l%N]);
		dp[l%N][r%N] = max(dp[l%N][r%N], Search(l, r - 1, turn + 1) + num[r%N]);
	}
	//cout << l%N << " " << r%N << " " << dp[l%N][r%N] << endl;
	return dp[l%N][r%N];
}

int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> num[i];
		if(N%2)dp[i][i] = num[i];
	}
	for (int i = 0; i < N; i++) {
		ans = max(ans, Search(i + N, i + N + N - 1, 1));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 34432