akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        String res = scan.nextLine();

        System.out.print(res.charAt(0));
        System.out.print(res.length()-2);
        System.out.println(res.charAt(res.length()-1));

    }
}

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

using namespace std;

typedef long long ll;

bool lucky(int x)
{
    if (x == 0)
    {
        return 0;
    }
    if (x % 10 == 7)
    {
        return 1;
    }
    else
    {
        return lucky(x / 10);
    }
}

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

    int x;
    cin >> x;
    if (lucky(x))
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m, 0);
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		for (int j = 0; j < k; j++) {
			int k; cin >> k;
			k = k - 1;
			a[k] = a[k] + 1;
		}
	}

	int ans = 0;
	for (int i = 0; i < m; i++) {
		if (a[i] == n) {
			ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ca = Counter(A)
cb = Counter(B)

# ca_inv = {v:k for k, v in ca.items()}
# cb_inv = {v:k for k, v in cb.items()}
is_ok = 1
for num, cnt in ca.items():
    if cnt + cb[num] > N:
        is_ok = 0
        break
if not is_ok:
    print("No")
    exit()

C = [0]*(N+1)
D = [0]*(N+1)
for i in range(1, N+1):
    C[i] = C[i-1] + ca[i]
    D[i] = D[i-1] + cb[i]

print("Yes")

x = max([-D[i-1] + C[i] for i in range(1, N+1)])
ans = B[-x:] + B[:N-x]
print(*ans)


Measured memory_bytes: 179572
from collections import defaultdict

n = int(input())
dct = defaultdict(int)

for i in range(n):
    s = input()
    sorted_s = "".join(sorted(s))
    dct[sorted_s] += 1

ans = 0
for k, v in dct.items():
    ans += v * (v - 1) // 2

print(ans)


Measured memory_bytes: 18148
import math
N,M=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
ls.sort(reverse=True)
x=ls[0]
L=int(math.log2(x))
#2**L より大きいものをわける
def cut(lst,exp):
    for ii in range(len(lst)):
        if ii+1==len(lst):
            break
        if lst[ii+1]<exp:
           break
    return ii
m=M #残り回数
b=-1
ls3=[]
while True:
    if m==0:
        break
    a=b+1
    b=cut(ls,2**L)
    ls2=ls[a:b+1]
    ls3=ls3+ls2
    if ls2!=[]:
        ls3.sort(reverse=True)
    for j in range(len(ls3)):
        ls3[j]=ls3[j]//2
        m-=1
        if m==0:
            break
    L-=1
#    print(ls3,m,b)
#print(ls3,ls[b+1:])
s=sum(ls3)+sum(ls[b+1:])
print(s)
    

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    if(is_sorted(v.begin(),v.end())){
        cout<<"YES"<<endl;
        return 0;
    }
    else
    {
      int c=0;
      for(int i=0;i<n;i++)
      {
          if(v[i]!=(i+1))
            ++c;
        if(c>2)
        {
            cout<<"NO"<<endl;
            return 0;
        }
      }
      if(c==2)
      {
          cout<<"YES"<<endl;
          return 0;
      }
      else
      {
          cout<<"NO"<<endl;
          return 0;
      }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

struct Edge {
  ll from, to;
  ll cost;
  Edge(ll from, ll to, ll cost):
  from(from),to(to),cost(cost){}
};

ll minv = -1ll * (1ll << 35ll);
ll n, m, p;
ll s, t, c;
ll dist[3000];
vector<Edge> G;

int bellman_ford(vector<Edge> &edges) {
  int state = 1;
  dist[1] = 0;
  for(int i = 0; i < n - 1; i++) {
    for(auto &e : edges) {
      if(dist[e.from] == minv) continue;
      dist[e.to] = max(dist[e.to], dist[e.from] + e.cost);
    }
  }
  
  ll d[3000];
  for (int i=0;i<3000;i++)d[i]=dist[i];
  for(int i = 0; i < n - 1; i++) {
    for(auto &e : edges) {
      if(d[e.from] == minv) continue;
      if(d[e.to]<d[e.from]+e.cost)d[e.to] = -1 * minv;
    }
  }
  
  return d[n]==dist[n];
}

int main() {
  for (int i=0;i<3000;i++) dist[i] = minv;
  cin >> n >> m >> p;
  
  for (int i=0;i<m;i++) {
    cin >> s >> t >> c;
    G.push_back(Edge(s,t,c-p));
  }
  
  if (bellman_ford(G)) cout << max(0ll,dist[n]) << endl;
  else cout << -1 << endl;
  
  return 0;
}


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

int main() {
  long long a, b, n;
  long long k, l;
  cin >> a >> b >> n;
  if(n < b) {
    k = (a * n) / b;
    l = n / b;
    cout << k - a * l << endl;
  }
  else {
    k = (a * (b-1)) / b;
    l = (b-1) / b;
    cout << k -a * l << endl;
  }
}

Measured memory_bytes: 3608
#include <stdio.h>
#define MAX 10000
#define T 1
#define F 0
int i;

int isPrime(int x){
  //  printf("%d",x);
  if(x<=1){
    return F;
  }

  if(x==2) return T;

  if(x%2==0) return F;
  
  for(i=3;i*i<=x;i+=2){
    if(x%i==0 && x!=i){
      return F;
    }
  }
      return T;
}

int main(){
  int i,j=0,x[MAX],n,c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&x[i]);
    c=isPrime(x[i]);
    if(c==1)j++;
  }

  printf("%d\n",j);

  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <string>
#include <numeric>

using namespace std;

string solve(int N, const vector<int> &a, const vector<int> &b)
{
	long long sa = accumulate(a.begin(), a.end(), 0LL);
	long long sb = accumulate(b.begin(), b.end(), 0LL);
	if (sa > sb) {
		return "No";
	}
	long long m = sb - sa;

	long long na = 0;
	long long nb = 0;
	for (int i = 0; i < N; ++i) {
		if (a[i] < b[i]) {
			na += (b[i] - a[i] + 1) / 2;
			nb += (b[i] - a[i]) % 2;
		}
		else {
			nb += a[i] - b[i];
		}
	}
	if (na > m || nb > m || nb > na) {
		return "No";
	}
	if (na - nb != m - na) {
		return "No";
	}
	return "Yes";
}

int main()
{
	int N;
	cin >> N;
	vector<int> a(N), b(N);
	for (auto &x : a) cin >> x;
	for (auto &x : b) cin >> x;
	cout << solve(N, a, b) << endl;
}


Measured memory_bytes: 384
N,W = map(int, input().split())

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

# i番目まで選べる時の価値とその時の最小重み
dp = [{} for _ in range(N+1)]
dp[0][0] = 0

for i, (w, v) in enumerate(wv):
    #i-1個目までの時の価値と対応する最小重みを取り出す
    for v0, w0 in dp[i].items(): # 典型的なDPの過去の部分を利用するのがi, 現在部分がi+1
        # iまで選べる時にその価値がすでに組み合わせが存在するなら小さいほう、
        if v0 in dp[i+1]:
            dp[i+1][v0] = min(dp[i+1][v0], w0)
        # 組み合わせがないならi-1個までで作った時の重みを採用
        else:
            dp[i+1][v0] = w0

        #i番目を利用して制限を超えるならその組み合わせはスキップ
        if w0 + w > W:
            continue
        #i-1番目までのそれぞれの組み合わせとi番目を選んだ場合
        if v0 + v in dp[i+1]:
            
            dp[i+1][v0 + v] = min(dp[i+1][v0 + v], w0 + w)
        else:
            dp[i+1][v0 + v] = w0 + w

print(max(dp[N].keys()))
        


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

int main()
{
  int N;
  int64_t ans = 0;

  cin >> N;
  for (int i = 1; i <= N; i++)
  {
    if (i % 3 != 0 && i % 5 != 0)
      ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0,(i##_len)=(n);(i)<(i##_len);(i)++)
#define rep2(i,a,b) for(ll (i)=(a),(i##_len)=(b);(i)<=(i##_len);(i++))
#define rrep(i,n) ll(i)=(n);ll now=-1;while((i)--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)<<"\n"
#define vll vector<ll>
#define pb push_back
using namespace std;
using ll = long long;

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

// Template ends here

void solve(string S){
    sort(all(S));
    rep(i, int(S.size()) - 1) {
        if (S.at(i) == S.at(i + 1)) {
            cout << "no\n";
            return;
        }
    }
    cout << "yes\n";
}

int main() {
    string S;
    cin >> S;
    solve(S);
    return 0;
}

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

int main() {
    string s, t;
    int a, b;
    string u;
    cin >> s >> t >> a >> b >> u;

    if (u == s)  --a;
    else --b;

    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
n, a, b, c, d = gets.chomp.split(" ").map(&:to_i)

(0...n).each do |k|
  if k * c - (n - 1 - k) * d <= b - a && k * d - (n - 1 - k) * c >= b - a then
    puts "YES"
    exit
  end
end
puts "NO"

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

using namespace std;

int main() {
    long long a, b, k;  cin >> a >> b >> k;
    if (b-k+1 <= a+k-1) {
        for (int i = a; i <= b; i++)
            cout << i << endl;
        return 0;
    }
    else {
        for (int i = a; i <= a+k-1; i++)
            cout << i << endl;
        for (int i = b-k+1; i <= b; i++)
            cout << i << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int t,n;
    for(int i=0;i<4;i++){
        cin>>t>>n;
        if(t==1){
            cout<<6000*n<<endl;
        }
        else if(t==2){
            cout<<4000*n<<endl;
        }
        else if(t==3){
            cout<<3000*n<<endl;
        }
        else if(t==4){
            cout<<2000*n<<endl;
        }
        }
}


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

using namespace std;

int main() {

	int N;
	cin >> N;

	vector<vector<int>> D(N, vector<int>(2));

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

	int ans = 0;

	for (int i = 0; i < N; ++i)
	{
		if (D[i][0] == D[i][1]) {
			ans++;
		}
		else ans = 0;
		if (ans >= 3) break;
	}

	if (ans >= 3) {
		cout << "Yes";
	}
	else cout << "No";

	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
typedef pair<pill,int> PA;
//ll MOD;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	ll weight;
};
int N;
int K;
ll H[500];
ll dp[500][500]={0};
vector<ll> rireki;
int main(){
	cin>>N>>K;
	ll ans=3e12;
	H[0]=(ll)0;
	rep(i,N){
		cin>>H[i+1];
	}
	rep(i,N+1)rep(j,N+1)dp[i][j]=3e12;
	dp[0][0]=(ll)0;
	rep(i,N+1)dp[i][1]=H[i];
	for(int i=1;i<=N;i++)for(int j=2;j<=N;j++){
	
			for(int k=1;k<i;k++){
				if(k>1)dp[i][j]=min(dp[i][j],dp[k][j-1]+max((ll)0,H[i]-H[k]));
				else dp[i][j]=dp[k][j-1]+max((ll)0,H[i]-H[k]);
			}

	}
	/*rep(i,N){
		rep(j,N){
			ll x=dp[i+1][j+1];
			if(x>=3e12)cout<<"inf";
			else cout<<dp[i+1][j+1];
		}
		cout<<endl;
	}*/
	rep(i,N)ans=min(ans,dp[i+1][N-K]);
	if(N==K)ans=0;
	cout<<ans<<endl;

}


Measured memory_bytes: 1408
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  int t , x;
  cin >> t >> x;
  double ans = (double)t / x;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
//ask the right questions.		

int32_t main() 
{
	int N, W;
	cin >> N >>W;
	int weights[N];
	int value[N];

	int x;
	for(int i=0;i<2*N;i++)
	{
		cin >> x;
		if(i%2==0)
		{
			weights[i/2]=x;
		}
		else
		{
			value[(i-1)/2]=x;
		}
	}

	//let denote the max value when you have capacity_left of w and deciding upon nth item.
	int dp[N+1][W+1];

	//trivial case : choosing over no elements
	for(int i=0; i<=W; i++)
	{
		dp[0][i]=0;
	}

	//base case: choosing when wight capacity is 0
	for(int i=0; i<=N; i++)
	{
		dp[i][0]=0;
	}


	//TIP:
	//you are deciding on the ith item: to take or not
	//if you want to take then you look previously for a state with wight gap of at least 
	//weight[i-1] (ie weight of ith item)
	//you need not look for a greater gap as the max value obtained by a state with greater
	//weight capacity will always be equal or greater than max value obtained by a lower weight capacity state.


	// shift i-1 in weights and values
	for(int i=1; i<=N; i++)
	{
		for(int j=1; j<=W; j++)
		{
			//want to take
			int a = 0;
			if(j>=weights[i-1])      //since we are deciding on inclusion of ith element always shift by 1 
									//in arrays except dp indexing		
			{
				a = dp[i-1][ j-weights[i-1] ] + value[i-1];	       		
			}
			//dont want to:
			dp[i][j] = max(a, dp[i-1][j]);
		}		
	}

	cout << dp[N][W] <<endl;

	return 0;
	
}

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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class K, class V> void cout_v(map<K, V>& m)
{ for(auto it=m.begin();it!=m.end();it++)cout<<it->first<<":"<<it->second<<endl;}
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
template<class T> inline bool is_overlap(const T& a, const T& b, const T& p, const T& q)
{ return p <=b && a <= q; }
#define MOD = 1000000007;
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}


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


    int N; cin >>N;
    vector<int> a(N); cin >> a;
    
    vector<int> n(9, 0);
    rep(i, N) {
        if (a[i] >= 3200)
            n.back()++;
        else
            n[a[i]/400]++;
    }
   
    int beyond_red = 0;
    rep(i, n.size()-1)
        if (n[i]) beyond_red++;
    int le_red = n.back();
    
    int ans_min;
    int ans_max;

    if (beyond_red == 0) {
        if (le_red > 0)
            ans_min = 1;
        else
            ans_min = 0;
    } else {
        ans_min = beyond_red;
    }
    ans_max = le_red + beyond_red;
    
    cout << ans_min << " " << ans_max << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int INF = INT_MAX / 2;

int main()
{
    for(int d=1; ; ++d){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

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

        if(c[0] != 1){
            cout << "Case #" << d << ": Cannot pay some amount" << endl;
            continue;
        }

        vector<int> dp(10000, INF);
        dp[0] = 0;
        for(int i=0; i<n; ++i){
            for(int j=0; j<10000; ++j){
                int k = j + c[i];
                if(k < 10000 && dp[j] + 1< dp[k])
                    dp[k] = dp[j] + 1;
            }
        }

        bool ok = true;
        for(int i=0; i<10000; ++i){
            int rest = i;
            int coin = 0;
            for(int j=n-1; j>=0; --j){
                coin += rest / c[j];
                rest %= c[j];
            }
            if(coin > dp[i])
                ok = false;
        }

        if(ok)
            cout << "Case #" << d << ": OK" << endl;
        else
            cout << "Case #" << d << ": Cannot use greedy algorithm" << endl;
    }
}

Measured memory_bytes: 1236
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);

   int N = sc.nextInt();
   char[] as = sc.next().toCharArray();
   
   int[] Esum = new int[N];
   int E =0;
   for(int i=0;i<N;i++) 
   {
     if(as[i]=='E') E++;
     Esum[i]=E;
   }
   int W = N - E;
   
   int ans= E;
   int tmpE=0;
   int tmpW=0;
   for(int i=1;i<N;i++)
   {
     tmpE=Esum[i-1];
     tmpW=i-tmpE;
     
     if(ans>E-Esum[i]+tmpW) ans = E-Esum[i] + tmpW;
   }
   System.out.println(ans);
 }
}

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

int main(){
    ll n;
    cin>>n;
    vector<ll> l(n);
    ll maxh=0;
    rep(i,n) {
        cin>>l[i];
        maxh=max(maxh,l[i]);
    }
    ll ans=n*(n-1)*(n-2)/6;
    sort(l.begin(),l.end());
    //cout<<l[0]<<endl;
    for(ll i=0;i<n-2;i++){
        for(ll j=i+1;j<n-1;j++){
            for(ll k=j+1;k<n;k++){
                if(l[i]+l[j]<=l[k]){
                    ans-=n-k;
                    //tmp=k;
                    //cout<<ans<<endl;
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3608
module Main where

import           Control.Monad
import           Data.Array.IO
import           Data.Char
import           Data.List
import           Data.List.Split
import           Data.Ord
import qualified Data.Vector.Unboxed as V
import           Text.Printf

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine :: IO [Int]
  s <- getLine
  forM_ [1 .. n]
    $ \i -> do
      if i == k
        then putChar $ toLower $ s !! (i - 1)
        else putChar $ s !! (i - 1)




Measured memory_bytes: 508
#include <stdio.h>

int main()
{
  int N,A[1000],i,j,key;

  scanf("%d",&N);
  for(i=0;i<N;i++) {
    scanf("%d",&A[i]);
      }

  for(j=0;j<N;j++) {
    if(j>0) { printf(" ");
    }
    
    printf("%d",A[j]);
  }
  printf("\n");

  for(i=1;i<N;i++) {
    key=A[i];
    j=i-1;

  while(j>=0 && A[j]>key){
    A[j+1] = A[j];
    j--;
  }
  A[j+1] = key;
  
  for(j=0;j<N;j++) {
    if(j>0) { printf(" ");
    }
    
    printf("%d",A[j]);
  }
  printf("\n");

  }

  return 0;
}

Measured memory_bytes: 604
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 1000005
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1005;
const long double epsilon = 1e-9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {

	fast
	ll n;
	cin >> n;
	vl a(n);
	ain(a, n);
	sort(all(a), greater<ll>());
	ll ans = a[0], k = n - 2, i = 1;
	while (k > 0)
	{
		ans += min(2LL, k) * a[i++];
		k -= min(2LL, k);
	}
	cout << ans << END;


// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}

Measured memory_bytes: 4776
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  int i=0;
  int ans=0;
  while(i<N){
    if(A[i] == A[i+1]){
      i++;
      continue;
    }
    ans++;
    if(A[i] < A[i+1]){
      while(A[i] <= A[i+1]){
        i++;
      }
    }else{
      while(A[i] >= A[i+1]){
        i++;
      }
    }
    i++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double tax = 1.08;
        int ans = (int) (n/tax);
        if((int)(ans*tax) == n){
            System.out.print(ans);
        }else{
            if((int)((ans+1)*tax) == n){
            System.out.print(ans+1);
             }else{
            //System.out.print(ans + " " + (int)(ans*tax));
            System.out.print(":(");
        }
        }
        
    }
    
}


Measured memory_bytes: 21844
#include <iostream>
#include <cassert>
#include <queue>

#define INF 922337203685477580
typedef long long ll;

using namespace std;

void countingSort(int* A, int* B, int k, int n) {
  int C[k + 10];
  for (int i = 0; i <= k + 5; i++) {
    C[i] = 0;
  }

  for (int j = 0; j < n; j++) {
    C[A[j]]++;
  }

  for (int i = 1; i <= k; i++) {
    C[i] = C[i] + C[i - 1];
  }

  for (int j = n - 1; j >= 0; j--) {
    B[C[A[j]] - 1] = A[j];
    C[A[j]]--;
  }
}

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

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

  countingSort(A, B, 10100, n);

  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    cout << B[i];
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 18740
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>
#include <fstream>
 
  using namespace std;
   
 
//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ

  typedef long long ll;
  typedef long double lld;
  typedef unsigned long long ull;
  // ll INF = INT_MAX;
  // ll mod = 1000000007;
  // lld PI = 3.141592653;
 
// const int N = 2e5 + 5;


  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
      // ifstream cin("input.txt");

      int n;
      cin>>n;
      if (n>=30)
        cout<<"Yes\n";
      else
        cout<<"No\n";

}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
bool prime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(){
	int n;cin>>n;
    ll a[n];
    rep(i,n)cin>>a[i];
    vl me(1000005,0);
    rep(i,n)me[a[i]]++;
    ll ans =0;
    if(me[1]){
        if(me[1]==1)cout<<1<<endl;
        else cout<<0<<endl;
        return 0;
    }
    rep(i,n){
        if(me[a[i]]>1)continue;
        if(prime(a[i])){
            ans++;
        }
        else{
            bool f=true;
            rep(j,sqrt(a[i])+1){
                if(j==0||j==1)continue;
                if(a[i]%j==0){
                    if(me[a[i]/j]!=0||me[j]!=0){
                    f=false;
                    }
                }
            }
            if(f){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

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

vector<pair<ll, ll> > prime_factorize(ll N) {
    vector<pair<ll, ll> > res;
    for (ll i = 2; i * i <= N; ++i) {
        if (N % i != 0) continue;
        ll ex = 0;
        while (N % i == 0) {
            ++ex;
            N /= i;
        }
        res.push_back({i, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

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

    ll A,B;
    cin >> A >> B;
    ll G = gcd(A,B);
    ll cnt=0;
    auto pf = prime_factorize(G);
    cout << pf.size() + 1 << endl;
    return 0;
}

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

int main() {
	int n;
	while(cin >> n && n != EOF) {
		bool* prime = new bool[n+1];
		int count = 0;
		for(int i = 0; i <= n; ++i) {
			prime[i] = true;
		}
		prime[0] = prime[1] = false;
		
		for(int i = 0; i <= n; ++i) {
			if(prime[i]) {
			//	cout << i << '\t';
				for(int j = 2 * i; j <= n; j += i) {
					prime[j] = false;
				}
			}
		}
		
		for(int i = 0; i <= n; ++i) {
			if(prime[i]) {
				count++;
			}
		}
		
		cout << count << endl;
		delete[] prime;
	}
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/f.in", "r", stdin);
//  freopen("../IO/f.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  out << fixed << setprecision(9);
  int n, m;
  in >> n >> m;
  vector<vector<int>> g(n + 1);
  for (int i = 0, u, v; i < m; ++i) {
    in >> u >> v;
    g[u].push_back(v);
  }
  vector<double> dp(n + 1, numeric_limits<double>::infinity());
  dp[n] = 0;
  for (int u = n - 1; u >= 1; --u) {
    dp[u] = 0;
    for (int v : g[u]) {
      dp[u] += dp[v] + 1;
    }
    dp[u] /= g[u].size();
  }
  double res = dp[1];
  for (int i = 1; i < n; ++i) {
    int num = g[i].size();
    if (num < 2) continue;
    vector<double> d = dp;
    double mx = 0, sum = 0;
    for (int u : g[i]) {
      sum += d[u];
      mx = max(d[u], mx);
    }
    d[i] = (sum - mx) / (num - 1) + 1;
    for (int j = i - 1; j >= 1; --j) {
      sum = 0;
      for (int u : g[j]) {
        sum += d[u] + 1;
      }
      d[j] = sum / g[j].size();
    }
    res = min(res, d[1]);
  }
  out << res << '\n';
}


Measured memory_bytes: 1408
/*
ID: tohoast1
TASK: gymnastics
LANG: C++
*/
#include <bits/stdc++.h>
#define speedup ios_base::sync_with_stdio(NULL)
#define fin freopen("allcodefs.in", "r", stdin)
#define fout freopen("allcodefs.out", "w", stdout)
#define FILENAME
#define PUBG push_back
#define p_b pop_back
#define mp make_pair
#define fi first
#define se second
#define cls clear
#define INF const int ci = 1e6 + 100
#define K_INF 1e9 + 7
#define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define MIN_INT -999999999
#define MOD 1000000007
#define d109 1000000000
#define basay break
#define bmbr exit(0)

using namespace std;
typedef long long LL;
typedef long L;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef string STR;
int N;

int main() {
    #ifdef FILENAMEs
        fin;
        fout;
    #endif // FILENAME
    cin >> N;
    (N < 1200) ? cout << "ABC" : cout << "ARC";
    ///time;
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
using namespace std;
int main()
{
	long long n,s;
	s=0;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
	}
	for(int i=0; i<n; i++)
	{
		for(int j=i+1; j<n; j++)
		{
			for(int k=j+1; k<n; k++)
			{
				if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[k]+a[j]>a[i] && a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k])
				{
					s=s+1;
				}
			}
		}
	}
	cout<<s;
}

Measured memory_bytes: 3632
#include <stdio.h> //printf()
#include <stdlib.h> //exit()

int main() {
	int A, B, C, D;
  if (scanf("%d %d %d %d", &A, &B, &C, &D) < 0) {
    exit(1);
  }
  int product_1 = A * B;
  int product_2 = C * D;
  if (product_1 >= product_2) {
    printf("%d\n", product_1);
  }else {
    printf("%d\n", product_2);
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
 
using lint=long long;
using pint=pair<int,int>;
template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

lint dp[110][2][10];

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

   dp[0][0][0]=1;
   for(int i=0;i<N;i++) for(int less=0;less<2;less++) for(int j=0;j<=K;j++){
      int maxD=(less? 9:s[i]-'0');
      for(int d=0;d<=maxD;d++){
         dp[i+1][less|(d<s[i]-'0')][j+(d!=0)]+=dp[i][less][j];
      }
   }
   cout<<dp[N][0][K]+dp[N][1][K]<<endl;
   return 0;
}


Measured memory_bytes: 256
a,b=map(int,input().split())
if a<b:
  a,b=b,a
def gcd(m,n):
  while n!=0:
    m,n=n,m%n
  return m
def div(l):
  division=[]
  for i in range(1,int(l**0.5)+1):
    if l%i==0:
      division.append(i)
      if i!=(l//i):
        division.append(l//i)
  return division
lst=div(gcd(a,b))
cnt=1
for i in range(len(lst)):
  if len(div(lst[i]))==2:
    cnt+=1
print(cnt)
    
    


Measured memory_bytes: 40796
#include<stdio.h>

int main() {
	int n,x,i,j,k,count=0;

	while (1) {
		scanf("%d %d", &n, &x);

		if(n==0&&x==0) break;
		
		count = 0;

		for (i = 1; i <= n;i++) {
			for (j = 1; j <= n; j++) {
				if (i == j) break;
				for (k = 1; k <= n; k++) {
					if (i == k || j == k) break;
					if (i + j + k == x) count++;
				}
			}
		}

		printf("%d\n", count);

	}

	return 0;
}


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

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
    int h, w;
    string str;
    vector<string> grid;
    long mod = 1e9 + 7;

    cin >> h >> w;
    getline(cin, str);

    for (int i = 0; i < h; i++) {
        getline(cin, str);
        grid.push_back(str);
    }

    vvi ways(h+1, vi(w+1, 0));
    ways[0][1] = 1;

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (grid[i-1][j-1] == '.') {
                ways[i][j] = (ways[i-1][j] + ways[i][j-1]) % mod;
            }
        }
    }
    cout << ways[h][w] << endl;
    return 0;
}



Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> a(N, 0);
  for(auto &i : a) cin >> i;
  int ans = 0, idx = 0;
  vector<bool> flag(N, false);
  while(idx != 1){
    if(flag[idx]){
      cout << -1 << endl;
      return 0;
    }else{
      flag[idx] = true;
      ans++;
      idx = a[idx] - 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <random>

using ll = long long;

//各種nil
template <class T>
constexpr T nil = static_cast<T>(-1);

constexpr int nil_i = nil<int>;
constexpr int nil_ll = nil<ll>;
constexpr double nil_d = nil<double>;

//vector
template <class T>
using vec = std::vector<T>;

struct Vec2D
{
    int x, y;
};

struct TimePos
{
    int time;
    Vec2D pos;
};

int ManhattanDistance(Vec2D v1, Vec2D v2)
{
    using namespace std;
    return abs(v1.x - v2.x) + abs(v1.y - v2.y);
}

void solve()
{
    using namespace std;
    string s;
    cin >> s;

    s.replace(0, 4, "2018");

    cout << s << endl;

}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int N=2e5+10;
int n,k;
int a[N];
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	long long sum=0;
	for(int i=0;i<n-k;i++) sum+=a[i];
	cout<<sum;
	return 0;
}


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

int main()
{
	int T;
	cin >> T;
	rep(i,T)
	{
		ll N;
		cin >> N;
		ll ans = 0;
		vector<pair<ll,P> > l,r;
		rep(j,N)
		{
			ll K,L,R;
			cin >> K >> L >> R;
			K--;
			if (L >= R)
			{
				l.push_back(make_pair(K,P(L,R)));
				ans += R;
			}
			else
			{
				if (K != N-1) r.push_back(make_pair(K,P(L,R)));
				ans += L;
			}
		}
		//cout << ans << " ";
		priority_queue<ll, vector<ll>, greater<ll> > Q1,Q2;
		sort(l.begin(), l.end());
		sort(r.begin(), r.end());
		reverse(r.begin(), r.end());
		int idx = 0;
		rep(j,N)
		{
			while(idx < l.size() && l[idx].first == j)
			{
				Q1.push(l[idx].second.first - l[idx].second.second);
				idx++;
			}
			while(Q1.size() > j+1)
			{
				Q1.pop();
			}
		}
		while(!Q1.empty())
		{
			ans += Q1.top();
			Q1.pop();
		}
		//cout << ans << " ";
		idx = 0;
		rep(j,N)
		{
			while(idx < r.size() && r[idx].first == N-2-j)
			{
				Q2.push(r[idx].second.second - r[idx].second.first);
				idx++;
			}
			while(Q2.size() > j+1)
			{
				Q2.pop();
			}
		}
		while(!Q2.empty())
		{
			ans += Q2.top();
			Q2.pop();
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
	int a[100000][2], i, I, b[100000];
	char n;
	for(i = 0 ;  ; i++)
	{
		scanf("%d %c %d", &a[i][0], &n, &a[i][1]);
		if(n == '+')
		{
			b[i] = a[i][0] + a[i][1];
			continue;
		}
		else if(n == '-')
		{
			b[i] = a[i][0] - a[i][1];
			continue;
		}
		else if(n == '*')
		{
			b[i] = a[i][0] * a[i][1];
			continue;
		}
		else if(n == '/')
		{
			b[i] = a[i][0] / a[i][1];
			continue;
		}
		else if(n == '?')
		{
			for(I = 0 ; I < i ; I++)
			{
				printf("%d\n", b[I]);
			}
			exit(0);
		}
	}
	
	return 0;
}


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

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define ll long long
#define pii pair<int, int>
#define is insert
#define er erase

using namespace std;

const int MAX_N = 2e5 + 5;

const ll INF = 1e18;

int solve();

#define TASK ""

int main()
{
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
        //freopen(TASK".in", "r", stdin);
        //freopen(TASK".out", "w", stdout);
    #endif // DEBUG
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

ll n;
ll ans = INF;

ll a[MAX_N];

ll dp[MAX_N][5];

ll get(ll x, int t)
{
    if (t == 0 || t == 4)
    {
        return x;
    }
    if (t == 1 || t == 3)
    {
        return (x == 0 ? 2 : x % 2);
    }
    return 1 - x % 2;
}

int solve()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }
    for (int i = 0; i <= n; ++i)
    {
        for (int j = 0; j < 5; ++j)
        {
            dp[i][j] = INF;
        }
    }
    for (int j = 0; j < 5; ++j)
    {
        dp[0][j] = 0;
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 0; j < 5; ++j)
        {
            for (int v = 0; v <= j; ++v)
            {
                dp[i][j] = min(dp[i][j], dp[i - 1][v] + get(a[i], v));
            }
            //cerr << i << ' ' << j << ' ' << dp[i][j] << '\n';
        }
    }
    cout << dp[n][4] << '\n';
    return 0;
}




Measured memory_bytes: 9600
#include <iostream>

using namespace std;

const int N = 10;

int main()
{
	int n;

	cin >> n;
	while (n--) {
		bool ans = true;
		int a, b = -1, c = -1;
		for (int i = 1; i <= N; i++) {
			cin >> a;
			if (ans) {
				if (a > b)
					b = a;
				else if (a > c)
					c = a;
				else
					ans = false;
			}
		}

		cout << (ans ? "YES" : "NO") << endl;
	}
	
	return 0;
}


Measured memory_bytes: 2960
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {in_x: usize};
    let mut money = 100;
    let mut year = 0;

    while money < in_x {
        money = (money as f64 * 1.01) as usize;
        year += 1;
    }
    println!("{}", year);
}


Measured memory_bytes: 2164
#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    int i;
    scanf("%d",&N);

    int a[105]={0};
    int sum=0;
   for(i=1;i<=N;i++){
    scanf("%d",&a[i]);
      sum+=a[i];
   }
   sort(a,a+N);
   int j=1;
   int b[103]={0};

   for(i=1;i<=N;i++)
   {
      if(a[i]%10!=0){
        b[j]=a[i];
        j++;
        }
        else
            continue;
   }
   for(j=1;j<sizeof(b);j++)
    if(sum%10==0)
      sum-=b[j];
    else if(sum%10!=0&&sum>=0){
        printf("%d",sum);
        return 0;
    }

   printf("0");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
	cout << setprecision(13) << fixed;
	while(true) {
		int n; cin >> n;
		if (n == 0) break;
		vd v(n); rep(i, 0, n) cin >> v[i];
		double avg = accumulate(all(v), 0.0) / n;
		double ans = 0.0;
		rep(i, 0, n) {
			ans = ans + pow(v[i] - avg, 2);
		}
		P(sqrt(ans / n));
	}
	return 0;
}

Measured memory_bytes: 3284
#def lunlun(n):
#    D = []
#    while n:
#        D.append(n%10)
#        n //= 10
#    return all(abs(D[i-1]-D[i])<=1 for i in range(1,len(D)))

def lunlun_gen(which):
    R = []

    D = [1]
    while len(R) < which:
        num = 0
        for d in D:
            num = 10*num + d
        R.append(num)

        for i in reversed(range(1, len(D))):
            if D[i] + 1 <= 9 and abs(D[i] + 1 - D[i-1]) <= 1:
                D[i] += 1
                break
        else:
            # last digit
            i = 0
            if D[0] == 9:
                D.append(0)
                D[0] = 1
            else:
                D[0] += 1

                
        for j in range(i+1, len(D)):
            D[j] = max(0, D[j-1] - 1)
    return R[which-1]

k = int(input())
print(lunlun_gen(k))


Measured memory_bytes: 7240
N = int(input())
x = [0]*N
y = [0]*N
L1_dict = dict()
for i in range(N):
    x[i], y[i] = map(int, input().split())
xy = zip(x, y)
xy = sorted(xy, key=lambda x: (x[0], x[1]))
x, y = zip(*xy)
for i in range(N-1):
    for j in range(i, N):
        if i != j:
            x_diff = x[j] - x[i]
            y_diff = y[j] - y[i]
            if (x_diff, y_diff) not in L1_dict:
                L1_dict[(x_diff, y_diff)] = 1
            else:
                L1_dict[(x_diff, y_diff)] = 1 + L1_dict[(x_diff, y_diff)]
if L1_dict:
    M = max(L1_dict.values())
    print(N - M)
else:
    print(N)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{ 
    cool;
    int n;
    cin>>n;
    int i,j,a[n],sum1=0,sum2=0,diff=0,mini=10e9;
    for(i=0;i<n;i++)
    cin>>a[i];
    for(i=1;i<n;i++)
    {
    	for(j=0;j<i;j++)
    	{
    		sum1+=a[j];
		}
		for(j=i;j<n;j++)
		{
			sum2+=a[j];
		}
		diff=abs(sum1-sum2);
		mini=min(mini,diff);
		sum1=0;
		sum2=0;
	}
	cout<<mini;
	return 0;
}

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

int main()
{
    int N, A, B;
    cin >> N >> A >> B;

    int sum = 0;
    for (int i = 1; i <= N; i++)
    {
        int t = i;
        int d = 0;
        while (t != 0)
        {
            d += t % 10;
            t /= 10;
        }

        if (A <= d && d <= B)
        {
            sum += i;
        }
    }

    cout << sum;
}

Measured memory_bytes: 3580
#include<iostream>
int main(){
	int a;
	long long b, n;
	std::cin >> a >> b >> n;

	long long x = n;
	long long ans;
	if(n >= b-1){
		x = b - 1;
	}
	ans = a*x/b - a*(x/b);
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int f(ll n) {
    int x = 0;
    
    while(1) {
        if(n == 0) {
            break;
        }
        n /= 10;
        x++;
    }

    return x;
}

int main() {
    ll N, A, B;
    cin >> N;
    int ans = 20;

    for(A = 1; A*A <= N; A++) {
        if(N % A == 0) {
            B = N/A;
            ans = min(ans, f(B));
        }
    }

    cout << ans;

    cout << endl;
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int tmp = 0;
  for(int i=0; i<N; ++i){
    int a;
    cin >> a;
    tmp ^= a;
  }
  if(tmp==0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    bool flag = true;
    if(n<10){
        cout << n << endl;
        return 0;
    }
    rep(i,n-1){
        ans += 9;
        if(n%10!=9){
            flag = false;
        }
        n /= 10;
    }
    if(flag){
        ans += n;
    }else{
        ans += n - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bitset>
#include<vector>
#include<limits>

using namespace std;

int MAX = numeric_limits<int>().max()/16;
vector<vector<int>> cost;

// int make(vector<int> &l, int target){
//   int s = 0;
//   for( auto &ll : l){
//     s += ll;
//   }
//   return l.size() + abs(target-s);
// }

int main(){
  cost.resize(3);
  cost[0].resize(256, MAX);
  cost[1].resize(256, MAX);
  cost[2].resize(256, MAX);
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> l(N);
  for( int i = 0; i < N; ++i ){
    cin >> l[i];
  }
  int bb = 1<<N;
  for( int i = 0; i < bb; ++i ){
    int s = 0;
    int c = 0;
    for( int j = 0; j < N; ++j ){
      if( (i & (1<<j)) == 0 ){ continue; }
      s += l[j];
      ++c;
    }
    // cout << c << "," << s << endl;
    cost[0][i] = (c-1)*10 + abs(s-A);
    cost[1][i] = (c-1)*10 + abs(s-B);
    cost[2][i] = (c-1)*10 + abs(s-C);
  }
  int ans = MAX;
  int M = 1<<24;
  for( int i = 0; i < M; ++i ){
    int a = (i & ((1<<8)-1));
    int b = (i & ((1<<16)-1)) >> 8;
    int c = (i & ((1<<24)-1)) >> 16;
    // if( i == 1052161 ){
    //   cout << cost[0][a] << endl;
    //   cout << cost[1][b] << endl;
    //   cout << cost[2][c] << endl;
    // }
    if( a & b ){ continue; }
    if( a & c ){ continue; }
    if( b & c ){ continue; }
    // if( ((a|b|c) & (255<<(N))) ){ continue; }
    if( a * b * c == 0 ){ continue; }
    if( cost[0][a] == MAX || cost[1][b] == MAX || cost[2][c] == MAX ){ continue; }
    int tmp = cost[0][a] + cost[1][b] + cost[2][c];
    // cout << bitset<24>(i) << endl;
    // cout << tmp << "," << bitset<8>(a) << "," << bitset<8>(b) << "," << bitset<8>(c) << endl;
    if( tmp < ans ){ ans = tmp; }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256