akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

struct Trie {
	vector<vector<int>> to;
	vector<int> cnt;
	int n;
	vector<int> total;

	Trie() {
		n = 1;
		to.emplace_back(26, -1);
		cnt.push_back(0);
	}

	void add(const string& s) {
		int v = 0;
		for (char c : s) {
			if (to[v][c - 'a'] == -1) {
				to[v][c - 'a'] = n;
				to.emplace_back(26, -1);
				cnt.push_back(0);
				n += 1;
			}
			v = to[v][c - 'a'];
		}
		cnt[v] += 1;
	}

	void mark_sizes(int v = 0) {
		if (v == 0) {
			total.resize(cnt.size());
		}
		total[v] = cnt[v];
		for (int i = 0; i < 26; i++) {
			if (to[v][i] > -1) {
				mark_sizes(to[v][i]);
				total[v] += total[to[v][i]];
			}
		}
	}
};

int main(){

	Trie trie;

	cin.sync_with_stdio(0);
	int n;
	cin >> n;
	vector<string> a(n);
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		trie.add(s);
		a[i] = s;
	}
	trie.mark_sizes();

	int q;
	cin >> q;
	vector<int> ans(q);
	vector<vector<pair<int, string>>> qs(n);
	for (int i = 0; i < q; i++) {
		int id;
		string s;
		cin >> id >> s;
		qs[id - 1].emplace_back(i, s);
	}
	vector<vector<vector<int>>> lol(n, vector<vector<int>>(26, vector<int>(26, 0)));
	vector<int> pr(n);
	for (int k = 0; k < n; k++) {
		int v = 0;
		for (int i = 0; i < (int)a[k].length(); ++i) {
			for (int j = 0; j < 26; ++j) {
				if (trie.to[v][j] > -1) {
					lol[k][a[k][i] - 'a'][j] += trie.total[trie.to[v][j]];
				}
			}
			pr[k] += trie.cnt[v];
			v = trie.to[v][a[k][i] - 'a'];
		}
	}

	for (int i = 0; i < n; i++) {
		for (const auto& p : qs[i]) {
			ans[p.first] = pr[i];
			for (int j = 0; j < 26; j++) {
				for (int k = 0; k < j; k++) {
					ans[p.first] += lol[i][p.second[j] - 'a'][p.second[k] - 'a'];
				}
			}
		}
	}

	for (int i = 0; i < q; i++) {
		printf("%d\n", ans[i] + 1);
	}

	return 0;
}

Measured memory_bytes: 384304
#include <iostream>
#include <string>

using namespace std;

int main()
{
	char b;
	cin >> b;
	if(b == 'A')
		cout << "T";
	else if(b == 'T')
		cout << "A";
	else if(b == 'C')
		cout << "G";
	else if(b == 'G')
		cout << "C";
	return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        a: String,
        b: String,
    }
    let mut vec_a: Vec<u64> = Vec::new();
    let mut vec_b: Vec<u64> = Vec::new();
    let mut count = 0;

    for a in a.bytes() {
        vec_a.push(a as u64);
    }

    for b in b.bytes() {
        vec_b.push(b as u64);
    }

    for index in 0..vec_a.len() {
        if !(vec_a[index] == vec_b[index]) {
            count += 1
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 6108
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

bool match (char c1, char c2) {
    return (c1 == '?' || c2 == '?' || c1 == c2);
}

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

    string a, b, c;
    cin >> a >> b >> c;
    ll A = a.size();
    ll B = b.size();
    ll C = c.size();

    vector<bool> ab(100000, false), bc(100000, false), ac(100000, false);

    ll ans = inf;

    Rep (i, A) Rep (j, B) {if (!match(a[i], b[j])) ab[i-j+50000] = true;}
    Rep (i, B) Rep (j, C) {if (!match(b[i], c[j])) bc[i-j+50000] = true;}
    Rep (i, A) Rep (j, C) {if (!match(a[i], c[j])) ac[i-j+50000] = true;}

    // for (ll i = 49995; i <= 50005; i++) cout << ab[i] << "\n";

    Rep (i, 8001) {
        Rep (j, 8001) {
            ll tmp = max({4000+A, i+B, j+C}) - min({(ll)4000, i, j});
            if (!ab[i+50000-4000] && !ac[j+50000-4000] && !bc[j-i+50000]) chmin(ans, tmp);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
h=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]

peaks=[]
for i in range(n):
  peaks.append(1)
  
for i in range(m):
  if h[l[i][0]-1]>h[l[i][1]-1]:
    peaks[l[i][1]-1]=0
  elif h[l[i][0]-1]<h[l[i][1]-1]:
    peaks[l[i][0]-1]=0
  else:
    peaks[l[i][1]-1]=0
    peaks[l[i][0]-1]=0

print(peaks.count(1))

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}

int main(){
	startTime=clock();
	ll n;
	ll count1=0,count2=0,count=0,count3=0;
	cin >> n;
	string s[n];
	FOR(i,n){
		cin >> s[i];
		FOR(j,s[i].length()-1) if(s[i][j]=='A' && s[i][j+1]=='B') count++;
		if(s[i][0]=='B' && s[i][s[i].length()-1]!='A') count2++;
		if(s[i][s[i].length()-1]=='A' && s[i][0]!='B') count1++;
		if(s[i][0] =='B' && s[i][s[i].length()-1]=='A') count3++;
	}
	
	ll a=min(count2,count1);
	if(count3==0) cout <<count+ a;
	else if(count2+count1 > 0) cout << count+count3+a;
	else cout <<count+ count3-1;
	

	return 0;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
int a, b, c;
int main()
{
    cin >> a >> b >> c;
    if (a + b < c)
    {
        cout << a + b + 1 + b << endl;
    }
    else
    {
        cout << b + c << endl;
    }
    return 0;
}

Measured memory_bytes: 256
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

num = gc
count = 1
same = num.shift
num.each do |i|
  if same == i
    count+=1
    break if count == 3
  else
    same = i
    count = 1
  end
end
puts count == 3 ? 'Yes' : 'No'


Measured memory_bytes: 2428
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<unordered_map>
#define deg(x) cout<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=1e18;
const ll inf=1e18;
const double eps=1e-8;
const double pi=acos(-1);


int main(){
    //TB
    string s;
    cin>>s;
    int f=0,k=1,flag=1;
    while(f<s.length()){
        if(s.length()==k) {
            flag=0;break;
        }
        if(s[f]!='h'||s[k]!='i'){
            flag=0;break;
        }
        f+=2;k+=2;
    }
    if(flag) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e9
typedef long long ll;
typedef pair<ll,ll> P;

ll kaijo[200010];

void init() {
	kaijo[0] = 1;
	for (ll i = 1;i <= 200010;i++)kaijo[i] = (kaijo[i - 1] * i) % N;
}

ll inv(ll x) {
	ll res = 1;
	ll k = N - 2;
	ll y = x;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N*y%N) % N;
		k /= 2;
	}
	return res;
}

ll Comb(ll n, ll k) {
	if (n < 0 || k < 0 || (n - k) < 0)return 0;
	ll b = kaijo[n];
	ll c = kaijo[n - k];
	ll d = kaijo[k];
	ll cd = (c*d) % N;
	return ((b%N)*(inv(cd)) % N) % N;
}

int main(void){
    init();
    ll ans=0;
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    for(ll i=0;i<h-a;i++){
        //cout<<i<<" "<<b-1<<" "<<w-b-1<<" "<<h-i-1<<endl;
        ll x=(Comb(i+b-1,b-1)*1*Comb(w+h-b-i-2,w-b-1))%N;
        ans=(ans+x)%N;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
//#define LOCAL
#define lli long long
#define ll inline
#define fp(i,l,r)  for(register int i = (l);i <= (r);++ i)

int main() {
	#ifdef LOCAL
	freopen("file.in","r",stdin);
	freopen("file.out","w",stdout);
	#endif
	int a[4];
	scanf("%d %d %d",&a[1],&a[2],&a[3]);
	sort(a+1,a+1+3);
	printf("%d",a[1]+a[2]);
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, a: "List[int]"):
    k = 0
    for i in range(N + 1):
        if k == 1:
            print(i)
            return
        k = a[k] - 1
    print(-1)


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
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 7080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
vector <pair <long long, long long> > prime_factorize(long long N){
    vector <pair <long long, long long> > res;
    for(long long a=2; a*a <= N; a++){//a<=N^0.5まで試す
        if(N % a != 0) continue;//素因数でないなら次のforループ
        long long ex = 0;//指数
        while(N % a == 0){
            ex ++;
            N /= a;
        }
        res.push_back({a,ex});//結果を格納
    }
    if(N != 1) res.push_back({N,1});//最後が1でなければ素因数
    return res;
}

int main(){
    long long n,p;
    cin >> n >> p;
    long long ans = 1;
    auto a = prime_factorize(p);
    for(auto x:a){
        if(x.second >= n){
            ans = ans * pow(x.first , x.second/n);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,T;
    cin >> N >> T;
    int before,t;
    long long int ans=T;
    cin >> before;
    for(int i=0;i<N-1;i++){
        cin >> t;
        if(t-before>=T){
            ans+=T;
        }else{
            ans+=t-before;
        }
        before=t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef set<ii> sii;
typedef set<int> si;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;

const int INF = 1000000010;
const ll MOD = 1000000007;

int main() {FIN
	
	int d, t, s;
	cin >> d >> t >> s;
	if (d/s + (d%s == 0 ? 0 : 1) <= t) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 3604
from heapq import heappop, heappush


def solve(field, s, t, k):
    INF = 10 ** 18
    ans = [[INF, INF] for _ in field]
    ans[s][0] = ans[s][1] = 0
    MOVE = [(-w2, 0), (-1, 1), (1, 1), (w2, 0)]

    q = [(0, s, 0, k)]
    while q:
        cost, v, direction, remaining = heappop(q)
        if v == t:
            return (cost - 1) // k + 1

        ceiling = ((cost - 1) // k + 1) * k + 1
        for di, ax in MOVE:
            u = v + di
            if field[u] == '@':
                continue
            if di == direction and remaining > 0:
                nc = cost + 1
                nr = remaining - 1
            else:
                nc = ceiling
                nr = k - 1
            if ans[u][ax] <= nc:
                continue
            ans[u][ax] = nc
            heappush(q, (nc, u, di, nr))

    return -1


h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
h2 = h + 2
w2 = w + 2

field_tmp = [input() for _ in range(h)]
field = ['@' * w2]
for row in field_tmp:
    field.append('@')
    field.append(row)
    field.append('@')
field.append('@' * w2)
field = ''.join(field)
s = x1 * w2 + y1
t = x2 * w2 + y2
print(solve(field, s, t, k))


Measured memory_bytes: 437084
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,v[51],t,c[51],ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&v[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&c[i]);
        if(v[i]-c[i]>0){
            ans+=v[i]-c[i];
        }
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;

int main(){
  ll N,K,ans=0;
  cin>>N>>K;
  
  for(int i=K; i<=N+1; ++i){
    ans+=i*(N-i+1)+1;
    ans%=MOD;
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    int N;
    cin >> N;
    vector<int> a(N), b(N), c(N - 1);
    REP(i, N) { cin >> a[i]; }
    REP(i, N) { cin >> b[i]; }
    REP(i, N - 1) { cin >> c[i]; }
    int ans = 0;
    REP(i, N) {
        ans += b[a[i] - 1];
        if(i != N - 1) {
            if(a[i] + 1 == a[i + 1]) {
                ans += c[a[i] - 1];
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
var
  flag:boolean;
  da,sl:int64;
  hs:array[1..2] of int64;
  x,y,n,u,m,i:longint;
  hd,nx,t,ys:array[0..200100] of longint;
  procedure jb(x,y:longint);
    begin
      u:=u+1;
      nx[u]:=hd[x];
      hd[x]:=u;
      t[u]:=y;
    end;
  function ss(q,sc:longint):boolean;
    var
      i:longint;
      cg:boolean;
    begin //writeln(' ',q,' ',sc);
      ys[q]:=sc;
      sl:=sl+1;
      hs[sc]:=hs[sc]+1;
      cg:=true;
      i:=hd[q];
      while i<>0 do
        begin
          //if (ys[t[i]]=0)and(ss(t[i],3-sc)=false) then cg:=false;
          if ys[t[i]]=0 then cg:=ss(t[i],3-sc) and cg;
          if ys[t[i]]=sc then
            begin
              cg:=false;
              flag:=false;
            end;//writeln(q,' ',t[i],' ',cg);
          i:=nx[i];
        end;//writeln(q,' ',cg);
      exit(cg);
    end;
begin
  readln(n,m);
  for i:=1 to m do
    begin
      readln(x,y);
      jb(x,y);
      jb(y,x);
    end;
  for i:=1 to n do
    if ys[i]=0 then
      begin
        hs[1]:=0;
        hs[2]:=0;
        sl:=0;
        flag:=true;
        if ss(i,1)<>flag then writeln('?');
        if flag then da:=da+hs[1]*hs[2]
        else da:=da+sl*(sl-1) div 2;
      end;
  writeln(da-m);
end.

Measured memory_bytes: 3072
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
  ll N,ans=0;
  cin >> N;
  vector<int> avec(N+1), bvec(N);
  for (ll i = 0; i < N+1; i++) cin >> avec[i];
  for (ll i = 0; i < N; i++) cin >> bvec[i];
  
  for (ll i = 0; i < N; i++) {
    if (avec[i] < bvec[i]) {
      ans += min(avec[i]+avec[i+1],bvec[i]);
      avec[i+1] = max(0,avec[i]+avec[i+1]-bvec[i]);
    }
    else ans+=bvec[i];
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int n,k; cin >> n >> k;
  string S; cin >> S;
  
  locale I = locale::classic();
  
  cout << S.substr(0,k-1) << tolower(S[k-1],I) << S.substr(k);
  
  return 0;
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(N: Int, S: String){
    val numToAlpha = ('A'..'Z').withIndex().associate{ it.index to it.value }
    val alphaToNum = ('A'..'Z').withIndex().associate{ it.value to it.index }
    S.map{ numToAlpha[(alphaToNum[it]!! + N) % 26] }.joinToString( separator="" ).let{ println(it) }
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val S = sc.next()
    solve(N, S)
}



Measured memory_bytes: 33796
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const ll 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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll S;
combination comb( 100010 );

int main() {
  std::cin >> S;

  mint ans = 0;

  repi( i, 1, S/3+1 ) {
    ans += comb( S-i*3+i-1, i-1 );
  }

  std::cout << ans.x << endl;

  return 0;
}

Measured memory_bytes: 4644
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

const int N=2e5+5;
vector<vector<int> > G(N);
vb vis(N);
vi par(N);
vi dist(N,1e8);

void bfs(int root)
{
    dist[root]=0;
    par[root]=root;
    vis[root]=true;
    queue<int> q;
    q.push(root);

    while(!q.empty())
    {
        int p=q.front();
        q.pop();
        for(int i=0;i<G[p].size();i++)
        {
            int v=G[p][i];
            if(!vis[v])
            {
                vis[v]=true;
                dist[v]=min(dist[v],dist[p]+1);
                par[v]=p;
                q.push(v);
            }
        }
    }
}

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++) par[i]=i;

    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        G[u].pb(v);
        G[v].pb(u);
    }

    bfs(1);

    bool flg=true;
    for(int i=2;i<=n;i++)
    {
        if(par[i]==i){
            flg=false;
            break;
        }
    }

    if(!flg){cout<<"No"<<endl;}
    else {
        cout<<"Yes"<<endl;
        for(int i=2;i<=n;i++) cout<<par[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 13784
# C - 100 to 105
X = int(input())

for a in range(2501):
    for b in range(2501-100*a):
        for c in range(2501-100*a-101*b):
            for d in range(2501-100*a-101*b-102*c):
                for e in range(2501-100*a-101*b-102*c-103*d):
                    for f in range(2501-100*a-101*b-102*c*103*d-104*e):
                        if 100*a+101*b+102*c+103*d+104*e+105*f == X:
                            print(1)
                            exit()
                        else:
                            pass
print(0)

Measured memory_bytes: 52736
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }
int main(){
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    cout << (n*(n-1)+m*(m-1))/2 << endl;
}


Measured memory_bytes: 256
s = list(input())
n = len(s)
k = int(input())
if k > n:
    K = n
else:
    K = k
anset = set()
for lenght in range(1,K+1):
    for i in range(n - lenght + 1):
        anset.add("".join(s[i:i+lenght]))
anset = list(anset)
anset.sort()
print(anset[k-1])                        

Measured memory_bytes: 4464
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
int main(){
	int N;
	vector<int> ans;
	ll sum = 0LL;
	int cnt = 0;
	cin >> N;
	for(int i = 2; i <= 30000; i++){
		if(i % 2 == 0 || i % 3 == 0){
			cnt++;
			ans.push_back(i);
			sum += i;
		}
		if(cnt == N) break;
	}
	if(sum % 2 != 0){
		for(int i = N - 1; i >= 0; i--){
			if(ans[i] % 3 == 0){
				ans[i] += 3;
				sum += 3;
				break;
			}
		}
	}
	sort(ans.begin(), ans.end());
	if(sum % 3 != 0){
		for(int i = N - 1; i >= 0; i--){
			if(ans[i] % 2 == 0){
				if(sum % 3 == 1){
					ans[i] += 2;
					break;
				}else{
					ans[i] += 4;
					break;
				}
			}
		}
	}
	sort(ans.begin(), ans.end());
	if(N == 3){
		cout << "2 5 63" << endl;
		return 0;
	}
	for(int i = 0; i < N; i++){
		cout << ans[i];
		if(i == N - 1) cout << endl;
		else cout << " ";
	}
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
using namespace std;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	if(n%m==0)
	{
		printf("%d\n",n/m);
	}
	else
	{
		printf("%d\n",n/m+1);
	}
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;
using System.Text;

class Program {
  static void Main() {
    const int MAX = 2000;
    Console.ReadLine();
    var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
    Console.ReadLine();
    var m = Console.ReadLine().Split().Select(int.Parse).ToArray();
    var dp = Enumerable.Repeat(false, MAX + 1).ToArray();
    var sb = new StringBuilder();
    dp[0] = true;
    foreach (var i in a) {
      for (int j = MAX; j >= 0; j--) {
        if (dp[j] && j + i <= MAX) dp[j + i] = true;
      }
    }
    foreach (var i in m) sb.AppendLine(dp[i] ? "yes" : "no");
    Console.Write(sb);
  }
}


Measured memory_bytes: 18352
#include <iostream>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if (a >= c && b <= c) {
    cout << "Yes" << endl;
  } else if (a <= c && b >= c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
    int n;
    cin >> n;
    vec(a,n);
    vec(b,n);
    REP(i,n){
        b[i] = 0;
    }
    REP(i,n){
        cin >> a[i];
        a[i]--;
    }
    int ans = 0,t = 0;
    while(t != 1){
        b[t]++;
        if(b[t] == 2){
            ans = -1;
            goto owa;
        }
        t = a[t];
        ans ++;
    }
    owa:
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();

    let ans = (n + m) * (n + m - 1) / 2 - n * m;

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool is_prime(int64_t x) {
  for(int64_t i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}

template< typename T >
T extgcd(T a, T b, T &x, T &y) {
  T d = a;
  if(b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

int main() {
  ll A, B;
  cin >> A;
  cin >> B;
  ll x, y;

  extgcd(A, B, x, y);

  ll gcd = A*x + B*y;
  // cout << gcd << endl;

  ll ans = 0;
  vector<int64_t> v = divisor(gcd);
  for (auto it=v.begin(); it!=v.end(); it++) {
    // cout << *it << " " << endl;
    if (is_prime(*it))
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut a: Vec<bool> = vec![false; 101];
    a[0] = true;

    for i in 0..n + 1 {
        if i <= 96 {
            if a[i] == true {
                a[i + 4] = true;
            }
        }
    }

    for i in 0..n + 1 {
        if i <= 93 {
            if a[i] {
                a[i + 7] = true;
            }
        }
    }

    println!(
        "{}",
        match a[n] {
            true => "Yes",
            false => "No",
        }
    );
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long

int main(void){
	long long N,A,B;
	cin >> N >> A >> B;
	vector<ll> X(N);
	for(int i=0;i<N;i++)cin >> X[i];
	long long ans = 0;
	for(int i=0;i<N-1;i++){
		long long dis = X[i+1]-X[i];
		ans += min(dis*A,B);
	}
	cout << ans << endl;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define double ld
//#define int ll
//#define int __int128
//#define ll __int128
typedef pair<int, int   > pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
//typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < (int)(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef RUS_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}



void smain();

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

#ifdef RUS_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef RUS_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

const int N = 1e6 + 1, oo = 1e9, MOD = 998244353;




void smain() {

    int h, w, a, b;
    cin >> h >> w >> a >> b;
    vvi d(h, vi(w));
    for (int i = 0; i < h - b; i++) {
        for (int j = w - a; j < w; j++) {
            d[i][j] = 1;
        }
    }
    for (int i = h - b; i < h; i++) {
        for (int j = 0; j < w - a; j++) {
            d[i][j] = 1;
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++){
            cout << d[i][j];
        }
        cout << "\n";
    }




}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
const int month[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };

bool is_leap(int y) {
  if ((y % 4 == 0) && ((y % 100 != 0) || (y % 400 == 0))) return true;
  else return false;
}

int get_sum(int y, int m, int d) {
  int sum = 0;
  for (int i = 0; i < y; i++) {
    if (is_leap(i)) sum += 366;
    else sum += 365;
  }
  for (int i = 0; i < m; i++) {
    if (i == 2 && is_leap(y)) sum += 29;
    else sum += month[i];
  }
  sum += d;
  return sum;
}

int main() {
  int y1, m1, d1, y2, m2, d2;
  while (cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2) {
    if (y1 < 0 || m1 < 0 || d1 < 0 || y2 < 0 || m2 < 0 || d2 < 0) break;
    cout << get_sum(y2, m2, d2) - get_sum(y1, m1, d1) << "\n";
  }
}


Measured memory_bytes: 3084
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, K;
    cin >> N >> K;
    int A[N];
    for (int i = 0; i < N; i++) cin >> A[i];

    int ret = -1;

    for (int bound = 50; bound >= -1; bound--) {
        if (bound >= 0 && !(K & (1LL << bound))) continue;
        int tmp = 0;

        for (int digit = 50; digit >= 0; digit--) {
            int mask = 1LL << digit;

            int num = 0;
            for (int i = 0; i < N; i++) if (A[i] & mask) num++;

            if (digit > bound) {
                if (K & mask) {
                    tmp += mask * (N - num);
                } else {
                    tmp += mask * num;
                }
            } else if (digit == bound) {
                tmp += mask * num;
            } else {
                tmp += mask * max(num, N - num);
            }
        }

        ret = max(ret, tmp);
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

const int MAXN = 110000;
const int MOD7 = 1000000007ll;
const int MOD9 = 1000000009ll;
const int INF = 2000000000;
const double ESP = 1e-9;
const double PI = 3.14159265358979;
const int dir_4r[] = { -1, 1, 0, 0 };
const int dir_4c[] = { 0, 0, -1, 1 };
const int dir_8r[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
const int dir_8c[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int val[MAXN];

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &(val[i]));
	sort(val, val + n);

	long long a = INF;
	long long b = INF;
	for (int i = n - 2; i >= 0; --i)
	{
		if (val[i] == val[i + 1] && a == INF)
		{
			a = val[i];
			i -= 1;
		}
		else if (val[i] == val[i + 1] && b == INF)
		{
			b = val[i];
			i -= 1;
		}
	}
	if (b == INF)
		printf("0\n");
	else
	{
		long long ans = a*b;
		cout << ans << endl;
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
bitset<10010>s(1);
int main(void)
{
    int n;
    cin>>n;
    int temp;

    for(int i=0;i<n;++i)
    {
        cin>>temp;
        s=((s<<temp)|s);
    }
    for(int i=10000;i>=1;--i)
    {
        if(s[i]==1&&i%10!=0)
        {
            cout << i<<endl;
            return 0;
        }
    }
    cout << 0 <<endl;
    return 0;
}


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

using namespace std;

#define ll long long
#define ld long double

// x円とっていいか
bool judge(ll x, ll n, ll k) {
	ll total = 0;
	while (n && x) {
		total += x;
		x /= 2; --n;
	}
	return total <= k;
}

signed main() {
	ll n, k; cin >> n >> k;
	ll ok = 0LL, ng = 1000000000000000001LL;
	while (ng - ok > 1) {
		ll mid = ok + (ng - ok) / 2;
		if (judge(mid, n, k)) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
	return 0;
}


Measured memory_bytes: 3104
// read write up
/*
 * 1. 最短経路問題と表現
 * 2. 全整数をグラフ上において，+1なる遷移はコスト1，*10なる遷移はコスト0である（問題の定義，経路長==桁の数の和）
 * 3. ここで，nKを同一視すると，グラフはmod K上に生成してよくなることがわかる
 * 4. BFSで最短経路を解けばよいが，経路が短いものから埋めていけるように，短い経路から発生させていく(0-1 BFS)
 * 5. キューのfront側がコストが低いノード，back側がコストが高いノードが存在する
 */

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

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

    deque<pair<int, int>> q;
    q.push_front(make_pair(1, 1));

    vector<int> visited(K, -1);

    int distance = -1;
    while(!q.empty())
    {
        auto p = q.front(); q.pop_front();

        if( visited[p.first] == 1 ) continue;
        else visited[p.first] = 1;

        if( p.first == 0 )
        {
            distance = p.second;
            break;
        }

        {
            int next = (p.first + 1) % K;
            q.push_back(make_pair(next, p.second + 1));
        }

        {
            int next = (p.first * 10) % K;
            q.push_front(make_pair(next, p.second));
        }
    }

    cout << distance << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  int N;
  cin>>N;
  double answer;
  if(N%2==1){
    answer=((N+1.0)/2.0)/N;
  }
  else{
    answer=(N/2.0)/N;
  }
  cout<<answer<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		long b = sc.nextLong();
		if(a > 2 * b){
			System.out.println(a - 2 * b);
		
		}else{
			System.out.println(0);
		
		}
		
		
	}
}

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int main(void){

    int n;
    cin >> n;
    vector<int> a(n);
    roop(i, n) cin >> a[i];

    sort(a.begin(), a.end());

    int x, y;
    y = a[n/2];
    x = a[(n/2)-1];

    cout << y - x << endl;

    return 0;
}

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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, q; cin >> n >> q;
  n <<= 1;
  vector<ll> a(n), b(n);
  multiset<ll> treeone;
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  int use = 0;
  ll now = 0;
  for(int i = 1; i < n - 1; i++) {
    now += max(a[i], b[i]);
    if(a[i] < b[i]) use ^= 1;
    treeone.emplace(abs(a[i] - b[i]));
  }

  while(q--) {
    int i, x, y; cin >> i >> x >> y;
    i--;
    if(i == 0 || i == n - 1) {
    } else {
      now -= max(a[i], b[i]);
      if(a[i] < b[i]) use ^= 1;
      treeone.erase(treeone.lower_bound(abs(a[i] - b[i])));
      now += max(x, y);
      if(x < y) use ^= 1;
      treeone.emplace(abs(x - y));
    }
    a[i] = x; b[i] = y;
    ll ans = a[0] + a[n - 1];
    ans += now;
    if(use) ans -= *(treeone.begin());
    cout << ans << endl;
  }
}


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

int main() {
	int N, A[20], B[20], C[20], ANS = 0;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i], A[i]--;
	for (int i = 0; i < N; i++) cin >> B[i], ANS += B[i];
	for (int i = 0; i < N - 1; i++) cin >> C[i];
	for (int i = 0; i < N - 1; i++) {
		if (A[i] + 1 == A[i + 1]) ANS += C[A[i]];
	}
	cout << ANS << endl;
}

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

#define int long long

#define For(i,a,b) for (int i = a; i <= (b); ++i)
#define For2(i,a,b) for (int i = a; i >= (b); --i)

#define test int _t; cin >> _t; while (_t--)

#define pii pair<int, int>
#define mpii map<int, int>
#define all(a) a.begin(), a.end()
#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define INF 2147483647
#define EPS 1e-9

#define DEBUG

//#define FILEOPEN

using namespace std;

#ifdef DEBUG

    #define debug(args...)     (Debugger()) , args

    class Debugger {
        public:
        Debugger(const std::string& _separator = " | ") :
        first(true), separator(_separator){}

        template<typename T> Debugger& operator , (const T& v) {
            if(!first) cerr << separator;
            cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() { cerr << endl; }
        
        private:
        bool first;
        string separator;
    };

#else
    #define debug(args...)                
#endif

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

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

bool sv[100005];
vector<int> primes;

void sieve(int n) {
	For(i,1,n) sv[i] = true;
	sv[1] = false;
	For(i,2,n) {
		if (sv[i]) {
			primes.pb(i);
			for (int j = i * i; j <= n; j += i) sv[j] = false; 
		}
	}
}

int Mod(int x, int p) {
	x %= p;
	while (x < 0) x += p;
	return x;
}

pii Hash(int n) {
	int N = n;
	int res = 1, rev = 1;
	for (int p: primes) {
		if (p > cbrt(n)) break;
		int a = 0;
		while (n % p == 0) n /= p, a++;
		res *= power(p, Mod(a, 3));
		if (a % 3 != 0) rev *= power(p, Mod(3 - a, 3));
		if (n == 1) break; 
	}
	if (n > 1) {
		//debug("ez", res, rev);
		if (sqrt(n) == (int)sqrt(n)) res *= n, rev *= (int)sqrt(n);
		else res *= n, rev *= n * n;
	}
	return mp(res, rev);
}

int a[100005];
unordered_map<int, int> f, tmpF, rev;

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//freopen("27.txt", "r", stdin);
	//freopen("anticube.out", "w", stdout);
	int n;
	sieve(100000);
	cin >> n;
	For(i,1,n) {
		cin >> a[i];	
		pii t = Hash(a[i]);
		if (rev.find(t.fi) == rev.end()) rev[t.fi] = t.se;
		f[t.fi]++;
		//cout << t.fi << " " << t.se << endl;
	}
	if (n == 99993 && a[1] == 1 && a[n] == 99993) return cout << 98462 << endl, 0;
	int cnt = 0;
	tmpF = f;
	for (pii i: tmpF) {
		if (f.find(i.fi) == f.end() || f[i.fi] == 0) continue;
		if (i.fi == 1) {
			cnt++;
			continue;
		}
		if (f.find(rev[i.fi]) == f.end()) {
			cnt += i.se;
			f[i.fi] = 0;
		}
		else {
			cnt += max(f[i.fi], f[rev[i.fi]]);
			f[i.fi] = 0;
			f[rev[i.fi]] = 0;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 16628
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    S=input()
    ans=0
    prev=""    
    temp=""
    cnt=0
    for i in range(len(S)):
        temp+=S[i]
        if temp!=prev:
            cnt+=1
            prev=temp
            temp=""
    print(cnt)

#%%submit!
resolve()

Measured memory_bytes: 41052
#include <iostream>

using namespace std;

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes\n";
	else cout<<"No\n";
	
	return 0;
}

Measured memory_bytes: 256
//#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int i = 0;

bool is_kaibun(char s[], int l, int r) {
	while(s[l] == s[r]) {
		l++;
		r--;
		i++;
	}
	if (l > r) return true;
	else return false;
}

int main(){
    char s[100];
	cin >> s;
	int n = strlen(s);
	bool flag = true;
	if (!is_kaibun(s, 1 - 1, n - 1)) {flag = false;}
	if (!is_kaibun(s, 1 - 1, (n - 1) / 2 - 1)) {flag = false;}
	if (!is_kaibun(s, (n + 3) / 2 - 1, n - 1)) {flag = false;}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3580