akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  ll n; cin >> n;
  int num = 0;
  vector<char> v;
  while(0 < n){
    num = n%26;
    n = (n-1)/26;
    if(num) v.push_back(char('a'+num-1));
    else v.push_back(char('z'));
  }
  reverse(all(v));
  rep(i,v.size()) cout << v[i];
  return 0;
}


Measured memory_bytes: 3616
N, M = map(int, input().split())
a, b, c = [], [], []
for _ in range(M):
    a_, b_ = map(int, input().split())
    c_ = list( map(int, input().split()) )
    a.append(a_)
    b.append(b_)
    c.append(c_)

INF = 10**9
bit_dp = [INF for _ in range(2**N)]
bit_dp[0] = 0
for i in range(M):
    bit_n = 0
    for j in c[i]:
        bit_n |=  1 << j - 1
    for j in range(2**N):
        if bit_dp[j|bit_n] > bit_dp[j] + a[i]:
            bit_dp[j|bit_n] = bit_dp[j] + a[i]

res = -1 if bit_dp[-1] >= INF else bit_dp[-1]
print(res)

Measured memory_bytes: 3316
#include<cstdio>
int main(){
    int n;
    scanf("%d",&n);
    long long max = -1000000,min = 1000000;
    long long sum = 0;
    long long a;
    for(int i=0;i<n;i++){
        scanf("%lld",&a);
        if(a > max) max = a;
        if(min > a) min = a;
        sum += a;
    }
    printf("%lld %lld %lld\n",min,max,sum);
}


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

int main(){
    int N,L; cin >> N >> L;
    int sum=0;
    vector <int> A(N);
    rep(i,N){
        A[i]=L+(i+1)-1;
        sum+=A[i];
    }
    int ans=1e9;
    rep(i,N){
        if (abs(A[i])<abs(ans)) ans=A[i];
    }
    cout << sum-ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;

int main() {
  INCANT;
  char a;
  cin >> a;
  char ans = (a - '0')<43?'A':'a';
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3632
/*
~Like a small boat
~On the ocean
~Sending big waves
~Into motion
!Like how a single word
!Can make a heart open
!I might only have one match
!But I can make an explosion
#And all those things I didn't say
#Wrecking balls inside my brain
#I will scream them loud tonight
#Can you hear my voice this time?
@This is my fight song
@Take back my life song
@Prove I'm alright song
@My power's turned on
$Starting right now I'll be strong
$I'll play my fight song
$And I don't really care if nobody else believes
$'Cause I've still got a lot of fight left in me!!!
*/

#include "bits/stdc++.h"
using namespace std;

#define  F  first
#define  S  second
#define  mp make_pair
#define  pb push_back
typedef long long int ll;
const int N = 2e5+5,mod = 1e9+7;
ll Arr[N],T[2*N],n;

void updt( int idx )
{
    idx += 1e5+2;
    while(idx<=2e5+5)
    {
        T[idx] += 1;
        idx += (idx&-idx);
    }
}

ll qry( int idx )
{
    idx += 1e5+2;
    ll Ret = 0;
    while(idx>0)
    {
        Ret += T[idx];
        idx -= (idx&-idx);
    }
    return Ret;
}

bool Ok( ll x )
{
    ll now = 0,cur = 0,total = (n*(n+1))/2;
    memset( T,0,sizeof T );
    updt(cur);
    total /= 2;
    total += 1;
    for(int i=1;i<=n;i++)
    {
        if( Arr[i]<x )++cur;
        else --cur;
        now += qry(cur-1);
        updt(cur);
    }
    return now<total;
}

int main()
{
//    ios_base::sync_with_stdio(0);
//    cin.tie(0);

    cin>>n;
    int Brr[n+2];
    Brr[0] = 0;
    for(int i=1;i<=n;i++)
    {
        cin>>Arr[i];
        Brr[i] = Arr[i];
    }
    sort(Brr+1,Brr+n+1);
    *Brr = unique(Brr+1,Brr+n+1)-Brr-1;
    int lo = 1,hi = *Brr,mid,now = 0;
    while(lo<=hi)
    {
        mid = (lo+hi)>>1;
        //cout<<mid<< "*\n";
        if( Ok(Brr[mid]) )lo = mid+1,now = mid;
        else hi = mid-1;
    }
    cout<<Brr[now]<< "\n";










    return 0;
}



Measured memory_bytes: 4736
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  cout << N / 3 << endl;
}

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


Measured memory_bytes: 256
#! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)


INF=10**20
def solve(N: int, K: int, P: "List[int]", C: "List[int]"):
    ans = -INF
    for i in range(N):
        start = i + 1 
        stack = [start]
        score_his = [0]
        scores = 0
        depth = 1
        seen = {}
        while stack:
            if depth > K: break
            current = stack.pop()
            
            if current in seen:
                loop_start_depth = seen[current]
                loop_end_depth = depth - 1 
                loop_scores = score_his[-1] - score_his[loop_start_depth-1]
                loop_len = loop_end_depth - loop_start_depth + 1
                if loop_scores < 0: break
 
                # print(start,score_his)
                # print(loop_start_depth,loop_end_depth,loop_scores,loop_len)
                
                rest_count = K - depth + 1
                available_loop_count = rest_count // loop_len
                res1 = (available_loop_count-1) * loop_scores + scores
 
                # print("a",rest_count,available_loop_count,res1)
                
                res2 = res1
                rest_loop_len = rest_count % loop_len + loop_len
 
                # print("b",rest_loop_len)
                ress = [res1,res2]
                for j in range(rest_loop_len):
                    score = C[P[current-1]-1]
                    res2 += score
                    ress.append(res2)
                    current = P[current-1]
 
                # print("ress",ress)
                score_his.append(max(ress))
 
                break
 
            
            score = C[P[current-1]-1]
            scores += score
            score_his.append(scores)
 
            seen[current] = depth
            stack.append(P[current-1])
 
            depth += 1
        
        ans = max(ans,max(score_his[1:]))
    
    print(ans)
 
 
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, P, C)



if __name__ == "__main__":
    main()


Measured memory_bytes: 220736
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <fstream>
#include <numeric>
#include <algorithm>

using namespace std;

int main(int argc, char **argv) {
  int n, sum = 0;
  for (int i = 0; i < 10; i++) {
    cin >> n;
    sum += n;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;


int main(void) {
    ll cnt[5]={};
    ll i;
    
    for(i=0; i<3; i++) {
        ll a, b;
        cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
    }
    
    for(i=0; i<5; i++) {
        if(cnt[i]==3) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    
}




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

int main(int argc, char const *argv[]) {

  int n1, n2, n3;
  char *m;
  char num1[7];
  m = (fgets(num1, sizeof(num1), stdin));
  sscanf(num1, "%d %d\n", &n1, &n2);

  if( (n1 <= 9) && (n2 <= 9) ){
    n3 = n1 * n2;
  }else{
    n3 = -1;
  }

  printf("%d\n", n3);

  return 0;
}


Measured memory_bytes: 128
#include <set>
#include <cstdio>
#include <cstring>
int i,n,v[9999];
main(){for(;scanf("%d",&n),n;){
	std::set<int>t;
	for(memset(v,0,sizeof(v)),i=1;i<n;i++)t.insert(i*i%n);
	std::set<int>::iterator s,S;
	for(s=t.begin();s!=t.end();s++)for(S=s;++S!=t.end();v[i>n/2?n-i:i]+=2)i=*S-*s;
	for(i=1;i<=n/2;i++)printf("%d\n",v[i]);
}}

Measured memory_bytes: 1308
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    int cnt = 0, curr = 1;

    while (curr <= n)
    {
        if (string(to_string(curr)).length() % 2)
            cnt++;
        curr++;
    }

    cout << cnt;
}

Measured memory_bytes: 3748
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=500010;
struct node{int x,y;bool operator<(const node &b)const{return x<b.x;}}p[N];
int n;
multiset<int>r,b;
int main()
{
	n=gi();
	for(int i=1;i<=n;i++)
	{
		int x=gi(),y=gi();if(x>y)swap(x,y);
		p[i]=(node){x,y};r.insert(x);b.insert(y);
	}
	sort(p+1,p+n+1);ll ans=0;
	ans=1ll*(*(--r.end())-*r.begin())*(*(--b.end())-*b.begin());
	for(int i=1;i<=n;i++)
	{
		r.erase(r.find(p[i].x));
		b.erase(b.find(p[i].y));
		r.insert(p[i].y);
		b.insert(p[i].x);
		ans=min(ans,1ll*(*(--r.end())-*r.begin())*(*(--b.end())-*b.begin()));
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 22656
#include <math.h>
#include <iostream>
#include <iomanip>
using namespace std;

int n;
int x[10], y[10];
double ans = 0;

double calc(int status, double sum, int p) {
  if (status == ((1 << n) - 1)) return sum;
  double ans = 0;
  for (size_t i = 0; i < n; i++) {
    if (status & (1 << i)) continue;
    double d;
    if (p == -1) {
      d = 0;
    } else {
      d = sqrt((x[i] - x[p]) * (x[i] - x[p]) + (y[i] - y[p]) * (y[i] - y[p]));
    }
    ans += calc(status | (1 << i), sum + d, i);
  }
  return ans;
}

int frac(int a) {
  int ans = 1;
  for (size_t i = 1; i <= a; i++) {
    ans *= i;
  }
  return ans;
}

int main() {
  cin >> n;
  for (size_t i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  double ans = calc(0, 0, -1);
  cout << setprecision(16) << ( ans / frac(n)) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
  //a_1 = 2
  //a_2 = 4
  //a_3 = 7
  //a_n = (1/2)n(n+1)+1
  int n;
  while(cin>>n){
    cout<<n*(n+1)/2+1<<endl;
  }
  return 0;
}

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

int main() {
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  cout << (a[0] * a[1]) / 2 << endl;
  return 0;
} 

Measured memory_bytes: 256
import math

k = int(input())

ab = []
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        ab.append(math.gcd(a, b))
for i in ab:
    for c in range(1,k+1):
        ans += math.gcd(i, c)

print(ans)

Measured memory_bytes: 72456
#include <stdio.h>

int main()
{
  int n,m,sum=0;
  int i,flag=0;
  double k;
  
  scanf("%d",&n);
  scanf("%d",&m);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    sum += a[i];
  }
  k = (double)sum/(4*m);
  for(i=0;i<n;i++){
    if(a[i]>=k){
      flag++;
    }
  }
  if(flag >= m){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 1648
let ( +^ ) x y = (x + y) mod 1000000007

let denote_amida amida k =
  if 0 < amida land (1 lsl k) then k + 1
  else if 0 <= k && 0 < amida land (1 lsl (k - 1)) then k - 1
  else k

let () = Scanf.scanf "%d %d %d" @@ fun h w k ->
  let valid_amidas =
    List.filter (fun amida -> amida land (amida lsl 1) = 0) @@
    Array.to_list @@
    Array.init (1 lsl (w - 1)) @@ fun admida -> admida in
  let dp = Array.make_matrix (h + 1) w 0 in
  dp.(0).(0) <- 1;
  for i = 1 to h do
    for j = 0 to w - 1 do
      List.iter (fun amida ->
        dp.(i).(denote_amida amida j) <- dp.(i - 1).(j) +^ dp.(i).(denote_amida amida j)) valid_amidas
    done
  done;
  Printf.printf "%d\n" dp.(h).(k - 1)


Measured memory_bytes: 2432
N, A, B, C = gets.split.map(&:to_i)
L = N.times.map{ gets.to_i }

def dfs(n, a, b, c)
    if n == N
        if [a, b, c].min > 0
            return (a-A).abs + (b-B).abs + (c-C).abs - 30
        end

        return 1e7
    end
    
    one = dfs(n+1, a + L[n], b, c) + 10
    two = dfs(n+1, a, b + L[n], c) + 10
    thr = dfs(n+1, a, b, c + L[n]) + 10
    fou = dfs(n+1, a, b, c)
    
    return [one,two,thr,fou].min
end

puts dfs(0, 0, 0, 0)


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A,B,C;
  cin >> A >> B >> C;
  int d=A-B;
  int ans=C-d;
  if(ans<0){
    cout << 0 << endl;
  }
  else if(d==0 && d<0)
    cout << C << endl;
  else
    cout << ans << endl;
                                                                                                                                                                                                            
}


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

// 插入此處

const LL MOD = 1e9 + 7;
LL n;

LL get_mod(LL x) {
    LL ret = 1;
    for (int i = 0; i < n; i++) {
        ret *= x;
        ret %= MOD;
    }
    return ret;
}

int main() {
    cin >> n;
    LL ans = get_mod(10) - 2 * get_mod(9) + get_mod(8);
    ans %= MOD;
    ans += MOD;
    ans %= MOD;
    cout << ans << endl;
}


Measured memory_bytes: 3588
#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>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
	int N;
	cin >> N;
	vector<vector<mint>> dp(N+1, vector<mint>(4,0));
	dp[0][0] = 1;
	for (int i = 0;i<N;++i) {
		dp[i + 1][0] = dp[i][0] * 8;
		dp[i + 1][1] = dp[i][0] + dp[i][1] * 9;
		dp[i + 1][2] = dp[i][0] + dp[i][2] * 9;
		dp[i + 1][3] = dp[i][3] * 10 + dp[i][1] + dp[i][2];
	}
	cout << dp[N][3]<<endl;
	return 0;
}

Measured memory_bytes: 73324
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n; cin >> n;
    if(n % 1000 == 0){
        cout << 0 << endl;
    }else{
        cout << 1000 - n % 1000 << endl;
    }
}

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

#define pb push_back
#define S second
#define F first
#define sz size()
#define eps 0.000001
#define oo 2000000007
#define endl '\n'
#define bg begin()
#define nd end()
#define up upper_bound
#define lw lower_bound
#define debug(x) #x << " = " << x << "; "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MAX = 3000;
ll arr[MAX], dp[MAX][MAX];

ll f(int i, int j, int turn){
	if(i >= j){
		if(turn) return arr[i];
		return 0;
	} 
	ll &ans = dp[i][j];
	if(ans != -1) return ans;
	ans = 0;
	if(turn){
		ans = max(f(i + 1, j, 0) + arr[i], f(i, j - 1, 0) + arr[j]);
	}else{
		ans = min(f(i + 1, j, 1), f(i, j - 1, 1));
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll tot = 0;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		tot += arr[i];
	}
	memset(dp, -1, sizeof(dp));
	ll ans = f(0, n - 1, 1);
	cout << 2ll*ans  - tot << endl;
	
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define MAXN 100100
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define INF 1000000
using namespace std;

int w[110],v[110];
int dp[MAXN][110];

int32_t main(){
	int n,W;
	cin>>n>>W;
	for(int i=1;i<=n;i++){
		cin>>w[i]>>v[i];
	}
	for(int i=0;i<=n;i++)
	dp[0][i]=0;
	
	for(int p=0;p<=W;p++)dp[p][0]=0;

	for(int p=1;p<=W;p++){
		for(int i=1;i<=n;i++){
		dp[p][i]=dp[p][i-1];
		if(p-w[i]>=0){
			dp[p][i]=max(dp[p][i],dp[p-w[i]][i-1]+v[i]);
		}
		}
	}
	cout<<dp[W][n]<<endl;
}

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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().ToCharArray().Select(x => int.Parse(x.ToString())).ToList();

            int count = 0;
            int position = 1;

            while (position < s.Count())
            {
                if (s[position - 1] != s[position])
                {
                    s.RemoveRange(position - 1, 2);
                    count++;
                    if (position > 1)
                    {
                        position--;
                    }
                }
                else
                {
                    position++;
                }
            }

            Console.WriteLine(2 * count);
        }
    }
}


Measured memory_bytes: 15452
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



def main():
    odd  = input()
    even = input()

    for o, e in itertools.zip_longest(odd, even):
        s = o+e if e is not None else o
        print(s, end="")
    print()

if __name__ == "__main__": main()


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
   ll n,m,a[200001],sum=0;
   cin>>n>>m;
   for(int i=0;i<n;i++){
    cin>>a[i];
   }
   sort(a,a+n);
   for(ll i=0;i<n-m;i++){
    sum+=a[i];
   }
   cout<<sum<<endl;
}


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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// 毎日1枚以上食べるときのi日目までにj枚食べる場合の数は
// dp[i][j] = Σ dp[i-1][j-k] | k=[1,x)
// 累積和でO(n^2)
// あとは Σ (dp[i][n] * dCi) | i=[1,min(n,d)] を求めるだけ

ll n, d, x, dp[2020][2020], sum[2020][2020];

signed main() {
	while (1) {
		cin >> n >> d >> x;
		if (n==0) break;
		dp[0][0] = 1;
		fill(sum[0], sum[0]+2020, 1);
		repst(i,1,n) {
			repst(j,i,n) dp[i][j] = (sum[i-1][j-1] - (j-x<0 ? 0 : sum[i-1][j-x]) + mod) %mod;
			rep(j,n) sum[i][j+1] = (sum[i][j] + dp[i][j+1]) %mod;
		}
		ll res = 0, c = 1;
		repst(i,1,min((ll)n,d)) {
			(c *= (d-i+1)%mod) %= mod;
			(c *= mop(i,mod-2)) %= mod;
			(res += dp[i][n] * c) %= mod;
		}
		cout << res << ln;
	}
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
typedef long long ll;


int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n){
        cin >> a[i];
    }
    int maxbit = log(*max_element(a.begin(), a.end())) / log(2) + 1; //sqrt(4) = 2 4 = 100 3bits
    maxbit = 60;
    ll ans = 0;
    rep(i, maxbit){
        ll bits[2] = {};
        rep(j, n){
            if(a[j] & (1LL << i)){ //i番目のbitが1
                bits[1]++;
            }else{
                bits[0]++;
            }
        }
        ans = (ans % MOD + (1LL * (bits[1] * bits[0]) % MOD * ((1LL << i) % MOD)) % MOD) % MOD;
        ans %= MOD;
        //cout << i+1 << ":" << bits[0] << " " << bits[1] <<  endl;
    }
    cout << ans%MOD << endl;
}


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

int main() {
  int n,k;
  string s;
  cin >> n >> k >> s;
  int cnt=0;
  for(int i=0;i<n-1;i++){
    if(s.at(i) == s.at(i+1)){
      cnt++;
    }
  }
  
  cout << min(n-1,cnt+2*k) << endl;
  
  return(0);
}

Measured memory_bytes: 3736
#include<cstdio>
long long mod=1000000007;
long long inv(long long n, long long p) {
	long long x = p, y = n, b = 0, b2 = 1;
	long long q, r, b3;
	while (y > 0) {
		q = x / y;
		r = x - q*y;
		if (b < q*b2) {
			b += ((q*b2 - b) / p + 1)*p;
		}
		b3 = (b - q*b2) % p;
		x = y;
		y = r;
		b = b2;
		b2 = b3;
	}
	return b;
}
long long factorial[200001],factinv[200001];
long long combi(long long n, long long r,long long p) {
	return ((factorial[n] * factinv[r]) % p)*factinv[n - r] % p;
}
int main() {
	int h, w, a, b, i;
	scanf("%d%d%d%d", &h, &w, &a, &b);
	factorial[0] = 1;
	factinv[0] = 1;
	for (i = 1; i < h + w; i++) {
		factorial[i] = (factorial[i - 1] * i) % mod;
		factinv[i] = inv(factorial[i], mod);
	}
	long long ans = 0;
	for (i = b + 1; i <= w; i++) {
		ans = (ans + combi(h - a + i - 2, i-1, mod)*combi(a + w - i - 1, a-1, mod)) % mod;
	}
	printf("%lld", ans);
	return 0;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

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; }
 
vector<int> c;


void solve(ll num)
{
    if(num < 1)
    {
        return;
    }
    num--;
    c.push_back(num%26);

    solve(num/26);
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    
    solve(N);

    reverse(c.begin(), c.end());

    rep(i, c.size())
    {
        char ans = c[i]+int('a');
        cout << ans ;
    }

    cout << endl;

    return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include <string>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i;
  int cnt = 0;
  for(i=1;i<=n;i++){
    string x = to_string(i);
    int a = x.size();
    if(a==1||a==3||a==5||a==7) cnt++;
  }
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 3712
g_memo = {0: 1}
h_memo = {0: 1}

def g(l):
    if not l in g_memo:
        g_memo[l] = 3 + 2*g(l-1)
    return g_memo[l]

def h(l):
    if not l in h_memo:
        h_memo[l] = 1 + 2*h(l-1)
    return h_memo[l]

def solve(l, x):
    if x <= 0:
        return 0
    if l == 0: # x > 0
        return 1
    if x >= g(l):
        return h(l)
    res = 0
    y = 1
    # f(l-1)
    res += solve(l-1, x-y)
    y += g(l-1)
    # P
    res += int(y < x)
    y += 1
    # f(l-1)
    res += solve(l-1, x-y)
    return res

n, x = map(int, raw_input().split())
print(solve(n, x))

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


int main() {
  int n,k;
  cin >> n>>k;
  
  vector<int>a(n);
  rep(i,n){
    cin>>a.at(i);
  }
  int g=a.at(0);
  rep2(i,1,n){
    g=__gcd(g,a.at(i));
  }
  sort(a.begin(),a.end());
  if(a.at(n-1)>=k&&g==__gcd(g,k)){
    cout<<"POSSIBLE"<<endl;
  }
  else{
    cout<<"IMPOSSIBLE"<<endl;
  }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,vl>;
using Tu = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
const ll INF=1LL<<60;
const ll MOD=1000000007;




int main(){
    ll N;
    cin >> N;
    ll Q;
    cin >> Q;
    vector<ll> S(N,0);
    vector<ll> T(N,0);
    vector<ll> X(N,0);
    vector<ll> D(Q,0);

    //イベントをおこる順に格納、１なら封鎖ー１なら封鎖解除
    priority_queue<Tu, vector<Tu>, greater<Tu>> event;

    //現在封鎖されている座標を格納
    set<ll> Y;

    for(ll i=0;i<N;i++){
        cin>>S[i]>>T[i]>>X[i];
        event.push(Tu(S[i]-X[i],1,X[i]));
        event.push(Tu(T[i]-X[i],-1,X[i]));
    ;}
    for(ll i=0;i<Q;i++){
        cin>>D[i]
    ;}

    for(ll i=0;i<Q;i++){
        while(!event.empty()&&get<0>(event.top())<=D[i]){
            Tu x=event.top();
            event.pop();
            if(get<1>(x)==1){
                Y.insert(get<2>(x));
            }
            else Y.erase(get<2>(x));
        }
        if(Y.empty())cout<<-1<<endl;
        else cout<<*Y.begin()<<endl;
    ;}

    

    return 0;
}


Measured memory_bytes: 26472
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	Info(int arg_to,int arg_time){
		to = arg_to;
		time = arg_time;
	}
	int to,time;
};

struct Data{
	Data(int arg_node_id,int arg_current_time){
		node_id = arg_node_id;
		current_time = arg_current_time;
	}
	bool operator<(const struct Data &arg) const{
		return current_time > arg.current_time;
	}
	int node_id,current_time;
};

vector<Info> V[100000];
int min_time[100000];

int main(){

	int N,M;
	scanf("%d %d",&N,&M);

	int from,to,time;
	for(int i = 0; i < M; i++){
		scanf("%d %d %d",&from,&to,&time);
		from--;
		to--;
		V[from].push_back(Info(to,time));
	}

	for(int i = 0; i < N; i++)min_time[i] = BIG_NUM;

	min_time[0] = 0;

	priority_queue<Data> Q;
	Q.push(Data(0,0));

	int ans = -1;

	while(!Q.empty()){

		if(Q.top().current_time > min_time[Q.top().node_id]){
			Q.pop();
		}else{

			for(int i = 0; i < V[Q.top().node_id].size(); i++){
				if(Q.top().current_time > V[Q.top().node_id][i].time)continue;

				if(V[Q.top().node_id][i].to == N-1){
					ans = max(ans,V[Q.top().node_id][i].time);
				}else{
					if(min_time[V[Q.top().node_id][i].to] > V[Q.top().node_id][i].time){
						min_time[V[Q.top().node_id][i].to] = V[Q.top().node_id][i].time;
						Q.push(Data(V[Q.top().node_id][i].to,V[Q.top().node_id][i].time));
					}
				}
			}
			Q.pop();
		}
	}

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 9504
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int a,b;
    cin>>a>>b;
    if(a<=9&&b<=9) cout<<a*b;
    else cout<<-1;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int A, B, C, K;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int res = 0;
    cin >> A >> B >> C >> K;
    if(A >= K){
        cout << K << endl;
    }else if(A + B >= K){
        cout << A << endl;
    }else{
        cout << A - (K - A - B) << endl;
    }
    return 0;
}

Measured memory_bytes: 3656
n = int(input())
w = [0] * 30
x = [0] * 30
y = [0] * 30
z = [0] * 30

for i in range(n):
    b, f, r, v = map(int, input().split())
    if b == 1:
        w[r + (f - 1)*10 - 1] += v
    if b == 2:
        x[r + (f - 1)*10 - 1] += v
    if b == 3:
        y[r + (f - 1)*10 - 1] += v
    if b == 4:
        z[r + (f - 1)*10 - 1] += v


first = ''
second = ''
third = ''

for i in range(10):
    first += ' ' + str(w[i])
print(first)
for i in range(10):
    second += ' ' + str(w[i + 10])
print(second)
for i in range(10):
    third += ' ' + str(w[i + 20])
print(third)
first = ''
second = ''
third = ''

print('#' * 20)

for i in range(10):
    first += ' ' + str(x[i])
print(first)
for i in range(10):
    second += ' ' + str(x[i + 10])
print(second)
for i in range(10):
    third += ' ' + str(x[i + 20])
print(third)
first = ''
second = ''
third = ''

print('#' * 20)

for i in range(10):
    first += ' ' + str(y[i])
print(first)
for i in range(10):
    second += ' ' + str(y[i + 10])
print(second)
for i in range(10):
    third += ' ' + str(y[i + 20])
print(third)
first = ''
second = ''
third = ''

print('#' * 20)

for i in range(10):
    first += ' ' + str(z[i])
print(first)
for i in range(10):
    second += ' ' + str(z[i + 10])
print(second)
for i in range(10):
    third += ' ' + str(z[i + 20])
print(third)



Measured memory_bytes: 5620
import math

n, m = map(int, input().split())

if abs(n - m) >= 2:
    print(0)

elif abs(n - m) == 1:
    ans = math.factorial(n) * math.factorial(m)
    ans %= 10 ** 9 + 7
    print(ans)

else:
    ans = 2*math.factorial(n) * math.factorial(m)
    ans %= 10 ** 9 + 7
    print(ans)

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

ll to[101010],from[101010];
int A[101010], deq[101010];

int main(){
  int N,M,K; cin>>N>>M>>K;
  for(int i=1;i<=N;i++){
    cin>>A[i];
    from[i]=1LL*A[i];
  }
  for(int i=2;i<=K;i++){
    int s=0,t=0;
    deq[s]=0;
    for(int j=1;j<i;j++){
      while(s<t&&from[deq[t-1]]<=from[j]) t--;
      deq[t++]=j;
    }
    for(int j=i;j<=N;j++){
      to[j]=1LL*A[j]*i+from[deq[s]];
      if(j-M>=1&&deq[s]==j-M) s++;
      while(s<t&&from[deq[t-1]]<=from[j]) t--;
      deq[t++]=j;
    }
    swap(to,from);
  }
  ll ans=0;
  rep(i,N) ans=max(ans,from[i+1]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 2e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

vector<int> adj[maxN], stcs[maxN], otr[maxN], sstc;
int n, col[maxN];
ll szs[maxN], ans[maxN];

ll F(ll x) {
	return x * (x + 1) / 2;
}

void calc(int nd, int an) {
	szs[nd] = 1;
	for(auto sn: adj[nd]) {
		if(sn != an) {
			calc(sn, nd);
			szs[nd] += szs[sn];
		}
	}
}

void dfs(int nd, int an) {
	sstc.push_back(nd);
	if(stcs[col[nd]].empty()) {
		ans[col[nd]] -= szs[nd];
	} else {
		int bue = sstc[stcs[col[nd]].back() + 1];
		otr[bue].push_back(nd);
		LOG << nd + 1 << ' ' << bue + 1 << '\n';
	}
	stcs[col[nd]].push_back(sstc.size() - 1);
	for(auto sn: adj[nd])
		if(sn != an)
			dfs(sn, nd);
	stcs[col[nd]].pop_back();
	sstc.pop_back();
}

void lst(int nd, int an) {
	for(auto sn: adj[nd]) {
		if(sn == an) continue;
		ll cr = szs[sn];
		for(auto grn: otr[sn])
			cr -= szs[grn];
		ans[col[nd]] += F(cr);
		lst(sn, nd);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> col[i];
		col[i]--;
	}

	for(int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	fill(ans, ans + n, n);
	calc(0, -1);
	dfs(0, -1);
	for(int i = 0; i < n; i++) ans[i] = F(ans[i]);
	int topr = 0;
	for(auto sn: otr[topr]) LOG << sn + 1 << ' '; LOG << '\n';
	//return 0;
	lst(0, -1);
	for(int i = 0; i < n; i++) cout << F(n) - ans[i] << '\n';
}


Measured memory_bytes: 51488
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  cout << n / 3 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string>
#include <vector>

using namespace std;

int n,m,a[10];

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

  cin>>n>>m;
    int x,y;
    for(int i = 0; i < 10; i++){
      a[i] = -1;
    }
    int flag=0;
    for (int i=1;i<=m;i++)
    {
        cin>>x>>y;
        if (a[x]==-1) a[x]=y;
        else if (a[x]!=y) {flag=1;}
    }
    if (flag|| (n>1&&a[1]==0)) puts("-1");
    else
    {
        if (n==1&&a[1]==-1) puts("0");
        else
        {
            if (a[1]==-1) a[1]=1;
            if (a[2]==-1) a[2]=0;
            if (a[3]==-1) a[3]=0;
            for (int i=1;i<=n;i++)
                cout<<a[i];
            cout<<endl;
        }

    }


}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;
	string s, t; cin >> s >> t;

	
	REP(i,N+1){
		string concat = s;
		concat += t.substr(N-i);
		int len = concat.length();
		if(concat.substr(0,N) == s and concat.substr(len-N) == t){
			cout << len << endl;
			return 0;
		}
	}

	


	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define _IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const ll N=1e5+9,inf=1e18,mod=1e9+7;

int main()
{
    _IO;

    ll n;
    cin>>n;
    ll sum=0;

   vector<pair<string,ll>>vc;
   while(n--)
   {
       string s;ll t;
       cin>>s>>t;
       sum+=t;
       vc.pb({s,t});
   }
   string s;
   cin>>s;
   for(auto x:vc)
   {
       sum-=x.S;
       if(x.F==s)break;
   }
   cout<<sum<<"\n";

}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n,abc[100005][3];
int dp[100005][4];
int rec(int i=0,int last=3)
{
    if(i==n)
        return 0;
    if(dp[i][last]!=-1)
        return dp[i][last];
    ll a,b,c;
    a = b = c = LONG_MIN;
    if(last==0)
    {
        b = abc[i][1]+rec(i+1,1);
        c = abc[i][2]+rec(i+1,2);
    }
    else if(last==1)
    {
        a = abc[i][0]+rec(i+1,0);
        c = abc[i][2]+rec(i+1,2);
    }
    else if(last==2)
    {
        a = abc[i][0]+rec(i+1,0);
        b = abc[i][1]+rec(i+1,1);
    }
    else
    {
        a = abc[i][0]+rec(i+1,0);
        b = abc[i][1]+rec(i+1,1);
        c = abc[i][2]+rec(i+1,2);
    }
    return dp[i][last] = max(a,max(b,c));
}


int main()
{
    memset(dp,-1,sizeof(dp));
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> abc[i][0];
        cin >> abc[i][1];
        cin >> abc[i][2];
    }
    cout << rec();

    return 0;
}


Measured memory_bytes: 9216
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han Elmuzaffer Daima
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid (start+end)/2
#define ort (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

int n,m,cev,b,a[li],k;
string s;
vector<int> v;

int main(void){
	fio();
	cin>>n>>m;
	for(int i=0;i<=m+1;i++)cout<<"#";
	cout<<endl;
	FOR{
		cin>>s;
		cout<<"#"<<s<<"#"<<endl;
	}
	for(int i=0;i<=m+1;i++)cout<<"#";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef pair<int,int> P;
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define lowbit(x) (x&-x)
const ll INF=0x3f3f3f3f;
const double EPS=1e-6;
const int N=2e5+10;
const ll mod=1e9+7;
inline ll read()
{  ll f=1,x=0;char ch=getchar();
   for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-') f=-1;
   for(;ch<='9'&&ch>='0';ch=getchar()) x=x*10+ch-'0';
   return x*f;
}
ll n,k;
long double a[N];
bool check(long double mid)
{  ll cnt=0;
   for(ll i=1;i<=n;i++)
   {  if(a[i]<=mid)continue;
      ll q=ceil((a[i]-mid)/mid);
      //printf("q=%d\n",q);
      if(q)cnt=cnt+q;
      if(cnt>1000000000)return 0;
   }
   if(cnt>k)return 0;
   else return 1;
}
int main()
{  //printf("%lf",ceil(0.5/0.2-1.0));
   cin>>n>>k;
   for(int i=1;i<=n;i++)cin>>a[i];
   double l=0.000001,r=1e9+5,ans;
   while(r-l>=EPS)
   {  double mid=(l+r)/2;
      if(check(mid))
      {  ans=mid;
         r=mid-0.00000001;
      }
      else
      {  l=mid+0.00000001;
      }
   }
   printf("%.0f\n",max(1.0,ceil(ans-0.000001)));
}

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

template <typename T>
struct UnionFind{
    std::vector<T> par, rank, sz;
    UnionFind(T n) : par(n), rank(n, 0), sz(n, 1){
        for(T i=0; i<n; i++) par[i] = i;
    }
    void init(T n){
        par.resize(n);
        rank.resize(n);
        sz.resize(n);
        for(T i=0; i<n; i++){
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }
    
    int root(T x){
        if(par[x] == x) return x;
        else  return par[x] = root(par[x]);
    }
    
    bool is_same(T x, T y){
        return root(x)==root(y);
    }
    
    int size(T x) {
        return sz[root(x)];
    }
    
    bool unite(T x, T y){
        x = root(x);
        y = root(y);
        if(x==y) return false;
        
        if(rank[x] < rank[y]) std::swap(x, y);
        if(rank[x]==rank[y]) rank[x]++;
        par[y] = x;
        sz[x] += sz[y];
        return true;
    }
};

int main() {
    ll N, M; cin >> N >> M;
    vector<pair<int, int>> v(M);
    for (int i = 0; i < M; i++)
    {
        cin >> v[M-1-i].first >> v[M-1-i].second;
        v[M-1-i].first--; v[M-1-i].second--;
    }

    UnionFind<int> uf(N);
    vector<ll> f;
    ll cur = N * (N-1) / 2;
    for (int i = 0; i < M; i++)
    {
        f.push_back(cur);
        if(uf.is_same(v[i].first, v[i].second)) continue;
        cur -= uf.size(v[i].first) * uf.size(v[i].second);
        uf.unite(v[i].first, v[i].second);
    }

    for (int i = 0; i < M; i++)
    {
        cout << f[M-1-i] << '\n'; 
    }
    
}

Measured memory_bytes: 4212
#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    stack<int> S1;
    stack<pair<int, int> > S2;
    char ch;
    int sum = 0;
    for (int i = 0; cin >> ch; i++) {
        if (ch == '\\')
            S1.push(i);
        else if (ch == '/' && S1.size() > 0) {
            int j = S1.top(); S1.pop();
            sum += i - j;
            int a = i - j;
            while (S2.size() > 0 && S2.top().first > j) {
                a += S2.top().second;   S2.pop();
            }
            S2.push(make_pair(j, a));
        }
//        cout << i << ch << endl;
    }

//    cout << "shba" << endl;

    vector<int> ans;
    while(S2.size() >0) {ans.push_back(S2.top().second); S2.pop(); }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for(int i = 0; i < ans.size(); i++){
        cout<< " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3184
import java.util.Scanner;
public class Main
{
  public static void main (String args[])
  {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int K = in.nextInt();
    
    int dp[] = new int[N+1];
    int H[] = new int[N+1];
    for (int i = 1; i <= N; i++)
    {
      H[i] = in.nextInt();
    }
    dp[1] = 0;
    
    for (int i = 2; i <= N; i++)
    {
      if (i > N)
        	break;
      int min = Integer.MAX_VALUE;
      for (int j = 1; j <= Math.min(i-1,K); j++)
      {
        if (i > N)
	        break;
        if (i-j > N)
	        break;
        int temp = dp[i-j] + Math.abs(H[i] - H[i-j]);
		if (temp < min)
			min = temp;
        
      }
		dp[i] = min;
      	
    }
    System.out.println(dp[N]);
  }
}

Measured memory_bytes: 61072
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = sum(b)
for a, b in zip(a, a[1:]):
    if a + 1 == b:
        ans += c[a - 1]
print(ans)


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
m = int(input())
dc = [list(map(int, input().split())) for _ in range(m)]
s = sum([d * c for d, c in dc])
k = sum([c for d, c in dc])
d = 1
if s % 9:
    d = 0
print(k - 1 + s // 9- d)


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	for (int i=0; i<2; i++) {
		if(s.substr(i,3)==string(3,s[i])) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> pow2;
  pow2.push_back(2);
  int i;
  for (i = 0; pow2[i] <= n * 2; i++) {
    pow2.push_back(pow2[i] * 2);
  }
  i = 0;
  while (pow2[i] <= n) {
    i++;
  }
  cout << pow2[i - 1] << endl;
  return 0;
}



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

int main() {
  int n, k;
  cin >> n >> k;
  
  int cnt;
  for (int i=0; i<n; i++) {
    int x;
    cin >> x;
    if (2*x < 2*abs(x - k)) cnt += 2*x;
    else cnt += 2*abs(x - k);
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b){swap(a,b);}
    if(b>c){
        swap(b,c);
    }
    if(a>b){
        swap(a,b);
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}




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

int main() {

  int N;
  cin >> N;

  set<int> treeSet;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    treeSet.insert(a);
  }

  int s = treeSet.size();

  if (s % 2 == 0) {
    cout << s - 1 << endl;
  } else {
    cout << s << endl;
  }

}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,m=0;
  cin>>n;
  map<int,int> mp;
  for(int i=0;i<n;i++){
    cin>>a;
    mp[a-1]++,mp[a]++,mp[a+1]++;
  }
  for(auto au:mp){
    m=max(au.second,m);
  }
  cout<<m;
}

Measured memory_bytes: 4736
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    if len(s)<26:
        for char in string.ascii_lowercase:
            if char not in s:
                print(s+char)
                break
    else:
        for i in range(25, -1, -1):
            ex = s[i:]
            late = list(ex)
            late.sort(reverse=True)
            late = "".join(late)
            if ex != late:
                index = late.index(s[i])
                ans = s[:i] + late[index-1]
                print(ans)
                break
        else:
            print(-1)
    

main()


Measured memory_bytes: 74512