akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  ll a, b;
  int k;
  cin >> a >> b >> k;
  set<ll> s;
  for(ll i = a; i < a+k; i++){
    if(i > b)continue;
    s.insert(i);
  }
  for(ll i = b-k+1; i <= b; i++){
    if(i < a)continue;
    s.insert(i);
  }
  for(auto itr = s.begin(); itr != s.end(); itr++){
    cout << *itr << endl;
  }
  system("pause");
}


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

int main(void){
    // Your code here!
    long long n;
    long long a[100000] = {};
    long long yojo = 0;
    long long num_type = 0;
    
    cin >> n;
    for(int i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        a[temp-1]++;
    }
    
    for(int i = 0; i < 100000; i++){
        if(a[i] > 0){
            num_type++;
            if(a[i] > 1)
                yojo += a[i] - 1;
        }
    }
    
    if(yojo % 2 == 0)
        cout << num_type << endl;
    else
        cout << num_type - 1 << endl;
    
    return 0;
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  cout << max(0,c-a+b) << endl;
  return 0;
}


Measured memory_bytes: 3584
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)*}
    };
}

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, 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")
    };
}

fn main() {
    input! {
        n: f64,
    }
    let p = (n - (n / 2.0).floor()) / n;
    println!("{}", p);

}


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

int main(){
	int n;cin >> n;
	vector<int> s(n);
	for(int i=0;i<n;i++){
		cin >> s[i];
	}
	vector<pair<int,int>> prime;
	for(int i=1;i<=sqrt(n);i++){
		if(n%i==0){
			prime.emplace_back(make_pair(n/i,i));
			prime.emplace_back(make_pair(i,n/i));
		}
	}
	int answer = 0;
	for(int unsigned i = 0;i<prime.size();i++){
		bool ans = true;
		for(int j=0;j<n;j++){
			if(s[j] != s[j%prime[i].first]) ans = false;
		}
		if(ans){
			if(answer < prime[i].second){
				answer = prime[i].second;
			}
		}
	}
	cout << answer << endl;
	return 0;
}

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

int N, M, arr[100002]; ll ans = 0;
priority_queue<ll, vector<ll>> nums;
int main(){
    scanf("%d %d", &N, &M);
    for (int i = 0; i < N; i++){ ll x;scanf("%lld", &x); nums.push(x); ans += x;}
    for (int i = 0; i < M; i++) {
        int tp = nums.top();
        int hf = tp/2;
        ans = ans - tp + hf;
        nums.pop();nums.push(hf);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 2e9;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  sort(a.begin(), a.end());
  vector<ll> sgn(3);
  sgn[0] = lower_bound(a.begin(), a.end(), (ll)0) - a.begin();
  sgn[1] = upper_bound(a.begin(), a.end(), (ll)0) - lower_bound(a.begin(), a.end(), (ll)0);
  sgn[2] = a.end() - upper_bound(a.begin(), a.end(), (ll)0);
  vector<ll> cnt(3);
  cnt[0] = sgn[0] * sgn[2];
  cnt[2] = sgn[0] * (sgn[0] - 1) / 2 + sgn[2] * (sgn[2] - 1) / 2;
  cnt[1] = n * (n - 1) / 2 - cnt[0] - cnt[2];
  if (cnt[0] >= k) {
    vector<ll> aneg(sgn[0]), apos(sgn[2]);
    rep(i, sgn[0]) aneg[i] = -a[sgn[0] - 1 - i];
    rep(i, sgn[2]) apos[i] = a[i + sgn[0] + sgn[1]];
    ll l = 0, r = INF;
    while (r - l > 1) {
      ll m = (l + r) / 2, res = cnt[0];
      rep(i, sgn[0]) {
        ll d = m / aneg[i];
        res -= upper_bound(apos.begin(), apos.end(), d) - apos.begin();
      }
      if (res >= k) l = m;
      else r = m;
    }
    cout << -r << endl;
  }
  else if (cnt[0] < k && cnt[0] + cnt[1] >= k) {
    cout << 0 << endl;
  }
  else {
    vector<ll> aneg(sgn[0]), apos(sgn[2]);
    rep(i, sgn[0]) aneg[i] = -a[sgn[0] - 1 - i];
    rep(i, sgn[2]) apos[i] = a[i + sgn[0] + sgn[1]];
    ll l = 0, r = INF;
    while (r - l > 1) {
      ll m = (l + r) / 2, res = cnt[0] + cnt[1];
      rep(i, sgn[0]) {
        ll d = m / aneg[i];
        ll now = upper_bound(aneg.begin(), aneg.end(), d) - aneg.begin() - i;
        if (d >= aneg[i]) now--;
        if (now > 0) res += now;
      }
      rep(i, sgn[2]) {
        ll d = m / apos[i];
        ll now = upper_bound(apos.begin(), apos.end(), d) - apos.begin() - i;
        if (d >= apos[i]) now--;
        if (now > 0) res += now;
      }
      if (res >= k) r = m;
      else l = m;
    }
    cout << r << endl;
  }




  
  return 0;
}

Measured memory_bytes: 3200
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<bitset>
#include<complex>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
using namespace std;
int n,m,d[100005],tot;
vector<int> a[100005];
void bfs();
queue<int> q;
int main()
{
	cin>>n>>m;
	for (int i=1;i<=m;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	bfs();
	return 0;
}
void bfs()
{
	d[1]=1;
	q.push(1);
	while (!q.empty() && tot<n)
	{
		int tmp=q.front();
		q.pop();
		++tot;
		for (int i=0;i<(int)a[tmp].size();++i)
		{
			if (d[a[tmp][i]]!=0) continue;
			d[a[tmp][i]]=tmp;
			q.push(a[tmp][i]);
		}
	}
	if (tot==n)
	{
		cout<<"Yes\n";
		for (int i=2;i<=n;++i)
			printf("%d\n",d[i]);
		return;
	}
	else cout<<"No";
}

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

int main(){
  int A,B;
  int res = 0;
  cin >> A >> B;
  if(A >= 13){
    res = B;
  }else if(6 <= A && A <= 12){
    res = B/2;
  }
  
  cout << res << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    ll ans=0;
    if (m1!=m2){
        ans = 1;
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <iostream>

typedef long long ll;
const ll MOD = 1e9 + 7;

int main()
{
  ll N;
  std::cin >> N;

  ll ans = 1;
  for (ll i = 1; i <= N; i++) {
    ans = (ans * i) % MOD;
  }

  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

struct I
{
	int l,r,v;
	I(int l, int r, int v) : l(l),r(r),v(v) {}
	double f(double t) {
		if(t>r) return v+t-r;
		if(t<l) return v+l-t;
		return v;
	}
};

signed main() {
	int n;
	std::cin >> n;
	std::vector<I> c;
	int tl=0;
	{
		std::vector<int> t(n),v(n);
		rep(i,n) std::cin >> t[i];
		rep(i,n) std::cin >> v[i];
		c.emplace_back(0,0,0);
		rep(i,n) {
			c.emplace_back(tl,t[i]+tl,v[i]);
			tl+=t[i];
		}
		c.emplace_back(tl,tl,0);
	}
	debug(tl);
	double sum=0;
	for(int ct2=0;ct2<tl*2;ct2++) {
		double ct=ct2*(double)0.5;
		double dt=0.5;
		double min0=1e9,min1=1e9;
		for(auto x:c) {
			min0=std::min(min0,x.f(ct));
			min1=std::min(min1,x.f(ct+dt));
		}
		sum+=(min0+min1)*dt*(double)0.5;
	}
	std::cout << std::setprecision(10) << sum << EL;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int InDegree[100005] , OutDegree[100005];
int Count[100005] , Parents[100005];
set<int> S[100005] , Leaves[2];
set<int>::iterator it , Fit;
map<int,int> M;
map<int,int>::iterator Mit;

int main(){
    int N , m , u , v , i;
    scanf( "%d%d" , &N , &m );

    for( i = 1 ; i <= N - 1 + m ; ++i ){
        scanf( "%d%d" , &u , &v );
        S[v].insert( u );
        ++InDegree[v];
        ++OutDegree[u];
    }

    int root;

    for( i = 1 ; i <= N ; ++i ){
        if( OutDegree[i] == 0 ){
            Leaves[0].insert( i );
            Count[i] = 0;

            for( it = S[i].begin() ; it != S[i].end() ; ++it ){
                Mit = M.find( *it );
                if( Mit == M.end() ) M[*it] = 1;
                else ++Mit->second;
            }
        }
        if( InDegree[i] == 0 ) root = i;
    }

    int Cur , Pre;
    i = 1;

    while( true ){
        Cur = (i&1);
        Pre = (i - 1)&1;

        for( Mit = M.begin() ; Mit != M.end() ; ++Mit ){
            OutDegree[Mit->first] -= Mit->second;
            
            if( OutDegree[Mit->first] == 0 ){ 
                Leaves[Cur].insert( Mit->first );
                Count[Mit->first] = i;
            }
        }

        if( *( Leaves[Cur].begin() ) == root ){
            Parents[root] = 0;
            break;
        }

        Leaves[Pre].clear();
        M.clear();

        for( it = Leaves[Cur].begin() ; it != Leaves[Cur].end() ; ++it ){
            u = *it;

            for( Fit = S[u].begin() ; Fit != S[u].end() ; ++Fit ){
                Mit = M.find( *Fit );
                if( Mit == M.end() ) M[*Fit] = 1;
                else ++Mit->second;
            }
        }

        ++i;
    }

    int Min , index;

    for( i = 1 ; i <= N ; ++i ){
        Min = 10000000;
        index = 0;

        for( it = S[i].begin() ; it != S[i].end() ; ++it ){
            if( Count[*it] < Min ){
                Min = Count[*it];
                index = *it;
            }
        }

        Parents[i] = index;
    }

    for( i = 1 ; i <= N ; ++i )
        printf( "%d\n" , Parents[i] );
    return 0;
}

Measured memory_bytes: 16512
#![allow(unused_imports)]
use proconio::marker::*;
use proconio::{fastout, input};
use std::cmp::max;

#[fastout]
fn main() {
    input! {
        a: isize,
        b: isize,
        c: isize,
        d: isize,
    }

    let res = solve(a, b, c, d);
    println!("{}", res);
}

fn solve(a: isize, b: isize, c: isize, d: isize) -> isize {
    let plus = b * d;
    let minus = a * c;
    let ab = a * d;
    let cd = c * b;
    max(plus, max(minus, max(ab, cd)))
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

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

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	#ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
	#endif

	int n;
	cin >> n;
	int ans = 0, mn = inf;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		mn = min(mn, x);
		if(mn >= x) {
			ans++;
		}
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
	import java.util.Arrays;
	import java.util.HashMap;
	import java.util.HashSet;
	import java.util.List;
	import java.util.Map;
	import java.util.Scanner;
	import java.util.Set;

	public class Main{


		public static void main(String[] args) {

			Scanner scanner = new Scanner(System.in);

			String[] temp = scanner.nextLine().split(" ");
			int n  = Integer.parseInt(temp[0]);

			long[] list  = divisor(n);
			int cnt = 0;
			for(long value : list) {
				cnt += value == 8 ? 1 : 0;
			}

			System.out.println(cnt);

		}
		private static long[] divisor(long num) {
			int MAX   = (int)num;
			long[] cnt = new long[(MAX + 2)];

			cnt[1] = 1;
			for(int i = 3; i <= MAX; i++) cnt[i] = 2;
			for(int i=2; i<=MAX/2; i++) {
				for(int j = 2*i; j <= MAX; j += i) {cnt[j]++;}
			}

			for(int i = 0; i < MAX+2; i++) {
				if(i % 2 == 0) cnt[i] = 0;
			}
			return cnt;

		}
	}


Measured memory_bytes: 35636
#include<iostream>
#include<string>
using namespace std;
int main(){
long n,i;
string s;
string::size_type p;
cin>>n;
getline(cin,s);
for(i=0;i<n;i++){
getline(cin,s);
p=-1;
for(;;){
p=s.find("Hoshino",p+1);
if(p==string::npos)break;
s.replace(p,7,"Hoshina");
}
cout<<s<<endl;
}
return 0;
}

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

int main(){
	long long int n;
	cin>>n;
	string s="";
	long long int b=1,t=1;
	while(n-pow(26,t)>=b)
		b+=pow(26,t),t++;
	n-=b;
	while(t--){
		s.push_back((long long int)(n/pow(26,t))+'a');
		n%=(long long int)pow(26,t);
	}
	cout<<s<<'\n';
}

Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ii {
    ll a, b;
    bool operator < (ii o) const {
        return tie(a, b) < tie(o.a, o.b);
    }
};
struct iii {
    ll a, b, c;
    bool operator < (iii o) const {
        return tie(a, b, c) < tie(o.a, o.b, o.c);
    }
};

const ll MOD = 1000000007;
const ll INF = 1000000000;
const ll MAXN = 2000005;
const double EPS = 1e-6;

ll N;
ll arr[MAXN], fact[63][63];

ll cntDiv(ll n, ll div) {
    ll cnt = 0;
    while (n%div == 0) {
        n /= div;
        cnt++;
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> N;
    for (ll i = 0; i < N; i++) {
        double x;
        cin >> x;
        arr[i] = x*INF + 0.5;
    }
    
    for (ll i = 0; i < N; i++) {
        ll f2 = cntDiv(arr[i], 2);
        ll f5 = cntDiv(arr[i], 5);
        fact[f2][f5]++;
    }
    
    ll ans = 0;
    const ll MAX = 60;
    for (ll i = 0; i < MAX; i++) {
        for (ll j = 0; j < MAX; j++) {
            for (ll k = 0; k < MAX; k++) {
                for (ll l = 0; l < MAX; l++) {
                    if (i + k >= 18 && j + l >= 18 && make_pair(i, j) <= make_pair(k, l)) {
                        if (i == k && j == l) ans += fact[i][j] * (fact[i][j] - 1) / 2;
                        else ans += fact[i][j] * fact[k][l];
                    }
                }
            }
            //~ cerr << i << " " << j << " " << ans << "\n";
        }
    }
    cout << ans << "\n";
    
}


Measured memory_bytes: 5288
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

# 余りの平均が１のもの
N, K = getNM()
A = getList()
A = [(i % K) - 1 for i in A]

for i in range(N - 1):
    A[i + 1] += A[i]
A.insert(0, 0)
A = [i % K if i >= 0 else i for i in A]

num = defaultdict(list)
for i in range(N + 1):
    num[A[i]].append(i)

cnt = 0
for key, opt in num.items():
    for i in range(len(opt)):
        index = bisect_right(opt, opt[i] + K - 1)
        cnt += index - i - 1
print(cnt)

Measured memory_bytes: 160112
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll p = 1e9+7;
const int N = 1e5+20;

ll fac[N];

inline long long mpow(long long b, long long ex){
    if (b==1)return 1;
    long long r = 1;
    while (ex ){
        if (ex&1)r=(r * b)%p;
        ex = ex >> 1;
        b = (b * b)%p;}
    return r;
}

// Returns n^(-1) mod p
ll modInverse(ll n)
{
    return mpow(n, p-2);
}

// Returns nCr % p using Fermat's little
// theorem.
ll nCr(ll n, ll r)
{
   // Base case
   if (r==0 || n == r)
      return 1L;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    return (((fac[n]* modInverse(fac[r]))%p)*
            (modInverse(fac[n-r]) % p)) % p;
}

int main(){
    int n, k;
    cin>> n>> k;
    fac[0] = 1;
    for(int i = 1; i <=n; ++i){
        fac[i] = (fac[i-1]*i)%p;
    }
    ll a[n];
    for(int i = 0; i < n; ++i){
        cin>> a[i];
    }
    sort(a, a+n);
    ll ans = 0;
    for(ll i = k-1; i < n; ++i){
        ans += (nCr(i, k-1)*a[i])%p;
    }
    for(int i = 0; i < n; ++i){
        if(n - i < k){
            break;
        }
        ans -= (nCr(n-i-1, k-1)*a[i])%p;
        ans = (ans+p)%p;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int dp[3050][8000] = {};
int main() {
	long long int k;
	cin >> k;
	queue<long long int>q;
	vector<long long int>ans;
	q.push(1);
	q.push(2);
	q.push(3);
	q.push(4);
	q.push(5);
	q.push(6);
	q.push(7);
	q.push(8);
	q.push(9);
	while (ans.size() <=100000) {
		long long int now = q.front();
		long long int  c = now % 10;
		if (c == 0) {
			q.push(now * 10 + 1);
			q.push(now * 10);
		}
		else if (c == 9) {
			q.push(now * 10 + 8);
			q.push(now * 10 + 9);
		}
		else {
			q.push(now * 10 +c-1);
			q.push(now * 10 +c  );
			q.push(now * 10 +c+1);
		}
		ans.push_back(now);
		q.pop();
	}
	sort(ans.begin(), ans.end());
	cout << ans[k - 1];
}

Measured memory_bytes: 4596
#include<iostream>

using namespace std;

int main(){
  int n,a;
  cin >> n >> a;
  bool ans=false;
  for(int i=0;i<=a;i++){
    if((n-i)%500==0){
      ans=true;
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


sys.setrecursionlimit(1000000)
MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("Sample.txt")
    N, M, R = Scanner.map_int()
    r = Scanner.map_int()
    for i in range(R):
        r[i] -= 1
    G = [[] for _ in range(N)]
    d = [[INF for _ in range(N)]for _ in range(N)]
    for i in range(N):
        d[i][i] = 0
    for i in range(M):
        a, b, c = Scanner.map_int()
        a -= 1
        b -= 1
        G[a].append((b, c))
        G[b].append((a, c))
        d[a][b] = c
        d[b][a] = c
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    r.sort()
    ans = INF
    for v in itertools.permutations(r):
        now = 0
        for i in range(len(v)-1):
            now += d[v[i]][v[i+1]]
        ans = min(ans, now)
    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 45400
/*
11111111
00000110
00001100
00011000
00110000
01100000
*/
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
#define ll long long
#define F first
#define S second
#define debug(x); printf("debug%d\n",x);
#define rep(f,t) for(int i=f;i<=t;i++)
const int inf=0x3f3f3f3f;
using namespace std;
char s[110];
int main()
{
    scanf("%s",s+1);
    if(strlen(s+1)%2!=0)
        printf("No\n");
    else
    {
        int len=strlen(s+1);
        int flag=0;
        for(int i=1;i<=len-1;i+=2)
        {
            if(s[i]!='h'||s[i+1]!='i')
            {
                flag=1;
                break;
            }
        }
        if(flag)
            printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
int main(){
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    vector<int> num(100002);
    rep(i,num.size()) num[i]=0;
    rep(i,n) num[a[i]]++;
    sort(a.begin(),a.end());
    int ans=0;
    for(int i=1;i<=100000;i++){
        ans=max(ans,num[i-1]+num[i]+num[i+1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1152
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
using namespace std;

const vector<pair<
	pair<int,int>,
	vector<vector<int>>
>>pattern={
	{{13,3},{
		{0,0,1,0,0},
		{0,1,1,1,0},
		{1,1,1,1,1},
		{0,1,1,1,0},
		{0,0,1,0,0},
	}},
	{{9,2},{
		{1,1,1},
		{1,1,1},
		{1,1,1},
	}},
	{{5,1},{
		{0,1,0},
		{1,1,1},
		{0,1,0},
	}},
};

vector<vector<int>>m(10);
vector<pair<pair<int,int>,int>>v;
bool dfs(int pat,int y,int x,int N,int d,int s){
	if(d==N)return s==0;
	if(s<(N-d)*5 || (N-d)*pattern[pat].first.first<s)return false;
	for(;pat<pattern.size();pat++,y=x=0)if(pattern[pat].first.first<=s){
		for(;y<=10-pattern[pat].second.size();y++,x=0){
			for(;x<=10-pattern[pat].second[0].size();x++){
				for(int dy=0;dy<pattern[pat].second.size();dy++){
					for(int dx=0;dx<pattern[pat].second[0].size();dx++){
						if(m[y+dy][x+dx]<pattern[pat].second[dy][dx])goto fail;
					}
				}
				for(int dy=0;dy<pattern[pat].second.size();dy++){
					for(int dx=0;dx<pattern[pat].second[0].size();dx++){
						m[y+dy][x+dx]-=pattern[pat].second[dy][dx];
					}
				}
				v[d]=make_pair(
					make_pair(x+pattern[pat].second[0].size()/2,y+pattern[pat].second.size()/2),
					pattern[pat].first.second
				);
				if(dfs(pat,y,x,N,d+1,s-pattern[pat].first.first))return true;
				for(int dy=0;dy<pattern[pat].second.size();dy++){
					for(int dx=0;dx<pattern[pat].second[0].size();dx++){
						m[y+dy][x+dx]+=pattern[pat].second[dy][dx];
					}
				}
				fail:;
			}
		}
	}
	return false;
}

int main(){
	int N,y,x,s=0,z;
	scanf("%d",&N);
	for(y=0;y<10;y++){
		m[y].resize(10);
		for(x=0;x<10;x++)scanf("%d",&m[y][x]),s+=m[y][x];
	}
	v.resize(N);
	dfs(0,0,0,N,0,s);
	for(auto &e:v)printf("%d %d %d\n",e.first.first,e.first.second,e.second);
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
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 h,w;
char s[110][110];
int dp[110][110];
int INF =1<<15;

int main() {
  //入力
  cin >> h >> w;
  rep(i,h)rep(j,w) cin >> s[i][j];

  //dpテーブルの初期化
  rep(i,h)rep(j,w) dp[i][j]=INF;
  if (s[0][0]=='.') dp[0][0]=0;
  else dp[0][0]=1;

  //DPの遷移
  rep(i,h){
    rep(j,w){
      if(s[i][j]==s[i+1][j]){
        chmin(dp[i+1][j],dp[i][j]);
      }
      chmin(dp[i+1][j],dp[i][j]+1);
      if(s[i][j]==s[i][j+1]){
        chmin(dp[i][j+1],dp[i][j]);
      }
      chmin(dp[i][j+1],dp[i][j]+1);
    }
  }
  cout << (dp[h-1][w-1]+1)/2 << endl;
  return 0;

}



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

typedef long long int lli;


int main(void){
    // Here your code !
    lli n;
    cin >> n;
    
    map<int,int> a;
    
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        a[t]++;
    } 
    
    if( a.size() % 2){
        cout << a.size() << endl;
    }else{
        cout << a.size()-1 << endl;
    }
    
    
    
}


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

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

	string str;
	set<string> s;
	for (int i = 0; i < n; ++i)
	{
		cin>>str;
		s.insert(str);
	}
	cout<<s.size()<<endl;
	
	return 0;
}

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

auto gcd(long long int a, long long int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

auto lcm(long long int a,long long int b){
    long long int g=gcd(a,b);
    return a/g*b;
}

int main(){
    long long int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << (b-b/c-b/d+b/lcm(c,d))-(a-1-(a-1)/c-(a-1)/d+(a-1)/lcm(c,d)) <<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

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

N = i()
ans = 0
for i in range(1,N+1,2):
    if len(dv(i)) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 73052
#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
int main(){
    //vector<int>d(101);
    vector<int>d(110);
    int N;
    cin>>N;
    if(N==0){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0;i<N;i++){
        cin>>d[i];
    }
    sort(d.begin(),d.end());
    /*
     unique(d.begin(),d.end());
     int ans=0;
     for(int i=0;i<=100;i++){
     if(d[i]!=0){
     ans++;
     }
     }
     */
    d.erase(unique(d.begin(),d.end()),d.end());
    int ans=0;
    for(int i=0;i<d.size();i++){
        if(d[i]!=0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	int r = 0;
	for (int i = a; i <= b; i++)
	{
		int s = i % 10, t = i / 10000 % 10;
		int u = i / 10 % 10, v = i / 1000 % 10;
		if (s == t&&u == v)r++;
	}
	printf("%d\n", r);
}

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

int main() {
	int N;
	int L[200];
	int count = 0;
	cin >> N;
	for (int i = 0; i < 2 * N; i++) {
		cin >> L[i];
	}
	sort(L, L + 2 * N);
	for (int i = 0; i < N; i++) {
		count += L[i * 2];
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

string a[100];
string b[100];

int main(int argc, char* argv[])
{
    long n,m;
    scanf("%ld", &n);

    long i,j;
    for(i=0; i<n; i++) {
        char str[11]={0};
        scanf("%s", str);
        a[i]=string(str);
    }

    scanf("%ld", &m);
    for(i=0; i<m; i++) {
        char str[11]={0};
        scanf("%s", str);
        b[i]=string(str);
    }

    long ans=0;
    for(i=0; i<n; i++) {
        long count=0;
        for(j=0; j<n; j++) {
            if(a[i]==a[j]) {
                count++;
            }
        }
        for(j=0; j<m; j++) {
            if(a[i]==b[j]) {
                count--;
            }
        }
        ans=MAX(ans,count);
    }
    printf("%ld\n", ans);

    return 0;
}


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

'''
A = sorted([i-k-1 for k,i in enumerate(A)])
b = A[N//2]
print(sum(abs(i-b) for i in A))
'''
for i in range(N):
    A[i] = A[i]-i-1
A.sort()
b = A[N//2]
print(sum(list(map(lambda x:abs(x-b),A))))


Measured memory_bytes: 26708
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  int n, x = 0;
  cin >> n;
  for (int m = n; m; m /= 10) x += m % 10;
  cout << (n % x == 0 ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <math.h> 
#include <iomanip>
#include <string.h>
#include <vector>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define PI 3.14159265358979323846264338327950L


const int N = 2e5 + 5;

 
int vis[N];


int32_t  main() {

	IOS;

 
	long double a, b, h, m;

	cin >> a >> b >> h >> m;

	long double hdeg = h * 30;
	long double mdeg = m * 6;

	hdeg += mdeg / 12;
	 
	long double degree = abs(hdeg - mdeg);


	long double rad = (degree * PI) / 180;

	long double rsq = (long double)(a * a + b * b) - (long double)(2 * a *
		b) * cosl(rad);

	cout << fixed << showpoint << setprecision(20)<<  sqrt(rsq) << endl;

}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

ll gcd(ll x, ll y) {
	int r = 0;
	if (x < y) swap(x, y);
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll A, B, C, D;
	cin >> A >> B >> C >> D;
	ll c = B / C - (A - 1) / C;
	ll d = B / D - (A - 1) / D;
	ll cd = B / lcm(C , D) - (A - 1) / lcm(C , D);
	cout << B - A + 1 - c - d + cd << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque

c = deque(input())
n = int(input())
head = 1

for _ in range(n):
  now = list(input().split())
  if now[0] == "1":
    head *= -1
  else:
    if now[1] == "1":
      if head == 1:
        c.appendleft(now[2])
      else:
        c.append(now[2])
    else:
      if head == 1:
        c.append(now[2])
      else:
        c.appendleft(now[2])
print("".join(c) if head == 1 else "".join([c.pop() for _ in range(len(c))]))

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

public class Main {
	public void solve() throws IOException {
		long[][] dp = new long[5][4001];
		dp[0][0] = 1;
		for(int i = 1; i < 5; i++){
			for(int j = 0; j <= 4000; j++){
				if( dp[i-1][j] > 0 ){
					for(int k = 0; k <= 1000 && j+k <= 4000; k++){
						dp[i][j+k] += dp[i-1][j];
					}
				}
			}
		}
		while( stdIn.hasNext()  ){
			int n = stdIn.nextInt();
			writer.println(dp[4][n]);			
		}
		writer.flush();
	}

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	Scanner stdIn;
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	public void run() throws IOException {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			stdIn = new Scanner(reader);
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			stdIn.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
}

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

int main() {
	int N, Q;
	string S;

	cin >> N >> Q;
	cin >> S;

	vector<int> l(Q);
	vector<int> r(Q);

	for (int i = 0; i < Q; i++) cin >> l[i] >> r[i];

	vector<int> sum(N, 0);
	for (int i = 1; i < N; i++) {
		if (S[i] == 'C' && S[i-1] == 'A') {
			sum[i] = sum[i - 1] + 1;
		}
		else {
			sum[i] = sum[i - 1];
		}
	}
	
	for (int i = 0; i < Q; i++) {
		cout << sum[r[i] - 1] - sum[l[i] - 1] << endl;
	}
}

Measured memory_bytes: 2176
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;

int main() {
    ll N;
    cin>>N;
    ll A[N];
    map<ll, ll> amap, bmap;
    ll max1 = 0;
    map<ll, ll> cmap;
    vector<ll> carr;
    for(ll i=0;i<N;++i){
        cin>>A[i];
        if(cmap[i+A[i]]==0)carr.push_back(i+A[i]);
        cmap[i+A[i]]++;
        amap[i - A[i]]++;
        bmap[i + A[i]]++;
    }
    ll ans = 0;
    for(ll i=0;i<=carr.size();++i){
        ans += amap[carr[i]]*bmap[carr[i]];
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 52096
#include <stdio.h>


int main(void) {
	int n,x,i;
	int enp[200001];
	
	for(x=0;x<200001;x++)
		enp[x]=0;
	
	scanf("%d",&n);
	
	
	for(i=1;i<n;i++){
		scanf("%d",&x);
		enp[x]++;
	}

	for(x=1;x<=n;x++){
		printf("%d\n",enp[x]);
	}
	
	return 0;
}

Measured memory_bytes: 2512
def f(n, k):
  num_bit = 3 - bin(k).count('1')
  c = [0, 0, 1, 3]
  return 3**n - num_bit*2**n + c[num_bit]

# k = 0:(), 1:(3), 2(5), 3:(3, 5), 4:(7), 5:(3, 7), 6:(5, 7), 7:(3, 5, 7)
def solve(N, k=0):
  n = len(N)
  num_used = bin(k).count('1')
  if n==0 and num_used==3:
    return 1
  elif n==0 or n+num_used<3:
    return 0
  else:
    a = int(N[0])
    if a > 7:
      return f(n-1, k|1) + f(n-1, k|2) + f(n-1, k|4)
    elif a == 7:
      return f(n-1, k|2) + f(n-1, k|1) + solve(N[1:], k|4)
    elif a > 5:
      return f(n-1, k|2) + f(n-1, k|1)
    elif a == 5:
      return f(n-1, k|1) + solve(N[1:], k|2)
    elif a > 3:
      return f(n-1, k|1)
    elif a == 3:
      return solve(N[1:], k|1)
    else:
      return 0

N = input()
base = sum([f(i, 0) for i in range(3, len(N))])
print(solve(N) + base)

Measured memory_bytes: 3064
/**
 * @Author:      WeakestRookie
 * @Email:       1311053296@qq.com
 * @DateTime:    2019-05-19 20:21:12
 * @Description: Description 
 */
#include<bits/stdc++.h>
using namespace std;

#define rep(x, y, z) for(int x = y; x < z; ++x)
#define dwn(x, y, z) for(int x = y; x >= z;--x)
#define mst(a, b) memset(a, b, sizeof(a));
#define clr(a) mst(a, 0);
#define lbit(x) (x & (-x))
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;

const double PI = 3.1415926535898;
const double E = 2.718281828459;
const int INF = 0x7fffffff;
const int MOD = 1e9+7;
const int MAXN = 1e5+10;

double n,k;

int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    double ans=0;
    double pos = 1.0/n;
    if(n <= k) {
       for(int i = 1; i <= n; i++) {
           double y = k*1.0/i;
           int x = log(y)/log(2);
           if(pow(2,x) < y)
           	  x++;
           ans += pos*pow(0.5,x);
       }
    }else {
        for(int i = 1; i <= k; i++) {
           double y = k*1.0/i;
           int x = log(y)/log(2);
           if(pow(2,x) < y)
           	  x++;
           ans += pos*pow(0.5,x);
       }
       for(int i = k+1; i <= n; i++)
       	   ans += pos;
    }
    cout << fixed << setprecision(12) << ans << endl;
    //system("pause");
    return 0;
}


Measured memory_bytes: 640
"use strict";

const main = arg => {
    const N = arg.split("\n")[0];
    const powerOf = [1]; 
    
    for(let i=2; i<=32; i++) {
        let pow = 2;
        while(Math.pow(i, pow) <= N) {
            powerOf.push(Math.pow(i,pow));
            pow++;
        }
    }
    
    console.log(Math.max(...powerOf));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9420
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main () {

  int C[VMAX + 1];
  int n,i,j;
  scanf("%d",&n);
  int A[n+1], B[n+1];

  for (i=0;i<=VMAX;i++) C[i] = 0;
  for (i=0;i<n;i++) {
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }

  for (i=1;i<=VMAX;i++) C[i] = C[i] + C[i-1];

  for (j=1;j<=n;j++) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  
  for (j=1;j<=n;j++) {
    if (j > 1) printf(" ");
    printf("%d",B[j]);
  }
  printf("\n");
}



Measured memory_bytes: 17368
import sys

def solve(n):
    ii=0
    for s in str(n):
        ii += int(s)
    if n%ii==0:
        return "Yes"
    else:
        return "No"
    
def readQuestion():
    line = sys.stdin.readline().rstrip()
    return int(line)

def main():
    n = readQuestion()
    answer = solve(n)
    print(answer)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
N=readline.to_i
vs = readline.chomp.split.map(&:to_i)

evens = []
odds = []
(N/2).times do |i|
  evens << vs[i*2]
  odds << vs[i*2+1]
end

e_count = {}
o_count = {}
evens.each {|v| e_count[v] = e_count[v].to_i + 1 }
odds.each {|v| o_count[v] = o_count[v].to_i + 1 }
e_count = e_count.sort_by {|k,v| v }.reverse
o_count = o_count.sort_by {|k,v| v }.reverse

#pp e_count, o_count
if e_count[0][0] != o_count[0][0]
  puts N - (e_count[0][1] + o_count[0][1])
else
  e_count[1] = [nil,0] if e_count.size == 1
  o_count[1] = [nil,0] if o_count.size == 1
  if e_count[1][1] >= o_count[1][1]
    puts N - (e_count[1][1] + o_count[0][1])
  else
    puts N - (e_count[0][1] + o_count[1][1])
  end
end



Measured memory_bytes: 19848