akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    int n,k;
    string s;
    cin>>n>>k>>s;
    vector<int> zo;
    rep(i,n){
        char c=s[i];
        int cnt=0;
        while(c==s[i]){
            i+++
            cnt++;
        }
        i--;
        zo.push_back(cnt);
    }
    vector<int> sum(zo.size()+1,0);
    rep(i,zo.size()) sum[i+1]+=sum[i]+zo[i];
    
    /*if(k>(zo.size()-1)/2){
        cout<<sum[sum.size()-1];
    }else{
    */
        int t;
        int ans=0;
        if(s[0]=='0'){
            rep(i,sum.size()){
                if(i%2){
                    //1　そのマスからk*2+1
                    int t=k*2+1;
                    if(i+t>sum.size()-1){
                        ans=max(ans,sum[sum.size()-1]-sum[i]);
                    }else{
                        ans=max(ans,sum[i+t]-sum[i]);
                    }
                }else{
                    //0　k*2
                    int t=k*2;
                    if(i+t>sum.size()-1){
                        ans=max(ans,sum[sum.size()-1]-sum[i]);
                    }else{
                        ans=max(ans,sum[i+t]-sum[i]);
                    }
                }
            }
        }else{
            rep(i,sum.size()){
                if(i%2){
                    //1　そのマスからk*2+1
                    int t=k*2;
                    if(i+t>sum.size()-1){
                        ans=max(ans,sum[sum.size()-1]-sum[i]);
                    }else{
                        ans=max(ans,sum[i+t]-sum[i]);
                    }
                }else{
                    //0　k*2
                    int t=k*2+1;
                    if(i+t>sum.size()-1){
                        ans=max(ans,sum[sum.size()-1]-sum[i]);
                    }else{
                        ans=max(ans,sum[i+t]-sum[i]);
                    }
                }
            }
        }
        cout<<ans<<endl;
}

Measured memory_bytes: 1272
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        for (int i = 0; i < s.length; i++) {
            int x = s[i] + n;
            if('Z' < x) x -= 26;
            s[i] = (char)(x);
        }
        System.out.println(String.valueOf(s));
        sc.close();

    }

}


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

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));
#ifdef LOCAL
#define debug(x) std::cerr << #x << ": " << x << endl
#else
#define debug(x) 860111
#endif
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}

//------------------------------------------------------------------------//
int T;
const int maxn = 2e5+7;
//ll a[maxn];

//check T
void solve()
{
  double n;
	cin >> n;// rep(i, 0, n) cin >> a[i];
  cout << fixed << setprecision(20) <<  (n*n*n/27.0) << endl;
  return;
}


signed main()
{
  fastIO();
  T = 1;
  //cin >> T; //this
  while(T--) solve();
  return 0;
}


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

#define oo (1L<<62)
#define ll long long int

int N;
int h[100005];
ll memo[100005];
char vis[100005];

ll elJoshua(int n){
	if(n < 0) return oo;
	if(!n) return 0;
	if(n == 1) return memo[1]=abs(h[0]-h[1]);
	if(vis[n]) return memo[n];
	vis[n] = 1;
	return memo[n] = min(elJoshua(n-1)+abs(h[n]-h[n-1]), 
						 elJoshua(n-2)+abs(h[n]-h[n-2]));
}

int main() {
	cin>>N;
	for(int i = 0; i<N;i++)
		cin>>h[i];
	cout<<elJoshua(N-1)<<"\n";
	return 0;
}

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

int main(void) {
    int n, r, i, j;
    char s;
    char suits[4] = {'S', 'H', 'C', 'D'};
    int ls[4][13];
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 13; j++) {
            ls[i][j] = 0;
        }
    }
    
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> s >> r;
        if (s == 'S') j = 0;
        else if (s == 'H') j = 1;
        else if (s == 'C') j = 2;
        else j = 3;
        ls[j][r-1] = 1;
    }

    for (i = 0; i < 4; i++) {
        for (j = 0; j < 13; j++) {
            if (!ls[i][j]) cout << suits[i] << " " << j + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int a; cin>>a;
    string s; cin>>s;
    if(a>=3200) cout<<s<<endl;
    else cout<<"red"<<endl;
}


Measured memory_bytes: 256
using System;
using System.Linq; 

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
      int N=int.Parse(Console.ReadLine());
      int[] ans=new int[N];
      int sqrtN=(int)Math.Sqrt(N);
	for(int x=1;x<sqrtN;x++){
      for(int y=1;y<sqrtN;y++){
        for(int z=1;z<sqrtN;z++){
         
         int n=x*x+y*y+z*z+x*y+y*z+z*x;
         if(n<=N){
           ans[n-1]++;
          
         }
        }
      }
    }
        for(int i=0;i<N;i++){
          Console.WriteLine(ans[i]);
        }
      
    }
    
  }

}

Measured memory_bytes: 27392
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        for(int i=k;i<n;i++){
            if(a[i]>a[i-k])
                cout<<"Yes\n";
            else
                cout<<"No\n";
        }
    }
    return 0;
}

Measured memory_bytes: 4444
import itertools

n,m,q=map(int,input().split())
qry=[]*q
for i in range(q):
    l=list(map(int,input().split()))
    qry.append(l)

ans=0

for l in itertools.combinations_with_replacement(range(1,m+1),n):
    val=0
    for i in range(q):
        if l[qry[i][1]-1]-l[qry[i][0]-1]==qry[i][2]:
            val+=qry[i][3]
    ans=max(ans,val)
    
print(ans)

Measured memory_bytes: 67884
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int P, Q, R;
    cin >> P >> Q >> R;

    int ans = min(P + Q, Q + R);
    ans = min(ans, P + R);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
from collections import deque
def main():
    s = deque(input())
    q = int(input())

    counter = 0
    for _ in range(q):
        query = [t for t in input().split()]
        if len(query)==1:
            counter +=1

        else:
            f = (counter+int(query[1]))%2
            if f==1:
                s.appendleft(query[2])
            else:
                s.append(query[2])

    s = list(s)
    if counter%2==1:
        s = s[::-1]

    for c in s:
        print(c,end='')

    print()


if __name__ == "__main__":
    main()

Measured memory_bytes: 10476
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

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

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(all(a));
    ll sum = 0;
    rep(i,0,k) sum += a[i];

    cout << sum << endl; 
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd;
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>
#define go_precise cout << fixed << setprecision(18);

const int maxk = 1e5 + 10;
bool dp[maxk];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);  cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int n,k;
    cin >> n >> k;
    int a[n];
    for (int i=0; i<n; i++) cin >> a[i];
    dp[0] = false;
    for (int i=1; i<=k; i++) {
        for (int j=0; j<n; j++) {
            if (i-a[j]>=0 && !dp[i-a[j]]) dp[i] = true;
        }
    }
    if (dp[k]) cout << "First\n";
    else cout << "Second\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif // LOCAL
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T>
using vec = vector<T>;

#define FOR(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define all(x) (x).begin(),(x).end()

int main(){
  int n,l;
  cin >>n >>l;
  vec<string> s(n);
  REP(i,n) cin >>s[i];

  sort(all(s));
  string ans;
  REP(i,n) ans += s[i];

  cout <<ans <<endl;
}


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

using ll =  long long;
using pint =  pair<int,int>;

#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i))
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(x,v) for(const auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//lambda: [&](int x, int y){return x<y;}

signed main(void){
    int n;cin>>n;
    ll h[2];
    priority_queue<int> q;
    rep(i,n){
        int t;cin>>t;
        q.push(t);
    }

    rep(i,2){
        h[i]=q.top();q.pop();
        while(!q.empty()&&h[i]!=q.top()){
            h[i]=q.top();
            q.pop();
        }
        if(q.empty()){
            cout << 0 << endl;
            return 0;
        }
        q.pop();
    } 
    cout << h[0]*h[1] << endl;
}


Measured memory_bytes: 1400
#include <iostream>
using namespace std;
int main(void){
    int E,Y,c;
    cin >>E>>Y;
    if(E==0){
        if(1868<=Y&&Y<=1911){
            c=Y-1868+1;
            cout <<"M"<<c<<endl;
        }
        else if(1912<=Y&&Y<=1925){
            c=Y-1912+1;
            cout <<"T"<<c<<endl;
        }
        else if(1926<=Y&&Y<=1988){
            c=Y-1926+1;
            cout <<"S"<<c<<endl;
        }
        else if(1989<=Y&&Y<=2016){
            c=Y-1989+1;
            cout <<"H"<<c<<endl;
        }
    }
    else if(E==1){
        c=1867+Y;
        cout <<c<<endl;
    }
    else if(E==2){
        c=1911+Y;
        cout <<c<<endl;
    }
    else if(E==3){
        c=1925+Y;
        cout <<c<<endl;
    }
    else if(E==4){
        c=1988+Y;
        cout <<c<<endl;
    }
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
#define int long long
using namespace std;
int n, a, b, ai;
vector<int> data;
int32_t main(){
    cin >> n >> a >> b;
    for (int i=0;i<n;i++){
        cin >> ai;
        data.push_back(ai);
    }
    int left = 0;
    int right = pow(10, 10);
    int zero = 0;
    while (right - left > 1){
        int mid = (left + right) / 2;
        int wanted = 0;
        for (int i=0;i<n;i++){
            double del = ((double) data[i] - (double) b * (double) mid) / ((double) a - (double) b);
            int go = ceil(del);
            go = max(go, zero);
            wanted += go;
        }
        if (wanted <= mid) right = mid;
        else left = mid;
    }
    cout << right << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 2;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld DINF = 1e12;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  ll a, b, c;
  cin >> a >> b >> c;
  ll t = c - a - b;
  Yes(t > 0 && 4 * a * b < t * t);
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

public static class Program {
    public static void Main() {
        int[]nm=Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n=nm[0];
        int m=nm[1];
        List<int>[]graph=Enumerable.Range(0,n).Select(_=>new List<int>()).ToArray();
        for(int i=0;i<m;i++){
            int[]uv=Console.ReadLine().Split().Select(int.Parse).ToArray();
            graph[uv[0]-1].Add(uv[1]-1);
        }

        int[]dp=new int[n];
        bool[]ckd=new bool[n];
        Action<int>dfs=null;
        dfs=(int x)=>{
            ckd[x]=true;
            foreach(int y in graph[x]){
                if(!ckd[y])dfs(y);
                dp[x]=Math.Max(dp[x],dp[y]+1);
            }
        };
        for(int i=0;i<n;i++){
            if(!ckd[i])dfs(i);
        }
        int ans=0;
        for(int i=0;i<n;i++){
            ans=Math.Max(ans,dp[i]);
        }
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 31744
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		int digit = ((int) Math.log10(N)) + 1;
		List<Long> s = sevenfivethree(digit);
		if(s.isEmpty()) {
			System.out.println(0);
			return;
		}

		int ans = 0;
		for(int i=0;i<s.size();i++) {
//			System.out.println(s.get(i) + ":" + ans);
			if(s.get(i) > N) {
				System.out.println(ans);
				return;
			}else {
				ans++;
			}
		}
		System.out.println(ans);
	}

	public static List<Long> sevenfivethree(int N) {
		List<String> s = new ArrayList<>();

		for(int i=N;i>=3;i--) {
			s.addAll(semisevenfivethree(i, ""));
		}

		List<Long> t = new ArrayList<>();

		for(int i=0;i<s.size();i++) {
			String temp = s.get(i);
			if(temp.contains("3") && temp.contains("5") && temp.contains("7")) {
				t.add(Long.parseLong(temp));
//				System.out.println(temp);
			}
		}
		Collections.sort(t);
		return t;
	}

	public static List<String> semisevenfivethree(int N,String a) {

		List<String> s = new ArrayList<>();
		if(N == 0) {
			s.add(a);
			return s;
		}

		List<String> temp = new ArrayList<>();
		temp.addAll(semisevenfivethree(N-1,a+"3"));
		temp.addAll(semisevenfivethree(N-1,a+"5"));
		temp.addAll(semisevenfivethree(N-1,a+"7"));

		s.addAll(temp);
		return s;
	}
}


Measured memory_bytes: 44752
#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int n; cin >> n;
	vector<int> l(n);
	for (int i = 0; i < n; ++i)
		cin >> l[i];
	sort(l.begin(), l.end());
	ll ans = 0;
	for (auto i1 = l.begin(); i1 < l.end(); ++i1) {
		for (auto i2 = i1 + 1; i2 < l.end(); ++i2) {
			auto iter = lower_bound(i2 + 1, l.end(), (*i1) + (*i2));
			ans += iter - i2 - 1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 1e18;
const int MB = 20;
const int MOD = 998244353;
const int maxN = 1e6;

void solve() {
	int n;
	cin >> n;
	int d = 2, ans = 0;
	while (d * d <= n) {
		if (n % d == 0) {
			int cnt = 0;
			while (n % d == 0) {
				n /= d;
				cnt++;
			}
			int x = 1;
			while ((x + 1) * (x + 2) / 2 <= cnt) x++;
			ans += x;
		}
		d++;
	}
	if (n > 1) ans++;
	cout << ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll n,ans,mx,a[200005],c[1000005];
bool b[1000005];
int main(){
	n=read();
	for(int i=0;i<n;i++)
		a[i]=read(),c[a[i]]++,mx=max(mx,a[i]);
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(c[a[i]]==1 and !b[a[i]])ans++;
		if(b[a[i]])continue;
		for(int j=a[i];j<=mx;j+=a[i])
			b[j]=1;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 13816
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int h[n], h_max=0;
	for(int i=0; i<n; i++){
		cin >> h[i];
		if(h_max<h[i]) h_max=h[i];
	}

	int ans=0;
	for(int i=1; i<=h_max; i++){
		bool h_in=false;
		for(int j=0; j<n; j++){
			if(h[j]>=i) h_in=true;
			if(h[j]<i && h_in){
				ans++;
				h_in=false;
			}
		}
		if(h_in) ans++;
	}
	cout << ans << endl;
	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 main() {
    int K, X;
    cin >> K >> X;
    rep(i, K * 2 - 1) {
        cout << X - K + i + 1;
        if (i == K * 2 - 2) cout << endl;
        else cout << " ";
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long int ll;
int main()
{
  ll x;
  cin>>x;
  if(x>=400&&x<=599)
    cout<<8<<"\n";
  else if(x>=600&&x<=799)
    cout<<7<<"\n";
   else if(x>=800&&x<=999)
    cout<<6<<"\n";
   else if(x>=1000&&x<=1199)
    cout<<5<<"\n";
   else if(x>=1200&&x<=1399)
    cout<<4<<"\n";
   else if(x>=1400&&x<=1599)
    cout<<3<<"\n";
   else if(x>=1600&&x<=1799)
    cout<<2<<"\n";
   else if(x>=1800&&x<=1999)
    cout<<1<<"\n";
  else
    ;
  return 0;
}  
  

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

int main(){
    
    int n;cin >>n;
    unsigned long arr[n];
    for(int i=0;i<n;i++){
        cin >> arr[i];
    }

    sort(arr,arr+n, std::greater<>());



    unsigned long ans = 0;
    int index = 0;
    for(int i=0;i<n-1;i++){
        if(i%2!=0){
            index++;
        }
        ans+=arr[index];

    }

    cout << ans << endl;
}

Measured memory_bytes: 5164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
typedef long long ll;

int main() {
  vector<vector<int>> a(3,vector<int>(3));
  vector<vector<bool>> p(3,vector<bool>(3));
  
  rep(i,3){
    rep(j,3){
      cin >> a.at(i).at(j);
      p.at(i).at(j)=false;
    }
  }
  
  int n;
  cin >> n;
  vector<int> b(n);
  rep(i,n){
   cin >> b.at(i);
   rep(j,3){
     rep(k,3){
       if(a.at(j).at(k)==b.at(i)){
         p.at(j).at(k)=true;
       }
     }
   }
  }
  
  bool bingo=false;
  rep(i,3){
    if(p.at(i).at(0)&&p.at(i).at(1)&&p.at(i).at(2)) bingo=true;
    if(p.at(0).at(i)&&p.at(1).at(i)&&p.at(2).at(i)) bingo=true;
    if(p.at(0).at(0)&&p.at(1).at(1)&&p.at(2).at(2)) bingo=true;
    if(p.at(0).at(2)&&p.at(1).at(1)&&p.at(2).at(0)) bingo=true;
  }

  if(bingo){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}



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

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

  vector<int> times;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int t;
    cin >> t;
    times.push_back(t);
    sum += t;
  }

  int M;
  cin >> M;
  // 合計は計算済みであるため、ドリンク適用後の時間を差分計算する
  for (int i = 0; i < M; i++) {
    int p, x;
    cin >> p >> x;
    p--;  // 0 base に合わせる

    int time = (sum - times[p]) + x;
    cout << time << endl;
  }
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        final Scanner scanner = new Scanner(System.in);
        final String str = scanner.next();
        int minNumber = Integer.MAX_VALUE;
        for (int i = 0; i + 2 < str.length(); ++i) {
            int current = (str.charAt(i) - '0') * 100 +
                    (str.charAt(i + 1) - '0') * 10 +
                    (str.charAt(i + 2) - '0');
            int diff = Math.abs(current - 753);
            if (diff < minNumber) {
                minNumber = diff;
            }
        }
        System.out.println(minNumber);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 998244353;

const int N = 303;
const int M = 90003;
ll dp[N][M][2][2];

ll mod_pow(ll x, ll n){
    ll ret = 1;
    while(n){
        if(n&1) (ret *= x) %= mod;
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

ll mod_inv(ll x){
    return mod_pow(x,mod-2);
}

const ll DIV = mod_inv(2);
int main(){
    int n;
    cin >>n;
    vector<int> a(n);
    int sa = 0;
    rep(i,n){
        cin >>a[i];
        sa += a[i];
    }

    dp[0][0][0][0] = 1;
    rep(i,n)rep(j,M)rep(x,2)rep(y,2)if(dp[i][j][x][y]){
        int nx = j+a[i];
        if(nx < M) (dp[i+1][nx][x][y] += dp[i][j][x][y]) %= mod;

        (dp[i+1][j][x|1][y] += dp[i][j][x][y]) %= mod;
        (dp[i+1][j][x][y|1] += dp[i][j][x][y]) %= mod;
    }

    ll sub = 0;
    rep(i,M)rep(x,2)rep(y,2){
        if(sa-i <= i){
            if(sa-i==i && (x==0 || y==0)) sub += dp[n][i][x][y]*DIV;
            else sub += dp[n][i][x][y];
            sub %= mod;
        }
    }
    sub *= 3;
    sub %= mod;

    ll ans = mod_pow(3,n) - sub + mod;
    ans %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 815360
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<ll> hum_layer(55,0); //各層の枚数
vector<ll> pate_num(55, 0); //各層のパティの枚数

ll eat_layer(int n, ll pos, ll sum){
    //cout << "n:" << n << " pos:" << pos << " sum: " << sum << ln;
    if(n == 1){
        sum += min((ll)3, pos);
        return sum;
    }
    ll layer = hum_layer[n], pate = pate_num[n];
    if(pos == 0) return sum;
    if(pos == layer-1) return (sum + pate);
    if(pos == (layer-1)/2) return (sum + pate / 2 + 1);

    if(pos > (layer-1)/2){
        pos -= layer/2+1;
        sum += pate / 2+1;
    } else{
        pos--;
    }
    return eat_layer(n-1, pos, sum);
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int res = min(c, b/a);
    cout << res << ln;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
      int c = scanner.nextInt();
      if (c % 39 != 0) {
        System.out.printf("3C%02d\n", c % 39);
      } else {
        System.out.println("3C39");
      }
    }
  }
}

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

int main(void)
{
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    int f = min(a, min(b,c));
    int g = min(d,e);
    cout << f+g-50 << endl;
    return 0;
}

Measured memory_bytes: 0
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL gcd(LL x, LL y){
	return x ? gcd(y % x, x) : y;
}

void Main()
{
	LL a,b;cin>>a>>b;
	if(a < b){
		LL t = a;
		a = b;
		b = t;
	}
	LL g = gcd(a,b);

	map< LL, int > ret;
  	for(LL i = 2; i * i <= g; i++) {
    	while(g % i == 0) {
    		ret[i]++;
    		g /= i;
  		}
	}
	if(g != 1) ret[g] = 1;

	cout << SIZE(ret) + 1 << endl;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <list>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
// const ll MOD = 1000000009;

#define M 1000000007

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> A(n);
    for (auto & a : A) {
        cin >> a;
    }
    sort(A.begin(), A.end(), greater<ll>());
    vector<pair<ll,ll>> C(m);
    for (auto & c : C) {
        cin >> c.first >> c.second;
    }
    sort(C.begin(), C.end(), [](const pair<ll,ll> &l , const pair<ll,ll> &r){ return l.second > r.second;});

    auto a = A.begin();
    auto c = C.begin();
    ll cnum = 1;

    ll res = 0;
    for (ll i = 0; i < n; ++ i) {
        if (c != C.end() && c->second > *a) {
            res += c->second;
            cnum++;
            if (cnum > c->first) {
                cnum = 1;
                ++c;
            }
        } else {
            res += *a;
            ++a;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define deb(x) cout << #x << "=" << x << endl
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
int M=1e9+7,N=205001;

int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M



void solve() {
	string s,t;
	cin>>s>>t;
	int ans=0,i;
	rep(i,0,s.size()) if(s[i]!=t[i]) ans++;
	cout<<ans;
}


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





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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}


int N;
ll A[101];

ll ceil_l(ll a, ll b){
    return (a + b - 1) / b;
}

ll fin(){

    ll step = 0;
    while(1){
        {
            ll max_v = -1;
            for(int i = 0; i < N; i++){
                max_v = max(max_v, A[i] );
            }
            if(max_v < N){
                return step;
            }
        }

        int max_idx= -1;
        for(int i = 0; i < N; i++){
            if(A[max_idx] <= A[i]){
                max_idx = i;
            }
        }
        for(int i = 0; i < N; i++){
            if(i == max_idx){
                A[i] -= N;
            }
            else{
                A[i]++;
            }
        }
        step++;
    }
}

int main(){

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

    ll step = 0;
    while(1){
        sort(A, A + N, greater<ll>());

        if(A[0] <= 2 * N){
            step += fin();
            cout << step << endl;
            return 0;
        }


        // 一番大きい要素からN以内の要素はひとまとめにして扱う
        int less_than_n_index = 0;
        int less_than_n_count = 0;
        for(int i = 1; i < N; i++){
            if(abs(A[0] - N) <= A[i]){
                less_than_n_index = i;
                less_than_n_count++;
            }
        }

        // 最後までいったのであれば、終了
        if(less_than_n_index == N - 1){
            ll min_v = 1LL<<60;
            for(int i = 0; i < N; i++)
                min_v = min(min_v, A[i]);

            ll d = max(0LL, min_v - N);

            step += d * N;
            for(int i = 0; i < N; i++){
                A[i] -= d;
            }

            cout << step + fin() << endl;
            return 0;
        }
        
        // 次の要素との差がN以下、または最大値がN以上となる最小の場所まで移動する
        ll next = A[less_than_n_index + 1];
        
        //  (A[0] - (N - less_than_n_count) * i) -  (next + i) <= N
        //  (N - less_than_n_count + 1) * i)  >= -N - next + A[0]
        // i >= (A[0] - N - next) / (N - less_than_n_count + 1)
        ll j = ceil_l(A[0] - N - next, N - less_than_n_count + 1);
        if(A[0] - (N - less_than_n_count) * j <= N){
            j--;
        }

        for(int i = 0; i < N; i++){
            if(i <= less_than_n_index){
                A[i] -= (N - less_than_n_count) * j;
            }
            else{
                A[i] += j * (less_than_n_count + 1);
            }
        }
        step += j * (1 + less_than_n_count);

    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    LL k;
    Problem(LL k):k(k){};

    void solve(){
        cout << 50 <<"\n";
        vector<LL> ans(50,49);
        for(int i=0; i<50; ++i){
            ans[i]+=k/50;
        }
        for(int i=0; i<k%50; ++i){
            for(int j=0; j<50; ++j){
                if(j==i)ans[j]+=50;
                else ans[j]--;
            }
        }
        for(int i=0; i<50; ++i){
            cout << ans[i];
            if(i<49)cout << ' ';
        }
        cout <<"\n";
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
#define ll long long

int main(){
    ll N,M,i;
    cin >> N >> M;
    ll L=0,R=N;
    ll tL,tR;
    for(i=0;i<M;i++){
        cin >> tL >> tR;
        L=max(tL,L);
        R=min(tR,R);
    }
    cout << max(R-L+1,(ll) 0);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int Q = sc.nextInt();
		long[] s = new long[A];
		long[] t = new long[B];
		long x;
		for(int i=0;i<A;i++) {
			s[i] = sc.nextLong();
		}
		for(int i=0;i<B;i++) {
			t[i] = sc.nextLong();
		}
		for(int i=0;i<Q;i++) {
			x = sc.nextLong();
			long[] slr = bins(s,x);
			long[] tlr = bins(t,x);
			System.out.println(minleng(x,slr[0],slr[1],tlr[0],tlr[1]));
			
		}
		
	}
	
	public static long[] bins(long[] s, long x) {
		long[] ret = new long[2];
		int sr = Arrays.binarySearch(s,x);
		if (sr < 0) sr = -sr-1;
		long maxinf = Long.MAX_VALUE/10;
		ret[0] = (sr-1>=0 && sr-1<s.length)? s[sr-1] : maxinf;
		ret[1] = (sr>=0 && sr<s.length)? s[sr] : maxinf;
		//System.out.println(ret[0] + " " + ret[1]);
		return ret;
	}
	
	public static long minleng(long x, long sl, long sr, long tl, long tr) {
		long c1 = Math.max(Math.abs(x-tr), Math.abs(x-sr));
		long c2 = Math.max(Math.abs(x-tl), Math.abs(x-sl));
		long c3 = Math.abs(tr-sl) + Math.min(Math.abs(x-tr), Math.abs(x-sl));
		long c4 = Math.abs(sr-tl) + Math.min(Math.abs(x-tl), Math.abs(x-sr));
		//System.out.println(c1 + " " + c2 + " " + c3 + " " + c4);
		return Math.min(Math.min(c1, c2),Math.min(c3,c4));
	}
}


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

int compare_int(const void *a,const void *b){
	return *(int*)a-*(int*)b;
}

long long rui(int a,int b){
	long long r=1;
	for(int i=0;i<b;i++)r=(r*a)%998244353;
	return r;
}

int main(){
	int n,d[100000],i,c=0,dd[100000]={0};
	long long ans=1;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&d[i]);
	if(d[0]!=0){
		puts("0");
		return 0;
	}
	qsort(d,n,sizeof(int),compare_int);
	if(d[1]==0){
		puts("0");
		return 0;
	}
	for(i=0;i<n;i++)dd[d[i]]++;
	for(i=1;i<=d[n-1];i++)ans=(ans*rui(dd[i-1],dd[i]))%998244353;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1276
s=input()
t=input()
n=len(s)
m=len(t)
dp=[[0 for j in range(m+1)] for i in range(n+1)]
for i in range(1,n+1):
	for j in range(1,m+1):
		if s[i-1]==t[j-1]:
			dp[i][j]=dp[i-1][j-1]+1
		else:
			dp[i][j]=max(dp[i-1][j],dp[i][j-1])
i=n
j=m
st=""
while dp[i][j]:
	while dp[i-1][j]==dp[i][j]:
		i-=1
	while dp[i][j-1]==dp[i][j]:
		j=j-1
	j-=1
	st+=s[i-1]
	i-=1
print(st[::-1])
	

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

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i < (int)vec.size(); ++i) {
        os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
void dump_func() {
    cerr << "\n";
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail) {
    cerr << head;
    if (sizeof...(Tail) == 0) {
        cerr << " ";
    } else {
        cerr << ", ";
    }
    dump_func(std::move(tail)...);
}
#define dump(...) cerr << "[" << to_string(__LINE__) << "]"        \
                       << "    " << string(#__VA_ARGS__) << " = ", \
                  dump_func(__VA_ARGS__)

using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<double>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using PI = pair<int, int>;
using PL = pair<ll, ll>;
using VPI = vector<PI>;
using VPL = vector<PL>;
using VS = vector<string>;

#define ln '\n'
#define REP(t, n) for (int t = 0; t < (n); ++t)
#define FOR(t, a, b) for (int t = (a); t <= (b); ++t)
#define FORR(t, a, b) for (int t = (a); t >= (b); --t)
#define ALL(c) (c).begin(), (c).end()
#define CAUTO const auto&

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

    int a, b;
    cin >> a >> b;
    if (a == b)
        cout << 2 * a << ln;
    else
        cout << (a > b ? 2 * a - 1 : 2 * b - 1) << ln;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int diceo[6];
  int dicet[6];
  int i, j, k, a;
  int tatea[7] = {0, 1, 5, 4, 0, 1, 5};
  int tateb[7] = {0, 4, 5, 1, 0, 4, 5};
  int yokoa[7] = {1, 2, 4, 3, 1, 2, 4};
  int yokob[7] = {1, 3, 4, 2, 1, 3, 4};
  int hokaa[7] = {0, 2, 5, 3, 0, 2, 5};
  int hokab[7] = {0, 3, 5, 2, 0, 3, 5};
  int ue[6] = {2, 3, 0, 5, 4, 1};
  int ty[7];
  int idice[4];
  int co = 0;

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

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

  for(i = 0; i < 6; i++){
    for(j = 0; j < 7; j++){
      switch(i){
      case 0:
        ty[j] = tatea[j];
	break;
      case 1:
	ty[j] = tateb[j];
	break;
      case 2:
	ty[j] = yokoa[j];
	break;
      case 3:
	ty[j] = yokob[j];
	break;
      case 4:
	ty[j] = hokaa[j];
	break;
      case 5:
	ty[j] = hokab[j];
	break;
      }
    }
    for(j = 0; j < 4; j++){
      for(k = 0; k < 4; k++){
	idice[k] = dicet[ty[k+j]];
      }
      for(k = 0; k < 4; k++){
        if(idice[k] != diceo[yokoa[k]]) break;
	if((idice[3] == diceo[yokoa[3]]) && (k = 3)) co++;
      }
      if(co == 1) break;
    }
    if(co == 1) break;
  }
  if(dicet[ue[i]] == diceo[0]) co++;
  if(co == 2) printf("Yes\n");
  else printf("No\n");
  return 0;
}	

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

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

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

int main(){
   int n;
   cin >> n;
   vl a(n);
   rep(i, n) cin >> a[i];
   sort(all(a));
   ll ans = 0LL;
   rep(i, n) REP(j, i+1, n-1) {
       ll c = a[i] + a[j];
       auto it = lower_bound(a.begin()+j+1, a.end(), c);
       int idx = it - a.begin();
       ll tmp = idx - j - 1; 
       ans += tmp;
       dump(i);
       dump(j);
       dumpL(tmp);
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

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

static const int INFTY = 12345678910;

struct edge { int from, to, cost; };

signed main() {
	int N, M, R;
	int r[10];
	cin >> N >> M >> R;

	REP(i, R) {
		cin >> r[i];
	}

	edge es[20004];
	REP(i, M) {
		cin >> es[i].from >> es[i].to >> es[i].cost;//1-indexed
	}

	int d[210][210];
	REP(i, N) {
		REP(j, N) {
			d[i][j] = INFTY;
		}
	}
	REP(i, M) {
		d[es[i].from - 1][es[i].to - 1] = es[i].cost;
		d[es[i].to - 1][es[i].from - 1] = es[i].cost;
	}
	REP(i, N) {
		d[i][i] = 0;
	}

	/*
	REP(i, N) {
		REP(j, N) cout << d[i][j] << " ";
		cout << endl;
	}
	*/

	for (int k = 0;k < N;k++) {
		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	/*
	REP(i, N) {
		REP(j, N) cout << d[i][j] << " ";
		cout << endl;
	}
	*/

	sort(r, r + R);

	int sum = 0;
	int ans = INFTY;
	do {
		sum = 0;
		for (int i = 0;i < R - 1;i++) {
			sum += d[r[i] - 1][r[i + 1] - 1];
		}

		ans = min(ans, sum);

	} while (next_permutation(r, r + R));

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


Measured memory_bytes: 1024
// A.cpp
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f, MX_N = 1e5 + 200;
ll n, arr[MX_N], dp[MX_N];
int main()
{
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &arr[i]);
    dp[2] = abs(arr[2] - arr[1]);
    for (int i = 3; i <= n; i++)
        dp[i] = min(dp[i - 1] + abs(arr[i - 1] - arr[i]), dp[i - 2] + abs(arr[i] - arr[i - 2]));
    printf("%lld", dp[n]);
    return 0;
}

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

int main() {
  string A, B;
  cin >> A >> B;
  if (A.length() > B.length()) {
    cout << "GREATER";
  }
  else if (B.length() > A.length()) {
    cout << "LESS";
  }
  else {
    if (A == B) {
      cout << "EQUAL";
    }
    else {
      for (int i = 0; i < A.length(); i++) {
        if (A[i] > B[i]) {
          cout << "GREATER";
          break;
        }
        else if (B[i] > A[i]) {
          cout << "LESS";
          break;
        }
      }
    }
  }
}

Measured memory_bytes: 256
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    N = I()
    print(pow(N, 3))
    return


# B
def B():
    N = I()
    A = LI()
    B = LI()
    C = LI()
    a_p = -1
    ans = 0
    for a in A:
        if (a - a_p == 1):
            ans += B[a - 1] + C[a - 2]
        else:
            ans += B[a - 1]
        a_p = a
    print(ans)
    return


# C
def C():
    N = I()
    B = LI()
    A = [0 for i in range(N)]
    A[0] = B[0]
    A[N - 1] = B[N - 2]
    for i in range(1, N - 1):
        A[i] = min(B[i - 1], B[i])
    print(sum(A))
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    C()
    return


# Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REV(i,a,n) for(int i=a;i>=n;i--)
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int num_tests=1; 
    //cin >> num_tests;
    while(num_tests-->0){
        int n; cin >> n;
        int ans = 0;
        vector<int> a(n);
        FOR(i,0,n) cin >> a[i];
        FOR(i,1,n){
            if(a[i] >= a[i-1]) continue;
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
        cout << ans;
    }    
}

Measured memory_bytes: 4672