akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,ans=0;
    vector<int>b[10];
    char a[30009];
    scanf("%d%s",&n,a);
    for(int i=0; i<n; i++)
        b[a[i]-'0'].push_back(i);
    for(int i=0; i<10; i++)
    {
        int tmp=upper_bound(b[i].begin(),b[i].end(),-1)-b[i].begin();
        if(tmp==b[i].size())
            continue;
        tmp=b[i][tmp];
        for(int j=0; j<10; j++)
        {
            int tmp1=upper_bound(b[j].begin(),b[j].end(),tmp)-b[j].begin();
            if(tmp1==b[j].size())
                continue;
            tmp1=b[j][tmp1];
            for(int k=0; k<10; k++)
            {
                int tmp2=upper_bound(b[k].begin(),b[k].end(),tmp1)-b[k].begin();
                if(tmp2==b[k].size())
                    continue;
                //printf("%d %d %d\n",i,j,k);
                ans++;
            }
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#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(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string sdir = "DRUL";

int H,W;           
int dir_v[4][6] =   {{4, 1, 0, 3, 5, 2},
                     {1, 5, 2, 0, 4, 3},
                     {2, 1, 5, 3, 0, 4},
                     {3, 0, 2, 5, 4, 1}
                  };
int v_idx[] = {4, 1, 2, 3};
bool visited[110][110];
bool IsIn(int x,int y){
    return 0<=x&&x<H&&0<=y&&y<W;
}
vector<string> s, tmp;
void debug(){
    rep(i,H){
        cerr << s[i] << endl;
    }
    cerr << endl;
}
bool can_move(vector<int>& v, int nx, int ny, int dir){
    //cerr <<sdir[dir] << endl;
    //dump(v[v_idx[dir]]);
    //cerr << "can_move: " << nx << " " << ny << " " << v[v_idx[dir]] << " " << s[nx][ny] << endl;
    //print(v);
    return v[v_idx[dir]] == s[nx][ny] - '0';
}
 
vector<int> next_v(vector<int>& v, int dir){
    vector<int> res(6, 0);
    rep(i,6){
        res[i] = v[dir_v[dir][i]];
    }
    return res;
}

void dfs(int sx, int sy, vector<int>& t){
    if(visited[sx][sy])return;
    //cerr << endl << "now: " << sx << " " << sy << endl;
    visited[sx][sy] = true;
    rep(i,4){
        int nx = sx + dx[i];
        int ny = sy + dy[i];
        if(!IsIn(nx, ny))continue;
        if(can_move(t, nx, ny, i)){
            vector<int> nv = next_v(t, i);
            dfs(nx, ny, nv);
        }
    }
    return;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    cin >> H >> W;
    s.resize(H);
    rep(i,H)cin >> s[i];
    vector<int> ts = {6, 3, 5, 4, 2, 1};
    rep(i,H)rep(j,W){
        visited[i][j] = false;
    }
    dfs(0, 0, ts);
    if(visited[H-1][W-1]){
        cout << YES << endl;
    }
    else{
        cout << NO << endl;
    }
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    bool t = false;
    while(1){
        c -= b;
        if(c<=0){
            t = true;
            break;
        }
        a -= d;
        if(a<=0){
            t = false;
            break;
        }
    }
    cout << (t ? "Yes" : "No") << endl;
}

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


int main() {

    string x;
    cin >> x;
    for(int i=0;i<x.size();i++){
        if(x[i]=='1')x[i]='9';
        else if(x[i]=='9')x[i] = '1';
    }
    cout << x;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

struct DisjointSet {
   DisjointSet(Int n)
      : ps(n, -1), ns(n, 0) {}
   std::vector<Int> ps, ns;
   Int find(Int x) {
      if( ps[x] == -1 ) return x;
      return ps[x] = find(ps[x]);
   }
   void unite(Int x, Int y) {
      x = find(x), y = find(y);
      if( x == y ) return;
      if( ns[x] < ns[y] ) std::swap(x, y);
      ps[y] = x;
      ns[x] += ns[y];
   }
   bool same(Int x, Int y) {
      return find(x) == find(y);
   }
};

int main() {
   Int v, e;
   std::cin >> v >> e;
   std::vector<Int> ss(e), ts(e);
   rep(i, e) std::cin >> ss[i] >> ts[i];
   std::vector<std::vector<Int>> fnexts(v), bnexts(v);
   rep(i, e) {
      Int s = ss[i], t = ts[i];
      fnexts[s].emplace_back(t);
      bnexts[t].emplace_back(s);
   }
   Int id = 0;
   std::vector<Int> xs(v, -1);
   std::vector<Int> ys;
   std::function<void(Int)> dfs1 = [&](Int i) {
      if( xs[i] != -1 ) return;
      xs[i] = -2;
      for(Int k : fnexts[i]) {
         guard( xs[k] == -1 );
         dfs1(k);
      }
      xs[i] = id;
      id += 1;
      ys.emplace_back(i);
   };
   rep(i, v) dfs1(i);
   std::reverse(ys.begin(), ys.end());
   DisjointSet dset(v);
   std::vector<bool> us(v);
   std::function<void(Int)> dfs2 = [&](Int i) {
      if( us[i] ) return;
      us[i] = true;
      for(Int k : bnexts[i]) {
         guard( not us[k] );
         dset.unite(i, k);
         dfs2(k);
      }
   };
   rep(i, v) dfs2(ys[i]);
   Int q;
   std::cin >> q;
   rep(i, q) {
      Int s, t;
      std::cin >> s >> t;
      puts(dset.same(s, t) ? "1" : "0");
   }
}



Measured memory_bytes: 5360
N = int(input())

sum_ = 0
for i in range(1, N+1):
    if i % 3 == 0 and i % 5 == 0:
        pass
    elif i % 3 == 0:
        pass
    elif i % 5 == 0:
        pass
    else:
        sum_ += i

print(sum_)

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

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	int n;
	cin >> n;
	vector<int> cnt(n + 1, 0);
	for(int i = 0; i < n -1; ++i){
		int x;
		cin >> x;
		x--;
		cnt[x]++;
	}
	for (int i = 0; i < n; ++i){
		cout << cnt[i] << "\n"; 
	}
	return 0;
}



Measured memory_bytes: 4056
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(int i=1;i<=n;i++)
#define FORl(i,l,n) for(int i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll mod = 1e9 + 7;

ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}


int main(){
	int n;
	cin >> n;
	int a[n+5];
	FOR0(i,n){
		cin >> a[i];
	}
	sort(a,a+n);
	ll sum = 0;
	sum += a[n-1];
	ll idx = n-2;
	ll cnt = 2;
	while(cnt < n){
		sum += a[idx];
		cnt++;
		if(cnt >= n){
			break;
		}
		sum += a[idx];
		cnt++;
		if(cnt >= n){
			break;
		}
		idx--;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 4420
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll H;
    cin >> H;
    ll W;
    cin >> W;
    ll K;
    cin >> K;
    vector<vector<char>> c(H, vector<char>(W));
    for(ll i=0;i<H;++i)
        for(ll j=0;j<W;++j)cin>>c[i][j];
    ll ans=0;
    for(ll i=0;i<(1LL<<H);++i)
        for(ll j=0;j<(1LL<<W);++j){
            vector<vector<char>> d=c;
            for(ll k=0;k<H;++k){
                if(i&1LL<<k){
                    for(ll l=0;l<W;++l)d[k][l]='d';
                }
            }
            for(ll k=0;k<W;++k){
                if(j&1LL<<k){
                    for(ll l=0;l<H;++l)d[l][k]='d';
                }
            }
            ll cou=0;
            for(ll i=0;i<H;++i)
                for(ll j=0;j<W;++j)if(d[i][j]=='#')cou++;
            if(cou==K)ans++;
        }
        prt(ans);fl

    return 0;
}



Measured memory_bytes: 3632
import math
K=int(input())
k=2
m=0
def D(x):
  s=str(x)
  array=list(map(int,list(s)))
  return sum(array)
N=1
S=1
a=0
print(1)
while k<=K:
  N+=10**a
  S=D(N)
  if a<math.log10(N/S):
    a+=1
    N=(N//10**a+1)*10**a-1
  S=D(N)
  print(N)
  k+=1
    
    


Measured memory_bytes: 3188
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N = int(input())
    d = defaultdict(int)
    for _ in range(N):
        S = input()
        d[S] += 1

    print(f"AC x {d['AC']}")
    print(f"WA x {d['WA']}")
    print(f"TLE x {d['TLE']}")
    print(f"RE x {d['RE']}")


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9948
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

	int D;
	cin >> D;
	cout << "Christmas";
	for(int i = 25; i > D; i --){
		cout << " Eve";
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
#include<cmath>
#define int long long
#define pb emplace_back
#define Mod 1000000007
#define all(a) a.begin(),a.end()
using namespace std;
double Pi = 3.141592653589793238;
signed main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    double p = c*30;
    double q = d*6;
    double r = (double)q/12;
    p += r;
    p -= q;
    double ang = min(p,(double)360 - p);
    double x = sqrt(a*a + b*b - (double)2*a*b*(cos(ang/180 * Pi)));
    printf("%.20f",x);
}


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

a = sorted(a)
p = list(set(a))

if len(p) <= k:
    print('0')
    exit()

j = 0
ans = [0 for _ in range(len(p))]
ans[0] = 1
for i in range(1, n):
    if a[i] == a[i - 1]:
        ans[j] += 1
    else:
        j += 1
        ans[j] += 1

ans = sorted(ans)

print(sum(ans[:len(p) - k]))

Measured memory_bytes: 92880
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

template <typename T>
vector<int> tpsort_Kahn(const vector< vector< T > > &g) {
    const int V = g.size();
    vector<int> indeg(V, 0);
    stack<int> S;

    rep(i,0,V) rep(j,0,g[i].size())
        indeg[ g[i][j] ]++;
    rep(i,0,V) if(indeg[i] == 0) S.push(i);

    vector<int> ans;
    while(S.size() > 0) {
        int u = S.top(); S.pop();
        ans.push_back(u);
        rep(i,0,g[u].size()) {
            indeg[ g[u][i] ]--;
            if(indeg[ g[u][i] ] ==  0)
                S.push( g[u][i] );
        }
    }
    return ans;
}

int H, W;
char board[60][60];
int min_x[35], max_x[35], min_y[35], max_y[35];

signed main() {
    int DATA; cin >> DATA;
    while(DATA--) {
        // initialize
        fill(min_x, min_x + 35, INF);
        fill(min_y, min_y + 35, INF);

        fill(max_x, max_x + 35, -1);
        fill(max_y, max_y + 35, -1);

        cin >> H >> W;
        rep(i,0,H) rep(j,0,W) {
            cin >> board[i][j];
            if(board[i][j] == '.') continue;
            int alph = board[i][j] - 'A';

            chmin(min_x[alph], i);
            chmin(min_y[alph], j);

            chmax(max_x[alph], i+1);
            chmax(max_y[alph], j+1);
        }

        bool ng = false;
        vector< vector<int> > G(30);
        rep(f,0,26) {
            if(min_x[f] == INF) continue;
            // printf("search: character %c\n", (char)('A' + f));
            // printf("debug: min_x = %lld, max_x = %lld, min_y = %lld, max_y = %lld\n", min_x[f], max_x[f], min_y[f], max_y[f]);
            rep(i,min_x[f],max_x[f]) {
                rep(j,min_y[f],max_y[f]) {
                    if(board[i][j] == '.') ng = true;
                    else if(board[i][j] - 'A' != f) {
                        int v = board[i][j] - 'A';
                        G[f].push_back(v);
                    }
                }
            }
        }

        vector<int> ans = tpsort_Kahn(G);
        if(ans.size() != 30) ng = true;

        cout << (ng ? "SUSPICIOUS" : "SAFE") << endl;
    }
    return 0;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int c,n;
	cin>>n;
	cin>>s;
	if(s.length()>=1)
	c=1;
	char x=s[0];
	for(int i=1;i<s.length();i++)
	{
		if(s[i]!=x)
		{
		c++;
		
	}
	x=s[i];
		}
		if(s.length()==1)
		cout<<"1";
		else
		cout<<c;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n>>a>>b;
	b=b/n*n;
	if(a<=b)cout<<"OK"<<endl;
	else cout<<"NG"<<endl;
}


Measured memory_bytes: 3600
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

vector<ll> fac(1000000,1);
vector<ll> refac(1000000,1);

ll modpow(ll n) {
	ll res = 1;
	ll p = MOD-2;
	while (p > 0) {
		if (p & 1) res = res * n % MOD;
		n = n * n % MOD;
		p >>= 1;
	}
	return res;
}

ll com(ll n, ll r) {
	if (r < 0) return 0;
	if (n < r) return 0;
	ll res = 1;
	res = res * fac[n] % MOD;
	res = res * refac[n-r] % MOD;
	res = res * refac[r] % MOD;
	return res;
}





int main() {
	for (ll i = 2; i < 1000000; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		refac[i] = modpow(fac[i]) % MOD;
	}
	ll h, w, a, b; cin >> h >> w >> a >> b;
	ll ans = 0;
	rep(i, h - a) {
		ans = (ans + (com(b - 1  + i, i)* com(w + h - 2 - b - i, w - 1 -b)) % MOD) % MOD;
	}
	cout << ans << endl;
}

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

#define INF 1000000000
#define eb emplace_back
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define log(x) cout << (x) << endl;

using vi = vector<int>;

int dp[10001] = {0};
int main() {
	int n, mx=-INF;
	cin >> n;

	vi a(n);
	rep (i,n) cin>>a[i];

	dp[a[n-1]] = 1;
	for (int i=n-2; i>=0; --i) {
		for (int j=10000; j>=0; --j) {
			if (dp[j]) {
				dp[j+a[i]] = 1;
				if ((j+a[i])%10)
					mx = max(mx, j+a[i]);
			}
		}
		dp[a[i]] = 1;

    }
	
	if(a[0]%10) mx=max(a[0], mx);

    if (mx<0) mx = 0;
	log(mx)

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var ab, bc, ca int
	fmt.Scanf("%d %d %d", &ab, &bc, &ca)

	res := 0
	if ab < bc {
		if bc < ca {
			res += ab + bc
		} else {
			res += ab + ca
		}
	} else {
		if ab < ca {
			res += bc + ab
		} else {
			res += bc + ca
		}
	}

	fmt.Print(res)
}


Measured memory_bytes: 512
#include <stdio.h>
int main(){
    int n,x,r=1<<29;
    for(scanf("%d",&n);n--;){
        int r0=0;
       
        for( scanf("%d",&x);x%2<1;x/=2)r0++;
        if(r>r0)r=r0;
    }
    printf("%d\n",r);
    return 0;
}

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

int main() {
    ll N, A, B; cin >> N >> A >> B;
    ll x = N / (A+B);
    if(A==0) cout << 0 << endl;
    else {
        ll n = min(A, N - (A+B) * x);
        cout << x * A + n << endl;
    }
}

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

int main() {
  int N,A,B;
  cin >> N >> A >> B;
  
  if(N<=20){
    cout << min(A*N,B) << endl;
  }
  
  if(N > 20){
    cout << B << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 3010, p = 998244353;
#define int ll
int a, b, c, d;
int dp[maxn][maxn], v[maxn][maxn], h[maxn][maxn];
void dfs(int c, int d) {
	if (~dp[c][d]) return;
	if (c < a || d < b) {
		dp[c][d] = v[c][d] = h[c][d] = 0;
		return;
	}
	dfs(c-1, d), dfs(c, d-1), dfs(c-1, d-1);
	dp[c][d] = dp[c-1][d] * d + dp[c][d-1] * c - dp[c-1][d-1] * ((c-1) * (d-1));
	dp[c][d] %= p;
	if (dp[c][d] < 0) dp[c][d] += p;
	h[c][d] = dp[c-1][d] * c % p;
	v[c][d] = dp[c][d-1] * d % p;
	//printf("dp[%lld][%lld] : %lld\n", c, d, dp[c][d]);

}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> a >> b >> c >> d;
	memset(dp, -1, sizeof(dp));
	dp[a][b] = 1;
	dfs(c, d);
	cout << dp[c][d] << '\n';
}


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

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

using namespace std;


map<long long, int> dp;

int solve(double X) {
	if (dp[X] > 0)return dp[X];

	int ret = log10(X) + 1;

	dp[X] = ret;

	return ret;
}




int main(void)
{
	long long N, A, B;
	int ans = INT_MAX, tmp;

	cin >> N;

	rep(A, sqrt(N) + 1) {
		if (N % A != 0)continue;

		B = N / A;
		tmp = max(solve(A), solve(B));
		if (ans > tmp) {
			ans = tmp;
		}
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

void solve() {
  ll count = 0;
  while (true) {
    count++;
    ll x;
    cin >> x;
    if (x == 0) return;
    cout << "Case " << count << ": " << x << endl;
  }
}

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



Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll minthis(ll a, ll b){return a<b?a:b;}
ll maxthis(ll a, ll b){return a>b?a:b;}
bool sortbysec(const pair<int, int>& a,const pair<int, int>& b){return (a.second < b.second);} 
 
 
void solve(){
    string s;
    cin >> s;
    if(s[(int)s.length()-1] == 's'){
        cout << s << "es" << "\n";
    }
    else cout << s << "s" << "\n";
}
 
 
int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
  return 0; 
}

Measured memory_bytes: 3660
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int cnt,mx,mn=1e9,n,t[N];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&t[i]),mx=max(mx,t[i]),mn=min(mn,t[i]);
    if(mx-mn>1){puts("No");return 0;}
    if(mx==mn){
        if(mx==n-1){puts("Yes");return 0;}
        if(mx*2<=n)puts("Yes");
        else puts("No");
        return 0;
    }
    for(int i=1;i<=n;i++)
        if(t[i]==mn)++cnt;
    if(cnt<mx&&cnt+(mx-cnt)*2<=n)puts("Yes");
    else puts("No");
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100010
using namespace std;
int n, sum[N], x, s;
int main(){
	scanf("%d", &n);
	memset(sum, 0, sizeof(sum));
	for(int i=1; i<=n; i++){scanf("%d", &x); sum[x]++;}
	s=0; for(int i=1; i<=n-1; i++)if(sum[i]){x=i; s++;}
	if(s>=3){printf("No"); return 0;}
	if(s==1){
		if(x==n-1||x<=n/2)printf("Yes"); else printf("No");
		return 0;
	}
	if(!sum[x-1]){printf("No"); return 0;}
	if(sum[x-1]>=x){printf("No"); return 0;}
	if(x-sum[x-1]<=(n-sum[x-1])/2)printf("Yes"); else printf("No");
	return 0;
}

Measured memory_bytes: 512
package main

import (
  "fmt"
)

func main() {

  var a, b int

  fmt.Scan(&a, &b)
  
  plused := a + b

  if plused % 2 != 0 {
      fmt.Println("IMPOSSIBLE")
  } else {
      fmt.Println(plused / 2)
  }
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int a[300000],flg[300000]={0},a1[300000],ans;
int main(void)
{
	int n,q,x,y,i,cnt,box,flg2;
	scanf("%d",&n);
	cnt=0;
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		a1[i]=a[i];
	}
	sort(a1,a1+n);
	for(i=0;i<n;i++){
		if(a[i]!=a1[i]){
			flg[i]=1;
			cnt++;
		}
	}
	flg2=0;
	if(cnt==0){
		ans=0;
		flg2=1;
	}
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d %d",&x,&y);
		if(flg2==0){
		   x=x-1;
		   y=y-1;
		   box=a[x];
		   a[x]=a[y];
		   a[y]=box;
		   if(flg[x]==1&&a1[x]==a[x]){
			    cnt=cnt-1;
			    flg[x]=0;
			}
		    if(flg[y]==1&&a1[y]==a[y]){
				cnt=cnt-1;
				flg[y]=0;
			}
		    if(flg[x]==0&&a1[x]!=a[x]){
				cnt++;
				flg[x]=1;
			}
		    if(flg[y]==0&&a1[y]!=a[y]){
				cnt++;
				flg[y]=1;
			}
		    if(cnt==0&&flg2==0){
			ans=i+1;
			flg2=1;
		    }
		}
	}
	if(flg2==1){
	printf("%d\n",ans);
	}
	if(flg2==0){
		printf("-1\n");
	}
	return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 a, b, c; cin >> a >> b >> c;
    cout << min(b / a, c) << endl;

    return 0;
}

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

int main() {
    int W,H,x,y,r;
    int leftX, rightX, ueY, shitaY;
    cin >> W >> H >> x >> y >> r;

    leftX = x - r;
    rightX = x + r;
    ueY = y + r;
    shitaY = y - r;

    if (leftX >= 0 && rightX <= W && ueY <= H && shitaY >= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3080
li = ['KIHBR','KIHBRA','KIHBAR','KIHBARA','KIHABR','KIHABRA','KIHABAR','KIHABARA',]
S = input()

if S in li:
    print('YES')
elif S[0]=='A' and S[1:] in li:
    print('YES')
else:
    print('NO')

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

#define ForA(i,b,a) for(int i = a; i >= b; i--)
#define ForB(i,a,b) for(int i = a; i <= b; i++)
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mmset(arr, n) memset(arr, n, sizeof arr)
#define PI 3.1415926535897932384626433832795l
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define ALPHA 27
#define IT(a , b) map <a , b> :: iterator
#define ll long long int
#define ld long double
#define debug(x) cerr << '#' << ' ' << x << '\n'
#define len(s) s.length()
#define maxn 1000010

using namespace std;

const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;

class Print{
   public:
   void print(int n){
       cout << n << '\n';
       exit(0);
   }
   void print(ll n){
       cout << n << '\n';
       exit(0);
   }
   void print(string s){
       cout << s << '\n';
       exit(0);
   }
   void print(ld n){
       cout << n << '\n';
       exit(0);
   }
};


int main()
{
    IOS;
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //#endif
    Print _p;
    int n,k; cin >> n >> k;
    if(k == 1) _p.print(0);
    _p.print(n - k);    
    #ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}


Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
res = 0
c = 0
for i in range(N - 1):
    if S[i] == S[i + 1]:
        res += 1
    else:
        c += 1
        
if (c + 1)//2 <= K:
    print(res + c)
else:
    print(res + 2*K)

Measured memory_bytes: 3316
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [usize; n],
        l: usize,
        q: usize,
        qs: [(usize1, usize1); q]
    }
    let mut p = 1;
    while 1 << p < n - 1 {
        p += 1;
    }
    p += 1;
    let mut tab = vec![vec![0; p]; n];
    for i in 0..p {
        tab[n - 1][i] = n - 1;
    }
    let mut il = 0;
    let mut ir = 0;
    let mut d = 0;
    while il < n - 1 {
        if ir == n - 1 || d + v[ir + 1] - v[ir] > l {
            tab[il][0] = ir;
            d -= v[il + 1] - v[il];
            il += 1;
        } else {
            d += v[ir + 1] - v[ir];
            ir += 1;
        }
    }
    for i in (0..n - 1).rev() {
        for j in 1..p {
            tab[i][j] = tab[tab[i][j - 1]][j - 1];
        }
    }
    for &(a, b) in &qs {
        let a1 = min(a, b);
        let b1 = max(a, b);
        let mut day = 0;
        let mut x = a1;
        while x < b1 {
            if tab[x][0] >= b1 {
                day += 1;
                break;
            }
            for i in 0..p {
                if tab[x][i] >= b1 {
                    day += 1 << (i - 1);
                    x = tab[x][i - 1];
                    break;
                }
            }
        }
        println!("{}", day);
    }
}


Measured memory_bytes: 27388
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    rep = W//2
    rem = W%2
    for i in range(H):
        if i % 2 == 0:
            prf = "#."
            end = '#'
        else:
            prf = ".#"
            end = '.'
        print(prf*rep+end*rem)
    print()



Measured memory_bytes: 5608
#include "bits/stdc++.h"
using namespace std;


int main(){

	int N; 
	long tmp;
	vector<long> A;

	cin >> N;
	
	for (int i = 0 ; i < N; i++){
		cin >> tmp;
		A.push_back(tmp);
	}
	sort(A.begin(),A.end());
	// 要素数が奇数か偶数か
	int L = A.size();

	//偶数
	if (L%2==0){
		//cout << accumulate(A.begin(),A.end(), 0) << endl;
		for (int i = 0 ; i < N-1; i=i+2){
			if (A[i]+A[i+1]<0){
				A[i]= -A[i];
				A[i+1]= -A[i+1];
			}
		}
	}
	// 奇数
	else if (L%2==1){
		//cout << accumulate(A.begin(),A.end(), 0) << endl;
		for (int i = 0 ; i < N-1; i=i+2){
			if (A[i]+A[i+1]<0){
				A[i]= -A[i];
				A[i+1]= -A[i+1];
			}
		}
	}

	long ans = accumulate(A.begin(),A.end(), 0LL);
	cout << ans << endl;

	return 0;
}



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

int main()
{
  long long k, s;
  cin >> k >> s;
  long long cnt = 0;
  for (size_t x = 0; x <= k; x++)
  {
    for (size_t y = 0; y <= k; y++)
    {
      if (x + y <= s)
      {
        long long z = s - (x + y);
        if (0 <= z && z <= k)
        {
          if (x != y && y != z && z != x)
          {
            cnt += 1;
          }
          else if (x == y && y == z && z == x)
          {
            cnt += 1;
          }
          else
          {
            cnt += 1;
          }
        }
      }
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 3552
N=int(input())
a=list(map(int,input().split()))
def gcd(a,b):
    if a>b:
        a,b=b,a
    while b:
        a,b=b,a%b
    return a
c=a[0]
for i in range(N-1):
    c=gcd(c,a[i+1])
print(c)

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

int main()
{
	int n;
	std::cin >> n;
	std::vector<int> vec(n);

	for (int i = 1; i <= vec.size(); i++) {
		if (i % 3 == 0) {
			std::cout << " " << i;
			continue;
		}
		int j = i;
		while (j > 0) {
			if (j % 10 == 3) {
				std::cout << " " << i;
				break;
			}
			else
				j /= 10;
		}
	}
	std::cout << std::endl;
}

Measured memory_bytes: 1232
#include <iostream>
#define MAXSIZE 3000
int main(){
  int a[MAXSIZE],b[MAXSIZE],tmp;
  for(int i=0;;i++){
    std::cin >> a[i]>>b[i];
    if(0==a[i]&&0==b[i]){break;}
    if(a[i]>b[i]){
      tmp=a[i];
      a[i]=b[i];
      b[i]=tmp;
    }

  }
  for(int i=0;;i++){
    if(0==a[i]&&0==b[i]){break;}
    std::cout << a[i]<<" "<<b[i] << '\n';
  }
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int a[11];
string s;
signed main()
{
	scanf("%d%d%d",&a[1],&a[2],&a[3]);
	sort(a+1,a+4);
	if(a[1]==a[2]&&a[2]!=a[3])
		printf("Yes");
	else if(a[2]==a[3]&&a[1]!=a[3])
		printf("Yes");
	else
		printf("No");
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,b)  for(int i=0;i<(int)(b);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
typedef long long ll;
typedef long double ld;

using namespace std;

int main(){
    cs
    string s;int n,p=2019;ll t=0;
    cin>>s;
    n=s.size();
    map<int,int> pam;int tt=0,base=1;
    pam[0]++;
    Repp(i,n-1,0) {
        tt+=(s[i]-'0')*base;
        tt%=p;
        t+=pam[tt];
        pam[tt]++;
        base=(base*10)%p;
    }
    cout<<t;
}

Measured memory_bytes: 3740
N, X, M = map(int, input().split())
D = {i:0 for i in range(M)}
L = [X]
c = X
D[X]=0
S = X
for i in range(1, N):
  c = (c**2)%M
  if D[c]==0:
    D[c] = i
    L.append(c)
    S += c
    continue
  else:
    p, q = D[c], i
    break
else:
  print(S)
  exit()  
cycle = L[p:q]
cycle_sum = sum(cycle)
cycle_num = (N-q)//(q-p)
rest = (N-q)%(q-p)
S += cycle_sum*cycle_num
S += sum(cycle[:rest])
print(S)

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define INF 1152921504606846976
#define MAX_N 100'000
i64 memo[MAX_N + 1];

i64 rec(i64 N) {
    if (N == 0) return 0;
    if (memo[N] >= 0) return memo[N];

    i64 min_c = INF;
    i64 p = 1;
    while (p <= N) {
        chmin(min_c, rec(N - p) + 1);
        p *= 6;
    }
    p = 1;
    while (p <= N) {
        chmin(min_c, rec(N - p) + 1);
        p *= 9;
    }
    return memo[N] = min_c;
}


#define INF 1152921504606846976


int main() {
    i64 N; cin >> N;
    vector<i64> dp(N + 1, INF);
    dp[0] = 0;

    REP(i, N) {
        chmin(dp[i + 1], dp[i] + 1);
        i64 p = 6;
        while ((i + p) <= N) {
            chmin(dp[i + p], dp[i] + 1);
            p *= 6;
        }
        p = 9;
        while ((i + p) <= N) {
            chmin(dp[i + p], dp[i] + 1);
            p *= 9;
        }
    }

    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	n,k = MI()
	mod = 10**9+7

	def f(n,r,mod):
		if (r < 0) or (n < r):
			return 0
		r = min(r, n-r)
		return fact[n] * factinv[r] * factinv[n-r] % mod

	fact = [1,1]
	factinv = [1,1]
	inv = [0,1]

	for i in range(2,n+1):
		fact.append((fact[-1]*i)%mod)
		inv.append((-inv[mod % i] * (mod // i)) % mod)
		factinv.append((factinv[-1] * inv[-1]) % mod)

	ans = 1
	for m in range(1,min(n,k)+1):
		ans += (f(n,m,mod) * f(n-1, m, mod)) % mod
		ans %= mod

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 27128
#include<iostream>
#include<fstream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include <chrono>
#include<math.h>

#define FIO ios_base::sync_with_stdio(0);  cin.tie(0);
#define PI 3.14159265358979323846
#define mod 998244353
#define ll long long
#define vll vector<long long>  
#define all(c) c.begin(), c.end()
// Used to traverse in any STL container with iterators
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
// Find whether element is present in given container or not
#define present(container, element) (container.find(element) != container.end())
// Finds whether element in present container is present in vector or not
#define cpresent(container, element) (find(all(container),element) != container.end())

using namespace std;
using namespace std::chrono; 

const ll INF = 1e13;

// void dfs(int v, vector<vector<int> >& adj, vector<bool> visited){
//     visited[v] = true;
//     for(int u: adj[v]){
//         if(!visited[u])
//             dfs(u, adj, visited);
//     }
// }

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    FIO

    int n,m;
    cin>>n>>m;
    vector<string> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    ll dp[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)dp[i][j] = 0;
    }
    if(v[0][0] == '.')dp[0][0] = 1;
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(i==0 && j==0)continue;
            if(v[i][j]=='.'){
                dp[i][j] = (dp[max(i-1, 0)][j] + dp[i][max(j-1, 0)]) % (1000000007);
            }
        }
    }
    cout<<dp[n-1][m-1]<<endl;

    return 0;
}

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


//TEMPLATE
#define pb              push_back
#define mp              make_pair
#define ll              long long
#define ld              long double
//#define pi              3.1415926536
#define pi              acos(-1)
//#define mod             1000000007
#define newline         printf("\n")
#define printminusone   printf("-1\n")
#define scl1(n)         scanf("%lld", &n)
#define scl2(a, b)      scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)   scanf("%lld %lld %lld", &a, &b, &c)
#define printl(n)       printf("%lld\n", n)
#define ssl1(str)       scanf(" %[^\n]", str)
#define scd1(n)         scanf("%lf", &n)
#define scd2(a, b)      scanf("%lf %lf", &a, &b)
#define printd(n)       printf("%lf\n", n)
#define printld(n)      printf("%Lf\n", n)
#define printcase       printf("Case %lld: ", i)
#define reversed(s)     reverse(s.begin(), s.end())
#define asorted(s)      sort(s.begin(), s.end())
#define dsorted(s)      sort(s.begin(), s.end(), cmp)
#define for0(i, n)      for (i = 0; i < n; i++)
#define for1(i, n)      for (i = 1; i <= n; i++)
#define fori(itt, stt)  for(auto itt = stt.begin(); itt != stt.end(); itt++)
#define pii             pair <ll, ll>
#define piii            pair <ll, pii>
//#define SIZE            100005
//#define INF             1000000005
#define F               first
#define S               second
#define FR              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(arr, x)      memset(arr, x, sizeof arr)
#define bitcount(n)     __builtin_popcountll(n)

const ll INF = LLONG_MAX;
const ll SIZE = 4e5+5;
const ll mod = 1e9+7;


ll a[SIZE];

int main() {
    ll t = 0, n, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0;
    string s, s1, s2;

    scl2(n, k);
    for1(i, n) scl1(a[i]);

    sort(a+1, a+n+1, greater<ll>());

    for(i = k+1; i <= n; i++) {
        ans += a[i];
    }
    printl(ans);

    return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;
string s;
string color() {
	char l[6];
	for (int i = 0; i < 6; i++) {
		l[i] = s[i + 1];
	}
	int r, g, b;
	int z[6];
	for (int i = 0; i < 6; i++) {
		if (l[i] == '0') {
			z[i] = 0;
		}
		else if (l[i] == '1') {
			z[i] = 1;
		}
		else if (l[i] == '2') {
			z[i] = 2;
		}
		else if (l[i] == '3') {
			z[i] = 3;
		}
		else if (l[i] == '4') {
			z[i] = 4;
		}
		else if (l[i] == '5') {
			z[i] = 5;
		}
		else if (l[i] == '6') {
			z[i] = 6;
		}
		else if (l[i] == '7') {
			z[i] = 7;
		}
		else if (l[i] == '8') {
			z[i] = 8;
		}
		else if (l[i] == '9') {
			z[i] = 9;
		}
		else if (l[i] == 'a') {
			z[i] = 10;
		}
		else if (l[i] == 'b') {
			z[i] = 11;
		}
		else if (l[i] == 'c') {
			z[i] = 12;
		}
		else if (l[i] == 'd') {
			z[i] = 13;
		}
		else if (l[i] == 'e') {
			z[i] = 14;
		}
		else if (l[i] == 'f') {
			z[i] = 15;
		}
	}
	r = z[0] * 16 + z[1];
	g = z[2] * 16 + z[3];
	b = z[4] * 16 + z[5];
	if (r <= 127) {
		if (g <= 127) {
			if (b <= 127) {
				return "black";
			}else {
				return "blue";
			}
		}else if (b <= 127) {
				return "lime";
			  }else {
				return "aqua";
			  }
	}
	else if (g <= 127) {
			if (b <= 127) {
				return "red";
			}else{
				return "fuchsia";
			}
		}
		else if (b <= 127) {
				return "yellow";
			}else{
				return "white";
			}
}

int main() {
	string g[1001];
	int x;
	for (int i = 0;; i++){
		cin >> s;
		if (s == "0") {
			x = i;
			break;
		}
		g[i] = color();
	}
	for (int i = 0; i < x; i++){
		cout << g[i] << endl;
	}
	char c;
	cin >> c;
	return 0;
}

Measured memory_bytes: 3184
import sys
import itertools

N, K = map(int, input().split())
a = 0

h = 0
l = 0
for j in range(0,K-1):
    h += j
for j in range(N+2-K,N+1):
    l += j

for i in range(K,N+2):
    h += i-1
    l += N+1-i
    a += l - h + 1

a %= 10 ** 9 + 7
print(a)



Measured memory_bytes: 64384
#include<bits/stdc++.h>
#define Mid ((l+r)>>1)
#define ls (rt<<1)
#define rs (rt<<1|1)
#define lson ls,l,Mid
#define rson rs,Mid+1,r
using namespace std;
const int MAXN=300000+10;
int w,h,n,ans,cnt[2],stk[2][MAXN];
struct node{
	int x,y;
	bool operator < (const node &A) const {
		return x<A.x||(x==A.x&&y<A.y);
	};
};
node pt[MAXN];
struct Segment_Tree{
	int mx[MAXN<<2],add[MAXN<<2];
	void init()
	{
		memset(mx,0,sizeof(mx));
		memset(add,0,sizeof(add));
	}
	void pushdown(int rt)
	{
		mx[ls]+=add[rt],mx[rs]+=add[rt];
		add[ls]+=add[rt],add[rs]+=add[rt];
		add[rt]=0;
	}
	void update(int rt,int l,int r,int L,int R,int k)
	{
		if(L<=l&&r<=R)
		{
			mx[rt]+=k,add[rt]+=k;
			return ;
		}
		else
		{
			if(add[rt])pushdown(rt);
			if(L<=Mid)update(lson,L,R,k);
			if(R>Mid)update(rson,L,R,k);
			mx[rt]=max(mx[ls],mx[rs]);
		}
	}
};
Segment_Tree T;
void solve()
{
	T.init();
	memset(cnt,0,sizeof(cnt));
	memset(stk,0,sizeof(stk));
	T.update(1,1,n,1,n,2*h);
	for(int i=2;i<=n;++i)
	{
		T.update(1,1,n,1,i-1,2*(pt[i].x-pt[i-1].x));
		ans=max(ans,T.mx[1]);
		if(pt[i].y>=h/2)
		{
			T.update(1,1,n,stk[0][cnt[0]],i-1,2*(pt[i].y-h));
			while(cnt[0]&&pt[stk[0][cnt[0]]].y>=pt[i].y)
			{
				T.update(1,1,n,stk[0][cnt[0]-1],stk[0][cnt[0]]-1,2*(pt[i].y-pt[stk[0][cnt[0]]].y));
				cnt[0]--;
			}
			stk[0][++cnt[0]]=i;
		}
		else
		{
			T.update(1,1,n,stk[1][cnt[1]],i-1,-2*pt[i].y);
			while(cnt[1]&&pt[stk[1][cnt[1]]].y<=pt[i].y)
			{
				T.update(1,1,n,stk[1][cnt[1]-1],stk[1][cnt[1]]-1,2*(pt[stk[1][cnt[1]]].y-pt[i].y));
				cnt[1]--;
			}
			stk[1][++cnt[1]]=i;
		}
	}
}
int main()
{
	scanf("%d%d%d",&w,&h,&n);
	for(int i=1;i<=n;++i)scanf("%d%d",&pt[i].x,&pt[i].y);
	pt[++n]=(node){0,0};
	pt[++n]=(node){w,h};
	sort(pt+1,pt+n+1);
	solve();
	swap(w,h);
	for(int i=1;i<=n;++i)swap(pt[i].x,pt[i].y);
	sort(pt+1,pt+n+1);
	solve();
	printf("%d\n",ans);
	return 0;
}

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

int main()
{
	int x[10];
	for (int i = 0; i < 10; i++)
	{
		cin >> x[i];
	}
	sort(begin(x),end(x));
	cout << x[9] << endl;
	cout << x[8] << endl;
	cout << x[7] << endl;

	return 0;
}


Measured memory_bytes: 3148
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t[] = new int[n];
		for(int i=0; i<n; i++){
			t[i] = sc.nextInt();
		}
		int m = sc.nextInt();
		int p[] = new int[m];
		int x[] = new int[m];
		for(int i=0; i<m; i++){
			p[i] = sc.nextInt();
			x[i] = sc.nextInt();
		}

		int time = 0;
		for(int i=0; i<m; i++){
			for(int j=0; j<n; j++){
				if(j+1==p[i]){
					time += x[i];
				}else{
					time += t[j];
				}
			}
			System.out.println(time);
			time = 0;
		}

	}
}

Measured memory_bytes: 10188