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

using ll = long long;
using db = double;
using pll = pair < ll, ll >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;

vector<ll>a, b, c, d;
ll n, m, q; 
ll ans = 0;

void solve(vector<ll>&v) {
	if(v.size() == n) {
		ll sum = 0;
		for(ll i = 0 ; i < q; i++) {
			if((v[b[i]] - v[a[i]]) == c[i]) {
				sum += d[i];
			}
		}
		ans = max(sum, ans);
	} else {
		ll st = 1;
		if(v.size()) st = v.back();
		for(ll i = st; i <= m; i++) {
			v.push_back(i);
			solve(v);
			v.pop_back();
		}
	}
}

int main(){
	cin >> n >> m >> q;
	a.resize(q);
	b.resize(q);
	c.resize(q);
	d.resize(q);
	for(ll i = 0; i < q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}
	vector<ll>v;
	solve(v);
	cout << ans << endl;
}

Measured memory_bytes: 3600
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]
from itertools import accumulate as acc
MOD = 10**9+7

def main():
    n, k = MII()
    cnt = 0
    dd = [i for i in range(n+1)]
    # print(dd)
    dd_a = [0]
    for i in range(n+1):
        d = dd_a[i] + dd[i]
        dd_a.append(d)
    # print(dd_a)
    dd_b = [0]
    dd_r = dd[::-1]
    for i in range(n+1):
        d = dd_b[i] + dd_r[i]
        dd_b.append(d)
    # print(dd_b)
    for i in range(k,len(dd_a)):
        cnt += dd_b[i]-(dd_a[i]-1)
    print(cnt%MOD)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39760
# import bisect
# import copy
# import fractions
# import math
import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    N,M=map(int,input().split())
    A=np.array([[_ for _ in input()] for _ in range(N)])
    B=np.array([[_ for _ in input()] for _ in range(M)])

    #print(A[1:3][1:3])
    def main():
        for i in range(N-M+1):
            for j in range(N-M+1):
                if (A[i:i + M, j:j + M] == B).all():
                    return 'Yes'
                elif i==N-M and j==N-M:
                    return 'No'
    print(main())

resolve()

Measured memory_bytes: 12496
#include <bits/stdc++.h>
using namespace std;
int main(){
	set<int> v;
	vector<int> vv;
	int n,a;
	cin>>n;

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

		if(a/100<=3){
			v.insert(0);
		}else if(a/100<=7){
			v.insert(1);	
		}else if(a/100<=11){
			v.insert(2);
		}else if(a/100<=15){
			v.insert(3);
		}else if(a/100<=19){
			v.insert(4);
		}else if(a/100<=23){
			v.insert(5);
		}else if(a/100<=27){
			v.insert(6);	
		}else if(a/100<=31){
			v.insert(7);
		}else {
			vv.push_back(8);
		}
	}

	if(vv.size()==0){
		cout<<v.size()<<"\n";
		cout<<v.size()<<"\n";
	} else if(v.size()==0) {
		cout<<"1"<<"\n";
		cout<<v.size()+vv.size()<<"\n";
	} else {
		cout<<v.size()<<"\n";
		cout<<v.size()+vv.size()<<"\n";
	}
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner as = new Scanner(System.in);
		long n=as.nextLong();
		//long l=0;
		if(n<1200){
			System.out.println("ABC");
		}else{
			System.out.println("ARC");
		}
	}
}

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


//#define int long long 


const int inf = 0x3f3f3f3f, N = 3e5;

struct RMQ {
        vector <int> t;
        int n;
        RMQ(int n) : n(n) {
                t.resize(n << 1, 0);
        }
        
        void modify(int p, int v) {
                for(t[p += n] = v; p > 1; p >>= 1) t[p >> 1] = max(t[p], t[p ^ 1]);
        }
        int query(int l, int r) { int res = 0;
                for(l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
                        if(l & 1) res = max(res, t[l++]);
                        if(r & 1) res = max(res, t[--r]);
                }
                return res;
        }
};

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	long long ans = 1LL * (n - 2) * (n - 2);

	RMQ h(n + 7), v(n + 7);
	h.modify(n, n);
	v.modify(n, n);

	for(int i = 1; i <= q; i++) {
		
		int t, x; cin >> t >> x;
		if(t == 1) {
			int l = 1, r = n;
			while(l < r) {
				int mid = (l + r + 1) / 2;
				if(h.query(1, mid) >= x) r = mid - 1;
				else l = mid;
			}

			if(l - 1 > 0) {
				ans -= (l - 1);
				v.modify(x, l);
			}
		} else {
			int l = 1, r = n;
			while(l < r) {
				int mid = (l + r + 1) / 2;
				if(v.query(1, mid) >= x) r = mid - 1;
				else l = mid;
			}

			if(l - 1 > 0) {
				ans -= l - 1;
				h.modify(x, l);
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 6332
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
int a[maxn];
int tb[maxn];
LL cnt[maxn];
LL val[maxn];
int stk[maxn],top,tot;

inline int hs(int x) {
    return lower_bound(tb+1,tb+tot+1,x)-tb;
}

int main() {
    int n;
    read(n);
    REP(i,1,n) read(a[i]),tb[++tot]=a[i];
    PER(i,n,1) {
        while(top && a[i]>a[stk[top]]) top--;
        stk[++top]=i;
    } 
    sort(tb+1,tb+tot+1);
    tot=unique(tb+1,tb+tot+1)-tb-1;
    REP(i,1,n) a[i]=hs(a[i]);
    int now=tot,ps=1;stk[top+1]=0;
    PER(i,n,1) {
        cnt[a[i]]++;
        if(stk[ps]==i) {
            while(now>a[stk[ps+1]]) {
                val[stk[ps]]+=1LL*cnt[now]*(tb[now]-tb[now-1]);
                now--;cnt[now]+=cnt[now+1];
            } ps++;
        }
    }
    REP(i,1,n) printf("%lld\n",val[i]);
    return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define pi acos(-1)
#define pb push_back
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 10;

ll a[310][310];
bool vis[310][310];

int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
#endif
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            scanf("%lld",&a[i][j]);
    int flag=1;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++) {
            if(i==j) continue;
            for(int k=1; k<=n; k++) {
                if(i==k||j==k) continue;
                if(a[i][k]+a[k][j]<a[i][j]) flag=0;
                if(a[i][k]+a[k][j]==a[i][j]) vis[i][j]=1;
            }
        }
    if(!flag) {
        puts("-1");
        return 0;
    }
    ll ans=0;
    for(int i=1; i<=n; i++)
        for(int j=i+1; j<=n; j++)
            if(!vis[i][j]) ans+=a[i][j];
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  llong N, K;
  cin >> N >> K;
  llong ans=1;
  while(true){
    if(pow(K,ans-1)<=N && N<pow(K,ans)) break;
    else ++ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
	int a=0,n,b=0;
	cin >> n;
	for (int i=1;i<n+1;i++)
	{
	  if(i%2!=0){ 
		for(int j=1;j<i+1;j++){
		   if(i%j==0)a++;
		}
      }
		if(a==8)b++;
		a=0;
	}
	cout << b << endl;
}

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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  unordered_map<i64, i64> dp;
  auto rec = [&](auto rec, i64 h) -> i64 {
    if (h == 1) return 1;
    if (dp.count(h)) return dp[h];
    return dp[h] = 1 + rec(rec, h / 2) * 2;
  };
  i64 H;
  cin >> H;
  cout << rec(rec, H) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    if ((n % 2 == 1) || (n < 2)) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    n /= 2;
    while(n > 0) {
        ans += n / 5;
        n /= 5;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(void) {
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    A.push_back(K+A[0]);
    adjacent_difference(A.begin(), A.end(), A.begin());

    cout << K - *max_element(A.begin(), A.end()) << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >> N;
  int num[110];
  for(int i = 0; i < N; i++){
   cin >> num[i]; 
  }
  bool ans = 1;
  for(int i = 0; i < N; i++){
   if(num[i] % 2 == 0){
     if(num[i] % 3 != 0 && num[i] % 5 != 0){
       ans = 0;
     }
   }
  }
  if(ans == 0) cout << "DENIED" << endl;
  else cout << "APPROVED" << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <climits>
#include <cmath>
#include <unordered_map>

using namespace std;

typedef long long ll;

int main(void) {
  string S;
  cin >> S;
  int count = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'o')
      count++;
  }

  if ((count + 15 - S.size()) >= 8)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int g = 0, p = 0, ans = 0;
  for(char a: S){
    if(a == 'g'){
      if(g >= p + 1){
        p++;
        ans++;
      } else {
        g++;
      }
    } else {
      if(g >= p + 1){
        p++;
      } else {
        g++;
        ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define int long long

signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int a, b;
  cin >> a >> b;
  cout << (a > b ? "safe" : "unsafe") << '\n';

  return 0;
}

Measured memory_bytes: 3652
use utf8;
use warnings;
use strict;
use feature qw/say/;

chomp(my $line = <>);
my ($a, $b) = split(/ /, $line);

if ($a == $b) {
    say 0;
} elsif (($a + $b) % 2 == 0) {
    my $tot = $a + $b;
    say $tot/2;
} else {
    say 'IMPOSSIBLE';
}

Measured memory_bytes: 768
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-27 14:25:56
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int n; cin >> n;
  vector<int64> a(n); cin >> a;
  int neg = 0;
  for (int64 x : a) neg += (x < 0);

  int64 sum = 0;
  for (int64 x : a) sum += abs(x);

  debug(neg, sum);

  if (neg & 1) {
    int64 mn = 1e9;
    for (int64 x : a) mn = min(mn, abs(x));
    cout << sum - 2LL * mn << endl;
  } else {
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(){
	string s;
	getline(cin,s);
	vector<int>count;
	int c=0;;
	for(int i=0;i<3;i++){
		if(s[i]=='R'){
			c++;
		}
		else{
			count.push_back(c);
			c=0;
		}
		count.push_back(c);
	}
	sort(count.begin(),count.end(),greater<int>());
	cout<<count[0];
	return 0;
}

Measured memory_bytes: 3596
a, b, c = map(int, input().split())
ans = 0
if a == b == c and a != 1:
  ans = -1
else:
  while a % 2 == b % 2 == c % 2 == 0:
    x = a // 2
    y = b // 2
    z = c // 2
    if x % 2 == y % 2 == z % 2:
      a = y + z
      b = z + x
      c = z + x
      ans += 1
    else:
      ans += 1
      break
print(ans)

Measured memory_bytes: 9104
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ull unsigned long long
#define pii pair<ull ,ull >
vector < pair < ull , ull > > kat;
bool comp(pii a,pii b)
{
	if(a.first < b.first) return false;
	if(a.first > b.first) return true;
	if(a.second < b.second) return true;
	return false;
}
int main()
{
	int H,N;
	cin >> N >> H;
	for(int i = 0; i < N; ++i)
	{
		int x,y;
		cin >> x >> y;
		kat.push_back(make_pair(x,y));
	}
	sort(kat.begin(),kat.end(), comp);
	vector< ull > secondary;
	for(int i =0; i<N;++i)
	{
		if(kat[i].second > kat[0].first)
			secondary.push_back(kat[i].second);
	}
	sort(secondary.begin(), secondary.end());
	ull cnt = 0;
	for(int i = secondary.size()-1; i>=0;--i)
	{
		cnt++;
		if(H <= secondary[i])
		{ H=0;	break;}
		H-=secondary[i];
	}
	if(H > 0)
	{
			cnt+=(H+kat[0].first-1)/kat[0].first;
	}
	cout << cnt << endl;
}

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

using ll = long long;

int INF = 1e9;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N)cin >> A[i];
  int ans = 0;
  
  sort(A.begin(), A.end());
  int max_A = A[N-1];
  vector<int> Checker(max_A+1,0);
  // Bはその値(の最小因子)が既出のときfalse
  for(int i=0;i<N;i++){
    for(int x=A[i];x<=max_A;x+=A[i]){
      Checker[x] += 1;
      //cout << x << ",";
    }
    //cout << i << ".";
  }

  for(int i=0;i<N;i++){
    if(Checker[A[i]] == 1)ans++;
  }
  cout << ans << endl;
}

/*
i != j -> (Ai%Aj)!=0となる i の個数を答える
AiがAi以外のA内のどの要素の倍数でもないもの(「互いに素」ではない)
1がある→その時点で他がすべてアウト
小さい値から見ていくとよさそう

sortしても問題ないのでsort
1がある→その時点で他がすべてアウト
2がある→2nの物が全てアウト
mがある→mnの物が全てアウト
と末尾までやっていって(O(N^2) = 4*10^10 ←間に合わねえ)
アウトじゃないもののみカウントすればいいっぽ
アウト値は0にしておこうかな

同じ数があるパターンがあるらしい、詰んだ
→解説動画みた。
個数で管理すれば1のときだけカウントすればいいし、
ダブってたときは2になるのでOK
ＴＥＮＳＡＩすぎる…

*/

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

int main () {
  int n ;
  cin >> n ;
  int a , b, c , d ;
  a = n / 1000 ;
  b = ( n - 1000 * a ) / 100 ;
  c = ( n - 1000 * a - 100 * b ) / 10 ;
  d = n - 1000 * a - 100 * b - 10 * c ;
  if ( a == b && b == c && c == d ) {
    cout << "Yes" << endl ;
  } else if ( a == b && b == c ) {
    cout << "Yes" << endl ;
  } else if ( b == c && c == d ) {
    cout << "Yes" << endl ;
  } else {
    cout << "No" << endl ;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long ans=0,b,n;
	cin>>n;
	for(int i=sqrt(n);i>=1;i--)
	{
		if(n%i==0){b=n/i;break;}
	}
	while(b)
	{
		b=b/10;
		ans++;
	}
	cout<<ans;
	return 0;
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = 1e9+7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VL a(n);
	rep(i, n) cin >>a[i];
	
	ll ans = accumulate(all(a), 0LL) - n;
	cout << ans <<endl;
	return 0;
}


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

int main(){
  int N,K;
  cin>>N>>K;
  vector<long long int> H(N);
  for(int i=0;i<N;i++){
    cin>>H.at(i);
  }
  sort(H.begin(),H.end());
  if(K>=N){
    cout<<0<<endl;
  }else{
    long long int sum=0;
    for(int i=0;i<N-K;i++){
      sum+=H.at(i);
    }
    cout<<sum<<endl;
  }
  
  
  
    
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Trie {
    int value;  // all
    int cnt[26];
    Trie* next[26];
    Trie() : value(0) {
        fill(next, next + 26, nullptr);
        memset(cnt, 0, sizeof(cnt));
    }
};

Trie* find(const string& t, Trie* r) {
    for (int i = 0; i < t.size(); ++i) {
        char c = t[i] - 'a';
        if (!r->next[c]) r->next[c] = new Trie;
        r = r->next[c];
    }
    r->value += 1;
    return r;
}

void dfs(Trie* r) {
    rep(i, 26) {
        if (r->next[i]) {
            dfs(r->next[i]);
            r->value += r->next[i]->value;
            rep(j, 26) {
                r->cnt[j] += (i == j ? r->next[i]->value : r->next[i]->cnt[j]);
            }
        }
    }
    /*
    debug(r->value);
    rep(i, 26) cout << r->cnt[i] << " ";
    cout << endl;*/
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    V<string> S(N);

    Trie* r = new Trie();

    rep(i, N) {
        cin >> S[i];
        reverse(ALL(S[i]));
        find(S[i], r);
    }
    dfs(r);

    ll ans = 0;
    rep(i, N) {
        auto cur = r;
        int ad = 0;
        debug("now=", i);
        rep(j, S[i].size()) {
            char c = S[i][j] - 'a';
            if (j + 1 == S[i].size()) {
                ad += cur->cnt[c] - 1;
                debug(ad);
            }
            cur = cur->next[c];
        }
        debug(cur->value);
        // ad += cur->value - 1;
        // ad -= cur->cnt[c];
        ans += ad;
        debug(i, ad);
    }
    cout << ans << endl;

    return 0;
}

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

int ans;
string s;
int main()
{
    cin >> s;
    if (s[0] == '1')
        ans++;
    if (s[1] == '1')
        ans++;
    if (s[2] == '1')
        ans++;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

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

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    ll x;
    cin >> x;

    ll m = 100;
    double rate = 0.01;
    int cnt = 0;
    while(m < x){
        m+= m * rate;
        cnt++;
    }
    
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3624
// input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(a: usize, b: usize) -> usize {
  if a % b == 0 {
    b
  } else {
    gcd(b, a % b)
  }
}

fn solve(target: usize, c: usize, d: usize) -> usize {
  target - (target / c + target / d - target / ((c * d) / gcd(c, d)))
}

// body
fn main() {
  input! {
      a: usize,
      b: usize,
      c: usize,
      d: usize
  }
  println!("{}", solve(b, c, d) - solve(a - 1, c, d));
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int main(){
  ll n,s,i,j,a;scanf("%lld%lld",&n,&s);
  ll dp[n+1][s+1] = {};dp[0][0] = 1;
  for(i=0;i<n;i++){
    scanf("%lld",&a);
    for(j=0;j<=s;j++) dp[i+1][j] = dp[i][j]*2%mod;
    for(j=0;j+a<=s;j++) dp[i+1][j+a] = (dp[i+1][j+a]+dp[i][j])%mod;
  }
  printf("%lld\n",dp[n][s]);
}

Measured memory_bytes: 74112
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int k, x;
  cin >> k >> x;
  if(k*500 >= x) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [0]*N
X = []
Y = []
for i in range(N):
    A[i] = int(input())
    X.append([])
    Y.append([])
    for j in range(A[i]):
        x, y = map(int, input().split())
        X[i].append(x-1)
        Y[i].append(y)
ans = 0
for bit in range(1<<N):
    honest = 0
    ok = True
    for i in range(N):
        if bit&(1<<i):
            honest += 1
            for j in range(A[i]):
                if Y[i][j] == 0:
                    if bit&(1<<X[i][j]):
                        ok = False
                else:
                    if not bit&(1<<X[i][j]):
                        ok = False
    if ok:
        ans = max(ans, honest)
print(ans)

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 1e5+5;

ll n,m,a[N],par[100005] , sz[100005] , ans[N] , sum;
vector< pair<int,int> > ed;

int findPar(int node)
{
    if (par[node]==node) return node;
    return par[node] = findPar(par[node]);
}

void mergeCom(int node , int node2)
{
    int led = findPar(node) , led2 = findPar(node2);

    if (led==led2) return;
    if (sz[led] > sz[led2])
    {
        sum -= (sz[led]*(sz[led]-1)/2);
        sum -= (sz[led2]*(sz[led2]-1)/2);

        par[led2]=led , sz[led] += sz[led2];

        sum += (sz[led]*(sz[led]-1)/2);
    }
    else
    {
        sum -= (sz[led]*(sz[led]-1)/2);
        sum -= (sz[led2]*(sz[led2]-1)/2);

        par[led]=led2 , sz[led2] += sz[led];

        sum += (sz[led2]*(sz[led2]-1)/2);
    }
}

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

    cin >> n >> m;
    for(int i=1; i<=n; i++)
    {
        par[i] = i;
        sz[i]=1;
    }

    ed.push_back({0,0});
    for(int i=1; i<=m; i++)
    {
        int x,y;
        cin >> x >> y;
        ed.push_back({x,y});
    }


    ll res = 0 , tmp = n*(n-1)/2 , tmp2; //start

    for(int i=m; i>=1; i--)
    {
        ll v = ed[i].f , u = ed[i].s;

        res = (tmp-sum);
        ans[i] = res;

        mergeCom(v,u);
    }

    for(int i=1; i<=m; i++)
        cout << ans[i] << '\n';

//
    return 0;
}

Measured memory_bytes: 4596
# ABC057 C - Digits in Multiplication
from itertools import combinations
def factorize(n):
    retlist = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
                retlist.append(i)
    if temp!=1:
        retlist.append(temp)

    if retlist==[]:
        retlist.append(n)

    return retlist

N = int(input())

ans = 10000000
L = []
L = factorize(N)
# print(L)

for i in range(1,len(L)+1):
    C = []
    C = list(combinations(L,i))
    # print(C)
    for c in C:
        a,b = 1,0
        for j in range(len(c)):
            a *= c[j]
        b = N//a
        a = str(a)
        b = str(b)
        # print('a:',a,'b:',b)
        ans = min(ans,max(len(a),len(b)))

print(ans)


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

int main(){

    string s;

    cin >> s;

    cout << s[0] << s.size()-2 << s.back() << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define  fo(i,a,b) for(ll i=a;i<b;i++)
#define rfo(i,a,b) for(ll i=a;i>=b;i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)

#define err() cout<<"----------"<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define pb push_back
#define deb(x) cout<< #x << " = "<<x<<endl;
#define F first
#define S second
#define MP make_pair
#define all(x) (x).begin(), (x).end()
#define pi 3.141592653589
char a[6][6],b[6][6];
ll n,m,k;
void copy_matrix()
{
    fo(i,0,n)
    {
        fo(j,0,m)
        {
            b[i][j]=a[i][j];
        }
    }
    return;
}
void color(ll i,ll j)
{
    fo(x,0,n)
    {
        if(i&(1<<x))
        {
            fo(y,0,m)
            {
                b[x][y]='r';
            }
        }
    }
    fo(x,0,m)
    {
        if(j&(1<<x))
        {
            fo(y,0,n)
            {
                b[y][x]='r';
            }
        }
    }
    return;
}
bool check()
{
    ll c=0;
    fo(i,0,n)
    {
        fo(j,0,m)
        {
            if(b[i][j]=='#')
            {
                c+=1;
            }
        }
    }
    if(c==k) return true;
    else return false;
}
void solve()
{
    cin>>n>>m>>k;
    fo(i,0,n)
    {
        fo(j,0,m)
        {
            cin>>a[i][j];
            //deb(a[i][j]);
        }
    }
    ll total=0;
    for(ll i=0;i<(1<<n);i++)
    {
        for(ll j=0;j<(1<<m);j++)
        {
            copy_matrix();
            color(i,j);
            if(check()) total+=1;
        }
    }
    //deb(total);
    cout<<total<<endl;
}
int main()
{

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
//  clock_t time_req;
//  time_req = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

// time_req = clock()-time_req;
//  cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;

    return 0;
}

Measured memory_bytes: 3608
N, K = map(int, input().split())
X = list(map(int, input().split()))
Y = []
Z = []
zc = 0
for i in range(N):
    if X[i] > 0:
        Y.append(X[i])
    if X[i] == 0:
        zc = 1
for i in range(N-1, -1, -1):
    if X[i] < 0:
        Z.append(-X[i])

cs = []
K -= zc
if K == 0:
    print(0)
else:
    if len(Y) >= K:
        cs.append(Y[K-1])
    if len(Z) >= K:
        cs.append(Z[K-1])
    for i in range(min(K-1, len(Y))):
        if K-i-2 < len(Z):
            cs.append(2*Y[i]+Z[K-i-2])
    for i in range(min(K-1, len(Z))):
        if K-i-2 < len(Y):
            cs.append(2*Z[i]+Y[K-i-2])
    print(min(cs))


Measured memory_bytes: 63512
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int x = sc.nextInt();
		int y = sc.nextInt();
		sc.close();
		
		List<Integer> xmv = new ArrayList<Integer>();
		List<Integer> ymv = new ArrayList<Integer>();
		
		int cnt = 0;
		boolean goX = true;
		for(int i=0;i<s.length()+1;i++) {
			if(i!=s.length()&&s.charAt(i)=='F')cnt++;
			else {
				if(goX) {
					xmv.add(cnt);
					goX = false;
				}else {
					ymv.add(cnt);
					goX = true;
				}
				cnt = 0;
			}
		}
		
		int xmax = 0;
		for(int i=0;i<xmv.size();i++)xmax+=xmv.get(i);
		boolean dp[][] = new boolean[xmv.size()][35000];
		dp[0][xmv.get(0)+16005]=true;
		for(int i=1;i<xmv.size();i++) {
			int dist = xmv.get(i);
			for(int j=-xmax;j<=xmax;j++) {
				dp[i][j+16005] = dp[i-1][j-dist+16005]||dp[i-1][j+dist+16005];
			}
		}
		int ymax = 0;
		if(ymv.size()==0)ymv.add(0);
		for(int i=0;i<ymv.size();i++)ymax+=ymv.get(i);
		boolean dpy[][] = new boolean[ymv.size()][30000];

		dpy[0][ymv.get(0)+16005]=true;
		dpy[0][-ymv.get(0)+16005]=true;
		for(int i=1;i<ymv.size();i++) {
			int dist = ymv.get(i);
			for(int j=-ymax;j<=ymax;j++) {
				dpy[i][j+16005] = dpy[i-1][j-dist+16005]||dpy[i-1][j+dist+16005];
			}
		}
		
		String ans = "No";
		if(dp[xmv.size()-1][x+16005]&&dpy[ymv.size()-1][y+16005]) ans = "Yes";
		System.out.println(ans);
		
	}
}


Measured memory_bytes: 301524
eval'N,M,*A='+`dd`.split*?,
s=[i=x=0]*9**6
A.map{|a|b=A[i+=1]
i<N&&(a>b&&b+=M
x+=b-a
[0,M].map{|j|s[j-~a]+=1
s[j+b]+=a-b
s[j-~b]+=b+~a})}
2.times{(3*M).times{|i|s[i+1]+=s[i]}}
p x-s.max

Measured memory_bytes: 32268
import bisect
import sys,io
import math
from collections import deque
from heapq import heappush, heappop

input = sys.stdin.buffer.readline

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7
#DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    D,T,S = isRaw()
    print("Yes" if T>=D/S else "No")

main()


Measured memory_bytes: 66032
import java.io.*;

class Main{
    public static void main(String[] args){
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String line = reader.readLine();
            String str[] = line.split(" ",0);
            int a = Integer.parseInt(str[0]);
            int b = Integer.parseInt(str[1]);
            System.out.println(a*b + " " + (a+b)*2);
        }catch(IOException e){
            System.out.println(e);
        }
    }
}


Measured memory_bytes: 24344
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pr pair<ll, ll>
#define vct vector<ll>
#define vpt vector<pr>
#define st set<ll>
#define pq priority_queue<ll>
#define mat vector<vector<ll> >
#define F(i, n) for (i = 0; i < n; i++)
#define Fr(i, n) for (i = n - 1; i >= 0; i--)
struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<long long, int, custom_hash>
void prv(vct v)
{
    for (ll i = 0; i < v.size(); i++)
        cout << v[i] << " ";
    cout << "\n";
}
ll poww(ll x, ll y, ll m)
{
    ll res = 1;
    while (y)
    {
        if (y % 2 == 0)
        {
            x = (x * x) % m;
            y = y / 2;
        }
        else
        {
            res = (res * x) % m;
            y--;
        }
    }
    return res;
}
void deb(string s, ll n)
{
    cout << s << " : " << n << "\n";
}
void prn(ll n) { cout << n << "\n"; }
void prs(string n) { cout << n << "\n"; }
ll cntd(ll n){
    ll an=0;
    while(n){
        an+=(n%10);
        n/=10;
    }
    return an;
}
mat mt;
void setmtsize(ll m,ll n, ll ini=0){
    mt.resize(m,vector<ll>(n,ini));
}
void prmt(mat m){
    for(ll i=0;i<m.size();i++)prv(m[i]);
}

ll n, k, m, l, r, x, y, ans=0;
ll t, t1, t2;

ll i, j;
ll a, b;
ll mod = 1000000007;


void solve()
{
    ans=0;
    ll an1=0,an2=0;
    cin>>n;
    vct v(n);
    F(i,n)cin>>v[i];
    sort(v.begin(),v.end(),greater<ll>());
    ans=0;
    k=1;ll cn=1;j=0;
    while(k<n){
        ans+=v[j];
        cn++;
        if(cn==2){j++;cn=0;}
        k++;
    }
    prn(ans);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}


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

int main(){
  int a,b,c,maxa=0,sum=0;
  scanf("%d %d %d",&a,&b,&c);
  sum=a+b+c;
  maxa=max(a,b);
  maxa=max(maxa,c);
  printf("%d\n",sum-maxa);
}

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

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

const long long MOD = 1000000007;

int main(){
  ll n;
  ll ans=0;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  rep(i,n-1){
    if(a.at(i+1) < a.at(i)){
      ans += a.at(i) - a.at(i+1);
      a.at(i+1) = a.at(i);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4836
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,ans=0;
	cin>>a>>b>>c;
	for(int i=a;i<=b;i++)
		ans+=(c%i==0);
	cout<<ans<<endl;
}

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

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

	double ans = 0.0, A;
	
	for (int i = 1; i <= N; i++) {
		cin >> A;
		ans += 1.0 / A;
	}

	ans = 1.0 / ans;
	cout << setprecision(16) << ans << endl;
}

Measured memory_bytes: 3760
require 'matrix'

v, l, cos, div = [], [], [], []
3.times do |i|
    x, y = gets.split.map(&:to_i)
    v[i] = Vector[x, y]
end

3.times do |i|
    j, k = (i+1)%3, (i+2)%3
    l[i] = (v[j]-v[k]).norm
    vdj, vdk = (v[j]-v[i]).normalize, (v[k]-v[i]).normalize
    cos[i] = vdj.dot(vdk)
    div[i] = (vdj + vdk) / Math.sqrt(1-cos[i]**2)
end

n1, n2 = 3.times.sort_by{|i| -cos[i]}[0, 2]

max = 10**10
[n1, n2].each do |i|
    j, k = (i+1)%3, (i+2)%3
    lm = [l[j], l[k]].min
    tan2 = Math.sqrt((1-cos[i])/(1+cos[i]))
    max = [max, lm*tan2].min
end
min = 0.0

while max-min > 10**(-10)
    r = (max+min)/2
    c1 = v[n1] + div[n1]*r
    c2 = v[n2] + div[n2]*r
    if (c1-c2).norm >= 2*r
        min = r
    else
        max = r
    end
end
puts min

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

using namespace std;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;

    vector<int> t(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
    }

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

    vector<int> lower(n, -1);
    vector<int> upper(n, -1);

    lower[0] = t[0];
    upper[0] = t[0];
    for (int i = 1; i < n; ++i) {
        if (t[i] == t[i - 1]) {
            lower[i] = 1;
            upper[i] = t[i];
        } else {
            lower[i] = t[i];
            upper[i] = t[i];
        }
    }

    if (lower[n - 1] > a[n - 1] || upper[n - 1] < a[n - 1]) {
        cout << 0 << endl;
        return 0;
    }

    lower[n - 1] = a[n - 1];
    upper[n - 1] = a[n - 1];

    for (int i = n - 2; i >= 0; --i) {
        if (a[i] == a[i + 1]) {
            lower[i] = max(lower[i], 1);
            upper[i] = min(upper[i], a[i]);

            if (lower[i] > upper[i]) {
                cout << 0 << endl;
                return 0;
            }

        } else {
            if (lower[i] > a[i] || upper[i] < a[i]) {
                cout << 0 << endl;
                return 0;
            }
            lower[i] = a[i];
            upper[i] = a[i];
        }
    }

    int answer = 1;
    for (int i = 0; i < n; ++i) {
        answer = 1LL * answer * (upper[i] - lower[i] + 1) % MOD;
    }

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <cmath>
#define ll long long
#define ull unsigned long long
using namespace std;
vector<vector<int>> g;
vector<int> len;
vector<vector<int>> col(2);
vector<int> ans;
vector<int> s;
void yn(bool a){
    if(a){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

int main(){
 

        int x,n;
        cin>>x>>n;
        vector<bool> vis(101,false);
        int a;
        for(int i=0;i<n;i++){
            cin>>a;
            vis[a]=true;
        }
        int ans1=0;
        int i=x;
        while(i>0){
            if(!vis[i]){
                ans1=i;
                break;
            }
            i--;
        }
        int ans2=101;
        i=x+1;
        while(i<101){
            if(!vis[i]){
                ans2=i;
                break;
            }
            i++;
        }
        if(ans2-x<x-ans1){
            cout<<ans2<<endl;
        }else{
            cout<<ans1<<endl;
        }
    
    
}


Measured memory_bytes: 3620
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    left = min(A[i], B[i])
    A[i] -= left
    B[i] -= left
    ans += left
    right = min(A[i + 1], B[i])
    A[i + 1] -= right
    B[i] -= right
    ans += right

print(ans)

Measured memory_bytes: 19156
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=a;i>b;i--)
#define mkp(a,b) make_pair(a,b)
#define all(v) v.begin(),v.end()
#define max3(a,b,c) max(a,(max(b,c))
#define min3(a,b,c) min(a,(min(b,c))
#define read(a) cin>>a
#define readt(a,b) read(a),read(b)
using namespace std;
bool compare(pair<int,int>& p1,pair<int,int>& p2)
{
    return p1.second<p2.second;
}
int main()
{
    fastio
    ll n;
    read(n);
    ll ma=LLONG_MIN;
    ll ans=0;
    rep(i,0,n)
    {
        ll temp;
        cin>>temp;
        ma=max(temp,ma);
        if(temp<ma) ans+=(ma-temp);
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s,t="AIDUNYAN";
vector<int>b(26);
main(){
    set<vector<int> >se;
    cin>>s;
    r(i,t.size())b[t[i]-'A']++;
    se.insert(b);
    if(s.size()>7)r(i,s.size()-7){
        vector<int>a(26);
        r(j,8)a[s[j+i]-'A']++;
        if(se.count(a)){
            r(c,8)s[c+i]=t[c];
            s[i+2]='Z';
            i+=7;
        }
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3200
#include <iostream>

using namespace std;
const int maxn = 200000 + 10;

typedef long long LL;
int N, nums[maxn];
LL res;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> nums[i];
	}

	int ind = 0, state = 0;
	bool flag = true;
	LL res = 0;

	if (nums[0] != 0) {
		cout << -1 << endl;
		return 0;
	}

	while (ind < N) {
		if(ind != 0 && nums[ind] > nums[ind - 1]) {
			flag = false;
			break;
		}
		else {
			int st = ind;
			while (ind + 1 < N && (nums[ind + 1] == nums[ind] || nums[ind + 1] == nums[ind] + 1))
				ind++;

			int ed = ind, nu = nums[ed];
			res += nums[ed];
			while (ed >= st) {
				if (nu == nums[ed]) {
					ed--;
					nu--;
				}
				else {
					res += nums[ed];
					ed--;
				}
			}//while
			ind += 1;
		}//else 

	}//while ind
	if (!flag)
		cout << -1 << endl;
	else
		cout << res << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

bool restaurant_comp(const pair<int, pair<string, int>>& r1,
                     const pair<int, pair<string, int>>& r2) {
    return r1.second.first != r2.second.first ?
            r1.second.first < r2.second.first : r1.second.second > r2.second.second;
}

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

    vector<pair<int, pair<string, int>>> restaurant(n);
    for (int i = 0; i < n; i++) {
        string s;
        int p;
        cin >> s >> p;
        restaurant[i] = make_pair(i + 1, make_pair(s, p));
    }

    sort(restaurant.begin(), restaurant.end(), restaurant_comp);

    for (int i = 0; i < n; i++) {
        cout << restaurant[i].first << endl;
    }
}


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

int main(){
  string s;
  cin >> s;
  int a_ans = 0, z_ans = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'A'){
      a_ans = i;
      break;
    }
  }
  for(int i = s.size(); i >= 0; i--){
    if(s[i] == 'Z'){
      z_ans = i;
      break;
    }
  }
  cout << z_ans - a_ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 3700