akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

typedef pair<int, int> pii;

int n, m;
int a[1000], b[1000], c[1000];
int d[100][100];

#define INF (10000000)

int main(int argc, char **argv) {
	cin >> n >> m;
	REP(i, n) REP(j, n) d[i][j] = INF;
	REP(i, m) {
		cin >> a[i] >> b[i] >> c[i];
		--a[i]; --b[i];
		d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
	}
	REP(k, n) REP(i, n) REP(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	int res = 0;
	REP(i, m) {
		if (d[a[i]][b[i]] != c[i]) ++res;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int b[30],ans=1e8;
string str;
int main()
{
	cin>>str;
	int n=str.size();
	for(int i=0;i<n;i++)
	{
		b[str[i]-'a']=1;
	}
	for(int k=0;k<=25;k++)
	{
		string s=str;
		int flag=0;char c='a'+k;
		for(int i=0;i<n;i++)
		{
			if(s[i]!=c){flag=1;break;}
		}
		if(flag==0){cout<<"0"<<endl;return 0;}
		if(b[k])
		{
			for(int i=n-1;i>=0;i--)
			{
				for(int j=0;j<i;j++)
				{
					if(s[j]==c||s[j+1]==c){s[j]=c;}
				}
				int flag=0;
				for(int j=0;j<i;j++)
				{
					if(s[j]!=c){flag=1;break;}
				}
				if(flag==0){if(ans>n-i)ans=n-i;break;}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    for(ll i = 0; i <= K; i++){
        for(ll j = 0; j <= K; j++){
            for(ll k = 0; k <= K; k++){
                if(i + j + k == K){
                    if(B*pow(2, j) > A*pow(2, i) && C*pow(2, k) > B*pow(2, j)){
                        cout << "Yes";
                        return 0;
                    }
                }
            }
        }
    }
    cout << "No";   
}


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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0, __##i##_length = (n); i < __##i##_length; i++)
#define rep_reverse(i, n) for (ll i = (n)-1; 0 <= i; i--)
#define FOR(i, from, to) for (ll i = (from), __##i##_end = (to); i < __##i##_end; i++)
#define FOR_REVERSE(i, from, to) for (ll i = (to)-1, __##i##_end = (from); __##i##_end <= i; i--)
#define foreach(e, v) for (const auto e : (v))
#define vfree(v) std::vector<int>().swap(v)
#define DEBUG(x) cout << #x << " = " << (x) << endl

using namespace std;
typedef int64_t ll;
typedef vector<ll> llv;
typedef vector<llv> llvv;

ll gcd(ll a, ll b)
{
    return (a < b) ? gcd(b, a) : ((a % b) ? gcd(b, a % b) : b);
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    string S;
    cin >> S;
    llv a(26, 0);
    rep(i, 4)
    {
        a[S[i] - 'A']++;
    }
    ll cnt;
    rep(i, 26)
    {
        if (a[i] != 0 && a[i] != 2)
        {
            cout << "No" << endl;
            return 0;
        }
        if (a[i] == 2)
            cnt++;
    }
    cout << (cnt == 2 ? "Yes" : "No") << endl;
    return 0;
}


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

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; }

using ll = long long;
using P = pair<ll,ll>;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll> v(N);
  rep(i,N) cin>>v[i];
  vector<ll> p,m,z;
  rep(i,N) {
    if(v[i]>0) p.push_back(v[i]);
    if(v[i]==0) z.push_back(0);
    if(v[i]<0) m.push_back(v[i]);
  }
  bool ok = true;//can be +
  ll P = p.size(),Z = z.size(),M = m.size();
  if(P+(M/2)*2>=K&&(P>0||K%2==0))ok = true;
  else ok = false;
  ll ans = 0;
  if(!ok){
    if(Z!=0) ans=0;
    else{
      ans = 1LL;
      sort(m.begin(),m.end());
      reverse(m.begin(),m.end());
      sort(p.begin(),p.end());
      ll pcnt=0,mcnt = 0;
      while(pcnt+mcnt<K){
        if(pcnt==P) mcnt++;
        else if(mcnt==M) pcnt++;
        else{
          if(p[pcnt]<=-m[mcnt]) pcnt++;
          else mcnt++;
        }
      }
      rep(i,pcnt) ans = (ans*p[i])%mod;
      rep(i,mcnt) ans = (ans*(-m[i]))%mod;
      ans = mod - ans;
    }
  }
  else{
    ans = 1LL;
    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());
    sort(m.begin(),m.end());
    ll pcnt=0,mcnt = 0;
    while(pcnt+mcnt<K){
      if(pcnt==P) mcnt++;
      else if(mcnt==M) pcnt++;
      else{
        if(p[pcnt]>=-m[mcnt]) pcnt++;
        else mcnt++;
      }
    }
    if(mcnt%2!=0){
      if(mcnt==M||pcnt==0) {
        mcnt--;
        pcnt++;
      }
      else if(pcnt==P||mcnt==0){
        mcnt++;
        pcnt--;
      }
      else{
        ll a = p[pcnt-1],b=p[pcnt],c=-m[mcnt-1],d=-m[mcnt];
        if(a*b>=c*d) {
          mcnt--;
          pcnt++;
        }
        else {
          mcnt++;
          pcnt--;
        }
      }
    }
    rep(i,pcnt) ans = (ans * p[i])%mod;
    rep(i,mcnt) ans = (ans * m[i])%mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6916
class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0] * (n + 1)

    def add(self, k, x):
        k += 1
        while k <= self.n:
            self.bit[k] += x
            k += k & -k

    def sum(self, k):
        s = 0
        while k > 0:
            s += self.bit[k]
            k -= k & -k
        return s


from collections import defaultdict
N, K = map(int, input().split())
A = []
for i in range(N):
    A.append(int(input()))


B = [0]
s = 0
for i in range(N):
    B.append(s + A[i] - (i + 1) * K)
    s += A[i]

D = [0] * (N + 1)
d = defaultdict(list)
for i in range(len(B)):
    d[B[i]].append(i)

B = sorted(B)
k = 0
i = 0
while i < N + 1:
    m = len(d[B[i]])
    for l in d[B[i]]:
        D[l] = k
    k += 1
    i += m

bt = BIT(N + 1)
num = 0
for i in range(N + 1):
    num += bt.sum(D[i] + 1)
    bt.add(D[i], 1)
print(num)





Measured memory_bytes: 69376
#include <stdio.h>
#include <deque>
#include <map>

struct PoolInfoEntry
{
	int position;
	int capacity;
};
typedef std::deque<PoolInfoEntry> PoolInfo;

typedef std::deque<int> OutData;

//left : depth
//right : position
typedef std::map<int,int> PositionInfo;

void create_outdata( const PoolInfo& pool , OutData& odata )
{
	odata.clear();
	if( pool.empty() )
	{
		return;
	}

	PoolInfo::const_reverse_iterator itr = pool.rbegin();
	int position = itr->position;
	int capacity = itr->capacity;
	itr++;

	for( ; itr != pool.rend() ; itr++ )
	{
		if( position < itr->position )
		{
			capacity += itr->capacity;
		}
		else
		{
			odata.push_front( capacity );
			position = itr->position;
			capacity = itr->capacity;
		}
	}

	if( capacity != 0 )
	{
		odata.push_front( capacity );
	}
}

int main( int argc , char** argv )
{
	int total_capacity = 0;
	int position = 0;
	int depth = 0;
	PoolInfo pool_info;
	PositionInfo position_info;

	while( 1 )
	{
		int c = getchar();
		if( c == EOF )
		{
			break;
		}
		if( c == '\\' )
		{
			depth--;
			position_info[ depth ] = position;
		}
		if( c == '/' )
		{
			PositionInfo::iterator itr = position_info.find( depth );
			if( itr != position_info.end() )
			{
				int capacity = position - itr->second;
				total_capacity += capacity;

				PoolInfoEntry entry;
				entry.capacity = capacity;
				entry.position = itr->second;
				pool_info.push_back( entry );

				position_info.erase( itr );
			}
			depth++;
		}
		position++;
	}

	OutData out_data;
	create_outdata( pool_info , out_data );

	printf( "%d\n" , total_capacity );
	printf( "%d" , out_data.size() );
	for( OutData::iterator itr = out_data.begin() ; itr != out_data.end() ; itr++ )
	{
		printf( " %d" , *itr );
	}
	printf( "\n" );
	return 0;

}

Measured memory_bytes: 1912
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end
s=gets.chomp
t=gets.chomp
puts (s==t[0...(t.size-1)])? "Yes": "No"
#() puts (a[0]) "Yes": "No"

Measured memory_bytes: 14408
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let[a,b,c]=srin(3)
  out(eval(a+b+c))
}
main()

Measured memory_bytes: 7372
//Balance

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
using ll = long long;
#define range(a) (a).begin(),(a).end()


int main (){
    int N,sum=0,a=0,Ans;cin >> N;
    vector<int> c(N);
    rep(i,0,N){
        cin >> c[i];
        sum += c[i];
    }
    Ans = sum;
    rep(i,0,N){
        a += c[i];
        Ans = min(Ans,abs((sum-a)-a));
    }
    cout << Ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

string s;
int n,k;
set<string>Set;

inline void file() {
	freopen("ARC097C.in","r",stdin);
	freopen("ARC097C.out","w",stdout);
}

int main() {
//	file();
	cin >> s;
	n=s.length(); scanf("%d",&k);
	For (i,0,n-1) {
		string ss="";
		For (j,0,min(k-1,n-1-i)) {
			ss=ss+s[i+j]; Set.insert(ss);
		}
	}
	for (set<string>::iterator it=Set.begin();it!=Set.end();++it) {
		--k;
		if (!k) {
			cout << *it << endl; return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int count = 0;
    int[] a = new int[N + 1];
    for(int i = 1; i <= N; i++) {
      a[i] = sc.nextInt();
    }
    for(int i = 1; i <= N; i++) {
      if(i == a[i]) {
        count++;
        i++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 50684
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int h = sc.nextInt();
            if (m <= h) {
                ans++;
            }
            m = Math.max(m, h);
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
 
using namespace std;
 
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
 
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
 
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
 
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
 
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}
 
 
int N;

int main()
{
  cin >> N;

  vector<ll> A(N),B(N),C(N);
	
  rep(i,N)cin>>A[i];
  rep(i,N)cin>>B[i];
  rep(i,N)cin>>C[i];

  sort(all(A));
  sort(all(B));
  sort(all(C));

  ll ans = 0;

  rep(i, N) {
    ll l = lower_bound(all(A), B[i]) - begin(A);
    ll r = N - (upper_bound(all(C), B[i]) - begin(C));

    ans += l * r;
  }

  cout << ans << endl;
}



Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
const int N=4000002;
char s[N],t[N];
int a,b,ne[N],ans,g[N],i,j;
int main(){
	scanf("%s%s",s+1,t+1),a=strlen(s+1),b=strlen(t+1);
	for (;a<b*2;a*=2)
		for (i=1;i<=a;i++) s[i+a]=s[i];
	for (i=1;i<=a;i++) s[i+a]=s[i];
	a*=2;
//	for (i=2,j=1;i<=b;i++){
//		while (j>1 && t[i]!=t[j]) j=ne[j-1];
//		if (t[i]==t[j]) j++;
//		ne[i]=j;
//	}
//	for (i=1,j=1;i<=a;i++){
//		while (j>1 && s[i]!=t[j]) j=ne[j-1];
//		if (s[i]==t[j]) j++;
//		if (j==b+1) ans=max(ans,g[i]=g[i-b]+1);
//	}
//	ne[0]=-1;
//	for (i=1;i<=b;i++){
//		j=i-1;
//		while (j && t[ne[j]+1]!=t[i]) j=ne[j];
//		ne[i]=ne[j]+1;
//	}
//	for (i=1,j=0;i<=a;i++){
//		while (~j && s[i]!=t[j+1]) j=ne[j];
//		if (++j==b) ans=max(ans,g[i]=g[i-b]+1);
//	}
//	ne[0]=-1;
	for (i=1;i<=b;i++){
		j=i-1;
		while (j && t[ne[j]]!=t[i]) j=ne[j]-1;
		ne[i]=ne[j]+1;
	}
//	for (i=1;i<=b;i++) ne[i]++;
	for (i=1,j=1;i<=a;i++){
		while (j && s[i]!=t[j]) j=ne[j-1];
		if (++j==b+1) ans=max(ans,g[i]=g[i-b]+1);
	}
	printf("%d",ans>=a/b-1?-1:ans);
}


Measured memory_bytes: 23040
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n;
	cin >> n;
	ll a[n];
	REP(i,n) cin >> a[i];
	int ans = 0;
	for(;;){
		REP(i,n){
			if(a[i] % 2 == 0) a[i] /= 2;
			else goto fin;
		}
		ans++;
	}
	fin:;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>

using namespace std;

int n;
long long int a, b, loc[100005], ans = 0;

int main () {
  scanf("%d%lld%lld",&n, &a,&b);
  for(int i = 1; i <= n; i ++) {
    scanf("%lld",&loc[i]);
  }
  for(int i = 1; i <= n - 1; i ++) {
    if(b < a * (loc[i + 1] - loc[i])) {
     ans += b;
    }
    else {
      ans += a * (loc[i + 1] - loc[i]);
    }
  }
  printf("%lld\n",ans);
 // system("pause");
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

void a_payment(void) {
	int n;
	cin >> n;
	int answer;
	if (n % 1000 != 0) answer = n / 1000 + 1;
	else               answer = n / 1000;
	cout << 1000*answer-n << endl;
}

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

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

#define endl "\n"
#define si(a) scanf("%d ",&a);
#define si2(a,b) scanf("%d %d ",&a,&b);
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sll(a) scanf("%lld ",&a);
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sf(a) scanf("%f ",&a);
#define sd(a) scanf("%lf ",&a);
#define sc(a) scanf("%c ",&a);
#define ss(a) scanf("%s ",a);
#define sf2(a,b) scanf("%f %f ",&a,&b);
#define sd2(a,b) scanf("%lf %lf ",&a,&b);
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
#define all(a) a.begin(),a.end()
#define forn(i,n) for(int i=0;i<n;i++)
#define forq(i,q,n) for(int i=q;i<n;i++)
#define form(i,n) for(int i=n;i>=0;i--)
#define forp(i,q,n) for(int i=q;i>=n;i--)
#define fi first
#define se second
#define INF 1000000010
#define MOD 1000000007
#define MAXN
#define LL long long int


using namespace std;

string S;

void init(){
	cin >> S;
	int l = S.size();
	//printf("%d\n", l);
	int cnt = 0;
	cin >> S;
	for (int i = 0; i < l; ++i) {
		if(S[l - 1 - i] == 'Z'){
			cnt = l - i;
			break;
		}
	}
	for (int i = 0; i < l; ++i) {
		if(S[i] == 'A'){
			cnt -= i;
			break;
		}
	}
		printf("%d\n",cnt);

}

int main(){
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	init();
	return 0;
}

Measured memory_bytes: 640
n = int(input())
d = [int(i) for i in input().split()]
x = [0] * 13
for i in d:
    x[i] += 1
x[0] += 1

if max(x) > 2:
    print(0)
    exit()
ans = 0
for i in range(1 << 13):
    a = []
    for j in range(13):
        if x[j]==1:
            if (i >> j) & 1 == 1:
                a.append(j)
            else:
                a.append(24 - j)
        elif x[j] == 2:
            a.append(j)
            a.append(24 - j)
    aa = 10**18
    for j in range(len(a)):
        for k in range(j + 1, len(a)):
            d = abs(a[j] - a[k])
            aa = min(aa, min(d, 24-d))
    ans = max(ans, aa)
print(ans)


Measured memory_bytes: 45804
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[2001][2001],a2[2001][2001];
int b[2001][2001];
int h,w,mx,mn;
bool test(int d){
    rep(i,h)rep(j,w){
        if(mn+d>=a[i][j]&&mx-d<=a[i][j]) b[i][j]=2;
        else if(mn+d>=a[i][j]) b[i][j]=1;
        else if(mx-d<=a[i][j]) b[i][j]=0;
        else return false;
    }
    int cur=0;
    rep(i,h){
        int cl=0,cr=w;
        rep(j,w)if(b[i][j]!=2&&b[i][j]==0){
            cr=j;break;
        }
        for(int j=w-1;j>=0;--j)if(b[i][j]!=2&&b[i][j]==1){
            cl=j+1;break;
        }
        if(cl>cr||cur>cr) return false;
        cur=max(cur,cl);
    }
    return true;
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>h>>w;
    mn=1000100010,mx=0;
    rep(i,h)rep(j,w){
        cin>>a[i][j];
        mn=min(mn,a[i][j]),mx=max(mx,a[i][j]);
    }
    int ans=1000100010;
    rep(k,4){
        int lb=0,ub=mx-mn+1;
        while(ub-lb>1){
            int mid=(ub+lb)/2;
            if(test(mid)) ub=mid;
            else lb=mid;
        }
        ans=min(ans,ub);
        rep(i,h)rep(j,w) a2[w-j-1][i]=a[i][j];
        swap(h,w);
        rep(i,h)rep(j,w) a[i][j]=a2[i][j];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 50144
N = int(input())
A = []
A.append(list(map(int,input().split())))
A.append(list(map(int,input().split())))

S1 = [sum(A[0][:j+1]) for j in range(N)]
S2 = [sum(A[1][j:]) for j in range(N)]

print(max([S1[i]+S2[i] for i in range(N)]))

Measured memory_bytes: 3064
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

int main() {
	cout << fixed << setprecision(12);	
	int n, k;
	vector<int> a;
	cin >>n >> k;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		a.push_back(t);
	}
	for (int i = k; i < n; i++) {
		if (a[i] > a[i - k]) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



Measured memory_bytes: 4284
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
if n==2:print(max(a[0],a[1]))
elif n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])))
else:
  no,mi=a[0],a[0]
  for i in range(1,n):
    s=gcd(no,a[i])
    if s!=no:
      no=max(s,mi)
      mi=gcd(s,mi)
  print(no)

Measured memory_bytes: 14052
from fractions import gcd
a, b, c, d = map(int, input().split())

def lcm(x, y):
    return x*y//gcd(x,y)

def notDiv(a, c, d):
    return a - a//c - a//d + a//lcm(c, d)

print( notDiv(b, c, d)-notDiv(a-1, c, d) )

Measured memory_bytes: 67052
from collections import Counter
from sys import exit

n=int(input())
s=input()

l=list(Counter(s).values())
if len(l)<3:
	print("0")
	exit()
	
res=l[0]*l[1]*l[2]

for i in range(1,n//2+1):
	for j in range(n):
		if j+i*2>n-1:
			break
		a=j
		b=j+i
		c=b+i
		if s[a]!=s[b] and s[b]!=s[c] and s[c]!=s[a]:
			res-=1
			
print(res)

Measured memory_bytes: 9492
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int n;
    cin >> n;
    int m = 0;
    unordered_map<int, int> a;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a[x]++;
        m = max(m, x);
    }
    bool flag_pair = true;
    bool flag_all = true;
    for(int i = 2; i <= m; i++) {
        int x = 0;
        for(int j = i; j <= m; j += i) {
            if(a[j]) {
                x += a[j];
            }
        }
        // cout << i << " : " << x << endl;
        if(x > 1) {
            flag_pair = false;
        }
        if(x == n) {
            flag_all = false;
        }
    }
    if(flag_pair) {
        cout << "pairwise coprime" << endl;
        return 0;
    }
    if(flag_all) {
        cout << "setwise coprime" << endl;
        return 0;
    }
    cout << "not coprime" << endl;
}

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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int k;
string s;
set<string> st;
vector<string> v;
signed main() {
    cin>>s>>k;
    rep(i,0,s.size()){
        rep(j,1,6){
            if(i+j>s.size())break;
            string t=s.substr(i,j);
            v.pb(t);
        }
    }
    sort(all(v));
    v.erase(unique(all(v)),v.end());
    cout<<v[k-1]<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 1660
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
need = [[True]*N for _ in range(N)]

for i in range(N):
    for j in range(N):
        for k in range(N):
            if i==j or j==k or k==i:
                continue
            
            if A[i][j]+A[j][k]<A[i][k]:
                print(-1)
                exit()
                
            if A[i][j]+A[j][k]==A[i][k]:
                need[i][k] = False

ans = 0

for i in range(N):
    for j in range(N):
        if need[i][j]:
            ans += A[i][j]

print(ans//2)

Measured memory_bytes: 45976
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<Integer,Integer> map = new HashMap<>();
		for(int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if(map.containsKey(a)) {
				map.put(a, map.get(a)+1);
			} else {
				map.put(a, 1);
			}
		}
		int count = 0;
		for(int i : map.keySet()) {
			if(i == map.get(i)) {
				continue;
			} else if(i > map.get(i)) {
				count += map.get(i);
			} else {
				count += map.get(i)-i;
			}
		}
		System.out.println(count);
	}
}

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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

int main() {
	string a, b; cin >> a >> b;
	if(SZ(a) > SZ(b)) return puts("GREATER") < 0;
	else if(SZ(a) < SZ(b)) return puts("LESS") < 0;
	else{
		for(int i=0; i<SZ(a); i++) {
			if(a[i] > b[i]) return puts("GREATER") < 0;
			else if(a[i] < b[i]) return puts("LESS") < 0;
		}
		puts("EQUAL");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll x, y, a, b, c; cin >> x >> y >> a >> b >> c;
    vector<ll> p(a); rep(i,a) cin >> p[i];
    vector<ll> q(b); rep(i,b) cin >> q[i];
    vector<ll> r(c); rep(i,c) cin >> r[i];

    vector<ll> pq(x+y); ll pi = 0, qi = 0;
    sort(all(p)); sort(all(q));
    reverse(all(p)); reverse(all(q));

    rep(i,x) pq[i] = p[i];
    rep(i,y) pq[i+x] = q[i];

    sort(all(r)); sort(all(pq));
    reverse(all(r));

    ll ri = 0;
    ll pqi = 0;

    ll ans = 0;

    rep(i,x+y){
        if(pq[pqi] < r[ri]){
            pq[pqi] = r[ri];
            ri++;
            pqi++;
        }
        else{
            pqi++;
        }
    }

    sort(all(pq)); reverse(all(pq));

    rep(i,x+y) ans += pq[i];

    cout << ans << endl;

}


Measured memory_bytes: 3968
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- getIntList
    let os = length $ filter odd as
        fs = length $ filter ((==0) . (`mod` 4)) as
    putStrLn $ if os <= fs || (os+fs == n && os-fs == 1) then "Yes" else "No"

Measured memory_bytes: 13812
r,g,b,n = map(int,input().split())
r1 = 0
count = 0

while r*r1 <= n:
    g1 = 0
    while r*r1+g*g1 <= n:
        if (n-(r*r1+g*g1))%b==0:
            count += 1
        g1 += 1
    r1 += 1
print(count)


Measured memory_bytes: 40556
#include <bits/stdc++.h>
#define int long long
#define V 100011
#define N 111

using namespace std;
const int INF = (int)1e15;

int n, mw, w[N], v[N], min_w[N][V];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n >> mw;
	for(int i=0; i<n; i++) {
		cin >> w[i+1] >> v[i+1];
	}
	for(int i=0; i<=n; i++) {
		for(int j=0; j<100001; j++) {
			if(i == 0) min_w[i][j] = (j == 0) ? 0 : INF;
			else {
				min_w[i][j] = min_w[i-1][j];
				if(v[i] <= j) min_w[i][j] = min(min_w[i][j], min_w[i-1][j-v[i]]+w[i]);
			}
		}
	}
	for(int i=100000; i>=0; i--) {
		if(min_w[n][i] <= mw) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	cout << (a+b+c>=22?"bust":"win");
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

int n, s;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> s;
    if(n == s)
    {
        cout << n + 1 << "\n";
        return 0;
    }
    int ans = 2e18;
    for(int i = 2; i * i <= n; i++)
    {
        int cursum = 0, x = n;
        while(x > 0)
        {
            cursum += x % i;
            x /= i;
        }
        if(cursum == s)
            ans = min(ans, i);
    }
    for(int i = 1; i * i < n; i++)
        if((n - s) % i == 0)
        {
            int b = (n - s) / i + 1;
            if(b < 2)
                continue;
            int cursum = 0, x = n;
            while(x > 0)
            {
                cursum += x % b;
                x /= b;
            }
            if(cursum == s)
                ans = min(ans, b);
        }
    if(ans < 1e18)
        cout << ans << "\n";
    else
        cout << "-1\n";
    return 0;
}

Measured memory_bytes: 3536
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;

#define df(b, e) ((b) > (e))
#define fore(i, b, e) for (auto i = (b) - df(b, e); i != e - df(b, e); i += 1 - 2 * df(b, e))
#define sz(x) (int)(x.size())
#define all(x) begin(x), end(x)
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mp make_pair

using lli = long long;
using ld = long double;
using ii = pair<int, int>;
using vi = vector<int>;

#ifdef LOCAL
  #include "debug.h"
  const int N = 10;
#else
  #define debug(...)
  const int N = 2e5 + 5;
#endif
const int mod = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

lli ans[N], dp[N], fact[N], ifact[N];
vi g[N];
int sz[N], n;

lli fpow (lli x, lli y) {
  lli ans = 1;
  for (; y ; y >>= 1) {
    if (y & 1)
      (ans *= x) %= mod;
    (x *= x) %= mod;
  }
  return ans;
}

void dfs (int u, int parent = 1) {
  dp[u] = sz[u] = 1;
  for (int v: g[u]) {
    if (v != parent) {
      dfs(v, u);
      (dp[u] *= dp[v]) %= mod;
      (dp[u] *= ifact[sz[v]]) %= mod;
      sz[u] += sz[v];
    }
  }
  (dp[u] *= fact[sz[u] - 1]) %= mod;
}


void solve (int u, int parent = 1) {

  vector<lli> pre, suf;
  dp[u] = sz[u] = 1;
  for (int v: g[u]) {
    (dp[u] *= dp[v]) %= mod;
    (dp[u] *= ifact[sz[v]]) %= mod;
    sz[u] += sz[v];
    pre.eb(dp[u]);
  }

  reverse(all(g[u]));
  dp[u] = 1;
  for (int v: g[u]) {
    (dp[u] *= dp[v]) %= mod;
    (dp[u] *= ifact[sz[v]]) %= mod;
    suf.eb(dp[u]);
  }
  reverse(all(suf));
  reverse(all(g[u]));
  (dp[u] *= fact[sz[u] - 1]) %= mod;
  
  ans[u] = dp[u];

  int cnt = 0;
  for (int v: g[u]) {
    if (v != parent) {
      int aux = sz[u];
      sz[u] -= sz[v];
      (dp[u] = (cnt == 0 ? 1LL: pre[cnt - 1]) * (cnt == sz(g[u]) - 1 ? 1LL: suf[cnt + 1])) %= mod;
      debug(sz[u]);
      (dp[u] *= fact[sz[u] - 1]) %= mod;

      solve(v, u);

      sz[u] = aux;
    }
    cnt++;
  }
}



int main() {
  cin.tie(0) -> sync_with_stdio(0), cout.tie(0);
  #ifdef LOCAL
	  auto start_time = clock();
  #endif
  int u, v;
  cin >> n;

  fact[0] = 1;
  fore (i, 1, n + 1)
    (fact[i] = fact[i - 1] * i) %= mod;

  ifact[n] = fpow(fact[n], mod - 2);
  debug(ifact[n]);
  fore(i, n, 0)
    ifact[i] = lli(i + 1) * ifact[i + 1] % mod;

  debug(ifact);
  fore (i, 0, n - 1) {
    cin >> u >> v;
    g[u].eb(v);
    g[v].eb(u);
  }

  dfs(1);
  solve(1);

  fore (u, 1, n + 1)
    cout << ans[u] << '\n';

  #ifdef LOCAL
	  auto end_time = clock();
	  cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
  #endif
  return 0;
}

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

int main(){
  ll n,m,Q,l,r,p,q,c[505][505]={},d[505][505]={},e[505][505]={};
  cin>>n>>m>>Q;
  fr(i,m){cin>>l>>r;c[--r][--l]++;}
  fr(R,n) for(int L=R;L>=0;L--) d[R][L]=d[R][L+1]+c[R][L];
  e[0][0]=c[0][0];
  for(int R=1;R<n;R++) for(int L=R;L>=0;L--) e[R][L]=e[R-1][L]+d[R][L];
  fr(i,Q){
    cin>>p>>q;
    cout<<e[--q][--p]<<endl;
  }
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 9223372037ll;

void solve()
  {
   int n;
   cin>>n;
  // pii best = {1,n};
   int mn = n+1;
   for(int i=2; i*i<=n; i++){
    if(n%i == 0 && n/i + i < mn){
      mn = n/i + i;
      //best = {i,n/i};
    }
   }
   int ans = mn - 2;
   cout<<ans;
  } 
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0); 
 
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
} 

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define LL long long int

using namespace std;

int main(){
    int i,j,n,k;
    cin>> n;
    int arr[n][3];
    for(i = 0;i < n;i++){
        for(j  = 0;j < 3;j++){
            cin>>arr[i][j];
        }
    }
    int dp[n + 1][3];
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for(i = 0;i < n;i++){
        for(j = 0;j < 3;j++){
            dp[i + 1][j] = max(dp[i][(j - 1 + 3)%3] + arr[i][j],dp[i][(j +1+3)%3] + arr[i][j]);
        }
    }
    cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
    /*
    dp[i][] = max(dp[i-1][] + )
    dpij - max possible happiness upto i days including jth activity 
    */
    
}

Measured memory_bytes: 2560
#include <stdio.h>

int main(void){
  int sum, max = 0, count = 0;
  scanf("%d\n", &sum);
  int num[sum];
  num[0] = 0;
  for(int i=1; i <= sum; i++){
    scanf("%d ", &num[i]);
    if(max <= num[i]){
      max = num[i];
    }
    if(num[i-i] <= num[i] && num[1] <= num[i] && max <= num[i]){
      count++;
    };
  }
  printf("%d", count);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  long long x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  if (x1 > x2) swap(x1, x2), swap(y1, y2);
  bool flg = y1 > y2;
  if (flg) y2 = -(y2 - y1) + y1;
  int N;
  cin >> N;
  vector<pair<long long, long long>> ps;
  for (int i = 0; i < N; i++) {
    long long X, Y;
    cin >> X >> Y;
    if (X < x1 || x2 < X) continue;
    if (flg) Y = -(Y - y1) + y1;
    if (Y < y1 || y2 < Y) continue;
    ps.emplace_back(X, Y);
  }
  sort(ps.begin(), ps.end());
  const double PI = acos(-1);
  vector<long long> v;
  for (auto [x, y] : ps) {
    auto itr = lower_bound(v.begin(), v.end(), y);
    if (itr == v.end()) {
      v.push_back(y);
    } else {
      *itr = y;
    }
  }
  double ans = (x2 - x1 + y2 - y1) * 100 + v.size() * (-20 + 5 * PI);
  if ((long long)v.size() == min(x2 - x1, y2 - y1) + 1) ans += 5 * PI;
  cout << fixed << setprecision(12) << ans << '\n';
  return 0;
}


Measured memory_bytes: 10044
n = int(input())
b_l = list(map(int, input().split()))
sum_a = 0

for i in range(n):
    if i is 0:
        sum_a += b_l[i]
    elif i == n-1:
        sum_a += b_l[i-1]
    else:
        sum_a += min(b_l[i],b_l[i-1])

print(sum_a)

Measured memory_bytes: 3060
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
   int a,b;
   cin>>a>>b;
   vector<int> rvec(b);
   vector<int> lvec(b);
   rep(i,b){
      cin>>rvec.at(i)>>lvec.at(i);
   }
   int max = *std::max_element(rvec.begin(), rvec.end());
   int min = *std::min_element(lvec.begin(), lvec.end());
   if(min>=max){
      cout<<min-max+1<<endl;
   }
   else{
      cout<<0<<endl;
   }
}



Measured memory_bytes: 1024
#include <stdio.h>

int main() {
  int number[3];
  scanf("%d %d %d", &number[0], &number[1], &number[2]);
  if(number[0] <= number[2] && number[2] <= number[1]) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
import math
def D():
    N = int(input())
    if N == 1:
        print(0)
        return
    temp = N
    count = 0
    while temp % 2 == 0: 
       temp //= 2
       count += 1
    track = 1
    # print(count)
    while count-track >= 0:
        count -= track
        track += 1
    # print(temp, track-1)
    ans = track - 1
    for i in range(3,int(math.sqrt(temp))+1,2): 
        count = 0
        while temp % i== 0: 
            temp //= i
            count += 1
        track = 1
        while count-track >= 0:
            count -= track
            track += 1
        ans += track - 1
    if temp > 2:
        ans += 1
    print(ans)
D()

Measured memory_bytes: 9216
#include <iostream>

using namespace std;

int N;
int C[30], V[30];
int main() {
    cin >> N;
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> V[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> C[i];
    }
    for (int i = 0; i <N ; ++i) {
        if (V[i] > C[i])
            sum+=V[i]-C[i];
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 256
function main (input) {
	const args = input.split(' ');
	const a = parseInt(args[0], 10);
	const b = parseInt(args[1], 10);

	if ((a * b) % 2 === 0) {
        console.log('Even');
    } else {
        console.log('Odd');
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

int dp[1005][10005];
const int N = 10005;
 int a[N],b[N];
  
int calculate(int ind,int health){
 
//cout << ind <<" , "<< health << "," <<endl;

 if( health <= 0){
     return 0;
 } 
 if( ind < 0) return INT_MAX;  
  if( dp[ind][health] != -1) return dp[ind][health];

  //int ans = min(calculate(ind,health-a[ind]) + b[ind], calculate(ind-1,health));
  
  return dp[ind][health] = min(calculate(ind,health-a[ind]) + b[ind], calculate(ind-1,health));
}




int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  int h,n;
  cin >> h >> n;
  memset(dp,-1,sizeof(dp));
  for(int i =0;i<n;i++){
      cin >> a[i] >> b[i];
  }
  //cout << "ans" << endl;
 
int ans = calculate(n-1,h);
  cout << ans << endl;
 }


Measured memory_bytes: 40064
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
using ll = long long;
const char E = '\n';
const int N = 1005;
const ll mod = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie(0);
    string s, t, c;
    int n;
    cin >> s;
    n = s.size();
    t = s;
    reverse(t.begin(), t.end());
    if (s != t) {
        cout << "No";
        return 0;
    }
    c = s.substr(0, (n-1)/2);
    t = c;
    reverse (t.begin(), t.end());
    if (c != t) {
        cout << "No";
        return 0;
    }
    c = s.substr((n-1)/2+1, n-(n-1)/2);
    t = c;
    reverse (t.begin(), t.end());
    if (c != t) {
        cout << "No";
        return 0;
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
  int D, N;
  std::cin >> D >> N;
  int ans = 0;
  if (N != 100) ans = N;
  else ans = 101;
  while (D)
  {
    ans *= 100;
    D--;
  }
  std::cout << ans << std::endl;
}


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

int main()
{
    string s;
    cin>>s;
    int l = s.length();
    int ans=0;
    for(int i=0;i<l/2;i++){
        if(s[i] == s[l-i-1]){
            //nothing
        }
        else{
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
temp_list = []
flag = 1

for i in range(N):
  if A[i] % 2 == 0:
    temp_list.append(A[i])

for i in range(len(temp_list)):
  if not (temp_list[i] % 3 == 0 or temp_list[i] % 5 == 0):
    flag = 0
    
if flag == 1:
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
vector<ll> visit,lg;
vector<vector<ll>> adj;

ll dfs(ll i,ll depth)
{
	visit[i]=1;
	for(auto j:adj[i])
	{
		if(visit[j]==-1)
		{
			ll x=dfs(j,0LL);
			depth=max(depth,1+x);
			lg[j]=max(lg[j],x);
		}
		else
		{
			depth=max(depth,1+lg[j]);
		}
	}
	return depth;
}
void solve()
{
	ll n,m;
	rl2(n,m);
	visit.assign(n,-1);
	lg.assign(n,0);
	adj.assign(n,VL());
	fr(i,0,m)
	{
		ll x,y;
		rl2(x,y);
		x--,y--;
		adj[x].PB(y);
	}
	fr(i,0,n)
	{
		if(visit[i]==-1)
		{
			//visit[i]=max(visit[i],dfs(i));
			lg[i]=max(lg[i],dfs(i,0LL));
		}
	}
	ll ans=*max_element(ALL(lg));
	cout<<ans<<endl;
	return;
}
int main()
{
	
	ll t=1;
	//rl(t);

	//cin>>t;
	//scanf()
	while(t--)
	{
		solve();
	}
	
	return 0;
}

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

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

    int A, B;
    int result = 0;
    cin >> A >> B;

    if(A > B*2){
        result = A - B*2;
    }else{
        result = 0;
    }
    cout << result;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void solve(){
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a+b>=k){
    if(a>k) cout<<k<<endl;
    else cout<<a<<endl;
  }
  else{
    k-=(a+b);
    a-=k;
    cout<<a<<endl;
  }
}
int main(){
    optimizeIO();
    // tc
    {
      solve();
    }
}


Measured memory_bytes: 3652