akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define _GLIBCXX_DEBUG

using _loop_ll = long long;
#define REP(i,n) for(_loop_ll (i)=0; (i)<(_loop_ll)(n); (i)++)
#define FOR(i,a,b) for(_loop_ll (i)=(_loop_ll)(a); (i)<(_loop_ll)(b); (i)++)
#define FORR(i,a,b) for(_loop_ll (i)=(_loop_ll)(b)-1; (i)>=(_loop_ll)(a); (i)--)
 
#define ALL(v) (v).begin(),(v).end()
 
#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;

constexpr long long int MOD = 1e9 + 7;

int saijoi(ll a){
    while(true){
        if(a / 10 == 0) break;
        a /= 10;
    }
    return a;
}

int saikai(ll a){
    return a % 10;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n;
    cin >> n;
    
    if(n <= 9){
        cout << n << endl;
        return 0;
    }

    ll ans = 0;

    ll cnt[10][10];
    FOR(i, 0, 10){
        FOR(j, 0, 10){
            cnt[i][j] = 0;
        }
    }

    FOR(a, 1, n + 1){
        cnt[saijoi(ll(a))][saikai(ll(a))]++;
    }

    FOR(a, 1, n + 1){
        if(saikai(ll(a)) == 0) continue;
        ans += cnt[saikai(ll(a))][saijoi(ll(a))];
    }


    cout << ans << endl;

    return 0;
};


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        if (n % 2 == 0) {
            System.out.println(0.5);
        } else {
            System.out.println((n - (n / 2)) / (n * 1.0));
        }
    }
}

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

int main(void)
{
    string s;
    cin >> s;
    int n;
    n = s.size();
    bool fin = true;
    if (n % 2 == 0)
    {
        for (int i = 0; i < n; i += 2)
        {
            if (s.at(i) != 'h' || s.at(i + 1) != 'i')
            {
                fin = false;
                break;
            }
        }
    }
    else
    {
        fin = false;
    }
    if (fin)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


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

using namespace std;

#define Char2Int(C) ((C) - '0')

int main (void) {
    long long A;
    string B_;
    cin >> A >> B_;

    int Bx100 = 100 * Char2Int(B_.at(0)) + 10 * Char2Int(B_.at(2)) + Char2Int(B_.at(3));
    long long ansx100 = A * Bx100;

    cout << ansx100 / 100 << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end

int main() {
    unsigned int A,B,C;
    int ans=0,K;

    cin >> A >> B >> C >> K;

    int Max = max({A,B,C});

    rep(i,K){
        Max *=2;
    }
    cout << A+B+C+Max-max({A,B,C}) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
ll N;
vector<ll>key;
void dfs(ll x,ll a,ll b,ll c) {
	if (x > N)return;
	if (a >= 1 && b >= 1 && c >= 1)key.push_back(x);
	dfs(x * 10 + 3,a+1,b,c);
	dfs(x * 10 + 5,a,b+1,c);
	dfs(x * 10 + 7,a,b,c+1);
}
int main() {
	cin >> N;
	int ans = 0;
	dfs(0,0,0,0);
	cout << key.size() << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int y,m,d;
    scanf("%d%*c%d%*c%d",&y,&m,&d);
    if(y < 2019 ||
        y == 2019 && m <= 4){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (int)(s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
constexpr long long INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}



signed main(){
	int H,W,A,B;
	cin>>H>>W>>A>>B;
	REP(i,H){
		REP(j,W){
			cout<<((i<B)^(j<A));
		}
		cout<<endl;
	}
}


Measured memory_bytes: 1280
#include <iostream>//bit DP
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>PP;
ll h[100005]={0};
int main(){
  int n;
  int ans=0;
  cin>>n;
  for(int i=1;i<=100;i++){
    for(int j=1;j<=100;j++){
      for(int k=1;k<=100;k++){
        h[i*i+j*j+k*k+i*j+j*k+k*i]++;
      }
    }
  }
  for(int i=1;i<=n;i++){
    cout<<h[i]<<endl;
  }
}


Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
    while (1) {
        int x, h;
        cin >> x >> h;
        if (!x) return 0;
        double l = sqrt(h * h + x * x * 0.25);
        printf("%.9lf\n", x * (x + l * 2));
    }
}



Measured memory_bytes: 3048
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(s: str):
    ans = []
    for c in s:
        if c == "B":
            if len(ans) > 0:
                ans.pop()
        else:
            ans.append(c)
    if len(ans) == 0:
        print("error")
    else:
        print("".join(ans))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
struct cmp
{
	bool operator ()(const long long int &a,const long long int &b)
	{
		return a>b;
	}
};
priority_queue <long long int>back;
priority_queue <long long int,vector <long long int>,cmp>fro;
long long int mid[100000];
long long int sum1=0,sum2=0;
long long int flag[100000];
int main(int argc, char const *argv[])
{
	int n,i,j,k,l;
	long long temp,ans,f;
	memset(flag,0,sizeof(flag));
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&temp);
		sum1+=temp;
		fro.push(temp);
	}
	for(i=0;i<n;i++)
	{
		scanf("%lld",&mid[i]);
	}
	for(i=0;i<n;i++)
	{
		scanf("%lld",&temp);
		sum2+=temp;
		back.push(temp);
	}
	ans=sum1-sum2;
	for(i=0;i<n;i++)
	{
		temp=fro.top();
		if(mid[i]>temp)	
		{
			sum1=sum1-temp+mid[i];
			if(sum1-sum2>ans)	ans=sum1-sum2;
			flag[i]=temp;		
			temp=mid[i];	
			fro.pop();
			fro.push(temp);

		}
	}
	for(i=n-1;i>=0;i--)
	{
		if(flag[i]!=0)
		{
			sum1=sum1-mid[i]+flag[i];
		}
		temp=back.top();
		if(mid[i]<temp)
		{
			sum2=sum2-temp+mid[i];
			if(sum1-sum2>ans)	ans=sum1-sum2;
			temp=mid[i];
			back.pop();
			back.push(temp);
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4084
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int mod_pow(Int x, Int a, Int m = MOD){
    if(a == 0)return 1;
    Int res = mod_pow(x, a / 2, m);
    res = res * res % m;
    if(a % 2)res *= x;
    return res % m;
}

Int inv(Int x, Int m = MOD){
    return mod_pow(x, m-2, m);
}
Int n, d;
Int cnt[110000];


int main(){
    cin >> n;
    Int maxd = 0;
    for(int i = 0;i < n;i++){
        cin >> d;
        if(i == 0){
            if(d != 0){cout << 0 << endl;
                return 0;}
        }else{
            if(d == 0){cout << 0 << endl;
                return 0;}
        }
        cnt[d]++;
        maxd = max(maxd, d);
    }
    Int ans = 1;
    for(int i = 1;i <= maxd;i++){
        ans = ans * mod_pow(cnt[i-1], cnt[i]) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
// Author: Sayantanu
#include <bits/stdc++.h>

using namespace std;

#define ll long long int
const int mod = 1e9 + 7;


int main() {
    //code
    int n,k;
    cin>>n>>k;
    vector<int> arr(n);
    for(int i = 0;i<n;i++){
        cin>>arr[i];
    }
    vector<int> dp(n);
    dp[0] = 0;
    for(int i = 1;i<n;i++){
        dp[i] = INT_MAX;
        for(int s = 1;s<=k;s++){
            dp[i] = min(dp[i],abs(arr[i] - arr[max(0,i-s)]) + dp[max(0,i-s)]);
        }

        //dp[i] = min(abs(arr[i] - arr[i-1]) + dp[i-1],abs(arr[i] - arr[max(0,i-2)]) + dp[max(0,i-2)]);
    }

    cout<<dp[n-1]<<endl;
    return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string s; cin >> s;
    if(s.back() == 's') cout << s << "es" << endl;
    else cout << s << "s" << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7776
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int main() {
    int A, B, M;
    cin >> A;
    cin >> B;
    cin >> M;
    vector<int> priceA(A);
    vector<int> priceB(B);
    vector<tuple <int,int,int>> coupon;
    for(int i = 0; i < A; i++) {
        cin >> priceA[i];
    }
    for(int i = 0; i < B; i++) {
        cin >> priceB[i];
    }
    int a,b,c;
    for(int i = 0; i < M; i++) {
        cin >> a >> b >> c;
        coupon.emplace_back(a,b,c);
        // for(int j = 0; j < 3; j++){
        //     if(j == 0){
        //         cin >> a;
        //     } else if(j == 1){
        //         cin >> b;
        //     } else {
        //         cin >> c;
        //     }
        // }
        // if(coupon[a-1][b-1] < c){
        //     coupon[a-1][b-1] = c;
        // }
    }
    int min = 1000000000;
    int minA = *std::min_element(priceA.begin(), priceA.end());
    int minB = *std::min_element(priceB.begin(), priceB.end());
    int i, j;
    for(auto x: coupon) {
        // cout << get<0>(x) << " " << get<1>(x) << " " << get<2>(x) << endl;
        i = get<0>(x);
        j = get<1>(x);
        min = std::min(min, priceA[i-1] + priceB[j-1] - get<2>(x));
    }
    // for(int i = 0; i < A; i++){
    //     for(int j = 0; j < B; j++){
    //         // cout << "coupon: " << coupon[i][j] << endl;
    //         if(coupon[i][j] != 0){
    //             min = std::min(min, priceA[i] + priceB[j]-coupon[i][j]);
    //         }
    //     }
    // }
    min = std::min(min, minA+minB);
    cout << min << endl;
    return 0;
}

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

int main() {
  string s; cin>>s;
  int sums=0;
  for(int i=0;i<=3;i++){
    if(s[i]=='+')sums++;
    else sums--;}
  cout<<sums<<endl;

}

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

int main() {
 int a;
 int b;
 int c;
 cin >> a;
 cin >> b;
 cin >> c;
 
if(b-a == c-b){
	cout << "YES" << endl;
}
else {
	cout << "NO" << endl;
}
 	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define psb push_back
#define ppb pop_back

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

int main() {
    int a[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
    int K;
    cin >> K;

    cout << a[K-1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A,p500;
  cin >> N;
  cin >> A;
 
  if (N < 500) {
    if (N <= A){
    cout << "Yes" << endl;
    }
    else{
      cout<< "No" << endl;
  }
  }
  else{
  p500 = N/500;
    if(N - p500*500 <= A){
      cout << "Yes" << endl;
    }
      else{
    cout<< "No" <<endl;
      }  
      }
}


Measured memory_bytes: 256
N, K = [int(x) for x in input().split()]
S = str(input())

Unhappy = {}
Unhappy[1] = 0
Unhappy[2] = 0

for i in range(N):
    if i == 0:
        if S[i] == 'L':
            Unhappy[1] += 1
    if i == N - 1:
        if S[i] == 'R':
            Unhappy[1] += 1
    else:
        if S[i] == 'R' and S[i + 1] == 'L':
            Unhappy[2] += 1

if Unhappy[1] == 0:
    act = min(K, Unhappy[2] - 1)
    K -= act
    Unhappy[2] -= act
    if K != 0:
        K -= 1
        Unhappy[2] -= 1
        Unhappy[1] += 1
else:
    act = min(K, Unhappy[2])
    K -= act
    Unhappy[2] -= act
    if Unhappy[1] == 2 and K != 0:
        K -= 1
        Unhappy[1] -= 1

print(N - Unhappy[1] - Unhappy[2] * 2)

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

S = input().strip()
#-----

digit_2 = len(S)-1
total=0
for i in range( 2**(digit_2) ):
    bin_str = format(i, 'b').zfill(digit_2)
    bin_str = bin_str[:] + "0"

    calc_str=""
    for j in range(len(S)):
        if bin_str[j] == "1":
            calc_str += S[j] + "+"
        else:
            calc_str += S[j]
    
    calc = sum(map(int, calc_str.split("+")))
    total += calc
    
print(total)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;}
ll lcm(ll x, ll y) {return x/gcd(x,y)*y;}


int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    vector<ll> gl(n);
    gl[0]=a[0];
    rep(i,n-1){
        gl[i+1]=gcd(gl[i],a[i+1]);
    }
    vector<ll> gr(n);
    gr[n-1]=a[n-1];
    for(int i=n-1;i>=1;i--){
        gr[i-1]=gcd(gr[i],a[i-1]);
    }
    ll ans=gr[1];
    for(int i=1;i<n-1;i++){
        ans=max(ans,gcd(gl[i-1],gr[i+1]));
        //cout<<ans<<endl;
    }
    ans=max(ans,gl[n-2]);

    cout<<ans<<endl;
}

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

#define INF 214748360

int main(){
  int n;
  while(cin>>n, n){
    vector<pair<int,int>> vec[20];
    vector<vector<int>> d(n, vector<int>(n, INF));
    bool isleaf[20];
    rep(i,n-1){
      int a,b,c;
      cin>>a>>b>>c;
      a--;b--;
      vec[a].pb(mp(b,c));
      vec[b].pb(mp(a,c));
      d[a][b] = d[b][a] = c;
    }
    rep(i,n) isleaf[i] = vec[i].size()==1;

    function<int(int,int)> dfs = [&](int from, int i){
      int acc=0;
      for(auto to : vec[i]) if(to.fi!=from && !isleaf[to.fi]){
        acc += dfs(i, to.fi) + to.se*2;
      }
      return acc;
    };

    rep(i,n) d[i][i]=0;
    rep(k,n)rep(i,n)rep(j,n) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
    int mx = 0;
    rep(i,n) if(!isleaf[i]) mx = max(mx, d[0][i]);
//dbg(mx);
    cout << dfs(-1,0) - mx << endl;
  }
  return 0;
}

Measured memory_bytes: 3008
function main(input) {
    const nums = input.split(' ');
    const n = parseInt(nums[0]);
    const r = parseInt(nums[1]);
    if (n >= 10) {
        console.log(parseInt(r));
    }else {
        console.log(parseInt(r + 100 * (10 - n)));
    }
}

// 変更しない
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7496
def main():
    n, k = map(int, input().split())
    seq = {}
    for _ in range(n):
        a, b = map(int, input().split())
        if a in seq:
            seq[a] += b
        else:
            seq[a] = b
    seq = sorted(seq.items(), key=lambda x: x[0])
    answer = 0
    for n, c in seq:
        k -= min(c, k)
        if k <= 0:
            answer = n
            break
    print(answer)


if __name__ == '__main__':
    main()



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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll X;
int main(){
	cin >> X;
	if(X >= 2000){
		p(1);
	}
	else if((X % 100 <= (X / 100) * 5)){
		p(1);
	}else{
		p(0);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int MAX=2e5;
const ll MOD=1e9+7;
const int INF=1<<30;

bool prime(int num) {
  if (num<2) return false;
  else if (num==2) return true;
  else if (num%2==0) return false;
  double sqrtNum=sqrt(num);
  for (int i=3;i<=sqrtNum;i+=2){
    if (num%i==0)
      return false;
  }
  return true;
}

int main(){
  int X; cin >> X;
  while(!prime(X)){
    X++;
  }
  cout << X << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <cassert>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int,int>> vii;

class atB {
private:
    int solve(int i, vector<int> &dp, const vector<vector<int>> &g) {
        if (dp[i] != -1) {
            return dp[i];
        }
        
        if ((int)g[i].size() == 0) {
            return 0;
        }
        
        int ans = 0;
        vector<int> sz;
        for (int j = 0; j < (int)g[i].size(); ++j) {
            sz.push_back(solve(g[i][j], dp, g));
        }
        sort(sz.begin(), sz.end(), greater<int>());
        for (int j = 0; j < (int)sz.size(); ++j) {
            ans = max(ans, j+1 + sz[j]);
        }
        
        return (dp[i] = ans);
    }

public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        
        vector<int> a(N+1);
        for (int i = 2; i <= N; ++i) {
            in >> a[i];
        }
        vector<vector<int>> g(N+1);
        for (int i = 2; i <= N; ++i) {
            g[a[i]].push_back(i);
            //g[a[i]].push_back(a[i]);
        }
        vector<int> dp(N+1, -1);
        int ans = solve(1, dp, g);
        
        out << ans << endl;
        
    }
};


int main() {
	std::ios::sync_with_stdio(false);

	atB solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

    //long long
    using ll = long long;

    // pair<int, int>
    using PII = pair<int, int>;

    //最大値、mod
    const int MOD = 1000000007;
    const int INF = 1000000000;
    const long long LINF = 1e18;

    //出力系
    #define print(x) cout << x << endl
    #define prints(x) cout << fixed << setprecision(10) << x << endl
    #define printc(x) cout << setw(2) << setfill('0') << x << endl;
    #define yes cout << "Yes" << endl
    #define YES cout << "YES" << endl
    #define no cout << "No" << endl
    #define NO cout << "NO" << endl
    
    // begin() end()
    #define all(x) (x).begin(),(x).end()

    //for
    #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

    //最大公約数 
    unsigned gcd(unsigned a, unsigned b) {
      if(a < b) return gcd(b, a);
      unsigned r;
      while ((r=a%b)) {
        a = b;
        b = r;
      }
      return b;
    }

    // 最小公倍数
    unsigned lcm(unsigned a, unsigned b){
        return a / gcd(a, b) * b; 
    }

    // a = max(a, b), a = min(a, b)
    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; }

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









int main(){
    string S;
    cin >> S;
    if(S == "AAA" || S == "BBB") no;
    else yes;

}

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

int main() {
  int n, k;
  cin >> n;
  cin >> k;
  int v = 1;
  for (int i = 0; i < n; i++) {
    if (v <= k) {
      v *= 2;
    } else {
      v += k;
    }
  }
  cout << v << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,m;
  cin >> n >> m;
  vi s(n+2,0);
  rep(i,m){
    int l,r;
    cin >> l >> r;
    s[l]++;
    s[r+1]--;
  }
  rep(i,n){
    s[i+1]+=s[i];
  }
  int cnt = 0;
  rep(i,n+1){
    if(s[i] == m)cnt++;
  }
  print(cnt);
  return 0;
}

Measured memory_bytes: 3748
import java.io.*;
import java.util.*;

public class Main {
	static int mod = (int)1e9+7;
	static Comparator<Integer> lower_bound = (x, y) -> x.compareTo(y) >= 0 ? 1 : -1;
	static Comparator<Integer> upper_bound = (x, y) -> x.compareTo(y) > 0 ? 1 : -1;

	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		out.println(Math.max(a*b, Math.max(a-b,  a+b)));
 	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}

	public static long factorial(int n) {
		long a;

		if(n > 0) {
			a = n * factorial(n - 1);
		}else{
			a = 1;
		}
		return a;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(K key, V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class UnionFind {
	int[] par;

	public UnionFind(int n) {
		par = new int[n];

		Arrays.fill(par, -1);
	}

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

	boolean unite(int x,int y) {
		x = root(x);
		y = root(y);

		if(x == y) return false;

		if(size(x) < size(y)) {
			int tmp = x;
			x = y;
			y = tmp;
		}

		par[x] += par[y];
		par[y] = x;

		return true;
	}

	boolean same(int x,int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}

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

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

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

using namespace std;

int main()
{
	int n;
	int a[100];
	int al = 0;
	int bo = 0;

	cin >> n;
	for(int i = 0;i < n;i++)
	{
		cin >> a[i];
	}
	sort(a, a+n, greater<int>());

	for(int i = 0; i < n; i++)
	{
		if((i%2) == 0)
		{
			al += a[i];
		}
		else if ((i%2) == 1)
		{
			bo += a[i];
		}
	}
	printf("%d\n", (al-bo));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;

int main(){
        int A,B,C,D;
        cin >> A >> B >> C >> D;
        cout << min(A,B)+min(C,D) << endl;

        return 0;

}


Measured memory_bytes: 256
li = list(map(int,input().split()))
N = li[0]
A = li[1]
B = li[2]
count = 0
for i in range(1,N + 1):
  iti = i % 10
  zyuu = (i - iti) / 10 % 10
  hyaku = ((i - iti) / 10 - zyuu) / 10 % 10
  sen = (((i - iti) / 10 - zyuu) / 10  - hyaku) / 10 % 10
  man = ((((i - iti) / 10 - zyuu) / 10 - hyaku) / 10 - sen) / 10 % 10
  total = iti + zyuu + hyaku + sen + man
  
  if A <= total and B >= total:
    count += i

print(count)

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

int main() {
    string s;
    cin >> s;
    if (s == "ABC")
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define all(a) begin(a),end(a)
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define sz(x) ((int)x.size())
#define ins insert
#define rep(i,l,u) for(int i=l;i<=u;++i)
#define reb(i,l,u) for(int i=l;i>=u;--i)
using namespace std;
const int maxn=2e5+10;
const int mod=1e9+7;
const int inf=1e18;
int a[maxn];
int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    sort(a+1,a+n+1);
    map<int,int>vis;
    map<int,int>num;
    int ans=0;
    for(int i=1;i<=n;++i){
        num[a[i]]++;
    }
    for(int i=1;i<=n;++i){
        if(!vis[a[i]]){
            if(num[a[i]]==1)
                ans++;
            for(int j=1;a[i]*j<=1000000;++j){
                vis[a[i]*j]=1;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 79904
# Square869120Contest #4 B - Buildings are Colorful!　
# 全探探索　ver
 
import sys
 
N, K = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))
 
ans = float('inf')
for i in range(2 ** (N - 1)):
    bit = [(i >> j) & 1 for j in range(N - 1)]  # 左から2番目以降で見えるようにするビルを選択
 
    can_see = 0
    cost = 0
    height = a[0]
    for j, b in enumerate(bit):
        if (b == 1) & (height >= a[j+1]):
            cost += height - a[j + 1] + 1
            height = height + 1
            can_see += 1
        elif (b == 1):
            height = a[j + 1]
            can_see += 1
        elif height < a[j + 1]:
            can_see += 1
        height = max(height, a[j + 1])
 
    if can_see >= K-1:
        ans = min(ans, cost)
 
print(ans)
 

Measured memory_bytes: 3064
n, x, y = map(int, input().split())
ans = [0]*n
x -= 1
y -= 1
for i in range(n-1):
    for j in range(i+1, n):
        # print("DFGH")
        ans[min(j-i, abs(x-i)+abs(y-j)+1)] += 1

for i in range(1, n):
    print(ans[i])

    

Measured memory_bytes: 74320
alfabeto = "abcdefghijklmnopqrstuvwxyz"

n = int(input())
resposta = ""

for i in range(1, 99):
    if n <= 26 ** i:
        n -= 1

        for j in range(i):
            resposta += chr(ord("a") + n % 26)
            n //= 26

        break

    else:
        n -= 26 ** i

resposta = resposta[::-1]

print(resposta)


Measured memory_bytes: 9176
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
// 32 mil = ~1 sec 
long long mod = 1e9+7;
const int biggg = 1000000001;
const long long bigggest = 1000000000000000000LL;
const double eps = .0000000001;

int main(){
    prep();
    int n;
    cin >> n;
    int startind[n+1];
    memset(startind, -1, sizeof(int)*(n+1));
    int a[n];
    for (int i=0; i<n; i++) cin >> a[i];
    int b[n];
    for (int i=0; i<n; i++) cin >> b[i];
    int maxpush = 0;
    for (int i=0; i<n; i++){
    	startind[a[i]] = i;
	}

	for (int i=0; i<n; i++){
		if (i > 0 && b[i] == b[i-1]) continue;
		if (startind[b[i]] == -1) continue;
		if (startind[b[i]] >= i){
			maxpush = max(maxpush, (startind[b[i]]-i+1)%n);
		}
	}
	//cout << maxpush << '\n';
	int newarr[n];
	for (int i=maxpush; i<n; i++){
		newarr[i] = b[i-maxpush];
	}
	for (int i=0; i<maxpush; i++){
		newarr[i] = b[i+n-maxpush];
	}
	string printt = "";
	for (int i=0; i<n; i++){
		if (newarr[i] == a[i]){
			cout << "No";
			return 0;
		}
		printt += to_string(newarr[i]);
		printt += " ";
	}
	cout << "Yes\n" << printt;
	/*6
	1 2 2 3 4 4
	1 2 2 2 3 3*/
	
	//3 3 1 2 2 2
    return 0;
}


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

template<typename T> class Dijkstra {
public:
  struct edge {
    int to; T cost;
  };
  int V;
  vector<vector<edge>> G;
  vector<T> dist;
  using pti = pair<T,int>;
  Dijkstra(int n) : V(n), G(V), dist(V, numeric_limits<T>::max()) {}
  void add(int u, int v, T cost) {
    G.at(u).push_back((edge) {v, cost});
    G.at(v).push_back((edge) {u, cost});
  }
  void solve(int s) {
    priority_queue<pti, vector<pti>, greater<pti>> Q;
    dist.at(s) = 0;
    Q.push(pti(0, s));
    while (!Q.empty()) {
      pti p = Q.top();
      Q.pop();
      int v = p.second;
      if (dist.at(v) < p.first) continue;
      for (auto &w : G.at(v)) {
        if (dist.at(w.to) > dist.at(v) + w.cost) {
          dist.at(w.to) = dist.at(v) + w.cost;
          Q.push(pti(dist.at(w.to), w.to));
        }
      }
    }
  }
};

int main() {
  int N, M, S, G;
  cin >> N >> M >> S >> G;
  Dijkstra<long> D(N), D2(N);
  for (int i = 0; i < M; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    D.add(--a, --b, c);
    D2.add(a, b, d);
  }
  D.solve(--S);
  D2.solve(--G);
  vector<long> sum(N);
  for (int i = 0; i < N; i++) {
    sum.at(i) = D.dist.at(i) + D2.dist.at(i);
  }
  for (long i = N - 1, mi = LONG_MAX; i >= 0; i--) {
    sum.at(i) = (mi = min(mi, sum.at(i)));
  }
  for (int i = 0; i < N; i++) {
    cout << (long) 1e15 - sum.at(i) << "\n";
  }
}

Measured memory_bytes: 19012
use std::collections::BTreeMap;
const MOD: usize = 1_000_000_007;
fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let mut dp = BTreeMap::new();

    println!("{}", rec(n, n, &mut dp));
}

fn rec(sum: usize, xor: usize, dp: &mut BTreeMap<(usize, usize), usize>) -> usize {
    if sum == 0 {
        return 1;
    }

    if dp.contains_key(&(sum, xor)) {
        return dp[&(sum, xor)];
    }

    let even_even = rec(sum >> 1, xor >> 1, dp);
    let odd_even = rec((sum - 1) >> 1, (xor - 1) >> 1, dp);
    let odd_odd = if sum >= 2 {
        rec((sum - 2) >> 1, xor >> 1, dp)
    } else {
        0
    };

    let result = (even_even + odd_even + odd_odd) % MOD;
    dp.insert((sum, xor), result);
    return result;
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


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

int main(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  // split
  vector<int> blocks;
  char ref = '0';
  int cnt = 0;
  for ( int i=0; i<N; i++ ) {
	if ( S[i] == ref ) {
	  cnt++;
	} else {
	  blocks.push_back(cnt);
	  ref = S[i];
	  cnt = 1;
	}
  }
  blocks.push_back(cnt);
  // for ( int i=0; i<blocks.size(); i++ ) cout << "#" << blocks[i] << endl;
  
  int N_blocks = blocks.size();
  int tmp = 0;
  vector<int> blocks_acm(1, 0);
  for (int i=0; i<N_blocks; i++) {
	tmp += blocks[i];
	blocks_acm.push_back(tmp);
  }
  // for ( int i=0; i<blocks_acm.size(); i++ ) cout << "##" << blocks_acm[i] << endl;

  int ans = 0;
  int i_center = 1 - (K % 2);
  while ( i_center < N_blocks ) {
	int l = (i_center - K < 0) ? 0 : i_center - K;
	int r = (i_center + K >= N_blocks) ? N_blocks - 1 : i_center + K;
	// cout << "###" << blocks_acm[l]  << blocks_acm[r] << endl;
	int ans_tmp = blocks_acm[r + 1] - blocks_acm[l];
	if ( ans < ans_tmp ) ans = ans_tmp;
	i_center += 2;
  }

  if ( ( N_blocks == 1 ) || ( K > 0 ) ) {
	if ( ans < blocks[0] ) ans = blocks[0];
  }
  
  cout << ans << endl;
  
  return 0;
}


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

int main(){
   int a,b[15],c;
  cin >> a;
  for(int i=0;i<a;i++)
    cin >>b[i];
  
  sort(b,b+a,greater<int>());
  c =0;
  for(int i=1;i<a;i++){
    c += b[i];
  }
  
  if(b[0]< c){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;

int n;
int l[10];

int main(){
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> l[i];
	if( *max_element(l, l + n) < accumulate(l, l + n, 0) - *max_element(l, l + n) ){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

def GCD(a,b):
    c = a%b
    if c == 0:
        return b
    else:
        return GCD(b,c)


def modsum(m):
    s = 0
    for a in A:
        s += m % a
    return s


tmp = 1
for i in range(N):
    tmp = tmp * A[i] // GCD(tmp,A[i])
    
ans = modsum(tmp-1)
print(ans)

Measured memory_bytes: 50928
#include <iostream>

int main(void){
  int a; 
  int b[3];
  int count=0;

  std::cin >> a;

  b[0] = a%10;
  b[1] = (a%100-b[0])/10;
  b[2] = (a%1000-b[0]-b[1])/100;

  for(int i=0; i<3; i++){
    if(b[i] == 1){
      count++;
    }
  }
  
  std::cout << count << std::endl;
}

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

using namespace std;

bool solve(vector<int> &vec, int index, int num);

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

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

    int q;
    cin >> q;

    vector<int> m(q);
    for (int i = 0; i < q; ++i)
        cin >> m[i];

    for (int i = 0; i < q; ++i) {
        if (solve(a, 0, m[i]))
            cout << "yes\n";
        else
            cout << "no\n";
    }
}

bool solve(vector<int> &vec, int index, int num)
{
    if (num == 0)
        return true;

    if (index >= vec.size())
        return false;

    bool result = solve(vec, index + 1, num) || solve(vec, index + 1, num - vec[index]);
    return result;
}



Measured memory_bytes: 3072
/*author: hyperion_1724
  date: 
*/

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    map<string,string> A;
    A["Sunny"]="Cloudy";
    A["Cloudy"]="Rainy";
    A["Rainy"]="Sunny";
    string S;
    READ(S);
    cout<<A[S]<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;


int main(){
    long long x,ans;
    cin>>x;
    ans=min((2*x+10)/11,(2*x+9)/11);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

vector<int> g[100100];
int dp[100100];
int h[100100];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	for(int i=0;i<m;i++){
		int x,y; cin >> x >> y;
		x--; y--; 
		g[x].push_back(y);
		h[y]++;
	}
	queue<int> q;
	vector<int> ans;
	for(int i=0;i<n;i++){
		if(h[i]==0){
			q.push(i);
			ans.push_back(i);
		}
	}
	while(q.size()){
		int p=q.front(); q.pop();
		for(int pp:g[p]){
			h[pp]--;
			if(h[pp]==0){
				q.push(pp);
				ans.push_back(pp);
			}
		}
	}
	for(int p:ans){
		for(int pp:g[p]){
			dp[pp]=max(dp[pp],dp[p]+1);
		}
	}
	int ma=0;
	for(int i=0;i<n;i++){
		ma=max(ma,dp[i]);
	}
	cout << ma << endl;
}

Measured memory_bytes: 7032
#include<stdio.h>
int main()
{
	int x,r;
	scanf("%d",&x);
	r=x%7;
	switch(r){
	case 1:
		printf("fri\n");
		break;
	case 2:
		printf("sat\n");
		break;
	case 3:
		printf("sun\n");
		break;
	case 4:
		printf("mon\n");
		break;
	case 5:
		printf("tue\n");
		break;
	case 6:
		printf("wed\n");
		break;
	default:
		printf("thu\n");
	}
    return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> c(N);
  for (int i = 0; i < N; i++)
  {
    cin >> c.at(i);
  }
  deque<int> dq;
  dq.push_back(c.at(0));
  for (int i = 1; i < N; i++)
  {
    int p = lower_bound(dq.begin(), dq.end(), c.at(i)) - dq.begin();
    if (p)
    {
      p--;
      dq.at(p) = c.at(i);
    }
    else
    {
      dq.push_front(c.at(i));
    }
  }
  cout << dq.size() << endl;
}

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

int solve1(const string &n, int index) {
  if (index + 1 > n.size()) return 0;
  if (n.at(index) == '0') return solve1(n, index + 1);
  int d = n.size() - index;
  return n.at(index) - '0' + 9 * (d - 1);
}

int solve2(const string &n, int index) {
  if (index + 2 > n.size()) return 0;
  if (n.at(index) == '0') return solve2(n, index + 1);
  int d = n.size() - index;
  return (n.at(index) - '0' - 1) * 9 * (d - 1) + 81 * (d - 1) * (d - 2) / 2 + solve1(n, index + 1);
}

int solve3(const string &n) {
  if (n.size() < 3) return 0;
  int d = n.size();
  return (n.at(0) - '0' - 1) * 81 * (d - 1) * (d - 2) / 2 + 729 * (d - 1) * (d - 2) * (d - 3) / 6 + solve2(n, 1);
}

int main() {
  string n;
  int k;
  cin >> n >> k;
  if (k == 1) {
    cout << solve1(n, 0) << endl;
  } else if (k == 2) {
    cout << solve2(n, 0) << endl;
  } else {
    cout << solve3(n) << endl;
  }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N=Integer.parseInt(br.readLine());
        int[][] c=new int[10][10];
        int sum=0; int mid=0;
        for(int p=1;p<10;p++){
            for(int s=1;s<10;s++){
                for(int i=0;i<=N;i++){
                    String str=i+"";
                    if(str.substring(0,1).equals(p+"") 
                            && str.substring(str.length()-1,str.length()).equals(s+"")){
                        c[p][s]++;
                    }
                }
                
            }
        }
        for(int p=1;p<10;p++){
            for (int i = 1; i < 10; i++) {
                sum+=c[p][i]*c[i][p];
            }
        }
        System.out.println(sum);
    }
    
}

Measured memory_bytes: 347556