akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define ff first
#define mp make_pair
#define ss second
#define rep(i,a,b) for(int i = a; i < b; i++)
#define repp(i,a,b) for(int i = a; i <= b; i++)
#define endl '\n'
#define mod 1000000007
#define mod_in(a) bin(a, mod - 2)
#define fact(n) rep(i, 1, n+1) ft.pb((ft[i-1] * i) % mod)
#define ncr(n, r) (n >= r ? ((ft[n] * mod_in((ft[r] * ft[(n)-(r)]) % mod)) % mod) : 0LL)
#define pi 3.14159265358979323
#define INF 1e15
#define lb(v, a) lower_bound(v.begin(), v.end(), a)
#define ub(v, a) upper_bound(v.begin(), v.end(), a)

int power(int x, int n){
    int res=1;
    while(n>0){
        if(n&1)
            res=res*x;
        x*=x;
        n>>=1;
    }
    return res;
}

int bin(int x, int n){
    int res=1; x%=mod;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

bool prime(int n){
    if(n==3)return 1;
    repp(i,2,sqrt(n)){
        if(n%i==0)return 0;
    }
    return 1;
}


// vector<int> adj[2000005];
// vector<int> pr(2000005, 1), xx[2000005];
// void sieve(int n){ 
//     for(int p=2; p<n; p++){ 
//         if(pr[p]){ 
//             for(int i=p; i<n; i += p){
//                 pr[i]=0;
//                 xx[i].pb(p);
//             }
//         } 
//     } 
// }  
// vector<int> ft(40);

void solve(){
    string s, t; cin>>s>>t;
    if(s.size() > t.size()) swap(s, t);
    int dp[s.size()][t.size()];
    rep(i,0,s.size()){
        rep(j,0,t.size()){
            dp[i][j]=0;
        }
    }
    rep(i,0,s.size()){
        rep(j,0,t.size()){
            if(s[i]==t[j] && i && j){
                dp[i][j] = 1 + dp[i-1][j-1];
            }
            else if(s[i]==t[j]) dp[i][j] = 1;
            else{
                if(i) dp[i][j] = dp[i-1][j];
                if(j) dp[i][j] = max(dp[i][j], dp[i][j-1]);
            }
        }
    }
    int i=s.size()-1, j=t.size()-1;
    stack<char> res;
    while(i >=0 && j>=0){
        if(s[i]==t[j]){
            res.push(s[i]);
            i--; j--;
        }
        else{
            if( i && j){
                if(dp[i-1][j] > dp[i][j-1]){
                    i--;
                }
                else j--;
            }
            else if(i) i--;
            else j--;
        }
    }
    while(!res.empty()){
        cout<<res.top();
        res.pop();
    }
}

signed main(){
    fast
    int t=1;
    // cin>>t;
    while(t--) solve();
}

Measured memory_bytes: 73964
import java.util.Scanner;
import java.math.BigDecimal;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNextInt()){
			int a=sc.nextInt();
			int b=sc.nextInt();
			int c=sc.nextInt();
			int d=sc.nextInt();
			int e=sc.nextInt();
			int f=sc.nextInt();
			double det=(double)(a*e-b*d);
			double x=(double)(c*e-b*f)/det;
			double y=(double)(c-a*x)/b;
			System.out.println(new BigDecimal(x).setScale(3, BigDecimal.ROUND_FLOOR)+" "+new BigDecimal(y).setScale(3, BigDecimal.ROUND_HALF_UP));
			//System.out.printf("%.3f %.3f\n",x,y);
		}
	}
}

Measured memory_bytes: 18204
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f//3f3f3f3f
#define ll long long
#define ull unsigned long long
#define lowbit(a) ((a)&(-(a)))
using namespace std;

int main() {
    int a,b;
    while(cin>>a>>b){
        if(b%a){
            cout<<(b - a)<<endl;
        }else{
            cout<<(b+a)<<endl;
        }

    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}	
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
int ans[]={0,1800,1600,1400,1200,1000,800,600,400};
int main()
{
    int x;
    cin>>x;
    for(int i=1;i<=8;++i)
    if(x>=ans[i])
    {
        cout<<i<<endl;
        return 0;
    }
	return 0;
}


Measured memory_bytes: 3632
n = int(input())
a = list(map(int,input().split()))

m = 2+n%2
dp = [[-10**18]*m for i in range(n+2)]
dp[0][0] = 0
for i in range(n):
    for j in range(m):
        if i%2 == j%2:
            x = a[i]
        else:
            x = 0
        if dp[i+1][j] < dp[i][j] + x:
            dp[i+1][j] = dp[i][j] + x
        if j+1 < m and dp[i+1][j+1] < dp[i][j]:
            dp[i+1][j+1] = dp[i][j]
print(max(dp[n][m-2], dp[n][m-1]))

Measured memory_bytes: 114480
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

template<typename ID_TYPE = uint64_t>
class UnionFindTreeBase
{
private:
  std::vector<ID_TYPE> root, rank;

public:
  UnionFindTreeBase(ID_TYPE N)
  {
    root = std::vector<ID_TYPE>(N);
    for (ID_TYPE n = 0; n < N; ++n) { root[n] = n; }
    rank = std::vector<ID_TYPE>(N, 0);
  }

  ID_TYPE find(ID_TYPE x)
  {
    if (root[x] == x) { return x; }

    root[x] = find(root[x]);

    return root[x];
  }

  void unite(ID_TYPE x, ID_TYPE y)
  {
    ID_TYPE x_root = find(x), y_root = find(y);

    if (rank[x_root] > rank[y_root]) {
      root[y_root] = x_root;
    } else if (rank[x_root] < rank[y_root]) {
      root[x_root] = y_root;
    } else if (x_root != y_root) {
      root[y_root] = x_root;
      ++rank[x_root]; 
    }
  }

  bool is_same(ID_TYPE x, ID_TYPE y)
  {
    return find(x) == find(y);
  }
};

typedef UnionFindTreeBase<uint64_t> UnionFindTree;

ostream& operator<<(ostream &os, const vector<uint64_t> &v)
{
  N_TIMES(i, v.size()) {
    os << v[i];
    if (i + 1 < v.size()) { os << ' '; }
  }
  return os;
}

int main()
{
  uint64_t N, M, K;
  cin >> N >> M >> K;

  UnionFindTree uf_tree(N);

  map<uint64_t, set<uint64_t>> friends;
  N_TIMES(m, M) {
    uint64_t A, B;
    cin >> A >> B;
    
    uf_tree.unite(A - 1, B - 1);
    
    friends[A - 1].insert(B - 1);
    friends[B - 1].insert(A - 1);
  }

  map<uint64_t, set<uint64_t>> blocks;
  N_TIMES(k, K) {
    uint64_t C, D;
    cin >> C >> D;
    
    blocks[C - 1].insert(D - 1);
    blocks[D - 1].insert(C - 1);
  }

  vector<uint64_t> size_of_subtree(N, 0);
  N_TIMES(n, N) {
    ++size_of_subtree[uf_tree.find(n)];
  }

  vector<uint64_t> size_of_candidates(N, 0);
  N_TIMES(n, N) {
    uint64_t S = size_of_subtree[uf_tree.find(n)] - 1;
    S -= friends[n].size();

    for (const uint64_t &x : blocks[n]) {
      if (uf_tree.find(x) == uf_tree.find(n)) {
        --S;
      }
    }

    size_of_candidates[n] = S;
  }
  cout << size_of_candidates << endl;

  return 0;
}

Measured memory_bytes: 41472
#include<stdio.h>

main()
{
    int n,p[21],i,e=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    scanf("%d",&p[i]);
    for(i=1;i<n-1;i++)
    if((p[i]<p[i+1]&&p[i]>p[i-1])||(p[i]>p[i+1]&&p[i]<p[i-1]))
        e++;
    printf("%d",e);
        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(){
    ll k;cin >> k;
    ll cnt=k/50;
    ll rem=k%50;
    vector<ll> ans(50);
    rep(i,50) ans[i]=i+cnt;
    rep(t,rem){
        ll mx=LINF;
        ll idx=-1;
        rep(i,50){
            if(mx>ans[i]){
                mx=ans[i];
                idx=i;
            }
        }
        rep(i,50){
            if(i==idx){
                ans[i]+=50;
            }
            else ans[i]-=1;
        }
    }
    cout << 50 << endl;
    rep(i,50) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
    char *input;
    int i,n,diff01=0,diff10=0;
    input=(char *)malloc(sizeof(char)*100001);
    scanf("%s",input);
    n=strlen(input);
    for(i=0;i<n;i++){
        if(i%2==0){
            if(input[i]=='1'){
                diff01++;
            }
        }else{
            if(input[i]=='0'){
                diff01++;
            }
        }
    }
    for(i=0;i<n;i++){
        if(i%2==0){
            if(input[i]=='0'){
                diff10++;
            }
        }else{
            if(input[i]=='1'){
                diff10++;
            }
        }
    }
    if(diff01<diff10){
        printf("%d\n",diff01);
    }else{
        printf("%d\n",diff10);
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
alpha = ("abcdefghijklmnopqrstuvwxyz")
ans = [100] * 26

for i in range(n):
    S = list(input())
    tmp = [0]*26
    for j in range(len(S)):
        for k in range(26):
            if S[j] == alpha[k]:
                tmp[k] += 1
    for j in range(26):
        if ans[j] > tmp[j]:
            ans[j] = tmp[j]

ansa = ""
for i in range(26):
    for j in range(ans[i]):
        ansa = ansa + alpha[i]

print(ansa)

Measured memory_bytes: 39664
#include <stdio.h>
#include <string.h>
int main(void){
    int n,m,i,prbnum,cor=0,pen=0,wrcnt[100001]={0};
    char scr[3];
    scanf("%d %d",&n,&m);
    for(i=1;i<=m;i++){
        scanf("%d %s",&prbnum,scr);
        if(strcmp(scr,"WA")==0){
            if(wrcnt[prbnum]!=-1){
                wrcnt[prbnum]++;
            };
            //printf("problem#%d->%d\n",prbnum,wrcnt[prbnum]);
        };
        if(strcmp(scr,"AC")==0){
            if(wrcnt[prbnum]!=-1){
                cor++;
                pen+=wrcnt[prbnum];
                wrcnt[prbnum]=-1;
            };
        };
    };
    printf("%d %d",cor,pen);
    return 0;
}


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

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m;
int p[125252];
int x[125252], y[125252];

int dat[125252];
int root(int x){
  return dat[x]<0?x:(dat[x]=root(dat[x]));
}
void unite(int a,int b){
  a=root(a);
  b=root(b);
  if(a!=b){
    dat[a] += dat[b];
    dat[b] = a;
  }
}
bool same(int a,int b){
  return root(a) == root(b);
}

int main(){
  scanf("%d%d",&n,&m);
  REP(i,n)scanf("%d",p+i),p[i]--;
  REP(i,n)dat[i]=-1;
  REP(i,m){
    int x,y;
    scanf("%d%d",&x,&y);
    unite(x-1,y-1);
  }
  int ans = 0;
  REP(i,n)if(same(p[i],i))ans++;
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

#define ll long long

using namespace std;

int main() {
  string s; cin >> s;
  if(s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
s=raw_input()
l=0
r=len(s)-1

news=""
i=0
while i<len(s):
    if s[i]=="W":
        while i<len(s) and s[i]=="W":
            i+=1
        news+=s[i-1]
    else:
        while i<len(s) and s[i]=="B":
            i+=1
        news+=s[i-1]
print(len(news)-1)

Measured memory_bytes: 2820
#include<cstdio>
#include<iostream>
using namespace std;
int N,a,cnt=0;
int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;++i)
	{
		scanf("%d",&a);
		if(a%2!=0)
		{
			cnt++;
		}
	}
	if(cnt%2==0)
	{
		printf("YES");
		return 0;
	}
	printf("NO");
	return 0;
}

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

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);
    v.push_back(e);
    
    for(int i = 0; i < 5; i++){
        for(int j = i + 1; j < 5; j++){
            if(abs(v[i] - v[j]) > k){
                cout << ":(\n";
                return 0;
            }
        }
    }
    
    cout << "Yay!\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>; // グラフ型


int main()
{
    int x,y; cin >> x >> y;
    bool flg = false;
    if(y % 2 == 1) {cout << "No" << endl; return 0;}
    if(y < x*2 || x*4 < y) {cout << "No" << endl; return 0;}
    cout << "Yes" << endl;
}


Measured memory_bytes: 3652
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n+1);
	std::vector<int> b(n);
	rep(i,n+1) std::cin >> a[i];
	rep(i,n) std::cin >> b[i];
	
	int sum = 0;
	rep(i,n) {
		if(a[i]>=b[i]) {
			sum+=b[i];
			continue;
		}
		sum+=a[i];
		b[i]-=a[i];
		if(a[i+1]>=b[i]) {
			a[i+1]-=b[i];
			sum+=b[i];
			continue;
		}
		sum+=a[i+1];
		a[i+1] = 0;
	}
	print(sum);

	return 0;
}


Measured memory_bytes: 1792
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors[:-1]

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    # N = 200000
    # A = [1,0] * 100000
    B = [-1]*N
    dic = {}
    rest = N
    for i in reversed(range(1,N+1)):
        B[i-1] = A[i-1]
        rest -= 1
        div = make_divisors(i)
        for d in div:
            A[d-1] += B[i-1]
            rest -= 1
    B = [b % 2 for b in B]
    res = []
    for i, b in enumerate(B):
        if b == 1:
            res.append(str(i+1))
    print(len(res))
    print(" ".join(res))
main()

Measured memory_bytes: 73200
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int canSound = b/a;

        System.out.println(Math.min(canSound,c));
 
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
using namespace std;
#define ll  long long int
//#define d   double
 
const long double PI = acos(-1);
 
 
int main()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
 
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	double angel = (c * 30 + d * 0.5 )- d * 6;
	cout << setprecision(20) <<
		sqrt(a*a + b * b - 2 * a*b*cos(PI*angel / 180)) << endl;
	return 0;
}

Measured memory_bytes: 4164
#include<bits/stdc++.h>
using namespace std;
int main()
{
  	int n;
  cin>>n;
  float a[n],i,sum=0.0,m=1.0,x;
  for(i=0;i<n;i++)
  {
    cin>>x;
    sum+=1/x;
  }
  cout<<m/sum;
 return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

template<typename t1, class t2>
void input(t1 count,t2 array) {
	for(t1 i = 0;i < count;i++) {
		cin >> array[i];
	}
}

template<typename t1, class t2>
void output(t1 count,t2 array) {
	for(t1 i = 0;i < count;i++) {
		cout << array[i];
		if(i != count - 1) cout << " ";
	}
	cout << endl;
}

ll gcd(ll a,ll b) {
	int x = min(a,b),y = max(a,b);
	if(x == 0) return y;
	else return gcd(x,y % x);
}

set<ll> prime;

bool isPrime(ll x) {
	for(auto e:prime)
	{
		if(e >= x) return true;
		if(x % e == 0) return false;
	}
	return true;
}

int main(void) {
	bool flag;
	for(int i = 2;i <= 100000;i++) {
		flag = true;
		for(auto e:prime) {
			if(i % e == 0) {flag = false;
			break;
			}
		}
		if(flag) prime.insert(i);
	}
	int n,t,c=0;
	cin >> n;
	for(int i = 0; i < n;i++) {
		cin >> t;
		if(isPrime(t)) c++;
	}
	cout << c << endl;
}



Measured memory_bytes: 3552
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
using namespace std;
int main() {
	int x, a, b;
	cin >> x >> a >> b;

	if (abs(x-a) < abs(x-b)) {
		cout << "A" << endl;
	}
	else {
		cout << "B" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[102];
long long n;
int main()
{
	int s=0,i=0,m;
	scanf("%s",&a);
	//printf("%s",a);
	scanf("%d",&n);
	while(a[i]=='1')
		i++;
	if(i>=n)
	{
		printf("1");
	}
	else
	{
		printf("%c",a[i]);
	}
	return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100001

int swap(int a, int b) {
}
int gcd(int a, int b) {
    if(a < b) swap(a, b);
    if (b==0) return a;
    return gcd(b, a%b);
}

int n, m;
int l=-1, r=MAXN;
int dum_l, dum_r;
int main() {
    cin >> n >> m;
    for(int i=0; i<m; i++) {
        cin >> dum_l >> dum_r;
        if (dum_l>l) l = dum_l;
        if (dum_r<r) r = dum_r;
    }
    if (l > r) {
        cout << 0 << endl;
    } else {
        cout << (r-l+1) << endl;
    }
}


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

ll a[300010];
ll dp1[300010], dp2[300010];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < 3 * N; i++) {
    cin >> a[i];
  }
  ll sum1 = 0, sum2 = 0;
  priority_queue<ll> que1, que2;
  for (int i = 0; i < N; i++) {
    sum1 += a[i];
    que1.push(-a[i]);
  }
  dp1[N-1] = sum1;
  for (int i = N; i < 3 * N; i++) {
    sum1 += a[i]; 
    que1.push(-a[i]);
    sum1 -= -que1.top();
    que1.pop();
    dp1[i] = sum1;
  }
  for (int i = 3 * N - 1; i >= 2 * N; i--) {
    sum2 += a[i];
    que2.push(a[i]);
  }
  dp2[2 * N] = sum2;
  for (int i = 2 * N - 1; i >= 0; i--) {
    sum2 += a[i];
    que2.push(a[i]);
    sum2 -= que2.top();
    que2.pop();
    dp2[i] = sum2;
  }
  ll res = -(1ll << 62);
  for (int i = N - 1; i < 2 * N; i++) {
    res = max(res, dp1[i] - dp2[i+1]);
  }
  cout << res << endl;
  return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

ll n,k;
ll a[111111];
ll sum[111111];
ll psum[111111];

int main(){
	cin.sync_with_stdio(false);
	cin>>n>>k;
	rep(i,n)cin>>a[i];
	rep(i,n){
		sum[i+1]=sum[i]+a[i];
		psum[i+1]=psum[i]+max(0LL,a[i]);
	}
	ll res=0;
	rep(i,n-k+1){
		maxch(res,max(0LL,sum[i+k]-sum[i])+psum[i]+psum[n]-psum[i+k]);
		//dbg(sum[i+k]-sum[i]);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 2560
import fractions
N,X=map(int,input().split(' '))
towns=list(map(int,input().split(' ')))
dists=[ abs(X-town) for town in towns ]
if N==1:
	print(dists[0])
else:
	ans=-1
	for i in range(N-1):
		if ans==-1:
			ans=fractions.gcd(dists[i],dists[i+1])
		else:
			ans=fractions.gcd(ans,dists[i])
	print(ans)

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

using namespace std;

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

  int sum = T;
  for(int i = 1; i < N; i++) {
    if(t[i] < t[i - 1] + T) {
      sum += t[i] - t[i - 1];
    }
    else {
      sum += T;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc089a
{
    class Abc089a
    {
        static void Main(string[] args) {
            var n = int.Parse(Console.ReadLine());
            Console.WriteLine(n/3); 
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
  ll h;
  cin >> h;
  ll tmp=h;
  ll count = 0;
  while(tmp>=2){
    tmp/=2;
    count++;
  }
  cout << ll(powl(2,count)*2-1) << endl;
}

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


Measured memory_bytes: 256
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, k = map(int, readline().split())
p = list(map(int, readline().split()))

tmp = [(i+1)/2 for i in p]
cs = list(np.cumsum(tmp))

if n == k:
    print(cs[-1])
    exit()
ans = 0
for i in range(n - k):
    ans = max(ans, cs[i + k] - cs[i])
print(ans)

Measured memory_bytes: 52432
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
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; }
const int INF = 1<<30;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n,-1){}

    int root(int x){
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    bool unite(int x, int y){
        int rx = root(x), ry = root(y);
        if(rx == ry) return false;
        if(size(rx) < size(ry)) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }

    bool isSame(int x, int y){
        return root(x) == root(y);
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main(){
	int n, k, l;
	cin >> n >> k >> l;
	UnionFind R(n), T(n);
	for (int i = 0; i < k; i++) {
		int p, q;
		cin >> p >> q;
		R.unite(p-1, q-1);
	}
	for (int i = 0; i < l; i++) {
		int r, s;
		cin >> r >> s;
		T.unite(r-1, s-1);
	}
	map<pi, int> mp;
	for (int i = 0; i < n; i++) {
		int x = R.root(i), y = T.root(i);
		mp[make_pair(x, y)]++;
	}
	for (int i = 0; i < n; i++) {
		int x = R.root(i), y = T.root(i);
		cout << mp[make_pair(x, y)];
		if(i < n-1) cout << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 13568
h, w, a, b = map(int, input().split())

MOD = 10**9 + 7
MAX = h+w + 5
fact = [1 for _ in range(MAX)]
finv = [1 for _ in range(MAX)]
for i in range(2, MAX):
    fact[i] = fact[i - 1] * i % MOD
    finv[i] = pow(fact[i], MOD-2, MOD)

def comb(n: int, k: int) -> int:
    if n < k or n < 0 or k < 0:
        return 0
    return (fact[n] * finv[k] % MOD) * finv[n-k] % MOD

def path(x, y):
    return comb(x+y-2, x-1)

ans = 0
for j in range(b+1, w+1):
    # print((h-a, j), (a, w-j+1))
    ans += (path(h-a, j) * path(a, w-j+1)) % MOD
    ans %= MOD
print(ans)


Measured memory_bytes: 18928
#include<iostream>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
int main() {
	//input
	int A, B;
	cin >> A >> B;
	
	//compute
	if ((A - 2 * B) > 0)  cout << A - 2 * B;
	else cout << 0;
	//output

	return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a
fn gcd(a:usize, b:usize) -> usize {
    if b == 0 {
        return a
     } 
    gcd(b , a % b)
}
fn main() {
    input! {
        n: usize,
    }
    let mut result = 0;
    for a in 1..n+1{
        for b in 1..n+1{
            let d =  gcd(a,b);
            for c in 1..n+1{
                result += gcd (d,c);
            }
        }
    }
    println!("{}",result);

}


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

using namespace std;

int main(){
  	int n, x, actual=0, brick=0;
  	cin >> n;
  	
  	for(int i=0; i<n; i++){
    	cin >> x;
      	if(x==actual+1) actual++;
      	else brick++;
    }
  	
  	if(actual) cout << brick;
  	else cout << -1;
  
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> K;
	string S;
	cin >> S;
	S[K - 1] += (-'A' + 'a');
	cout << S << 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;
using P = pair<int,int>;

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  int ans = ((n-1) / x + 1) * t;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	int n, a, b;
	cin >> n >> a >> b;

	int ans1 = a * n;

	cout << ((ans1 > b)? b:ans1) << endl;	




	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	int black = h * W + H * w - h * w;
	int ans = H * W - black;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,A,B,C;
vector<int> l;
const int INF = 1e5;
int rec(int i, int a, int b, int c){
  if(i == n){
    if(a==0 || b==0 || c==0){
      return INF;
    }
    return abs(A-a) + abs(B-b) + abs(C-c);
  }
  int res = rec(i+1, a, b, c);

  res = min(res, rec(i+1, a+l[i], b, c) + (a ? 10 : 0));
  res = min(res, rec(i+1, a, b+l[i], c) + (b ? 10 : 0));
  res = min(res, rec(i+1, a, b, c+l[i]) + (c ? 10 : 0));
  return res;
}

int main(){
  cin >> n >> A >> B >> C;
  l.resize(n);
  for(int i=0 ; i<n ; i++){
    cin >> l[i];
  }
  cout << rec(0, 0, 0, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

# In[7]:


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


# In[9]:


for n in range(N+1):
    for m in range(M+1):
        if (N-n)*m + (M-m)*n == K:
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")


# In[ ]:






Measured memory_bytes: 9160
fun main(args: Array<String>) {
  val (N, M) = readInts()
  var l = 1
  var r = N
  repeat(M) {
    val (L, R) = readInts()
    l = Math.max(l, L)
    r = Math.min(r, R)
  }
  println((r - l + 1)?.let { if (it < 1) 0 else it })
}

fun readString() = readLine()!!
fun readStrings() = readString().split(' ')
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 57112
/*
[dp] J - Sushi
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 300;

int N;
int a[MAX_N];

double solve() {
    vector<vector<vector<double>>> dp(
        N + 1, vector<vector<double>>(N + 1, vector<double>(N + 1)));
    int cnt[4];

    for (int j = 1; j <= 3; j++) {
        cnt[j] = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] >= j) {
                cnt[j]++;
            }
        }
    }

    dp[0][0][0] = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= j; k++) {
                dp[i][j][k] = N;
                if (k > 0) {
                    dp[i][j][k] += dp[i][j][k - 1] * k;
                }
                if (j > k) {
                    dp[i][j][k] += dp[i][j - 1][k] * (j - k);
                }
                if (i > j) {
                    dp[i][j][k] += dp[i - 1][j][k] * (i - j);
                }
                dp[i][j][k] /= i;
            }
        }
    }

    return dp[cnt[1]][cnt[2]][cnt[3]];
}

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

    cout << setprecision(16) << solve() << endl;

    return 0;
}


Measured memory_bytes: 216832
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    fast_io();
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if (a != b && v <= w)
        cout << "NO\n";
    else
    {
        int ds = abs(v - w);
        if (abs(a - b) <= t * ds)
            cout << "YES\n";
        else
            cout << "NO\n";
    }

    return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ll dog, monky; cin >> dog >> monky;
    ll mod = 1000000007;
    ll ans = 1;
    if(abs(dog-monky)>=2) cout << 0 << endl;
    else{
        if(dog==monky){
            while(dog){
                ans = ans*dog%mod;
                dog--;
            }
            cout << ans*ans*2%mod << endl;
        }else{
            if(dog<monky) swap(dog,monky);
            while(dog){
                ans = ans*dog%mod;
                dog--;
            }while(monky){
                ans = ans*monky%mod;
                monky--;
            }
            cout << ans%mod << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
/*#include <atcoder/modint>
using namespace atcoder;*/
#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion

const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 100005;

//using mint = modint998244353;
//using mint = modint1000000007;
//These are for segment tree
/*int op(int a, int b){return max(a, b);}
int e(){return -1;}
bool f(int v){ return v < target;}
*/

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

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; }
ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}

/*--------------------------------------------------------------------------------------------------------------------------------*/
ll ans;
int n;
ll k;
vector<ll> degree;
vector<bool> used;

void dfs(const vector<vector<int>> &G, int p = -1, int v = 0){
	used[v] = true;
	if(p != -1){
		degree[v]++;
		degree[p]++;
		ans = ans * (k - degree[p]) % mod;
	}
	else ans *= k;
	for(auto nv : G[v]){
		if(used[nv]) continue;
		dfs(G, v, nv); 
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	degree.resize(n);
	vector<vector<int>> tree(n);
	for(int i = 0; i < n - 1; i++){
		int a, b; cin >> a >> b;
		a--; --b;
		tree[a].push_back(b);
		tree[b].push_back(a);
		degree[a]++;
		degree[b]++;
	}
	if(*max_element(all(degree)) >= k) ans = 0;
	else{
		ans = 1;
		degree.assign(n, 0);
		used.resize(n, false);
		dfs(tree);
	}
	cout << ans << endl;
} 

Measured memory_bytes: 12940
#include<iostream>
#include<vector>
#define ll long long
using namespace std;
int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N,h,i = 0;
  cin >> N;
  std::vector<ll> vec(N);
  while(cin >> h) {
    vec[i] = h;
    i++;
  }
  if (N == 1) cout << 0 << endl;
  else {
    ll ans = 0;
    ll ans_ = 0;
    for (ll j = 0; j < N-1; ++j) {
      if (vec[j] >= vec[j+1]) ans_++;
      else {
        if (ans_ > ans) ans = ans_;
        ans_ = 0;
      }
      if (ans_ > ans) ans = ans_;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 1024
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

ll gen(ll x, ll p){
  ll res = 1;
  if(p == 1)return x;
    if(p%2==1){
      return (x*gen(x,p-1)%MOD)%MOD;
    }else{
      ll k = gen(x,p/2);
      return (k%MOD*k%MOD)%MOD;
    }
  return res;
}

ll inverse(ll x, ll p){
  ll ans = 1;
  while(p){
    if(p&1){
      ans *= x;
      ans %= MOD;
    }
    x *= x;
    x %= MOD;
    p >>= 1;
  }
  return ans;
}

ll xPy(ll x,ll y){
  if(x == 0)return 1;
  ll res = 1;
  rep(i,y){
    res *= x;
    x--;
  }
  return res;
}




int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  for(int k = 1;k <= n;k++){
    ll max = n/k;
    ans += k*max*(max+1)/2;
  }
  cout << ans << endl;
}


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

int main() {

	long N; cin >> N;
	long A[200009]; for (int i = 1; i <= N; i++) cin >> A[i];
	bool inball[200009] = {}; long res = 0;

	for (int i = N; i >= 1; i--) {//iの倍数について考える。
		long link = 0;
		for (int j = 2; i * j <= N; j++) if (inball[i * j]) link++;

		if (link % 2 != A[i]) {inball[i] = true; res++;}
	}
	cout << res << endl;
	for (int i = 1; i <= N; i++) if (inball[i]) cout << i << " ";
}

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

int A, B, C;

int main() {
    cin >> A >> B >> C;

    if (A == B) cout << C << endl;
    else if (B == C) cout << A << endl;
    else if (C == A) cout << B << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <map>
#include <vector>
constexpr uint64_t tbl_1st[]{ 1u,2u,3u,4u,5u,6u,7u,8u,9u };
constexpr uint64_t min_size = 9u;
int main()
{
    int64_t k;
    std::cin  >> k;
    if (k < min_size) {
        std::cout << tbl_1st[k - 1] << std::endl;
        return 0;
    }
    std::vector<uint64_t> vals({1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u });
    int32_t cnt = min_size;
    k--;
    constexpr int32_t steps[]{ -1,0,1 };
    do {
        std::vector<uint64_t> next;
        next.reserve(100000);
        for (const auto& v : vals) {
            const auto upper = v * 10;
            const int64_t downer = v % 10;
            for (const auto s : steps) {
                if (downer + s >= 10) continue;
                if (downer + s < 0) continue;
                const auto ret = upper + downer + s;
                if (cnt == k) {
                    std::cout << ret << std::endl;
                    return 0;
                }
                cnt++;
                next.emplace_back(ret);
            }
        }
        vals=std::move(next);
    } while (true);
    
    return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int cnt = 0;
  for(int i=2;i<S.size();i++){
    if(S[i-2] == 'A' && S[i-1] == 'B' && S[i] == 'C'){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>

const int MaxN = 200000 + 5;

int N;
long long A[MaxN];

inline long long abs(long long x) { return x > 0 ? x : -x; }

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    scanf("%lld", &A[i]);
}

void solve() {
  long long s = 0, p = 0, ans = 0x7FFFFFFFFFFFFFFF;
  for (int i = 1; i <= N; ++i) s += A[i];
  for (int i = 1; i < N; ++i) {
    p += A[i];
    long long c = s - p;
    ans = std::min(ans, abs(p - c));
  }
  printf("%lld\n", ans);
}

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

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

int main() {
    string s;
    cin >> s;
    int count=0;
    
    if(s[0]!='A') goto FALSE;

    for(int i=1; i<s.length(); i++) {
        if(isupper(s[i]) && s[i] != 'C'){
            goto FALSE;
        }
    }

    for(int i=2; i<s.length()-1; i++) {
        if(s[i]=='C') count++;
    }
    if(count != 1) goto FALSE;

    cout << "AC" << endl;

    return 0;

    FALSE:
        cout << "WA" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.lang.Math

fun main(args: Array<String>) {
    val (N, W) = readInputLine().split(" ").map { it.toInt() }

    val dp = Array(2) { sortedMapOf(Pair(0, 0)) }

    for (i in 0 until N) {
        val (w, v) = readInputLine().split(" ").map { it.toInt() }

        for (k in dp[i % 2].keys) {
            dp[(i + 1) % 2][k] = Math.max(dp[i % 2][k]!!, dp[(i + 1) % 2][k] ?: 0)
            if (k + w <= W) {
                dp[(i + 1) % 2][k + w] = Math.max(dp[i % 2][k]!! + v, dp[(i + 1) % 2][k + w] ?: 0)
            }
        }
    }

    var ans = 0

    for ((k, v) in dp[N % 2]) {
        ans = Math.max(ans, v)
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


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

#define int            long long 
#define vi             vector<int>
#define mod            1000000007
#define MAX            INT_MIN
#define MIN            INT_MAX
#define ff             first
#define ss             second
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define pqb            priority_queue<int>
#define floop(x,n)       for(int i=x;i<n;i++)
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define ps(x,y)        fixed<<setprecision(y)<<x         
#define FIO            ios_base::sync_with_stdio(false); cin.tie(NULL);
                  
void c_p_c()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

}

void solution()
{
	string s;
	cin>>s;

	string t;
	cin>>t;

	int ans = 0;

	for(int i=0;i<s.length();i++)
	{
		if(s[i]!=t[i])
		{
			ans++;
		}
	}

	cout<<ans<<endl;
}

int32_t main()
{
	c_p_c();

	// int t;
	// cin>>t;

	// while(t--)
	// {
		solution();
	//}

	return 0;
}


Measured memory_bytes: 3876
/**
 * Main.cpp
 *
 *  Created on: 2018/12/02
 *      Author: EngineerChiyoko
 */
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <stack>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for(int i = x; i < (int)n; i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())

using namespace std;

typedef long long 				lint;
typedef unsigned long 			ul;
typedef vector<int> 				vi;
typedef vector<vector<int>> 		vvi;
typedef pair<int, int> 			pii;
typedef vector< pair<int, int> > 	vpii;

const int MOD = 1000000007;
const double EPS = 1e-9;

struct callBeforeMainMethod{
	callBeforeMainMethod(){
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout<<fixed<<setprecision(20);
	};
};

//int qp(int a,lint b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
//int qp(int a,lint b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

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

void precalc() {

    /*for (int i = 2; i < C; ++i) {
       if (!least_prime[i]) {
           least_prime[i] = i;
           for (li j = i * 1LL * i; j < C; j += i) {
               least_prime[j] = i;
           }
       }
   }*/

    /*fact[0] = revfact[0] = 1;
   for (int i = 1; i < 100500; ++i) {
   fact[i] = fact[i - 1] * i % curMod;
   revfact[i] = binpow(fact[i], curMod - 2, curMod);
   }*/

    /*for (int w = 0; w < 2; ++w) {
   powers[w][0] = 1;
   for (int j = 1; j < C; ++j) {
   powers[w][j] = (powers[w][j - 1] * 1LL * pr[w]) % mods[w];
   }
   }*/

    /*catalan[0] = 1;
   for (int n = 0; n < 200500 - 1; ++n) {
   catalan[n + 1] = catalan[n] * 2 * (2 * n + 1) % MOD * binpow(n + 2, MOD - 2, MOD) % MOD;
   }*/

    /*for (int i = 0; i < 5010; ++i) {
   c[i][i] = c[i][0] = 1;
   for (int j = 1; j < i; ++j) {
   c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
   }
   }*/

    /*for (int i = 0; i < 100; ++i) {
   doubleC[i][i] = doubleC[i][0] = 1.0;
   for (int j = 1; j < i; ++j) {
   doubleC[i][j] = doubleC[i - 1][j - 1] + doubleC[i - 1][j];
   }
   }*/
}

int main (){
//	int dx[4]={1,0,-1,0};
//	int dy[4]={0,1,0,-1};
	vi vc;
	string S;
	cin >> S;

	stack<char> st;
	int res = 0;
	REP(i, 0, S.size()){
		if(st.empty() || st.top() == S[i]){
			st.push(S[i]);
		}else{
			res += 2;
			st.pop();
		}
	}


	/* ここから出力処理 */
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 512
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int a;
	cin >> a;
	if (n % 500 <= a) puts("Yes");
	else puts("No");
	return 0;
}


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

int main(void)
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 1e18;
    rep(i, 1<<n)
    {
        if(__builtin_popcount(i) < k) continue;
        int preHight = 0;
        ll tmpAns = 0;
        rep(j, n)
        {
            if(i>>j&1){
                if(preHight >= a[j]){
                    tmpAns += preHight + 1 - a[j];
                    preHight++;
                }
                else
                {
                    preHight = a[j];
                }
            }
            preHight = max(preHight, a[j]);
        }
        ans = min(ans, tmpAns);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256