akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ll a[n][3];
    for(int i=0;i<n;i++)for(int j=0;j<3;j++)cin>>a[i][j];
    ll dp[n][3];mset(dp);
    ll ans=0;
    for(int i=0;i<3;i++){dp[0][i]=a[0][i];ans=max(ans,dp[0][i]);}
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k)continue;
                dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
                if(i==n-1)ans=max(ans,dp[i][j]);
            }
        }
    }
    cout<<ans<<"\n";
}



Measured memory_bytes: 4992
<?php
fscanf(STDIN, "%d %d", $N, $K);
$fmt = '%d';
for ($i = 0; $i < $N; $i++) $fmt .= ' %d';
$p = fscanf(STDIN, $fmt);

$skips = Array();
$sum = 0;
for ($i = 0; $i < $K; $i++) {
  $min = 9999;
  $id = -1;
  for ($j = 0; $j < $N; $j++) {
    if ($p[$j] < $min) {
      if (! in_array($j, $skips, true)) {
        $min = $p[$j];
        $id = $j;
      }
    }
  }
  $sum += $min;
  $skips[] = $id;
}

echo $sum;


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

int main() {
string s,t,u;
int a, b;
cin >> s >> t >> a >> b >>u;
if(s == u)a--;
else b--;
cout << a << " " << b << endl;
return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

n = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = a.pop()
a = a[::-1]

if n % 2 == 0:
    n -= 1

    n -= 1
    ans += 2*sum(a[:n//2])

else:
    n -= 1

    n -= 1
    ans += 2*sum(a[:n//2]) + a[n//2]
print(ans)





Measured memory_bytes: 94152
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) {
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    int ans = 0;
    rep(i, k) {
        ans += p[i];
    }
    cout << ans << endl;
} 

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r, d, x;
  cin >> r >> d >> x;
  rep(i, 10) {
    x = x*r-d;
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include  <stdio.h>
#define MAX 100001

int Partition(int *A, int left, int right);
void Swap(int *x, int i, int j);

int main()
{     
  int A[MAX], n, i, j, pivot;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  pivot=A[n-1];
  j=Partition(A, 0, n-1);
 
  for(i=0;i<j;i++){
    printf("%d ",A[i]);
  }
  printf("[%d]",pivot);
  for(i=j+1;i<n-1;i++){
  printf(" %d",A[i]);
  }
  printf(" %d\n",A[i]);  
  return 0;
}

int Partition(int *A, int left, int right)
{
  int i, j, x;
    x = A[right];
    i = left-1;
    for(j=left; j<right; j++){
      if(A[j]<=x){
	i++;
	Swap(A, i, j);
      } 
    }
    Swap(A, i+1, right);
    return i+1;
}

void Swap(int *x, int i, int j)
{
    int temp;
    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}

Measured memory_bytes: 988
#include <iostream>
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#define ll long long 
#define pb push_back
#define pf push_front

using namespace std;

void solve(){
    ll int n; cin>>n;
    ll int a[n]; for(int i=0; i<n; i++) cin>>a[i];
    ll int m[100001]; for(int i=0; i<=100000; i++) m[i]=0;
    //map<ll int, ll int>m;
     for(int i=0; i<n; i++) m[a[i]]++;
    ll int q; cin>>q; ll int b,c,sum=0; 
    for(int i=0; i<n; i++) sum+=a[i];
    while(q--){
        cin>>b>>c;
        sum-=(m[b]*b);
        sum+=(m[b]*c); m[c]+=m[b]; m[b]=0;
        
        cout<<sum<<endl;
    }

}

int main(){
	int t=1; //cin>>t;
	while(t--){
		solve();
	}

return 0;
}

Measured memory_bytes: 5172
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, m;
	cin >> n >> m;
	
	vector<bool> ok(n + 1, true);
	for(int i = 0; i < m; ++i) {
		int a;
		cin >> a;
		ok[a] = false;
	}
	
	vector<ll> dp(100005);
	dp[0] = 1;
	
	for(int i = 0; i < n; ++i) {
		if( ok[i + 1] ) {
			dp[i + 1] += dp[i];
			dp[i + 1] %= MOD_LL;
		}
		
		if( ok[i + 2] ) {
			dp[i + 2] += dp[i];
			dp[i + 2] %= MOD_LL;
		}
	}
	
	cout << dp[n] << endl;
	
	return 0;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return float(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()



def main():
	nn=II()
	A=LI()
	ans="pairwise coprime"

	n = 333335
	primes = set(range(2, n+1))
	for i in range(2, int(n**0.5+1)):
		primes.difference_update(range(i*2, n+1, i))
	primes=set(primes)

	#print(primes)


	B=set(range(1,333335))
	C=set()
	for i in A:
		a=set()
		while i%2==0:
			a.add(2)
			i//=2
		f=3
		while f*f<=i:
			if i in primes:
				break
			elif i%f==0:
				a.add(f)
				i//=f
			else:
				f+=2
		if i!=1:
			a.add(i)
		B&=a
		if C&a:
			ans="setwise coprime"
		C|=a

	if B:
		ans="not coprime"

	print(ans)





















if __name__ == "__main__":
	main()


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

int frc[1000];
int sum;
long long ans = 1;

int main()
{
    string s;
    cin >> s;
    for (auto i : s) {
        ans += sum - frc[i];
        frc[i]++, sum++;
    }

    cout << ans;
    return 0;
}


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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	int N;
	cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	multiset<int, greater<>> se;
	for (int i = 0; i < N; i++) {
		auto it = se.upper_bound(v[i]);
		if (it != se.end()) {
		}
		if (it != se.end()) {
			se.erase(it);
		}
		se.insert(v[i]);
	}

	cout << se.size() << endl;
	return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  int k,a;
  vector<int> list(m+1);
  for(int i=0; i<n; i++) {
    cin >> k;
    for(int j=0; j<k; j++) {
      cin >> a;
      list.at(a) += 1;
    }
  }
  int ans = 0;
  for(int i=1; i<=m; i++) {
    if(list.at(i) == n) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3600
using System;

namespace C
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] tmp = Console.ReadLine().Split(' ');
			long N = long.Parse(tmp[0]);
			long K = long.Parse(tmp[1]);

			Console.WriteLine(Math.Min(N % K, K - (N % K)));
			
		}
	}
}


Measured memory_bytes: 13140
#!/usr/bin/env python3
import sys


def solve(X: int):
    i = 0
    okane = 100
    while okane < X:
        okane = int(okane * 1.01)
        i += 1
    print(i)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63500
#include <stdio.h>
int main(){
  int i,j,h,w,c=0;
  char a[8][9];
  scanf("%d%d",&h,&w);
  for(i=0;i<h;i++)scanf("%s",a[i]);
  for(i=0;i<h;i++)for(j=1;j<w;j++)if(a[i][j]=='#'&&a[i][j-1]=='#')c++;
  for(i=1;i<h;i++)for(j=0;j<w;j++)if(a[i-1][j]=='#'&&a[i][j]=='#')c++;
  puts(w+h-2==c?"Possible":"Impossible");
  return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3
#define MAX_N 1000000001

int n;
int d[800][800];
bool visited[800];
int maxi, u;
set<int> st;

void dfs(int v, int c) {
    visited[v] = true;

    bool end = true;
    rep(i, n) {
        if (d[v][i] < INF && !visited[i] && !st.count(i)) {
            end = false;
            dfs(i, c + d[v][i]);
        }
    }

    if (end) {
        if (maxi <= c) {
            maxi = c;
            u = v;
        }
    }
}

int main(){
    cin.sync_with_stdio(false);
    while(cin >> n, n) {
        rep(i, n)rep(j, n) d[i][j] = INF;
        st.clear();

        vector<int> p(n);
        int sum = 0;
        repl(i, 1, n) cin >> p[i], p[i]--;
        repl(i, 1, n) {
            int tmp;
            cin >> tmp;
            d[i][p[i]] = d[p[i]][i] = tmp;
            sum += tmp;
        }

        int e = 0, tmp = -1;
        rep(i, n){
            int cnt = 0, len = 0;
            rep(j, n) if (d[i][j] < INF) cnt++, len = d[i][j];
            if (cnt == 1) st.insert(i), e += len;
            else tmp = i;
        }

        if (tmp >= 0) {
            memset(visited, 0, sizeof(visited)), maxi = 0;
            dfs(tmp, 0), tmp = u;
            memset(visited, 0, sizeof(visited)), maxi = 0;
            dfs(tmp, 0);
        } else maxi = 0;

        int ans = maxi * 2 + e + (sum - maxi - e) * 3;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 5768
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 9;
 
int _;

//========================================================================
int a[maxn];
//========================================================================
int main()
{
    int n,ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        ans^=a[i];
    }
    for(int i=1;i<=n;i++)
    {
        ans^=a[i];
        printf("%d ",ans);
        ans^=a[i];
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 4452
#pragma GCC optimize("Ofast")
#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;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

vector<int> knuth_morris_pratt(const string &s){
  int n=s.size();
  vector<int> kmp(n+1,-1),mp(n+1,-1);
  for(int i=0,j=-1;i<n;i++){
    while(~j&&s[i]!=s[j]) j=kmp[j];
    kmp[i+1]=mp[i+1]=++j;
    if(i+1<n&&s[i+1]==s[j]) kmp[i+1]=kmp[j];
  }
  return mp;
}
// smallest d s.t. s[x] == s[x + d] for all x
vector<int> minimum_period(const string &s){
  auto mp=knuth_morris_pratt(s);
  for(int i=1;i<(int)mp.size();i++) mp[i]=i-mp[i];
  return mp;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int N = S.size();

    auto A = minimum_period(S);
    if (N%A[N]!=0 or N==A[N]) {
        cout << 1 << ln;
        cout << 1 << ln;
        return 0;
    } 
    if (A[N]==1) {
        cout << N << ln;
        cout << 1 << ln;
        return 0;
    }
    cout << 2 << ln;
    vector<int> cnt(N,1);
    cnt[0] = 0;
    for (int i = 1; i < N; i++) {
        if (i != A[i] and i%A[i]==0) cnt[i] = 0;
    }
    reverse(all(S));
    auto B = minimum_period(S);
    for (int i = 1; i < N; i++) {
        if (i != B[i] and i%B[i]==0) cnt[N-i] = 0;
    }
    cout << accumulate(all(cnt),0) << ln;
}


Measured memory_bytes: 11492
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define INFLL 4557430888798830399
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
int n;
vector<int> v;
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	/*
	Firstly, a few elements are essential: 2, 3, 4 and 9. Then start putting multiples of 6 and
	we are good.
	*/
	if (n == 3) {
		cout << "2 5 63";
		return 0;
	}
	if (n == 5) {
		cout << "2 3 4 9 6";
		return 0;
	}
	v.pb(2), v.pb(3), v.pb(4), v.pb(9);
	n -= 4;
	int cur = 6;
	while (n > 1 && cur <= 30000) {
		v.pb(cur);
		n--;
		cur += 6;
	}
	cur = 8;
	while (n > 1 && cur <= 30000) {
		v.pb(cur), v.pb(cur + 2);
		n -= 2;
		cur += 6;
	}
	cur = 15;
	while (n > 1 && cur <= 30000) {
		v.pb(cur), v.pb(cur + 6);
		n -= 2;
		cur += 12;
	}
	if (n == 1) {
		v.erase(v.begin() + 4);
		v.pb(cur), v.pb(cur + 6);
	}
	fa (i, v) cout << i << " ";
	#ifdef BLU
	int sum = 0;
	fa (i, v) sum += i;
	fa (i, v) if (__gcd(i, sum - i) == 1) {
		cout << "NO";
		return 0;
	}
	#endif
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int vis[200000000];
int collatz(int n)
{
    return (n%2?3*n+1:n/2);
}
int main()
{
   int n,a,b,cnt=1,ans;
   cin >> n;
   memset(vis,0,sizeof(vis));
   vis[n]=1;

   while(1){
        n=collatz(n);
        cnt++;
        if(!vis[n]){
            vis[n]=1;
            //cnt++;
        }
        else {
                ans=cnt;
            break;
        }

   }
   cout << ans << endl;

}


Measured memory_bytes: 781568
/*input
5 4 4
1 2 2
2 3 2
3 4 3
4 5 2
20
2 1
3 1
4 1
5 1
1 2
3 2
4 2
5 2
1 3
2 3
4 3
5 3
1 4
2 4
3 4
5 4
1 5
2 5
3 5
4 5
*/
#include "bits/stdc++.h"
using namespace std;

struct tank_t{
	int refills;
	int rem;
	bool operator<(const tank_t &o) const{
		if(refills != o.refills)
			return refills < o.refills;
		return rem > o.rem;
	}
};
tank_t dis[305][305];
vector<pair<int,int>> v[305];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n, m, cap, q; cin >> n >> m >> cap;
	for(int i=0,x,y,z;i<m;++i){
		cin >> x >> y >> z;
		v[x].push_back({y,z});
		v[y].push_back({x,z});
	}
	for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
		dis[i][j] = {1<<30, 0};

	for(int s = 1; s <= n; ++s){
		queue<int> pq;
		dis[s][s] = {0,cap};
		pq.push(s);
		vector<int> in_pq(n+2);
		in_pq[s] = 1;
		while(!pq.empty()){
			auto u = pq.front(); pq.pop();
			in_pq[u] = 0;
			for(auto i:v[u]){
				tank_t now = dis[s][u];
				if(now.rem >= i.second)
					now.rem -= i.second;
				else if(cap >= i.second)
					now.refills++, now.rem = cap - i.second;
				else
					continue;
				if(now < dis[s][i.first]){
					dis[s][i.first] = now;
					if(!in_pq[i.first]){
						pq.push(i.first);
						in_pq[i.first] = 1;
					}
				}
			}
		}
	}

	for(cin >> q; q--;){
		int s, t; cin >> s >> t;
		int ans = dis[s][t].refills;
		cout << (ans<1e8?ans:-1) << '\n';
	}
}


Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

const double PI = 3.14159265358979323846;

int main() {
    int n, p[201][3];
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> p[i][j];
        }
    }

    int r[201] = {};
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            bool isMatch = false;
            for (int k = 0; k < n; ++k) {
                if (i == k)continue;

                if (p[i][j] == p[k][j]) {
                    isMatch = true;
                    break;
                }
            }

            if (!isMatch) {
                r[i] += p[i][j];
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        cout << r[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 1164
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

NO = "IMPOSSIBLE"  # type: str

def solve(A: int, B: int):
    if (A + B) % 2 == 0:
        ret = (A + B) // 2
    else:
        ret = NO
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <cstdio>
#include <algorithm>

int const N = 555555;
long long const INF = 1LL << 60;
int main() {
  long long n, s;
  scanf("%lld%lld", &n, &s);
  for (int i = 2; i < N; i++) {
    long long sum = 0;
    long long p = n;
    while (p > 0) {
      sum += p % i;
      p /= i;
    }
    if (sum == s) {
      printf("%d\n", i);
      return 0;
    }
  }
  long long ans = INF;
  for (int i = 1; i <= s && i < N; i++) {
    long long d = s - i;
    if (d >= n || (n - d) % i != 0) {
      continue;
    }
    long long cur = (n - d) / i;
    if (cur <= d || cur <= i) continue;
    ans = std::min(ans, cur);
  }
  if (n == s) {
    ans = std::min(ans, n + 1);
  }
  if (INF == ans) ans = -1;
  printf("%lld\n", ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define N 1010
#define M 5050
using namespace std;
int rd[N],f[N];
int fa[N],v[N];
bool dp[N][M];
bool done[N];
vector<int> chs[N];
int n;
void dfs(int p){
	int tot=0,mi=0;
	done[p]=1;
	dp[p][0]=1;
	for(int i=chs[p].size()-1;i>=0;i--){
		int va1=f[chs[p][i]],va2=v[chs[p][i]];
		tot+=va1+va2;
		if(va1>va2) swap(va1,va2);
		mi+=va1;
		for(int j=v[p];j>=va2-va1;j--) dp[p][j]|=dp[p][j-va2+va1];
	}
	if(mi>v[p]){
		puts("IMPOSSIBLE");
		exit(0);
	}
	for(int i=v[p]-mi;i>=0;i--){
		if(dp[p][i]){
			f[p]=tot-i-mi;
			break;
		}
	}
	if(fa[p]){
		rd[fa[p]]--;
		if(!rd[fa[p]]) dfs(fa[p]);
	}
}
int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		scanf("%d",&fa[i]);
		chs[fa[i]].push_back(i);
		rd[fa[i]]++;
	}
	for(int i=1;i<=n;i++) scanf("%d",&v[i]);
	for(int i=1;i<=n;i++){
		if(!rd[i]&&!done[i]) dfs(i);
	}
	puts("POSSIBLE");
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n;
vector<vector<lli>> e;
int main() {
  cin >> n;
  init_n(e, n+1);
  for (lli i=0; i<n-1; ++i) {
    lli a, b; cin >> a >> b;
    e[a].push_back(b);
    e[b].push_back(a);
  }

  // bfs
  vector<lli> dist[2];
  for (lli i=0; i<2; ++i) {
    queue<lli> q;
    dist[i] = vector<lli>(n+1, -1);
    lli s = i==0 ? 1 : n;
    dist[i][s] = 0;
    q.push(s);
    while (!q.empty()) {
      lli v = q.front(); q.pop();
      for (lli u : e[v]) {
        if (dist[i][u] < 0) {
          q.push(u);
          dist[i][u] = dist[i][v] + 1;
        }
      }
    }
  }

  lli cnt = 0;
  for (lli i=1; i<=n; ++i) {
    //cout << i << ':' << dist[0][i] << '-' << dist[1][i] << endl;
    if (dist[0][i] <= dist[1][i]) ++cnt;
  }
  bool ans = cnt > (n-cnt);
  cout << (ans ? "Fennec" : "Snuke") << endl;

  return 0;
}


Measured memory_bytes: 7876
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>

using namespace std;


void func()
{
	int64_t R;
	cin >> R;
	printf("%.10lf\n", 2*R* 3.14159265358979323846);

}

int main() {

//	while (1)
		func();
	return 0;
}


Measured memory_bytes: 3220
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// chrono::steady_clock sc;
 //  	auto start = sc.now();
 //  	ifstream cin;
 //  	cin.open("INPUT.txt");

	int N,Q;
	cin>>N>>Q;
	string S;
	cin>>S;
	int A[N+1]={0};
	for (int i = 1; i < N; ++i)
	{
		if(S[i]=='C' && S[i-1]=='A')
		{
			A[i+1]++;
		}
	}
	for (int i = 1; i < N+1; ++i)
	{
		A[i]=A[i]+A[i-1];
	}
	for (int i = 0; i < Q; ++i)
	{
		int l,r;
		cin>>l>>r;
		l--;
		int ans=A[r]-A[l];
		if(S[l]=='C' && l>0)
		{
			if(S[l-1]=='A')
			{
				ans--;
			}
		}
		cout<<ans<<endl;
	}
	
	// cin.close();
	// auto end = sc.now();
 //   	auto time_span = static_cast<chrono::duration<double>>(end - start);
 //   	cout<<"Operation took: "<<time_span.count()<<" seconds";

	return 0;
}

Measured memory_bytes: 1488
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  ll a,b,n,re=1e15;
  cin>>a>>b>>n;
  reps(i,1,n+1) reps(j,1,n+1){
    if(b*i%j) continue;
    MN(re,abs(a-b*i/j));
  }
  cout<<re<<endl;
  return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int k;
int cnt;
int x[12];
void dfs(int cur, bool zero) {
    if (cur == 12) {
        cnt++;
        if (cnt == k + 1) {
            ll ans = 0;
            for (int i = 0; i < 12; i++) {
                ans = ans * 10 + x[i];
            }
            cout << ans << endl;
        }
        return;
    }
    if (zero) {
        for (int t = 0; t <= 9; t++) {
            if (cnt == k + 1) return;
            x[cur] = t;
            bool nzero = false;
            if (t == 0) nzero = true;
            dfs(cur + 1, nzero);
        }
    } else {
        int a = x[cur - 1];
        for (int t = a - 1; t <= a + 1; t++) {
            if (cnt == k + 1) return;
            if (t < 0 || t > 9) continue;
            x[cur] = t;
            dfs(cur + 1, false);
        }
    }
    return;
}

int main() {
    cin >> k;
    dfs(1, true);
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ANumberOfMultiples solver = new ANumberOfMultiples();
        solver.solve(1, in, out);
        out.close();
    }

    static class ANumberOfMultiples {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int l = in.nextInt(), r = in.nextInt() + 1, d = in.nextInt();

            int answer = 0;
            for (int i = l; i < r; i++) {
                if (i % d == 0)
                    answer++;
            }
            out.println(answer);
        }

    }

    static class InputReader {
        public final BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



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

using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(i,k,h) for(int i = k; i <= h; ++i)
#define INF LLong_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;


int main() {
    ll q,h,s,d,n;
    cin >> q >> h >> s >> d >> n;
    ll q4 = q * 4, h2= h * 2, qh = min(q4,h2), l1 = min(qh,s), l2=min(l1*2,d),ans=0;
    if(n % 2 == 1) {
        ans = n/2 * l2 + l1;
    } else {
        ans = n/2 * l2;
    }
    cout << ans << endl;

}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll K;
    cin >> K;

    ll N = 50;
    ll t = K / N;

    Vl a(N, N - 1 + t);
    ll r = K - t * N;
    for (ll i = 0; i < r; i++) {
        a[i] += N - r + 1;
    }
    for (ll i = r; i < N; i++) {
        a[i] -= r;
    }

    cout << N << "\n";
    for (ll i = 0; i < N; i++) {
        cout << a[i] << " ";
    }
    cout << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3636
def main():
    n,k = map(int, input().split())
    p = list(map(int, input().split()))

    ps = 0
    for i in range(k):
        ps += (p[i]+1)*p[i]/2/p[i]
    ans = ps

    for i in range(0,n-k):
        ps -= (p[i]+1)*p[i]/2/p[i]
        ps += (p[i+k]+1)*(p[i+k])/2/p[i+k]
        ans = max(ans,ps)
    

    print('{:.7f}'.format(ans))


main()

Measured memory_bytes: 71792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,ans=0;
  cin>>a>>b>>c>>d;
  for(int i=a;i<=b;i++){
    if(c<=i&&i<=d){
      ans++;
    }
  }
  cout<<max(ans-1,0)<<endl;
  return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n,m,t,ans;
ll dp[105][105][305];
int main(void){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        ll w,v;
        cin>>w>>v;
        if(i==0)t=w;
        for(int j=0;j<=i;j++){
            for(int k=0;k<=i*3;k++){
                dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k]);
                dp[i+1][j+1][k+w-t]=max(dp[i+1][j+1][k+w-t],dp[i][j][k]+v);
            }
        }
    }
    for(ll j=1;j<=n;j++)for(ll k=0;k<=n*3;k++)if(t*j+k<=m)ans=max(ans,dp[n][j][k]);
    cout<<ans<<endl;
}


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

int main()
{
  int n,k;
  cin>>n>>k;
  vector<string> v(n);
  for(auto &i:v) cin>>i;
  sort(v.begin(),v.end());
  for(auto i:v) cout<<i;

  return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE TypeApplications #-}

import           Control.Monad
import           Data.Array
import           Data.List
import qualified Data.Vector.Unboxed as VU

-- comb :: Int -> [a] -> [[a]]
-- comb 0 _      = [[]]
-- comb _ []     = []
-- comb n (x:xs) = [x:y | y <- comb (n-1) xs] ++ comb n xs

calc :: Array Int Int -> Int -> Int -> Int -> Int
calc hs i k m
  | i < k = m
  | m == 0 = 0
  | otherwise = calc hs (i - 1) k m'
  where
    x = hs ! i - hs ! (i - (k - 1))
    m'
      | m > x = x
      | otherwise = m

-- solve :: [Int] -> Int -> Int
-- solve t n = spl
--   where
--     vt = VU.fromList t
--     subL = VU.concat $ VU.forM (VU.fromList [1..VU.length vt - 1]) $ \x ->
--       return $ (vt VU.! (x - 1)) - (vt VU.! x)
--     spl = minimum . map (abs . sum) . comb (n-1) $ VU.toList subL

main :: IO ()
main = do
  _ : [n] <- map (read @Int) . words <$> getLine
  trees <- map (read @Int) . lines <$> getContents
  let trees' = sort trees
  let trees'' = listArray (1, length trees') trees'
  putStr $ show $ calc trees'' (length trees'') n (10 ^ 9 + 1)


Measured memory_bytes: 20140
# 解説と下記を参考に作成
# https://atcoder.jp/contests/abc113/submissions/15821617
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(H, W, K):
    mod = 10 ** 9 + 7
    dp = [[0] * W for _ in range(H + 1)]
    dp[0][0] = 1
    for h in range(H):
        for w in range(W):
            if dp[h][w] == 0:
                continue
            for i in range(3):
                new_w = w - 1 + i
                if not 0 <= new_w < W:
                    continue

                def cnt_tmp(n, r, l, flg):
                    re = 0
                    if n >= W - 2:
                        if r <= n <= l:
                            return 1
                        if flg:
                            return 1
                        else:
                            return 2
                    if r <= n <= l:
                        return cnt_tmp(n + 1, r, l, False)
                    re += cnt_tmp(n + 1, r, l, False)
                    re += cnt_tmp(n + 1, r, l, True) if not flg else 0
                    return re

                tmp = cnt_tmp(0, min(w, new_w) - 1, max(w, new_w), False)
                dp[h + 1][new_w] += dp[h][w] * tmp
                dp[h + 1][new_w] %= mod
    # for dpi in dp:
    #     print(dpi)
    print(dp[-1][K - 1])


if __name__ == '__main__':
    H, W, K = map(int, input().split())
    solve(H, W, K)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


Measured memory_bytes: 9136
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;
template <class _T> static _T tp_pow(int base, int exp)
{
	_T ans = 1;

	for (int i = 0; i < exp; i++) {
		ans *= base;
	}
	return ans;
}

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}
static const long long MOD_NUM = 1000000007LL;

static void D_task();

int main()
{
	D_task();
	fflush(stdout);
	return 0;
}


static void D_task()
{
	int N;
	getint(N);

	std::vector<int> vAi(N, 0);
	std::map<int, LLONG> mAi;
	int max = 200000;
	for (int i = 0; i < N; i++) {
		int tmp; getint(tmp);
		vAi[i] = tmp;
		mAi[tmp]++;
	}

	LLONG total = 0;
	for (auto it = mAi.begin(); it != mAi.end(); it++) {
		total += it->second * (it->second - 1) / 2;
	}

	for (int i = 0; i < N; i++) {
		LLONG val = mAi[vAi[i]];
		LLONG ans = total;
		if (val >= 2) {
			ans = total - (val * (val - 1) / 2) + ((val - 1) * (val - 2) / 2);
		}
		
		printf("%lld\n", ans);
	}
}


Measured memory_bytes: 11264
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
    long long x;
    cin>>x;
    long long i;
    long long a=100;
    for(i=0;a<x;++i){
        a=a*1.01;
    }
    cout<<i;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll N;
    cin >> N;
    ll X[N],Y[N];
    for(ll i=0;i<N;i++){
      cin >> X[i];
      Y[i]=X[i];
    }
    sort(Y,Y+N);
    for(ll i=0;i<N;i++){
      if(X[i]>=Y[N/2])cout <<Y[N/2-1]<<endl;else cout <<Y[N/2]<<endl;
    }
    return 0;
}


Measured memory_bytes: 5248
N = int(input())
robots = [tuple(map(int,input().split())) for _ in range(N)]

#print(robots)
# 最大値と最小値を計算する
robots = [(x+l,x-l) for x,l in robots]
#print(robots)
# ソートする
robots.sort()
#print(robots)

cnt = 0
last = -float('inf')
for r,l in robots:
    #print(last, l, r)
    # 1個前の最大値を、今回の最小値が上回っていたらOK
    if last <= l:
        cnt += 1
        # 次の最大値を更新する
        last = r

print(cnt)

Measured memory_bytes: 30044
let inputs = readLine()!.split(separator: " ").map { Int($0)! }

let X = inputs[0]
let Y = inputs[1]

let y = (2 * X - Y) / -2
let x = X - y

print(x >= 0 && y >= 0 && 2 * x + 4 * y == Y ? "Yes" : "No")

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define        sqr(a)       ((a)*(a))


ll dp[3001][3001][5];

ll ar[3001][3001];

ll n,m;
ll cal(ll i,ll j,ll cnt)
{
    if(i>=n || j >= m)return 0;
    if(cnt>=3)return 0;
    if(dp[i][j][cnt]!=-1)return dp[i][j][cnt];

    ll res=0,res1=0,res2=0,res3=0,res4=0;

    res1 = ar[i][j] + max(cal(i+1,j,0),cal(i,j+1,cnt+1));
    res2 =  max(cal(i+1,j,0),cal(i,j+1,cnt));

    res = max({res1,res2});

    return dp[i][j][cnt] = res;
}
int main()
{
    ll i,j,k,r,c,x,y;


    memset(dp,-1,sizeof dp);


    cin >> r >> c;
    cin >> k;
    n = r,m=c;

    for(i=0; i<k; i++)
    {
        cin >> x >> y;

        x--, y--;

        cin >> ar[x][y];
    }
//    for(i=0; i<n; i++)
//    {
//        for(j=0; j<m; j++)cout<<ar[i][j]<<" ";
//
//        cout << endl;
//    }

    cout << cal(0,0,0) << endl;


}


Measured memory_bytes: 426260
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var s = Reads();
        var N = s[0];
        var K = s[1];

        double total = 0; ;
        for (int i = 1; i <= N; i++)
        {
            var m = 0;
            var x = i;
            while (x <K )
            {
                x *= 2;
                m++;
            }

           
            total +=Math.Pow(0.5, m);
         
        }
        Console.WriteLine(1.0/N*total);
        Console.Out.Flush();
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    cout << setprecision(16);
    int n; cin >> n;
    int ans = 0;
    rep(i,n){
        int x; cin >> x;
        while(x % 2 == 0){
            ans++;
            x /= 2;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define int long long

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define rep(i,a,b) for (int i = a; i <= (int)b; ++i)
#define f first
#define s second

#define single_test

const int inf = 1e18;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n), dp(n, inf);
    for (int &x: a) {
        cin >> x;
    }
    dp[0] = 0;
    for (int i = 1; i < n; ++i) {
        for (int j = i - 1; j >= 0 && i - j <= k; --j) {
            dp[i] = min(dp[i], dp[j] + abs(a[j] - a[i]));
        }
    }
    cout << dp[n - 1] << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}

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

int main(){
	/*input*/
	string s;	cin >> s;
	/*calculation*/
	int ans = 0;
	for(int i = 0; i < 4; i++){
		switch(s.at(i)){
			case '+':
			ans++;
			break;
			case '-':
			ans--;
			break;
		}
	}
	/*output*/
	cout << ans << endl;
}


Measured memory_bytes: 256
import sys
from datetime import timedelta,date

for s in sys.stdin:
    y,m,d = map(int,s.split())
    d = date(y,m,d)
    lis = [
    [date(1989,1,8),"heisei"],
    [date(1926,12,25),"showa"],
    [date(1912,7,30),"taisho"],
    [date(1868,9,8),"meiji"]
    ]
    for e in lis:
        if d >= e[0]:
            print e[1],
            print d.year-e[0].year + 1,
            print d.month,
            print d.day
            break
    else:
        print "pre-meiji"

Measured memory_bytes: 4428
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 1000000000;
const ll M = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

int main() {
    int n;
    ll T = 0, A = 0;
    ll t, a;
    cin >> n;
    rep(i, n) {
        cin >> t >> a;
        ll k = 1;
        if (t != 0)
            k = max(k, (T + t - 1) / t);
        if (a != 0)
            k = max(k, (A + a - 1) / a);
        T = t * k;
        A = a * k;
    }
    cout << T + A;

    /* ====================================== */
    cout << endl;
    return 0;
}

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

void push();
int pop();

int s1[100];
int top=0;

int main(){
  int x,out1,out2,sum;
  char s[100];


  while(scanf("%s",s)!=EOF){



    if ( s[0]== '+' ){
      out1=pop();
      out2=pop();
      push(out1+out2);
    }
    else if ( s[0]== '-' ){
      out1=pop();
      out2=pop();
      push(out2-out1);
    }
    else if ( s[0]== '*' ){
      out1=pop();
      out2=pop();
      push(out1*out2);
    }
    else {
     x = atoi(s);
     push(x);
    }
  }

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

  return 0;
}

void push(int x){
  top++;
  s1[top]=x;
  }
int pop(void){
  top--;
  return s1[top+1];
}



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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////


//long long  Prime[3000000],nPrime;
//long long  mark[10000002];
//
//void seive(long long int n)
//{
//	long long int i,j,limit=sqrt(n*1.0)+2;
//	mark[1]=1;
//	for(i=4; i<=n ;i+=2)
//	mark[i]=1;
//	Prime[nPrime++]=2;
//	for(i=3; i<=n; i+=2)
//	{
//		if(!mark[i])
//		{
//			Prime[nPrime++]=i;
//			if(i<=limit)
//			{
//				for(j=i*i; j<=n ;j+=i*2)
//				{
//					mark[j]=1;
//				}
//			}
//		}
//	}
//}

int main()
{
    FASTIO;

    ll n;

    cin >> n;

    ll sum = 0;

    ll a[n+1];


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

        sum ^= a[i];

        //cout << sum << " ";

        //cout << (sum^a[i]) << endl;

    }

    for(int i=0; i<n; i++)
        a[i] ^= sum;


    for(int i=0; i<n; i++)
        cout << a[i] << " ";

    cout << endl;







    return 0;
}


Measured memory_bytes: 5152