akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>

#define rep( i, m, n ) for(int( i ) = ( m ); ( i ) < ( n ); ( i )++)

int main( void ){
	long long int  n;
	if (!scanf( "%lld", &n ))
		return -1;
	long long int sum = ( 1 + n ) * n / 2 - n;
	printf( "%lld\n", sum);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};


int a[100005];
int p[10005];

int main(){
   int a,b,c;
   cin>>a>>b>>c;
   if(a==b and a!=c)
      cout<<"Yes"<<endl;
   else if(a==c and b!=a)
      cout<<"Yes"<<endl;
   else if(b==c and a!=b)
      cout<<"Yes"<<endl;
   else 
      cout<<"No"<<endl;
   return 0;
}

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

int main(){
  int n;
  cin >> n ;
  
  for (int i = 0; i < n; i ++){
    string s;
    cin >> s;
    //cout << i << ":" << s;
    if(s == "Y"){
      cout << "Four" <<endl;
      break;
    }
    else if (i != n -1)
      continue;
    else
      cout << "Three" <<endl;
  }
  
}

Measured memory_bytes: 256
#include<iostream>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<vector>
#include<iterator>

int main() {
  using namespace std;

  ios_base::sync_with_stdio(false); 

  auto n = 0;
  cin >> n;

  vector<int> balls;
  multimap<int, int> mballs;
  for(int i = 0; i < n; i++)
  {
    int num = 0;
    cin >> num;
    balls.push_back(num);
    mballs.emplace(num, i);
  }

  const unordered_set<int> uniqueBalls(balls.begin(),balls.end());
  unordered_map<int, int> countBalls;
  long long cxcm1A = 0;
  for (const auto &b : uniqueBalls)
  {
    const auto c = mballs.count(b);
    countBalls.emplace(b, c);
    cxcm1A += c * (c - 1);
    mballs.erase(b);
  }

  for(int i = 0; i < n; i++)
  {
    const int kCount = countBalls.at(balls[i]);
    const long long && count = -(2 * kCount - cxcm1A - 2) / 2;
    cout << count << '\n';
  }
}

Measured memory_bytes: 20376
/*input
6
30 10 60 10 60 50
*/
 
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define ld long double
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define se second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<long long int, long long int> mpi;
typedef set<long long int> seti;
typedef multiset<long long int> mseti;
typedef priority_queue<long long int> pq;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define PI 3.14159265
#define dbg(x) cerr << "\n" << (#x) << " = " << (x) << endl ;
//#define cerr if(false)cerr
  
struct node{
    ll val;
};
struct Interval {int start, end;};
bool compare(struct node n1, struct node n2) {
    return (n1.val < n2.val);
}
 
 
 ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

int main() 
{
	ll n; cin>>n;
	ll dp[100005];
	dp[1]=0;
	ll h[100005];
	rep(i,n){cin>>h[i];}

	dp[2] = abs(h[1]-h[0]);
	repA(i,3,n){
		dp[i] = min(dp[i-2] + abs(h[i-1]-h[i-3]), dp[i-1] + abs(h[i-1] - h[i-2]));
	}
	cout<<dp[n];
    return 0;  
}



















 

Measured memory_bytes: 5092
MAXN=5000
def setBlocks(d,lng,pos):
    if d==1:
        for i in range(MAXN):
            if set(L[i][pos:pos+lng])!=set([False]):
                L[i-1][pos:pos+lng]=[True]*lng
                if set(L[i-1])==set([True]):
                    del L[i-1]
                    L.insert(0,[False]*5)
                break
        else:
            L[i][pos:pos+lng]=[True]*lng
            if set(L[i])==set([True]):
                del L[i]
                L.insert(0,[False]*5)
    elif d==2:
        for i in range(MAXN):
            if L[i][pos]:
                for j in range(i-lng,i):
                    L[j][pos]=True
                for j in range(i-lng,i):
                    if set(L[j])==set([True]):
                        del L[j]
                        L.insert(0,[False]*5)
                break
        else:
            for j in range(i-lng+1,i+1):
                L[j][pos]=True
            for j in range(i-lng+1,i+1):
                if set(L[j])==set([True]):
                    del L[j]
                    L.insert(0,[False]*5)

while True:
    n=input()
    if n==0:break
    L=[[False]*5 for i in range(MAXN)]
    for i in range(n):
        d,p,q=map(int,raw_input().split())
        setBlocks(d,p,q-1)
    print sum(sum(i) for i in L)

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

//#define DEBUG

using namespace std;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void solve(){
    int X, Y;
    cin >> X >> Y;
    if( Y % 2  == 1){
        cout << "No" << endl;
    }else{
        Y = Y / 2;
        int b = Y - X;
        int a = 2 * X - Y;
        if( a >= 0 && b >= 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    string S;
    cin >> S;
    for(int i = 0 ; i<S.size(); i++){
        if( (i+1)%2 == 0 ){
           if( S[i]=='L' || S[i] == 'U' || S[i] == 'D' ){

           }else{
                cout << "No" << endl;
                return 0;
           }
        }else{
           if( S[i]=='R' || S[i] == 'U' || S[i] == 'D' ){

           }else{
                cout << "No" << endl;
                return 0;
           }

        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
	char s[4];
	scanf("%s", s);
	if (strlen(s) == 2) {
		printf("%s\n", s);
	} else {
		char tmp = s[2];
		s[2] = s[0];
		s[0] = tmp;
		printf("%s\n", s);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >>N>>K;
  vector<int> len(N);
  for(int i=0; i<N;i++){
    cin>>len.at(i);
  }
  sort(len.begin(),len.end());
  reverse(len.begin(),len.end());
  int sum=0;
  for(int i=0 ;i<K ;i++){
    sum += len.at(i);
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

constexpr int MOD = 1000003;

ll modpow(ll a, int n) {
    if (n == 0) return 1LL;
    if (n % 2 == 1) return a * modpow(a, n-1) % MOD;
    ll h = modpow(a, n/2);
    return h * h % MOD;
}

ll modinv(ll a) { return modpow(a, MOD-2); }

ll fact[MOD], facti[MOD];
void init() {
    fact[0] = 1;
    facti[0] = modinv(fact[0]);
    for (int i = 1; i < MOD+10; ++i) {
        fact[i] = i * fact[i-1] % MOD;
        facti[i] = modinv(fact[i]);
    }
}

ll solve(ll x, ll d, ll n) {
    if (d == 0) return modpow(x, n);
    ll y0 = x * modinv(d) % MOD;
    if (y0+n-1 >= MOD) return 0LL;
    return modpow(d, n) * fact[y0+n-1] % MOD * facti[y0-1] % MOD;
}

int Q;

int main() {
    init();
    scanf("%d", &Q);
    for (int i = 0; i < Q; ++i) {
        int x, d, n;
        scanf(" %d %d %d", &x, &d, &n);
        cout << solve(x, d, n) << endl;
    }
    return 0;
}


Measured memory_bytes: 16512
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
const int INF = 0x3f3f3f3f;
const int MAX_N = 3002;
double dp[MAX_N][MAX_N];
int N;
double prob[MAX_N];
 
void solve()
{
	dp[0][0]=1;
	for(int i=1; i<=N; ++i){
		for(int j=0; j<=i; ++j){ //
			if(j==0) dp[i][j] = dp[i-1][j] * (1-prob[i]);
			else dp[i][j] = dp[i-1][j-1] * prob[i] + dp[i-1][j] * (1-prob[i]);
		}
	}
	double ans = 0;
	for(int i=N/2+1; i<=N; ++i) ans += dp[N][i];
	cout.precision(15);
	cout << ans << endl;
}
 
int main()
{
	cin >> N;
	for(int i=1; i<=N; ++i) cin >> prob[i];
	solve();
	return 0;
}

Measured memory_bytes: 68992
n = int(input())
h = list(map(int, input().split()))

INF = 10 ** 5 + 1

dp = [INF] * n

dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, n):
    skip1 = dp[i - 1] + abs(h[i] - h[i - 1])
    skip2 = dp[i - 2] + abs(h[i] - h[i - 2])
    dp[i] = min(skip1, skip2)

print(dp[-1])


Measured memory_bytes: 13928
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String b="",g="";
        int bc=0,gc=0;
        for(int i=0;i<n;i++){
            b=sc.next();
            g=sc.next();
            if(b.compareTo(g)>0){
                bc+=3;
            }else if(b.compareTo(g)<0){
                gc+=3;
            }else{
                bc++;
                gc++;
            }
        }
        System.out.println(bc+" "+gc);
        sc.close();
    }
}
    


Measured memory_bytes: 30552
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define pii pair <int, int>
#define all(vv) (vv).begin(), (vv).end()
#define rep(ii, jj, ll, ss) for(int ii = jj; ii < ll; ii += ss)
#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0;

int n, q;
vector <int> a;
vector <int> ans;
map <int, int> mp;
int sum;

int32_t main() {
	sum = 0;
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	rep(i, 0, n, 1) {
		int x; cin >> x; 
		a.pb(x);
		++mp[x];
		sum += x;
	}
	cin >> q;
	rep(i, 0, q, 1) {
		int B, C; cin >> B >> C;
		sum += mp[B]*(C-B);
		mp[C] += mp[B];
		mp[B] = 0;
		ans.pb(sum);
	}
	for(auto it:ans) cout << it << '\n';
}

Measured memory_bytes: 10728
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
signed main()
{
  ll mn,k,n,a,b,u;
  
  cin>>k>>n;
  mn = k;
  
  cin>>a;
  u = a;
  
  for(ll i=1; i<n; i++)
  {
    cin>>b;
    
    mn = min(mn , k-(b-a));
    
    a=b;
  }
  mn = min(mn, a-u);
  
  cout<<mn<<"\n";
  
  return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int q;
  cin >> q;
  VI a(q), b(q);
  REP(i, q) {
    cin >> a[i] >> b[i];
    if(a[i] > b[i]) swap(a[i], b[i]);
  }

  REP(i, q) {
    // if(abs(a[i]-b[i]) <= 1) {
    //   cout << 2*a[i] - 2 << endl;
    //   continue;
    // }
    int lb = 0, ub = b[i]-a[i]+1;
    auto check = [&](int mid) -> bool {
      for(int j=mid/2-2; j<=mid/2+2; ++j) {
        if(j<0 || b[i]-a[i]<j) continue;
        if((a[i]+j)*(a[i]+mid-j) >= a[i]*b[i]) return false;
      }
      return true;
    };
    while(ub-lb > 1) {
      int mid = (lb+ub)/2;
      if(check(mid)) {
        lb = mid;
      } else {
        ub = mid;
      }
    }
    cout << a[i]*2-2 + lb << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {

	int A[4], B[4];

	while (true) {
		for (int& a : A) {
			cin >> a;
		}
		for (int& b : B) {
			cin >> b;
		}
		if (cin.eof()) {
			break;
		}
		int hitCount = 0;
		int blowCount = 0;
		for (int i = 0; i < 4; ++i) {
			if (A[i] == B[i]) {
				++hitCount;
			}
			else {
				for (int j = 0; j < 4; ++j) {
					if (A[i] == B[j]) {
						++blowCount;
					}
				}
			}
		}
		cout << hitCount << ' ' << blowCount << endl;
	}
	return 0;
}

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

int N, B, pre = 1e9, ans;

int main() {
    cin >> N;
    for (int i = 1; i < N; i++) {
        cin >> B;
        ans += min(pre, B);
        pre = B;
    }
    ans += pre;
    cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# DFSでやる版

N, M = map(int, input().split())

# 入力値の頂点ペア(辺)を格納する配列
a = [0] * M
b = [0] * M

# 頂点ペアが隣接しているかどうかを格納する配列
graph = [[False for i in range(N)] for j in range(N)]

# 入力値の頂点ペア(辺)を格納していくループ
for i in range(M):
    a[i], b[i] = map(int, input().split())
    # 添字に合わせて入力値から1減らしておく
    a[i] -= 1
    b[i] -= 1
    # 入力値の内容に合わせて、隣接していることを記録
    graph[a[i]][b[i]] = True
    graph[b[i]][a[i]] = True

cnt = 0
p = [0] * N
def dfs(pos, mask):
    # 関数内で更新して外部で参照する変数のglobal宣言
    global cnt
    # 最後まで到達できた時はここを通る
    if pos == N:
        # 前提としてスタート地点(添字0)が0かどうか確認
        if p[0] == 0:
            for i in range(N-1):
                # 各辺が存在(各頂点ペアが隣接)しているか確認していく
                if graph[p[i]][p[i+1]] == False:
                    break
                # 全て存在すれば条件を満たすのでカウント+1
                if i == N-2:
                    cnt += 1
        return
    for i in range(N):
        # 残っている数の中にiがまだ残っている場合
        # (maskの中に(1<<i)のビットがまだ残っていればTrueを返す)
        if mask & (1<<i):
            p[pos] = i
            # 残っている数からiを取り除く
            # (排他的論理和XORで重複部分が0になる)
            dfs(pos+1, mask^(1<<i))
# 0からN-1までの数の集合
dfs(0, (1<<N)-1)
print(cnt)

# 参考：2進数の1を左へ3ビット移動(1→8)
# (1 << 3)

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  vector<int> Dish(5);
  rep(i, 5) {
    cin >> Dish[i];
  }
  int answer {};
  rep(i, 5) {
    answer += ((Dish[i]+9)/10)*10;
//    cout << answer << '\n';
  }
  int max_p {};
  rep(i, 5) {
    if (Dish[i]%10==0)continue;
    maxs(max_p, 10-Dish[i]%10);
  }
  cout << answer - max_p << '\n';
}


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

map<long long, int> prime_factorize(long long n) {
    map<long long, int> res;
    for (long long p = 2; p * p <= n; ++p) {
        while (n % p == 0) { ++res[p]; n /= p; }
    }
    if (n != 1) res[n] = 1;
    return res;
}

vector<long long> enum_divisors(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i * i <= n; i++) {
        if (n % i != 0) continue;
        res.emplace_back(i);
        if (i != n / i) res.emplace_back(n / i);
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    int n; cin >> n;
    vector<int> cnt(n + 1);
    for (int i = 1; i <= n; i++) {
        for (auto &p: prime_factorize(i)) cnt[p.first] += p.second;
    }
    cnt.erase(remove(cnt.begin(), cnt.end(), 0), cnt.end());
    int sz = cnt.size();
    auto ds = enum_divisors(75);
    vector<vector<int>> dp(sz + 1, vector<int>(75 + 1));
    dp[0][1] = 1;
    for (int i = 0; i < sz; i++) {
        for (auto d1: ds) for (auto d2: ds) if (d1 * d2 <= 75) {
            if (cnt[i] + 1 >= d2) dp[i + 1][d1 * d2] += dp[i][d1];
        }
    }
    cout << dp[sz][75] << endl;
    return 0;
}


Measured memory_bytes: 256
import math
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

for i in range(n-k):
  if t[i] == t[i+k]:
    t[i+k] = "0"

rr = t.count("s")
ss = t.count("p")
pp = t.count("r")
  
print(rr*r + ss*s + pp*p)

Measured memory_bytes: 4084
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main
int main() {
    const int ma[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    rep(i, m) cin >> a[i];
    sort(all(a));
    
    vector<int> mx(n + 1, -inf);
    auto rec = [&](auto f, int x) -> int {
        if (mx[x] != -inf) return mx[x];
        if (x == 0) return mx[x] = 0;
        mx[x] = -1;
        for (int i : a) {
            if (x < ma[i]) continue;
            int r = f(f, x - ma[i]);
            if (r != -1) chmax(mx[x], r + 1);
        }
        return mx[x];
    };
    rec(rec, n);
    
    int now = n;
    string ans;
    while (now) {
        int c = -1;
        for (int i : a) {
            if (now < ma[i]) continue;
            if (mx[now - ma[i]] == mx[now] - 1) {
                c = i;
            }
        }
        ans.push_back('0' + c);
        now -= ma[c];
    }
    
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4152
from collections import Counter
from collections import OrderedDict
N, M = map(int, input().split())
A = list(map(int, input().split()))
A_sorted = sorted(A)
A_counter = Counter(A)
A = OrderedDict({})
for a in A_sorted:
    A[a] = A_counter[a]
X = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)
result = 0
i = 0
for a in A.keys():
    num = A[a]
    while True:
        if i == M:
            result += a * num
            break
        b, c = X[i]
        if c < a:
            result += a * num
            break
        if num <= b:
            result += c * num
            X[i] = [b - num, c]
            break
        result += c * b
        num -= b
        i += 1
print(result)


Measured memory_bytes: 67512
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::slice::*;

fn main() {
    let mut io = IO::new(stdin(), stdout(), stderr());
    // ===================================== //
    let mut v = io.readn::<i64>(4);
    let (a, b, c, k) = (v[0], v[1], v[2], v[3]);
    let mut ans: i64 = 0;
    let mut k: i64 = k;
    ans += min(a, k) as i64;
    k -= (a + b);
    if k > 0 {
        ans -= min(c, k) as i64;
    }
    io.writeln(ans);
}

// IO
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
}


Measured memory_bytes: 2192
import math
from functools import lru_cache
from sys import stdin


@lru_cache(maxsize=None)
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main():
    N = int(stdin.readline().rstrip())
    A = [int(x) for x in stdin.readline().rstrip().split()]
    spam = {0: 1}
    temp = 0
    for x in A:
        temp += x
        spam[temp] = spam.get(temp, 0) + 1
    print(sum([combinations_count(value, 2) for key, value in spam.items() if value > 1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 39296
// In the name of god
#include <bits/stdc++.h>
using namespace std;
long long n,sum;
int main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		if(i%3>0&&i%5>0){
			sum+=i;
		}
	}
	cout<<sum;
}


Measured memory_bytes: 3660
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
//use proconio::marker::Usize1;
//use proconio::marker::Chars;
//use std::collections::HashSet;
//use std::cmp::*;
fn main() {
    input! {
        r: i32,g:i32
    }
    let ans = 2 * g - r;
    println!("{}", ans);
}


Measured memory_bytes: 2108
// g++ -std=c++14
#include<bits/stdc++.h>
typedef long long int lli;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x);
#define sd2(x,y) scanf("%d%d",&x,&y);
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z);

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(c) c.begin(),c.end()

#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

int main(){
  _
  int x,y;
  cin >> x >> y;
  cout << x + y/2 << "\n";
  return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
num_4 = 0
num_2 = 0
for a in A:
    if a%4 == 0:
        num_4 += 1
    elif a%2 == 0:
        num_2 += 1
    else:
        continue

flag = False
if num_4 >= n//2:
    flag = True
else:
    num = num_2 - num_2%2
    if num_4 >= (n - num)//2:
        flag = True

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 15020
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 3e5 + 10;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	cin >> n >> k;
	string str;
	cin >> str;
	int ans = 0;

	for (int i = 1; i < n; i++)
	{
		if (str[i - 1] == str[i])
			ans++;
	}
	ans = min(n - 1, ans + 2 * k);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e8;
using vi = vector <int>;
using vvi = vector <vi>;

signed main(){
	int n, a, b;
	cin >> n >> a >> b;
	cout << (n == 1 || a > b ? a == b : (b - a) * (n - 2) + 1) << endl;
}


Measured memory_bytes: 256
#pragma warning (disable :4996)
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-12;
#define For(i,n,m) for(int i=n;i<=m;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,l,r) for(int i=l;i>=r;--i)
#define clr(a,b) memset(a,b,sizeof(a))


string s;
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	cin >> s;
	if (s == "ABC") cout << "ARC\n";
	else cout << "ABC\n";
	return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < n; ++i)

map<int, set<int> > d1, d2;
map<int, vector<int> > d1s, d2s;
ll an;
int d;
pair<int, int> p1, p2;

void go(int x, int y) {
	stack<pair<int, int> > s;
	s.push(make_pair(x, y));
	while (!s.empty()) {
		x = s.top().first, y = s.top().second;
		s.pop();
		int z = x + y + d;
		an += upper_bound(d1s[z].begin(), d1s[z].end(), x + d) - lower_bound(d1s[z].begin(), d1s[z].end(), x + 1);
		set<int> *st = &d1[z];
		set<int>::iterator it = st->lower_bound(x), itd;
		while (it != st->end() && *it <= x + d) {
			int t = *it, y = z - t;
			d2[t - y].erase(t);
			itd = it;
			++it;
			st->erase(itd);
			s.push(make_pair(t, y));
		}
		z = x + y - d;
		an += upper_bound(d1s[z].begin(), d1s[z].end(), x - 1) - lower_bound(d1s[z].begin(), d1s[z].end(), x - d);
		st = &d1[z];
		it = st->lower_bound(x - d);
		while (it != st->end() && *it <= x) {
			int t = *it, y = z - t;
			d2[t - y].erase(t);
			itd = it;
			++it;
			st->erase(itd);
			s.push(make_pair(t, y));
		}
		z = x - y + d;
		an += upper_bound(d2s[z].begin(), d2s[z].end(), x + d - 1) - lower_bound(d2s[z].begin(), d2s[z].end(), x);
		st = &d2[z];
		it = st->lower_bound(x);
		while (it != st->end() && *it <= x + d) {
			int t = *it, y = -(z - t);
			d1[t + y].erase(t);
			itd = it;
			++it;
			st->erase(itd);
			s.push(make_pair(t, y));
		}
		z = x - y - d;
		an += upper_bound(d2s[z].begin(), d2s[z].end(), x) - lower_bound(d2s[z].begin(), d2s[z].end(), x - d + 1);
		st = &d2[z];
		it = st->lower_bound(x - d);
		while (it != st->end() && *it <= x) {
			int t = *it, y = -(z - t);
			d1[t + y].erase(t);
			itd = it;
			++it;
			st->erase(itd);
			s.push(make_pair(t, y));
		}
	}
}

int main() {
	int n, p, q;
	scanf("%d%d%d", &n, &p, &q);
	f(i, 1, n + 1) {
		int x, y;
		scanf("%d%d", &x, &y);
		d1s[x + y].push_back(x);
		d2s[x - y].push_back(x);
		if (i == p)p1 = make_pair(x, y);
		else {
			d1[x + y].insert(x);
			d2[x - y].insert(x);
			if (i == q)p2 = make_pair(x, y);
		}
	}
	for (map<int, vector<int> >::iterator it = d1s.begin(); it != d1s.end(); ++it)sort(it->second.begin(), it->second.end());
	for (map<int, vector<int> >::iterator it = d2s.begin(); it != d2s.end(); ++it)sort(it->second.begin(), it->second.end());
	d = abs(p1.first - p2.first) + abs(p1.second - p2.second);
	go(p1.first, p1.second);
	printf("%lld\n", an >> 1);
}

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

int main() {
    int n, x;

    while (true) {
        cin >> n >> x;
        if (n == 0 && x == 0) break;

        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                for (int k = j + 1; k <= n; k++) {
                    if (i + j + k == x) cnt++;
                }
            }
        }

        cout << cnt << endl;
    }

    return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main()
{
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while(0<A&&0<C){
    C -= B;
    if(C<=0){
      break;
    }
    A -= D;
  }
  if(A<=0){
    puts("No");
  }else{
    puts("Yes");
  }
}

Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  string s;
  cin >> s;
  int n = (int) s.size();
  int ans = 0;
  for (int i = 0, j = n - 1; i <= j; i++, j--) {
    if (i == j) continue;
    if (s[i] != s[j]) ans++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";}

// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
typedef long long ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
   
const ll Mod = 1e9 + 7;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    int n , m , l , r  , a = 0 , b = Mod;
    cin >> n >> m;
    for(int i = 0 ;i < m; i++){
        cin >> l >> r;
        a = max(a , l);
        b = min(r , b);
        
    }

    if(b < a)
        cout << 0 << endl;
    else
        cout << b-a+1 << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0 || i%5==0)
        {
            continue;
        }
        else
        {
            sum+=i;
        }
    }
    cout<<sum<<"\n";
}


Measured memory_bytes: 3636
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s; readV(s);

  foreach (i; 0..s.length-1) {
    if (s[i] == s[i+1]) {
      writeln(i+1, " ", i+2);
      return;
    }

    if (i < s.length-2 && s[i] == s[i+2]) {
      writeln(i+1, " ", i+3);
      return;
    }
  }

  writeln(-1, " ", -1);
}


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

int main() {
	//freopen("input.txt", "r", stdin);
	int a;
	cin >> a;
	a %= 10;
	switch (a)
	{
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		cout << "hon";
		break;
	case 0:
	case 1:
	case 6:
	case 8:
		cout << "pon";
		break;
	default:
		cout << "bon";
		break;
	}
	return 0;
}

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

int main() {
 string n;
 int count = 1;
 bool flag = true;
 cin >> n;
 for(int i = 0;i<3;i++){
   if(n[i] == n[i+1]){
     count ++;
     if(count == 3){
       cout << "Yes" << endl;
       flag = false;
     }
   }else{
     count = 1;
   }
 }
 if(flag == true){
   cout << "No" << endl;
 }
}

Measured memory_bytes: 256
a, b, k = [int(_) for _ in input().split()]
for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a = a - 1
            b += a // 2
            a = a // 2
        else:
            b += a // 2
            a = a // 2
    else:
        if b % 2 == 1:
            b = b - 1
            a += b // 2
            b = b // 2
        else:
            a += b // 2
            b = b // 2
print(a, b)

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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	int i;
	for(i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end(), greater<int>());
	
	int Alice = 0, Bob = 0;
	
	for(i = 0; i < N; i++) {
		if(i % 2 == 0) Alice += A[i];
		else Bob += A[i];
	}
	
	cout << Alice - Bob << endl;
}

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

int main(){
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, 0, N){
        cin >> a[i];
    }
    ll mx = *max_element(a.begin(), a.end());
    ll half = mx / 2;
    ll ans = 1e18, dmn = 1e18;
    if(N % 2 == 0){
        rep(i, 0, N){
            if(a[i] == mx) continue;
            if(dmn > abs(half - a[i])){
                dmn = abs(half - a[i]);
                ans = a[i];
            }
        }
    }else{
         rep(i, 0, N){
            if(a[i] == mx) continue;
            if(a[i] > half){
                if(dmn > abs(half + 1 - a[i])){
                    dmn = abs(half + 1 - a[i]);
                    ans = a[i];
                }
            }else{
                if(dmn > abs(half - a[i])){
                    dmn = abs(half - a[i]);
                    ans = a[i];
                }
            }
        }       
    }
    cout << mx << " " << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
(let* ((n (read))
       (k (read))
       (ll (map 'vector (lambda (x) x)(sort (loop :repeat n :collect (read)) #'<))))
  (princ (loop :for j :from (1- k) :upto (1- n)
               :minimize (- (aref ll j) (aref ll (- j (1- k)))))))

Measured memory_bytes: 59752
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace B_ABC167
{
    class MainClass
    {

        static long[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
            long a = s[0];
            long b = s[1];
            long c = s[2];
            long k = s[3];
            // long ans = 0;

            if(a>=k){
                WriteLine(k);
                return;
            }else if (a+b>=k){
                WriteLine(a);
                return;
            }else{
                WriteLine(a - (k-a-b));
                return;
            }

        }
    }
}


Measured memory_bytes: 27964
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def solve():
    N, M = map(int, input().split())
    uf = UnionFind(N)
    for i in range(M):
        a,b = map(lambda x: int(x)-1, input().split())
        uf.union(a,b)
    print(uf.group_count() - 1)

if __name__ == '__main__':
    solve()






Measured memory_bytes: 12956
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,j,N,ans=1,cnt=1;
  cin>>N;
  vec v(N);
  rep(i,N){
    cin>>j;
    v[j-1]=i;
  }
  rep1(i,N){
    if(v[i-1]<v[i]){
      cnt++;
    }else{
      cnt=1;
    }
    chmax(ans,cnt);
  }
  cout<<N-ans<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define for1(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define endl '\n'
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    double n;
    int ave = 0, sum = 0;;
    int a[100];
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        ave += a[i];
    }
    ave = round(ave / n);
    rep(i, n) {
        sum += ((a[i] - ave) * (a[i] - ave));
    }
    cout << sum << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt(), B = sc.nextInt();

        int result = 0;
        if (A >= 13) {
            result = B;
        } else if ( A >= 6 && A <= 12) {
            result = B / 2;
        } else {
            result = 0;
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 20564
// #pragma GCC optimize("Ofast,unroll-all-loops")

#include <bits/stdc++.h>

using namespace std;

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

#define all(v) v.begin(), v.end()
#define len(v) ((int)(v).size())
#define pb push_back
#define kek pop_back
#define pii pair<int, int>
#define mp make_pair
#define int ll

#define debug(x) cout << #x << " = " << x << endl;

const int INF = (is_same<int, ll>::value ? 1e18 + 666 : 1e9 + 666);
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

// const int MEM_SIZE = 1e8;
// char mem[MEM_SIZE];
// int cur_mem_ptr = 0;

// void* operator new(size_t n) {
//     cur_mem_ptr += n;
//     return mem + cur_mem_ptr - n;
// }

// void operator delete(void*) noexcept {}
// void operator delete(void*, size_t) noexcept {}

template<class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int bpow(int a, int b, int mod) {
    int res = 1;
    for (; b; b >>= 1) {
        if (b & 1) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
    }
    return res;
}

#ifndef LOCAL
void UseFiles(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
#else
void UseFiles(const string&) {}
#endif

void run();

signed main() {
    // UseFiles("squads");
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}


void run() {
    int n;
    cin >> n;
    n %= 10;
    if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) cout << 'h';
    if (n == 0 || n == 1 || n == 6 || n == 8) cout << 'p';
    if (n == 3) cout << 'b';
    cout << "on" << endl;
}

Measured memory_bytes: 3660
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int cannotNum = Math.max(c-a-b-1,0);

		// System.out.println(cannotNum);

		System.out.println(b+c - cannotNum);



	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;
using ll = long long;
int main()
{
    ll d;
    cin >> d;
    vector<ll> c;
    vector<vector<ll>> s;
    vector<ll> t;
    vector<ll> last(26, 0);

    for (ll i = 0; i < 26; i++) {
        ll tmp;
        cin >> tmp;
        c.push_back(tmp);
    }
    for (ll i = 0; i < d; i++) {
        vector<ll> tmp_v;
        for (ll j = 0; j < 26; j++) {
            ll tmp;
            cin >> tmp;
            tmp_v.push_back(tmp);

        }
        s.push_back(tmp_v);
    }

    for (int i = 0; i < d; i++) {
        ll tmp;
        cin >> tmp;
        t.push_back(tmp);
    }
    
    ll sat = 0;
    for (ll i = 0; i < d; i++) {
        ll contest = t[i] - 1;
        sat += s[i][contest];
        last[contest] = i + 1;
        for (ll j = 0; j < 26; j++) {
            sat -= (i + 1 - last[j]) * c[j];
        }
        
        cout << sat << endl;
    }

    return 0;

}



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

string t = "KIHBR";
string sub[] = {"A", "", "", "A", "A", "A"};
string s;

bool check(string a, string b) {
	if (b.size() < a.size()) return false;
	int len = a.size();
	for (int i = 0; i < b.size()-len+1; ++i) {
		string c = b.substr(i, len);
		if (c == a) return true;
	}
	return false;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> s;
	int cur = 0;
	string cur_s = "";
	for (int i = 0; i < s.size(); ++i) {
		if (cur < 5 && s[i] == t[cur]) ++cur, cur_s = "";
		else {
			cur_s += s[i];
			if (!check(cur_s, sub[cur])) return cout << "NO\n", 0;
		}
	}
	if (cur >= 5) cout << "YES\n"; else cout << "NO\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a[3];
	int tmp,sum,num;
	
	scanf("%d",&a[0]);
	scanf("%d",&a[1]);
	scanf("%d",&a[2]);

		for(num = 0;num < 2;num++){
			for(sum = num+1;sum<3;sum++){
				if(a[num] > a[sum]){
					
					tmp =  a[num];
					a[num] = a[sum];
					a[sum] = tmp;
					
				}
			}
		}
	printf("%d %d %d\n",a[0],a[1],a[2]);

	
	return 0;
}

Measured memory_bytes: 596
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eps 1e-12
#define int long long
const int mod = 1e9 + 7;
inline int ksm(int a, int b)
{
    int ans = 1;
    for (; b; b >>= 1, a = a * a % mod)
        if (b & 1)
            ans = ans * a % mod;
    return ans;
}
char s[200];
int cal(int x){
    return x/2;
}
signed main()
{
    io;
    vector<int> v;
    cin>>s+1; int k;cin>>k;
    int n=strlen(s+1);
    rep(i,1,n){
        int p=i;while(p+1<=n&&s[p+1]==s[p])p++;
        v.pb(p-i+1);
        i=p;
    }
    if(v.size() == 1){
        cout<<cal(k*v[0])<<endl;
    }
    else {
        if(s[1]==s[n]){
            int t=cal(v[0]);
            t += cal(v[v.size()-1]);
            t += (k-1)*cal(v[0]+v[v.size()-1]);
            for(int i=1;i<v.size()-1;i++){
                t += cal(v[i])*k;
            }
            cout<<t<<endl;
        }
        else {
            int t=0;
           // for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;
            for(int i=0;i<v.size();i++) t+=cal(v[i])*k;
            cout<<t<<endl;
        }
    }
    getchar(); //
    getchar();
}


Measured memory_bytes: 256
N = int(input())

if N >= 400 and N <= 599:
    print("8")
elif N >= 600 and N <= 799:
    print("7")
elif N <= 999:
    print("6")
elif N <= 1199:
    print("5")
elif N <= 1399:
    print("4")
elif N <= 1599:
    print("3")
elif N <= 1799:
    print("2")
elif N <= 1999:
    print("1")


Measured memory_bytes: 61800
#include <bits/stdc++.h>
#include <atcoder/all>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using namespace atcoder;
using namespace boost::multiprecision;
using ll = long long;

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

    rep(i,n)cout << "ACL";
    cout << endl;
    return 0;
}
/*
g++ -std=c++17 -Wall -Wextra -g -O0 -fsanitize=undefined,address main.cpp && oj t
*/

Measured memory_bytes: 3604