akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN];
int dp_old[MAXN], dp[MAXN], sums[MAXN];
int n, k;
const int MOD = 1e9 + 7;

inline int get_sum(int start, int end){
    if(start == 0)
        return sums[end];
    int ans = sums[end] - sums[start - 1];
    if(ans < 0){
        ans += MOD;
    }
    return ans;
}

inline long long int mod_ans(long long int a, int val){
    if(a >= val)
        return a % val;
    return a;
}

int main(){
    cin >> n >> k;
    
    for(int j = 0; j <= k; ++j){
        dp[j] = 0;
        dp_old[j] = 0;
    }
    
    dp_old[0] = 1;
    
    for(int x = 0; x < n; ++x){
        cin >> a[x];
        
        // Constructing sums  : O(K)
        int sum = 0;
        for(int i = 0; i <= k; ++i){
            sum = mod_ans(dp_old[i] + sum, MOD);
            sums[i] = sum;
        }
        
        // Getting new answers : O(K)
        for(int val = 0; val <= k; val++){
            dp[val] = get_sum(max(val - a[x], 0), val);
        }
        
        // Copying dp_old = dp_new  : O(K)
        for(int i = 0; i <= k; ++i){
            dp_old[i] = dp[i];
            // cout << dp[i] << "\t";
            sums[i] = 0;
            dp[i] = 0;
        }
        // cout << "\n";
    }
    
    
    cout << dp_old[k] << "\n";
    return 0;
}

Measured memory_bytes: 4752
n=int(input())
a=list(int(i) for i in input().split())
count=-1
exit_num=0

while exit_num==0:
    count=count+1
    for i in range(len(a)):
        if(a[i]%2==0):
            a[i]=a[i]/2
        else:
            exit_num=1
    
print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int t[10],u[10];
int main(){
  for(int i=0;i<10;i++)cin>>t[i];
  for(int i=0;i<10;i++)cin>>u[i];
  sort(t,t+10);
  sort(u,u+10);
  cout<<(t[9]+t[8]+t[7])<<' '<<(u[9]+u[8]+u[7])<<endl;
  return 0;
}

Measured memory_bytes: 1176
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C (GCC 5.4.1)
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n;
	int a[23],b[23],c[23];
	int sum = 0;

	scanf("%d",&n);
	for (int i = 0; i < n; ++i)	scanf("%d",&a[i]);
	for (int i = 0; i < n; ++i)	scanf("%d",&b[i]);
	for (int i = 0; i < n - 1; ++i)	scanf("%d",&c[i]);
	for (int i = 0; i < n; ++i)
	{
		sum += b[a[i] - 1];
		if(i > 0){
			if(a[i - 1] + 1 == a[i])	sum += c[a[i - 1] - 1];
		}
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

struct node
{
	vector <char> v;
	int len,mn,t;
}p[maxn];
char s[maxn];
int n,c1,c2;

inline bool cmp(node a,node b)
{
	if(a.mn==b.mn) return a.t>b.t;
	return a.mn>b.mn;
}

inline bool cmp2(node a,node b)
{
	int x1=a.mn-a.t,x2=b.mn-b.t;
	return x1<x2;
}

int main()
{
	n=read();
	rep(i,1,n)
	{
		scanf("%s",s+1); p[i].len=strlen(s+1); p[i].mn=0;
		rep(j,1,p[i].len)
		{
			p[i].v.pb(s[j]);
			if(s[j]=='(') p[i].t++,c1++; else p[i].t--,c2++;
			p[i].mn=min(p[i].mn,p[i].t);
		}
	}
	if(c1!=c2) return puts("No"),0;
	sort(p+1,p+n+1,cmp);
	int nw=0;
	rep(i,1,n)
	{
		if(p[i].t>=0)
		{
			if(p[i].mn+nw>=0) nw+=p[i].t;
			else return puts("No"),0;
		}
	}
	sort(p+1,p+n+1,cmp2);
	//rep(i,1,n) cout<<p[i].mn<<" "<<p[i].t<<endl;
	rep(i,1,n)
	{
		if(p[i].t<0)
		{
			if(p[i].mn+nw>=0) nw+=p[i].t;
			else return puts("No"),0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 73952
#include<iostream>
using namespace std;
int main(){
int ans=0,cnt=0,n,a,b;
cin>>n>>a>>b;
for(int i=1;i<=n;i++){
cnt++;
if(i%10==0)cnt-=9;
if(i%100==0)cnt-=9;
if(i%1000==0)cnt-=9;
if(i%10000==0)cnt-=9;
if(a<=cnt&&cnt<=b)ans+=i;
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
/*
[agc030] A - Poisonous Cookies
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

int A, B, C;

ll solve() { return min(C, A + B + 1) + B; }

int main() {
    cin >> A >> B >> C;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

int N,M,k,S,P,ans;
bool flag;

int main(){
    cin>>N>>M;
    vector<int> s[M];
    int p[M],cnt[M];
    rep(i,M){
        cin>>k;
        rep(j,k){
            cin>>S;
            S--;
            s[i].push_back(S);
        }
    }
    rep(i,M){
        cin>>p[i];
    }
    rep(i,(1<<N)){
        flag=true;
        rep(j,M){
            cnt[j]=0;
        }
        bitset<10> bs(i);
        rep(j,M){
            for(auto x : s[j]){
                if(bs[x])cnt[j]++;
            }
            if(cnt[j]%2!=p[j]){
                flag=false;
                break;
            }
        }
        // rep(j,M){
        //     out(cnt[j]);
        // }
        // out("");
        if(flag)ans++;

    }
    out(ans);


    
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int H,N;
  cin >> H >> N;
  int all=0;
  for(int n=0;n<N;n++){
    int a;
    cin >> a;
    all += a;
  }
  if(all>=H) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repx(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int a[101010];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N) scanf("%d", &a[i + 1]);
    
    // 2. 仲良しなペアの個数は？
    int ans = 0;
    rep(i, N) if(i + 1 == a[a[i + 1]]) ans++;
    
    // 3. 出力.
    printf("%d\n", ans / 2);
    return 0;
    
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define mo 1000000007ll
#define N 100010
#define int long long
int n,d[N],a[N],vi[N],c[N],le[N],s[N],f[N],ans;
void dfs(int x){
	int v=0,y=0,z=0,p=0;
	while(c[x]){
		v++;
		c[x]=0;
		if(le[x]){
			if(!y){
				z=y=v;
				p=le[x];
			}
			else{
				ans=ans*((le[x]<v-z)+(le[x]<=v-z))%mo;
				z=v;
			}
		}
		x=a[x];
	}
	if(!y)s[v]++;
	else ans=ans*((p<v-z+y)+(p<=v-z+y))%mo;
}
void dp(){
	for(int i=1;i<=n;i++){
		if(d[i])continue;
		int x=i,l=0;
		while(!c[x]){
			x=a[x];
			l++;
		}
		le[x]=l;
	}
	ans=1;
	for(int i=1;i<=n;i++)
		if(c[i])dfs(i);
	for(int i=1;i<=n;i++)
		if(s[i]){
			f[0]=1;
			for(int j=1;j<=s[i];j++){
				if(i>1&&(i&1))
					f[j]=f[j-1]*2ll%mo;
				else f[j]=f[j-1];
				if(j>1)f[j]=(f[j]+f[j-2]*(j-1)%mo*i%mo)%mo;
			}
			ans=ans*f[s[i]]%mo;
		}
}
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		d[a[i]]++;
	}
	for(int i=1;i<=n;i++){
		if(vi[i])continue;
		int x=i;
		while(!vi[x]){
			vi[x]=i;
			x=a[x];
		}
		if(vi[x]!=i)continue;
		while(!c[x]){
			c[x]=1;
			x=a[x];
		}
	}
	for(int i=1;i<=n;i++)
		if((c[i]&&d[i]>2)||(!c[i]&&d[i]>1)){
			puts("0");
			return 0;
		}
	dp();
	cout<<ans;
}

Measured memory_bytes: 4480
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tommy6073
 */

#include <iostream>
#include <string>

using namespace std;

class CSnack {
public:
    void solve(std::istream &in, std::ostream &out) {
        long long A, B;
        in >> A >> B;

        out << (A * B) / gcd(A, B);
    }

    int gcd(long long A, long long B) {
        int remainder = 0;
        do {
            remainder = A % B;
            A = B;
            B = remainder;
        } while (B != 0);
        return A;
    }
};


int main() {
	CSnack solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = int.Parse(Console.ReadLine());

            Console.WriteLine(N * N - A);
        }
    }
}

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

#define ub upper_bound
#define sum(a) accumulate(all(a),0ll)
#define lb lower_bound
#define all(v) begin(v),end(v)
#define allr(v) rbegin(v),rend(v)
#define sort_dec(v) sort(all(v),[](auto e1,auto e2){return e1>e2;})
#define For(n) for(ll i=0;i<n;i++)
#define Forj(n) for(ll j=0;j<n;j++)
typedef long long int ll;
typedef unsigned long long int ull;
#define fi first
#define se second
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define Mp 1e9+7
#define vpll vector< pair<ll,ll> >
#define bug(n) {cout<<n;return;}
#define cont(n) {cout<<n<<endl;continue;}
#define pb push_back

ll n;
ll w[101],v[101];

// ll dpArray[101][100001];

// ll dp(ll i,ll W){
// 	if(i==n)return 0;
// 	if(w[i]>W)return dp(i+1,W);
// 	if(dpArray[i][W]!=-1)return dpArray[i][W];
// 	return dpArray[i][W]=max(dp(i+1,W-w[i])+v[i],dp(i+1,W));
// }
 
void solve()
{
	// ll n;
	// memset(dpArray,-1,sizeof(dpArray));
	ll W;
	cin>>n>>W;
	For(n)cin>>w[i]>>v[i];
	ll dp[n+1][W+1];
	memset(dp,0,sizeof(dp));
	// dp[0][0]=1;
	For(n){
		Forj(W+1)
		{
			dp[i+1][j]=dp[i][j];
			if(w[i]<=j)dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
		}
	}
	// For(W+1)cout<<" "<<i;cout<<endl;
	// For(n+1)
	// {
	// 	cout<<i<<" ";
	// 	Forj(W+1)cout<<dp[i][j]<<" ";cout<<endl;
	// }
	cout<<dp[n][W];
	// cout<<dp(0,W);
}
 
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	 
	// freopen("error.txt", "w", stderr);
	 
	int t=1;
	 
	while(t--)
	{
		solve();
	}

	cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	 
	return 0;
}

Measured memory_bytes: 82580
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int ans = 1;
		while(n>3) {
			n = (n+2)/3;
			ans++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 17224
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<cstdio>

int v[1500001];
char s[1500001],t[500002];
void Zalgorithm(int N){
  int i=1,j=0,k=0;
  while(i<N){
    while(i+j<N&&s[i+j]==s[j])++j;
    if(!(v[i]=j)){
      ++i;
      continue;
    }
    k=1;
    while(v[k]+k<j){
      v[i+k]=v[k];
      ++k;
    }
    i+=k;
    j-=k;
  }
}
int i,j,K,que[500001],bf,ans,size;
inline void print(int N){
  if(!N)return;
  int k=N/10;
  print(k);
  putchar('0'+N-k*10);
}
int main(){
  int N,ng=500001,mid;
  std::fgets(t,1000000,stdin);
  std::fgets(s,1000000,stdin);
  while(ng-K>1){
    mid=(ng+K)>>1;
    (s[mid]?K:ng)=mid;
  }
  while(t[i]!='\n'){
    s[K+i]=t[i];++i;
  }
  N=i;
  i+=K;
  int M=N+(K<<1);
  while(i<M){
    s[i++]=t[j++];
    j*=j<N;
  }
  Zalgorithm(M);
  M=K%N;
  for(i=0;i<N;++i){
    if(v[i+M]=v[i+K]<K)que[size++]=(i+M)-(i+M>=N)*N;
  }
  for(i=0;i<N;++i){
    if(i==size){
      puts("-1");
      return 0;
    }
    if(!v[que[i]+=M]){
      que[size++]=que[i]-(que[i]>=N)*N;
      if(bf<=i){
        bf=size-1;
        ++ans;
      }
    }
  }
  if(ans)print(ans);
  else puts("0");
}

Measured memory_bytes: 9984
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


d = int(input())

if d==25:
    print("Christmas")
elif d==24:
    print("Christmas Eve")
elif d==23:
    print("Christmas Eve Eve")
elif d==22:
    print("Christmas Eve Eve Eve")

Measured memory_bytes: 2940
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val p = readLine()!!.split(' ').map(String::toDouble)
    val dp = Array(n + 2) { DoubleArray(n + 2) { 0.0 } }
    dp[0] = DoubleArray(n + 2) { 1.0 }
    for (r in 0 until n) {
        for (c in 0..r) {
            dp[r + 1][c] = dp[r][c] * (1 - p[r]) + dp[r + 1][c]
            dp[r + 1][c + 1] = dp[r][c] * p[r] + dp[r + 1][c + 1]
        }
    }
    println(dp[n].filterIndexed { index, d -> index > n / 2 }.sum())
}

Measured memory_bytes: 124476
using System;

class Program
{
  static void Main(string[] args)
  {
    int N = int.Parse(Console.ReadLine());
    string[] conditions = Console.ReadLine().Split(' ');
    string[] elevations = Console.ReadLine().Split(' ');
    int T = int.Parse(conditions[0]);
    int A = int.Parse(conditions[1]);
    double min = 1 << 30;
    int ans = -1;
    for (int i = 0; i < N; ++i)
    {
      int h = int.Parse(elevations[i]);
      double temp = Math.Abs(A - (T - h * 0.006));
      if (min > temp)
      {
        ans = i + 1;
        min = temp;
      }
    }

    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 11164
#include<bits/stdc++.h>
using namespace std;
const int N=4e5+5;
int n,a,b,s[N],f1[N],f2[N];
int t1[N],t2[N];
int query1(int x)
{
    int ans=0;
    while(x)
        ans=max(ans,t1[x]),x-=x&-x;
    return ans;
}
int query2(int x)
{
    int ans=0;
    x=n-x+1;
    while(x)
        ans=max(ans,t2[x]),x-=x&-x;
    return ans;
}
void add1(int x,int v)
{
    while(x<=n)
        t1[x]=max(t1[x],v),x+=x&-x;
}
void add2(int x,int v)
{
    x=n-x+1;
    while(x<=n)
        t2[x]=max(t2[x],v),x+=x&-x;
}
bool check()
{
    int ans1=0,ans2=0;
    for(int i=1;i<=n;i++)
    {
        f1[s[i]]=max(query1(s[i])+1,1);
        f2[s[i]]=max(query2(s[i])+1,1);
        add1(s[i],f1[s[i]]);
        add2(s[i],f2[s[i]]);
        ans1=max(ans1,f1[s[i]]);
        ans2=max(ans2,f2[s[i]]);
    }
    return ans1==a&&ans2==b;
}
void solve(int a,int b)
{
    int tot=0;
    for(int i=n-a+1;i<=n;i++)
        s[++tot]=i;
    n-=a;
    b--;
    if(b==0)
    {
        if(n==0)
            for(int i=1;i<=tot;i++) cout<<s[i]<<' ';
        else cout<<-1;
        return;
    }
    int len=n/b,k=n%b;
    for(int i=1;i<=k;i++)
    {
        int x=len+1;
        for(int i=n-x+1;i<=n;i++)
            s[++tot]=i;
        n-=x;
    }
    for(int i=1;i<=b-k;i++)
    {
        int x=len;
        for(int i=n-x+1;i<=n;i++)
            s[++tot]=i;
        n-=x;
    }
    n=tot;
    if(!check()) printf("-1\n");
    else for(int i=1;i<=n;i++)
        printf(i==n?"%d\n":"%d ",s[i]);
}
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    if(a+b-1>n||a>n||b>n) printf("-1\n");
    else solve(a,b);
}


Measured memory_bytes: 9088
q,n = map(int,input().split(" "))

A = [[] for i in range(q)]

for i in range(n):
    a = [int(j) for j in input().split(" ")]
    if a[0] == 0:
        A[a[1]].append(a[2])
    elif a[0] == 1:
        print(" ".join(map(str,A[a[1]])))
    elif a[0] == 2:
        A[a[1]].clear()
    



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef pair<ll,P>  PP;
typedef vector<ll> Vector;
typedef vector<Vector> DVector;
typedef priority_queue<PP, vector<PP>, greater<PP>> PPQueue;

#define fi          first
#define se          second
#define sfi         se.fi
#define sse         se.se
#define pb          push_back
#define INF         INT_MAX
#define MOD         1000000007
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define uni(x)      x.erase(unique(all(x)),x.end())
#define ub(x,y)     (upper_bound(all(x),y)-x.begin())
#define lb(x,y)     (lower_bound(all(x),y)-x.begin())
#define rep(i,n)    repl(i,0,n-1)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<ll>())
#define mkp(x,y)    make_pair(x,y)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)

string s;
ll judge2(){
  rep(i,s.size()-1)if(s[i] == s[i + 1])return i + 1;
  return -1;
}

ll judge3(){
  rep(i,s.size()-2)if(s[i] == s[i + 2])return i + 1;
  return -1;
}


int main(){
  cin.sync_with_stdio(false);
  cin >> s;
  ll j2 = judge2(), j3 = judge3();
  if (j2 >= 0){
    cout << j2 << " " << j2 + 1 << endl;
    return 0;
  }

  if (j3 >= 0) {
    cout << j3 << " " << j3 + 2 << endl;
    return 0;
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main ()
{
	int i,l;
	int value[31]={0};

	for(i=0;i<28;i++)
	{
		scanf("%d",&l);
		value[l]=1;
	}
	for(i=1;i<=30;i++)
	{
		if(value[i]!=1)
		{
			printf("%d\n",i);
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>
using namespace std;
#define all(x) (x).begin(), (x).end()

const int N = 500000;
const long long MOD = 1e9 + 7;

int X;
int n, q;
int r[N], t[N], a[N];
int A, B, C, T, U;

void go(int t)
{
    if (U == 0) C -= t - T;
    else C += t - T;
    if (C > X) C = X;
    if (C < -X) C = -X;
    if (C < 0) A = max(A, -C);
    if (C > 0) B = min(B, X - C);
    if (A > B && C < 0) B = A;
    if (A > B && C > 0) A = B;
    T = t;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> X >> n;
    B = X;
    for (int i = 0; i < n; i++)
    {
        cin >> r[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> t[i] >> a[i];
    }
    for (int i = 0, j = 0; j < q; )
    {
        int k = 0;
        if (i == n) k = 1;
        if (i < n && t[j] < r[i]) k = 1;
        if (k == 0)
        {
            go(r[i]);
            U ^= 1;
            i++;
        }
        else
        {
            go(t[j]);
            if (a[j] <= A) cout << A + C << "\n";
            if (A < a[j] && a[j] <= B) cout << a[j] + C << "\n";
            if (B < a[j]) cout << B + C << "\n";
            j++;
        }
    }
}


Measured memory_bytes: 3968
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] A = new int[3];
		for(int i=0;i<=2;i++) {
			A[i] = sc.nextInt();
		}
		for(int i=0;i<3;i++) {
			for(int j=2;j>i;j--) {
				if(A[i]>A[j]) {
					int temp=A[i];
					A[i] = A[j];
					A[j] = temp;
				}
			}
		}
		System.out.println((A[2]-A[1])+(A[1]-A[0]));
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define int long long

template<typename M>
struct segment_tree{
	typedef function<M(M, M)> F;
	int size;//2冪
	vector<M> val;//1-indexed
	F f;//結合関数
	M e;//単位元

	segment_tree(int N, vector<M> &data, F f, M e) : f(f), e(e){
		size = 1;
		while(size < N) size *= 2;
		val.assign(2 * size, e);
		for(int i = 0; i < N; i++) val[size + i] = data[i];
		for(int i = N; i < size; i++) val[size + i] = e;
		for(int i = size - 1; i > 0; i--) val[i] = f(val[2 * i], val[2 * i + 1]);
	}

	//k番目の要素をxに変更する
	void update(int k, M x){
		k += size;
		val[k] = x;
		while(k /= 2) val[k] = f(val[2 * k], val[2 * k + 1]);
	}

	//[l, r)の演算の結果を返す
	M query(int l, int r){
		M L = e, R = e;
		for(l += size, r += size; l < r; l /= 2, r /= 2){
			if(l & 1) L = f(L, val[l++]);
			if(r & 1) R = f(val[--r], R);
		}
		return f(L, R);
	}
};

//(int, my_min, inf)
#define inf (int)(1e18)

int my_min(int x, int y){
	return x < y ? x : y;
}


signed main(){
	int N, M, i, j;
	scanf("%lld%lld", &N, &M);
	vector<vector<pair<int, int>>> LC(N, vector<pair<int, int>>(0));
	for(i = 0; i < M; i++){
		int L, R, C;
		scanf("%lld%lld%lld", &L, &R, &C);
		L--;
		R--;
		LC[R].push_back(pair<int, int>(L, C));
	}
	vector<int> data(N, inf);
	segment_tree<int> t(N, data, my_min, inf);
	t.update(0, 0);
	for(i = 1; i < N; i++){
		int now = inf;
		for(j = 0; j < LC[i].size(); j++){
			now = min(now, t.query(LC[i][j].first, i) + LC[i][j].second);
		}
		t.update(i, now);
	}
	if(t.query(N - 1, N) >= inf){
		printf("-1\n");
	}
	else{
		printf("%lld\n", t.query(N - 1, N));
	}
	return 0;
}

Measured memory_bytes: 8448
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let S: Vec<char> = sc.chars();
    let N = S.len();
    let mut ones = 0;
    let mut zeros = 0;
    for i in 0..N {
        match S[i] {
            '0' => ones += 1,
            '1' => zeros += 1,
            _ => unreachable!(),
        }
    }
    println!("{}", min(ones, zeros) * 2);
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main()
{
	string s;
  	cin >> s;
  	int a = 0, b = 0, c = 0;
  	for(int i = 0; i < s.size(); i++)
      	if( s[i] == 'a' )
          	a++;
  		else if( s[i] == 'b' )
          	b++;
  		else
          	c++;
  	if( a == 1 and b == 1 and c == 1 )
    	cout << "Yes";
  	else
      	cout << "No";
}

Measured memory_bytes: 3596
#include <iostream>
#include <bitset>
#include <math.h>
#include <algorithm>
#include <vector>;
#include <numeric>
using namespace std;

int main() {
		
	string s;
	cin >> s;

	int k=0;
	for (int i = 0;i < s.length();i++) {
		k += s[i] - '0';
		k %= 9;
	}

	if (k == 0) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 3752
// By Atul Rathore

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

#define ll long long int
#define f(n) for(int i=0;i<n;i++)
#define p(x) cout<<x<<endl;
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main()
{
	fastio;
	int r;
	cin>>r;
	double x=(double)6.28*r;
	cout<<fixed<<setprecision(2)<<x;
	
		
	
	
	
}


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

int main(void){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k-1] = s[k-1]+32;
    cout << s << endl;
}

Measured memory_bytes: 256
Vertex = Struct.new(:id, :adjacencies, :group)

def grouping!(vertex, group)
 	return unless vertex.group.nil?

	stack = [].push(vertex)
	until stack.empty?
		vertex = stack.last
		vertex.group = group
		adjacency = vertex.adjacencies.find { |v| v.group.nil? }

		if adjacency.nil?
			stack.pop
		else
			stack.push(adjacency)
		end
	end
end

n, m = STDIN.gets.split.map(&:to_i)
vertex_list = Array.new(n) { |i| Vertex.new(i, []) }
m.times do
	vertex_id, friend_id = STDIN.gets.split.map(&:to_i)
	vertex_list[vertex_id].adjacencies << vertex_list[friend_id]
	vertex_list[friend_id].adjacencies << vertex_list[vertex_id]
end

vertex_list.each_with_index { |v, i| grouping!(v, i) }

q = STDIN.gets.to_i
q.times do
	a, b = STDIN.gets.split.map(&:to_i)
	puts vertex_list[a].group == vertex_list[b].group ? "yes" : "no"
end

Measured memory_bytes: 53580
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 500005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
char s[MAXN];
int nxt[MAXN][27],ri[MAXN][27];
void Solve() {
    scanf("%s",s + 1);
    N = strlen(s + 1);
    for(int i = 0 ; i <= N + 1; ++i) {
        for(int j = 0 ; j <= 26 ; ++j) {
            nxt[i][j] = N + 1;
        }
    }
    for(int i = 0 ; i <= N + 1 ; ++i) {
        for(int j = 0 ; j <= 19 ; ++j) ri[i][j] = N + 1;
    }
    for(int i = N - 1 ; i >= 0 ; --i) {
        int x = s[i + 1] - 'a';
        nxt[i][x] = i + 1;
        for(int j = x + 1 ; j <= 26 ; ++j) {
            nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
        }
        for(int j = 0 ; j < x ; ++j) {
            nxt[i][j] = nxt[nxt[i][26]][j];
        }
    }
    for(int j = 0 ; j <= 19 ; ++j) {
        for(int i = N - 1 ; i >= 0 ; --i) {
            if(j == 0) ri[i][j] = nxt[i][26];
            else ri[i][j] = ri[ri[i][j - 1]][j - 1];
        }
    }
    int Q;
    read(Q);
    int l,r;
    for(int i = 1 ; i <= Q ; ++i) {
        read(l);read(r);
        --l;
        for(int j = 19 ; j >= 0 ; --j) {
            if(ri[l][j] <= r) l = ri[l][j];
        }
        if(l == r) puts("Yes");
        else puts("No");
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 106624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n) for(ll i=0;i<(n);i++)
#define For1(i,n) for(ll i=1;i<(n);i++)
#define MOD 1000000007

ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}

int main(){
    ll n;cin>>n;
    vector<ll> vec(n);
    For(i,n){
        cin>>vec.at(i);
    }
    vector<ll> svec=vec;
    sort(svec.begin(),svec.end());
    ll dif=0;
    For(i,n){
        if(vec.at(i)!=svec.at(i)){
            dif++;
        }
    }
    if(dif<3){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }

}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;

int MOD = 1e9 + 7;


int main() {
    ll cnt = 0;
    ll K;
    int N;
    cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0 ; i < a.size() - 1; i++) {
        for (int j = i + 1; j < a.size(); j++) {
            if (a[i] > a[j]) {
                cnt += (K * (K + 1) / 2LL) % MOD;
                cnt = cnt % MOD;
            } else if(a[i] < a[j]){
                cnt += (K * (K - 1) / 2LL) % MOD;
                cnt = cnt % MOD;
            }
        }
    }
    cout << cnt <<endl;
}

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

public class Main {
    PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) throws Exception {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    }
    // greed. No need for advanced structure. A simply deque would work.
    long solve(){
        Scanner sc = new Scanner(System.in);
        long W = sc.nextLong(), H = sc.nextLong(), x = sc.nextLong(), y = sc.nextLong();
        double w = (double) W, h = (double) H;
        System.out.print(String.format("%f ",w*h/2.0));
        boolean ans = W==x*2 && H == y*2;
        int res = ans?1:0;
        System.out.println(res);
        System.exit(0);
        return 0;
    }
}



Measured memory_bytes: 21844
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include<numeric>
#include<complex>
#include<ctype.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void pV(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

ll x[110];
ll y[110];
ll h[110];
ll N;

ll max(ll a, ll b){
    if(a > b){
        return a;
    }else{
        return b;
    }
}

bool check(ll cx, ll cy, ll H){
    bool pass = true;
    FOR(i, 0, N){
        ll assumedH = max(H - abs(cx - x[i]) - abs(cy - y[i]), 0);
        if(assumedH != h[i]){
            pass = false;
        }
    }
    return pass;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    cin >> N;

    ll hintX, hintY, hintH;
    FOR(i, 0, N){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] > 0){
            hintX = x[i];
            hintY = y[i];
            hintH = h[i];
        }
    }

    FOR(cx, 0, 101){
        FOR(cy, 0, 101){
            ll H = hintH + abs(cx - hintX) + abs(cy - hintY);

            // cx, cy, Hが決まった
            // これが全データに適合するかチェック
            if(check(cx, cy, H)){
                cout << cx << " " << cy << " " << H << endl;
                return 0;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

void solve() {
    int p, q;
    cin >> p >> q;
    for (int m = 0; m < 10000; m++) {
        for (int n = 0; n < 10000; n++) {
            int A = m * m + n * n;
            int B = p * p + q * q;
            if (A <= 1) continue;
            if (2 * A > B) break;
            if (B % A) continue;
            if ((m * p + n * q) % A) continue;
            if ((m * q - n * p) % A) continue;
            cout << "C" << endl;
            return;
        }
    }
    cout << "P" << endl;
}

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

    int T;
    cin >> T;
    while (T--) {
        solve();
    }
}

Measured memory_bytes: 3124
import sys

H, W, K = map(int, input().split())
S = [list(sys.stdin.readline().strip()) for _ in range(H)]

i = 0
j = 0
ichigo = False
no = False
for i in range(H):
    j = 0
    if len(set(S[i])) == 1 and "." in S[i]:
        no = True
        continue
    while j < W:
        if S[i][j] == ".":
            S[i][j] = str(K)
        else:
            if ichigo is True:
                j -= 1
                K -= 1
                ichigo = False
            else:
                S[i][j] = str(K)
                ichigo = True
        j += 1
    ichigo = False
    K -= 1

if no is True:
    for i in range(H):
        if S[i][0] != ".":
            tmp = i
    for i in reversed(range(tmp)):
        if S[i][0] == ".":
            for j in range(W):
                S[i][j] = S[i + 1][j]
    for i in range(tmp + 1, H):
        if S[i][0] == ".":
            for j in range(W):
                S[i][j] = S[i - 1][j]
for i in range(H):
    print(*S[i])


Measured memory_bytes: 15360
x, y = map(int, input().split())

if (2 * x - y) % 3 != 0:
    print(0)
    exit()

if (2 * y - x) % 3 != 0:
    print(0)
    exit()

if 2 * x - y < 0:
    print(0)
    exit()

if 2 * y - x < 0:
    print(0)
    exit()

a = (2 * x - y) // 3
b = (2 * y - x) // 3

mod = 10**9 + 7
ans = 1
f1 = 1
f2 = 1

for i in range(1, a + b + 1):
    ans = ans * i % mod

for i in range(1, a + 1):
    f1 = f1 * i % mod

for i in range(1, b + 1):
    f2 = f2 * i % mod

ans = ans * pow(f1, mod-2, mod) % mod
ans = ans * pow(f2, mod-2, mod) % mod

print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOZ
{
	class MainClass
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var arr = Console.ReadLine().Split(' ');
			string ans2 = "";
			for (int i = arr.Length - 1; i >= 0; i--)
			{
				ans2 = (ans2 == "") ? arr[i] : ans2 + " " + arr[i];
			}
			Console.WriteLine(ans2);
		}
	}
}



Measured memory_bytes: 15960
import sys
sys.setrecursionlimit(10**9)

from collections import deque

class LCA1():
    def __init__(self, l, start):
        self.n = len(l)
        self.dep=[0]*self.n
        self.par=[[-1]*self.n for i in range(18)]

        def bfs(start):
            is_leaf = [0]*n
            que = deque()
            que.append((start, -1, 0))
            while que:
                c,p,d = que.pop()
                self.dep[c]=d
                self.par[0][c]=p
                cnt = 0
                for to in G[c]:
                    if to != p:
                        que.append((to,c,d+1))
                        cnt += 1
                if not cnt:
                    is_leaf[c] = 1
            return is_leaf

        self.is_leaf = bfs(start)

        for i in range(17):
            for j in range(self.n):
                self.par[i+1][j]=self.par[i][self.par[i][j]]

    def lca(self,a,b):
        if self.dep[a]>self.dep[b]:
            a,b=b,a
        for i in range(18):
            if (self.dep[b]-self.dep[a]) & 1<<i:
                b=self.par[i][b]
        if a==b:
            return a
        for i in range(18)[::-1]:
            if self.par[i][a]!=self.par[i][b]:
                a=self.par[i][a]
                b=self.par[i][b]
        return self.par[0][a]

    def dist(self, a,b):
        return abs(self.dep[a]-self.dep[b])

n, u, v = map(int, input().split())
u, v = u-1, v-1
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append(b)
    G[b].append(a)

LCA = LCA1(G, v)
ans = 0
for i in range(n):
    if not LCA.is_leaf[i]:
        continue
    lca = LCA.lca(u, i)
    if lca == v:
        continue
    if LCA.dist(lca, u) >= LCA.dist(lca, v):
        continue
    turn = 0
    tmp = 0
    d = LCA.dist(u, lca) + LCA.dist(lca, i)
    if d != 0:
        tmp = 2*d
        aoki = d
    else:
        aoki = 0
    tak = LCA.dep[i]
    m = tak-aoki
    if m%2==1:
        tmp += 2*m -1
    else:
        tmp += 2*(m-1)
    ans = max(ans, tmp)
print(ans//2)


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

vector <ll> input;
vector <ll> divi[1000005];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll i,j,k,l,m,n,t;

	cin >> n;

	for(i=0;i<n;i++)
	{
		cin >> k;
		input.push_back(k);
	}

	for(i=1;i<1000001;i++)
	{
		for(j=i;j<1000001;j+=i)
		{
			divi[j].push_back(i);
		}
	}

	// for(i=1;i<=10;i++)
	// 	for(j=0;j<divi[i].size();j++)
	// 		cout << divi[i][j] << " ";
	// 	cout << '\n';

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

	ll flag = 0;
	ll ans = 0;

	for(i=0;i<n;i++)
	{
		flag = 0;
		// cout << input[i] << "\n";
		for(j=0;j<divi[input[i]].size();j++)
		{
			
			m = lower_bound(input.begin(),input.end(),divi[input[i]][j])-input.begin();
			l = upper_bound(input.begin(),input.end(),divi[input[i]][j])-input.begin();
			
			// cout << l << " " << m << '\n';
			
			if(input[i] != divi[input[i]][j])
			{	
				if(l!=m)
				{
					flag = 1;
					break;
				}
			}

			if(input[i] == divi[input[i]][j])
			{
				if((l-m) > 1)
				{
					flag = 1;
					break;
				}
			}


			// if(binary_search(input.begin(),input.end(),divi[input[i]][j]) == true)
			// {
			// 	flag = 1
			// }

		}

		// cout << "flag: " << flag << '\n';

		if(flag == 0)
			ans++;
	}

	cout << ans << '\n';
}


Measured memory_bytes: 118228
#include<stdio.h>
int main(void)
{
	int N,K,s;
	scanf("%d %d", &N,&K);
	s= N%K;
	
	if(s != 0)
	{
		printf("1 \n");
	}
	
	else
	{
		printf("0 \n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

const int N = 100100;
double dp[N][7];
double tot[N];
double inv2[8];


int main(void) {
  inv2[0] = 1;
  REP(i, 1, 8) inv2[i] = inv2[i - 1] / 2;
  dp[0][0] = 1;
  REP(i, 0, N - 1) {
    REP(j, 0, 7) {
      double p = inv2[j];
      if (j < 7) {
        dp[i + 1][j + 1] += dp[i][j] * p;
        tot[i + 1] += dp[i][j] * p;
      }
      dp[i + 1][0] += dp[i][j] * (1 - p);
    }
    tot[i + 1] += tot[i];
  }
  int n;
  while (cin >> n && n) printf("%.15f\n", tot[n]);
}



Measured memory_bytes: 9452
#include <iostream>
#include <cstdio>

using namespace std;

const int N = 200005;

typedef long long LL;

int n, a[N], Lm[N], Rm[N];

LL L[N], R[N], f[N][3];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	if (n % 2 == 0) {
		memset(f, 0xcf, sizeof f);
		f[1][0] = a[1];
		f[2][1] = a[2];
		f[3][0] = a[1] + a[3];
		f[3][2] = a[3];
		for (int i = 4; i <= n; i++) {
			f[i][0] = f[i - 2][0] + a[i];
			f[i][1] = max(f[i - 3][0] + a[i], f[i - 2][1] + a[i]);
			f[i][2] = max(f[i - 3][1] + a[i], max(f[i - 4][0] + a[i], f[i - 2][2] + a[i]));
		}
		printf("%lld\n", max(f[n][1], f[n - 1][0]));
	} else {
		memset(f, 0xcf, sizeof f);
		f[1][0] = a[1];
		f[2][1] = a[2];
		f[3][0] = a[1] + a[3];
		f[3][2] = a[3];
		for (int i = 4; i <= n; i++) {
			f[i][0] = f[i - 2][0] + a[i];
			f[i][1] = max(f[i - 3][0] + a[i], f[i - 2][1] + a[i]);
			f[i][2] = max(f[i - 3][1] + a[i], max(f[i - 4][0] + a[i], f[i - 2][2] + a[i]));
		}
		printf("%lld\n", max(f[n][2], max(f[n - 1][1], f[n - 2][0])));
	}
	return 0;
}

Measured memory_bytes: 8692
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include<stdlib.h>
#include<ctype.h>
#include<limits.h>
#include<map>
#include<limits.h>
#include<ctype.h>
#include<set>
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz size()
#define fast ios_base::sync_with_stdio(false);
#define pq priority_queue
#define mp make_pair
#define mod 1000000007
#define inf 1000000000000000000
using namespace std;
typedef long long ll;
ll func(ll a,ll b)
{
	if(a<b)
	swap(a,b);
	if(b==0) return 0;
	ll d=(a/b)*2*b;
	if(a%b==0) d=d-b;
	return d+func(a%b,b);
}
int main()
{
	ll n,x;
	ll i;
	ll ans;
	cin>>n>>x;
	if(2*x==n)
	{
		cout<<3*x;
		return 0;
	}
	else
	{
		ans=n+func(n-x,x);
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

template<class T> class segtree {
	int n;
	vector<T> data;
	T id;
	function<T(T, T)> operation;
	function<T(T, T)> update;
public:
	segtree(int _n, T _id, function<T(T, T)> _operation, function<T(T, T)> _update)
		:id(_id), operation(_operation), update(_update) {
		n = 1;
		while (n < _n + 2) n <<= 1;
		data = vector<T>(2 * n, id);
	}
	void change(int i, T x) {
		i += n;
		data[i] = update(data[i], x);
		while (i > 1) {
			i >>= 1;
			data[i] = operation(data[i << 1], data[i << 1 | 1]);
		}
	}
	T get(int a, int b) {
		T left = id; T right = id;
		a += n; b += n;
		while (a < b) {
			if (a & 1) left = operation(left, data[a++]);
			if (b & 1) right = operation(data[--b], right);
			a >>= 1; b >>= 1;
		}
		return operation(left, right);
	}
	T get_all() { return data[1]; }
	T operator[](int i) { return data[i + n]; }
};

segtree<int> evenseg(200010, inf, [](int a, int b) {return min(a, b); }, [](int a, int b) {return b; });
segtree<int> oddseg(200010, inf, [](int a, int b) {return min(a, b); }, [](int a, int b) {return b; });
vector<int> edge(200010), pl(200010);
vector<vector<int>> graph(200010, vector<int>());
int root = -1;

void solve(int l, int r, int k, int prev) {
	if (l >= r) return;
	int mi;
	if (k) mi = oddseg.get(l, r);
	else mi = evenseg.get(l, r);
	int to;
	if (k) to = evenseg.get(pl[mi] + 1, r);
	else to = oddseg.get(pl[mi] + 1, r);
	edge[mi] = to;
	if (prev == -1) root = mi;
	else graph[prev].pb(mi);
	solve(l, pl[mi], k, mi);
	solve(pl[mi] + 1, pl[to], k ^ 1, mi);
	solve(pl[to] + 1, r, k, mi);
}

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

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
		if (i & 1) oddseg.change(i, a[i]);
		else evenseg.change(i, a[i]);
		pl[a[i]] = i;
	}
	solve(0, n, 0, -1);
	vector<int> ans;
	priority_queue<int, vector<int>, greater<int>> que;
	que.push(root);
	while (!que.empty()) {
		int q = que.top(); que.pop();
		ans.pb(q);
		ans.pb(edge[q]);
		for (int i : graph[q]) que.push(i);
	}
	for (int i : ans) cout << i << ' ';
	cout << '\n';
}

Measured memory_bytes: 35444
//url:
//problem name: 

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int H,W,N;
    cin >> W >> H  >> N;
    int xmin = 0,ymin = 0;
    int xmax = W,ymax = H;
    REP(i,N) {
        int x,y,a;
        cin >> x >> y >> a;
        if(a == 1) chmax(xmin,x);
        if(a == 2) chmin(xmax,x);
        if(a == 3) chmax(ymin,y);
        if(a == 4) chmin(ymax,y);
    }
    //cout << xmax << " " << xmin << " " << ymax << " " << ymin << endl;
    cout << (xmax-xmin > 0 && ymax - ymin > 0 ? (xmax-xmin)*(ymax-ymin) : 0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
static unsigned int inf = 1e9+7;
static int bn = 1e5;
int main(){
    int n = 0;
    cin >> n;
    int p[20];
    for(int i = 0;i < n;i++){
        cin >> p[i];
    }
    int sum = 0;
    for(int i = 1;i<n-1;i++){
        if(p[i-1]-p[i]>0 && p[i+1]-p[i]<0){
            sum++;
        }else if(p[i-1]-p[i]<0 && p[i+1]-p[i]>0){
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>

using namespace std;

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

	int ab, bc, ca;
	cin >> ab >> bc >> ca;

	cout << ab * bc / 2.0 << endl;

	return 0;
}

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

int main() {
    int a,b,c,d,in;
    c=d=0;
    vector<int> num;
    cin >>a;
    for(int i=0;i<a;i++){
      cin >>in;
      num.push_back(in);
    }
    while(c==0){
      for(int j=0;j<a;j++){
      	if(num[j]%2==0){
      		num[j]=num[j]/2;
      	}
      	else{
      		c=-1;
      		break;
      	}
      }
      if(c==0){
        d++;
      }
    }
    cout << d <<endl;
 }


Measured memory_bytes: 256