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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

int n,a[101],ct[101],M;

string imp="Impossible\n";

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for (int i=0;i<n;i++) {
		cin >> a[i];
		M=max(M,a[i]);
		ct[a[i]]++;
	}

	bool two=M%2==1;
	for (int i=0;i<(M+1)/2;i++) if (ct[i]!=0) {
		cout << imp;
		return 0;
	}

	if ((two && ct[(M+1)/2]!=2) || (!two && ct[(M+1)/2]!=1)) {
		cout << imp;
		return 0;
	}

	for (int i=(M+1)/2+1;i<=M;i++) if (ct[i]<2) {
		cout << imp;
		return 0;
	}

	cout << "Possible\n";
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <unordered_map>

using namespace std;

typedef long long ll;

void solve() {
	int x, n;
	cin >> x >> n;
	vector<int> used(102);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		used[a] = 1;
	}
	int otv = 0;
	int d = x;

	for (int i = 1; i < 102; i++) {
		if (!used[i]) {
			if (d > abs(x - i)) {
				d = abs(x - i);
				otv = i;
			}
		}
	}

	cout << otv;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 3664
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

//#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

//ostream& operator << (ostream &a, const vector<int> &b) {
//    for (auto k : b) cout << k << " ";
//    return a;
//}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {cin >> a[i]; a[i]--;}
    vector<int> pref(n);
    pref[0] = a[0];
    for (int i = 1; i < n; i++) pref[i] = pref[i - 1] + a[i];
    ld ans = 0;
    for (int i = 0; i < n - k + 1; i++) {
        ld cur = pref[i + k - 1];
        if (i != 0) cur -= pref[i - 1];
        ans = max(ans, cur / 2.0);
    }
    cout << ans + k;
}
/*

*/


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define inv 499122177
#define maxn 1000010
#define mod 998244353
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,N,len,lim=1;
int p[maxn],a[maxn];
int quick_pow(int x,int p)
{
    int an=1,po=x;
    while(p)
    {
        if(p&1)  an=1ll*an*po%mod;
        po=1ll*po*po%mod;
        p>>=1;
    }
    return an;
}
void FWT(int A[maxn],int type)
{
    for(int mid=1;mid<lim;mid<<=1)
    {
        for(int j=0;j<lim;j+=(mid<<1))
        {
            for(int k=0;k<mid;k++)
            {
                int x=A[j+k],y=A[j+k+mid];
                if(type==1)  A[j+k]=(x+y)%mod,A[j+k+mid]=(x-y+mod)%mod;
                else         A[j+k]=1ll*(x+y)*inv%mod,A[j+k+mid]=1ll*(x-y+mod)*inv%mod;
            }
        }
    }
}
int main()
{
    n=read();
    N=(1<<n);
    for(int i=0;i<N;i++)  p[i]=read();
    int sum=0;
    for(int i=0;i<N;i++)  sum+=p[i];
    sum=quick_pow(sum,mod-2);
    for(int i=0;i<N;i++)  p[i]=1ll*p[i]*sum%mod;
    p[0]=(p[0]-1+mod)%mod;
    for(int i=0;i<N;i++)  a[i]=mod-1;
    a[0]=N-1;
    while(lim<2*N)  lim<<=1,len++;
    FWT(p,1);
    for(int i=0;i<lim;i++)  p[i]=quick_pow(p[i],mod-2); 

    FWT(a,1);
    for(int i=0;i<lim;i++)  p[i]=1ll*p[i]*a[i]%mod;
    FWT(p,-1);
    for(int i=1;i<lim;i++)  p[i]=(p[i]-p[0]+mod)%mod;
    p[0]=0;
    for(int i=0;i<N;i++)  printf("%d\n",p[i]);
    return 0;
}

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

int main()
{
    

    int xgroup,ygroup;
    int x,y;
    cin>>x>>y;
    switch(x)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
        xgroup=1;
        break;
        case 4:
        case 6:
        case 9:
        case 11:
        xgroup=2;
        break;
        case 2:
        xgroup=3;
        break;
    }

    switch(y)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
        ygroup=1;
        break;
        case 4:
        case 6:
        case 9:
        case 11:
        ygroup=2;
        break;
        case 2:
        ygroup=3;
        break;
    }
    if(xgroup==ygroup)
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

int f[100000];
vector <int> v[100000];

int main() {
    int n, m, x, y, i;
    deque <int> d;
    
    scanf("%d %d", &n, &m);
    
    for (i = 0; i < m; i++) {
        int x, y;
        
        scanf("%d %d", &x, &y);
        
        x--;
        y--;
        
        v[x].push_back(y);
        v[y].push_back(x);
    }
    
    x = 0;
    y = v[0][0];
    f[x] = f[y] = 1;
    d.push_back(x);
    d.push_back(y);
    
    while (1) {
        for (i = 0; i < v[x].size(); i++) {
            if (f[v[x][i]] == 0) break;
        }
        
        if (i == v[x].size()) break;
        
        x = v[x][i];
        f[x] = 1;
        d.push_front(x);
    }
    
    while (1) {
        for (i = 0; i < v[y].size(); i++) {
            if (f[v[y][i]] == 0) break;
        }
        
        if (i == v[y].size()) break;
        
        y = v[y][i];
        f[y] = 1;
        d.push_back(y);
    }
    
    printf("%d\n", d.size());
    for (i = 0; i < d.size(); i++) {
        if (i > 0) putchar(' ');
        printf("%d", d[i] + 1);
    }
    puts("");
    
    return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmin(T & ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T & ref, const T value) {
    if (ref < value) ref = value;
}

const ll mod = 1000000007;

ll mpow(ll x, ll n) {
    ll ans = 1; x %= mod;
    while (n != 0) {
        if (n & 1) ans = ans * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    return ans;
}

int main() {
    ll m, n;
    cin >> m >> n;
    cout << mpow(m, n) << endl;
    return 0;
}




Measured memory_bytes: 3108
// JavaProgram.cpp
// Author : Priydarshi Singh (@dryairship)
// One cat just leads to another. One bug leads to two others.

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

// I like my types defined.
typedef long long           ll;
typedef pair<int, int>      pii;
typedef pair<ll, ll>        pll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef vector<pii>         vii;
typedef vector<pll>         vll;
typedef set<int>            si;
typedef map<string, int>    msi;
typedef map<int, int>       mii;

// Traditional science is all about finding "hashtag define"s.
#define fr(i, n)            for(int i=0; i<(n); ++i)
#define frC(i, n, c)        for(int i=0; (i<(n)) && (c); ++i)
#define frA(i, a, n)        for(int i=a; i<=(n); ++i)
#define frD(i, a, n)        for(int i=a; i>=(n); --i)
#define fill(a)             memset(a, 0, sizeof(a))
#define fill1(a)            memset(a, -1, sizeof(a))
#define revsort(a, b)       sort(a, b, greater<int>())
#define ff                  first
#define ss                  second
#define pb                  push_back 
#define dout                if(DEBUGGING) cout
#define dbg                 if(DEBUGGING) 
#define endl                "\n"

// When you realize MOD > INF...
int DEBUGGING    =          0;
const int INF    =          1000000000;
const int MOD    =          1000000007;
const ll LINF    =          1e18;
const double PI  =          3.1415926535897932;
const double EPS =          1e-7;

// I'D SPAM. Hehe.
ll gcdEx                    (ll a, ll b, ll *x, ll *y){if(!a){*x=0;*y=1;return b;} 
ll x1,y1,gcd=gcdEx          (b%a,a,&x1,&y1); *x=y1-(b/a)*x1;*y=x1; return gcd;}
ll modI(ll b, ll m)         {ll x,y;gcdEx(b,m,&x,&y);return (x%m+m)%m;}
ll modD(ll a, ll b)         {return (modI(b,MOD)*(a%MOD))%MOD;}
ll modS(ll a, ll b)         {return ((a%MOD)-(b%MOD)+MOD)%MOD;}
ll modP(ll x, ll y)         {ll r=1; x%=MOD; while(y>0){if(y&1){r=(r*x)%MOD;} y=y>>1; x=(x*x)%MOD;} return r;}
ll modA(ll a, ll b)         {return ((a%MOD)+(b%MOD))%MOD;}
ll modM(ll a, ll b)         {return ((a%MOD)*(b%MOD))%MOD;}

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

int c[15];
int a[15][15];
int n,m,x;
int p[5000];
int f[5000][15];

void solve(int TEST_CASE){
    cin >> n >> m >> x;
    fr(i,n){
        cin >> c[i];
        fr(j,m){
            cin >> a[i][j];
        }
    }
    int t;
    fr(i,(1<<n)){
        p[i]=0;
        fr(j,m) f[i][j]=0;
        t = i;
        fr(j,n){
            if(i&(1<<j)){
                p[i]+=c[j];
                fr(k,m){
                    f[i][k]+=a[j][k];
                }
            }
        }
        fr(j,m){
            if(f[i][j]<x){
                p[i]=INF;
                break;
            }
        }
    }
    sort(p,p+((int)(1<<n)));
    if(p[0]==INF){
        cout << -1;
    }else {
        cout << p[0];
    }
}

int main(int argc, char* argv[]){
    if(argc==2 && argv[1][1]=='v') DEBUGGING = 1;
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin.exceptions(cin.failbit);
    int nTestCases=1;
    //cin >> nTestCases;
    frA(i,1,nTestCases) solve(i);
    return 0;
}

Measured memory_bytes: 3876
#include <iostream>
using namespace std;
int main(void) {
    int a[200][200], b[200][200];
    long long int c[200][200] = {};
    int n, m, l;
    cin >> n >> m >> l;
    for (int d = 1; d <= n; d++) {
        for (int e = 1; e <= m; e++) {
            cin >> a[d][e];
        }
    }
    for (int d = 1; d <= m; d++) {
        for (int e = 1; e <= l; e++) {
            cin >> b[d][e];
        }
    }
    for (int d = 1; d <= n; d++) {
        for (int e = 1; e <= l; e++) {
            for (int f = 1; f <= m; f++) {
                c[d][e] += a[d][f] * b[f][e];
            }
        }
    }
    for (int d = 1; d <= n; d++) {
        for (int e = 1; e < l; e++) {
            cout << c[d][e] << " ";
        }
        cout << c[d][l] << endl;
    }
    return 0;
}

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

ma = max(a)
mi = min(a)

num = 0
ans = []

if ma >= -mi:
    ind = a.index(ma)
    for i in range(1, n):
        while a[i-1] > a[i]:
            num += 1
            ans.append(str(ind+1) + ' ' + str(i+1))
            a[i] += ma
            if a[i] > ma:
                ma = a[i]
                ind = i

else:
    ind = a.index(mi)
    for i in range(n-2, -1, -1):
        while a[i] > a[i+1]:
            num += 1
            ans.append(str(ind+1) + ' ' + str(i+1))
            a[i] += mi
            if a[i] < mi:
                mi = a[i]
                ind = i

print(num)
for i in ans:
    print(i)

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int n;
int a[100005];
int L[100005];
int len=1;
int main() {
    cin>>n;
    rep(i,n) cin>>a[i];
    L[0]=a[0];
    rep(i,n) if(i) {
        if(L[len-1]<a[i]) {
            L[len]=a[i];
            len++;
        }
        else {
            int pos=lower_bound(L,L+len,a[i])-L;
            L[pos]=a[i];
        }
        //cout<<len<<" : ";
        //rep(i,len) if(i) cout<<L[i]<<" ";
        //cout<<endl;
    }

    cout<<len<<endl;
    return 0;
}

Measured memory_bytes: 1940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] inputs = br.readLine().split(" ");
		int N = Integer.parseInt(inputs[0]);

		int rival[][] = new int[N + 1][N]; // pのn番目の対戦相手 r = rival[p][n]  (1-origin 
		int mday[][] = new int[N + 1][N];  // pのn番目の試合日   d = mday[p][n]  (1-origin 

		// p:player  r:rival
		for ( int p = 1; p <= N; p++ ) {
			inputs = br.readLine().split(" ");
			for ( int n = 1; n <= N - 1; n++ ) {
				rival[p][n] = Integer.parseInt(inputs[n - 1]);
			}
		}

		ArrayDeque<Integer> q = new ArrayDeque<Integer>(); // マッチメイクを試行するpのキュー
		int[] mcnt = new int[N + 1];				   			// p が何試合目まで進んだか =  prog[p]
		// 初日に成立する試合を見ていく
		for ( int p = 1; p <= N; p++ ) {
			int r = rival[p][1];
			
			if ( p == rival[r][1] && mday[p][1] * mday[r][1] == 0 ) {
				mday[p][1] = mday[r][1] = 1;
				mcnt[p] = mcnt[r] = 1;
				q.addLast(p);
				q.addLast(r);
			}
		}

		// 2日目以降
		while ( 0 < q.size() ) {
			int p = q.pollFirst();
			int pn = mcnt[p] + 1;
			if ( pn >= N ) continue;
			
			int r = rival[p][pn];
			int rn = mcnt[r] + 1;
			if ( rn >= N ) continue;

			// 試合が成立したら試合日テーブルに記入
			if ( p == rival[r][rn] ) {

				mday[p][pn] = mday[r][rn] = Math.max(mday[p][pn - 1] + 1, mday[r][rn - 1] + 1);

				mcnt[p]++;
				mcnt[r]++;
				q.addLast(p);				
				q.addLast(r);
			}
		}

		// pごとに最後の試合日を見てMaxを取る
		int mdayMax = 0;
		for ( int p = 1; p <= N; p++ ) {
			int d = mday[p][N - 1];
			if ( d == 0 ) {
				mdayMax = -1;
				break;
			} else {
				mdayMax = Math.max(mdayMax, d);
			}
		}
		System.out.println(mdayMax);
		br.close();
	}
}


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


Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	k, q := scanInt(), scanInt()
	d := scanInts(k)

	for i := 0; i < q; i++ {
		n, x, m := scanInt(), scanInt(), scanInt()
		a, c := x, 0
		n--

		for j := 0; j < k; j++ {
			cc := (n - j + k - 1) / k
			dd := d[j] % m
			if dd == 0 {
				c += cc
			}
			a += cc * dd
		}
		c += a/m - x/m
		fmt.Fprintln(wr, n-c)
	}
}


Measured memory_bytes: 2184
package main

import (
	"fmt"
)

func main() {
	var S string
	fmt.Scan(&S)
	rs := []rune(S)
	var r, l []rune
	if len(rs)%2 == 0 {
		l = rs[:len(rs)/2]
		r = rs[len(rs)/2:]
	} else {
		l = rs[:len(rs)/2]
		r = rs[len(rs)/2+1:]
	}
	rev(r)
	cnt := 0
	for i := 0; i < len(r); i++ {
		if string(l[i]) != string(r[i]) {
			cnt++
		}
	}
	fmt.Println(cnt)
}

func rev(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


Measured memory_bytes: 512
s = input()
x = [int(s[:2]), int(s[2:])]
y = [False, False]
for i, xi in enumerate(x):
    if 1 <= xi <= 12:
        y[i] = True
if y[0] and y[1]:
    print('AMBIGUOUS')
elif y[0]:
    print('MMYY')
elif y[1]:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
ll fact_[200000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 200000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, k;
bool a[300000];
int dp[300000];
signed main() {
	cin >> n >> k;
	string s;
	cin >> s;
	int r = 0;
	for (int i = 0; i < s.size(); i++) {
		dp[i] = Inf;
		if (s[i] == '0') {
			while (i - r > k) r++;
			while (s[r] == '1') r++;
			dp[i] = min(dp[i], dp[r] + 1);
		}
		if (i == 0) dp[i] = 0;
	}
	vector<int>b;
	if (dp[n] == Inf) {
		cout << -1 << endl;
		return 0;
	}
	int m = dp[n] - 1;
	r = n;
	for (int i = n; i >= 0; ) {
		int j = i - 1,  res = 0;
		while (j >= 0 && dp[j] >= m && i - j <= k) {
			if (dp[j] == m) {
				res = j;
			}
			j--;
		}
		b.push_back(i - res);
		i = res;
		m--;
		if (res == 0) break;
	}
	reverse(all(b));
	for (int i = 0; i < b.size(); i++) {
		cout << b[i] << (i == b.size() - 1 ? "\n" : " ");
	}
}

Measured memory_bytes: 4344
#include<stdio.h>

int kazu=0;

int merge(int A[],int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int i,j,k;
  int Le[250001];
  int Ri[250001];

  for(i=0;i<=n1-1;i++) Le[i]=A[left+i];
  for(i=0;i<=n2-1;i++) Ri[i]=A[mid+i];
  Le[n1]=1000000001;
  Ri[n2]=1000000001;
  i=0;
  j=0;

  for(k=left;k<=right-1;k++){
    kazu++;
    if(Le[i]<=Ri[j]){
      A[k]=Le[i];
      i++;
    }
    else {
      A[k]=Ri[j];
      j++;
    }
  }
}


int mergeSort(int A[], int left, int right)
{
	int mid;
	if(left+1<right)
	{
		mid=(left+right)/2;
		mergeSort(A,left,mid);
		mergeSort(A,mid,right);
		merge(A,left,mid,right);
	}
}


int main(void)
{
	int i,n;
	int S[500000];
	
	scanf("%d",&n);
	for(i=0;i<=n-1;i++) scanf("%d",&S[i]);
	
	mergeSort(S,0,n);
	for(i=0;i<=n-1;i++)
	{
		if(i) printf(" ");
		printf("%d",S[i]);
	}
	
	printf("\n%d\n",kazu);
	return 0;
}



Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(c) (c).begin(), (c).end()
#define REVERSE(c) reverse(ALL(c))
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort(ALL(c))
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


int main() {
	LL A, B;
	cin >> A >> B;

	LL max_d = 40;
	LL sum = 0;
	REP(d, max_d) {
		LL n = A / ((LL)1 << (d + 1));
		LL x = A % ((LL)1 << (d + 1));
		LL m = (B + 1) / ((LL)1 << (d + 1));
		LL y = (B + 1) % ((LL)1 << (d + 1));
		LL count1 = 0;
		if (d == 0) {
			count1 += m - n - 1;
		}
		count1 += min(((LL)1 << (d + 1)) - x, (LL)1 << d);
		count1 += max((LL)0, y - ((LL)1 << d));
		if (count1 % 2 == 1) {
			sum += ((LL)1 << d);
		}
	}
	cout << sum << endl;
	
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */



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

    int n; cin >> n;
    rep(i, n) {
        int a; cin >> a;
        if(a%2==0) {
            if(a%3!=0 && a%5!=0) { cout << "DENIED" << endl; return 0; }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

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

using namespace std;

int main(void) 
{
    long long N, K;
    std::vector<int> in;
    cin >> N >> K;
    in.resize(N);
    for (int i = 0; i < N; i++)
    {
        cin >> in[i];
    }
    
    std::vector<bool> isAppeared;
    isAppeared.resize(N + 1, false);

    std::vector<int> firstAppeared;
    firstAppeared.resize(N + 1, 0);
    
    int currentTown = 1;
    int loopStartId;
    int loopLength;
    bool loopExists = false;
    for(int i=0;i<N;i++)
    {
        if (true == isAppeared[currentTown-1])
        {
            loopStartId = firstAppeared[currentTown - 1];
            loopLength = i - firstAppeared[currentTown - 1];
            loopExists = true;
            break;
        }
        else
        {
            if (K == i) break;
            firstAppeared[currentTown - 1] = i;
            isAppeared[currentTown - 1] = true;
            currentTown = in[currentTown - 1];
        }
    }

    if (true == loopExists)
    {
        long long remain = (K - loopStartId) % loopLength;

        for (int i = 0; i < remain; i++)
        {
            currentTown = in[currentTown - 1];
        }
    }

    std::cout << currentTown << std::endl;

    return 0;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
using ll =long long;
using namespace std;

int main(){
    int n;
    cin>>n;
    int a=n%10;
    if(a==2||a==4||a==5||a==7||a==9){
        cout<<"hon"<<endl;
    }else if(a==0||a==1||a==6||a==8){
        cout<<"pon"<<endl;
    }else{
        cout<<"bon"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main() {
    int n;
    cin>>n;
    int height[n];
    for(int i=0;i<n;i++) cin>>height[i];
    int dp[n];
    dp[0]=0;
    dp[1]=abs(height[1]-height[0]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(height[i]-height[i-1]),dp[i-2]+abs(height[i]-height[i-2]));
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 4380
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >>s;
    int a = stoi(s.substr(0, 2));
    int b = stoi(s.substr(2));
    if(a >= 1 and a <= 12 and b >= 1 and b <= 12)
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if(a >= 1 and a <= 12)
    {
        cout << "MMYY" << endl;
    }
    else if(b >= 1 and b <= 12)
    {
        cout << "YYMM" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N;
    scanf("%d", &N);
    if (N < 10)
    {
        printf("%d", N);
    } else if (10 <= N && N <= 99)
    {
        printf("9");
    } else if (100 <= N && N <= 999)
    {
        printf("%d", 9 + N - 100 + 1);
    } else if (1000 <= N && N <= 9999)
    {
        printf("909");
    } else if (10000 <= N && N <= 99999)
    {
        printf("%d", 909 + N - 10000 + 1);
    } else if (N == 100000)
    {
        printf("90909");
    }
}

Measured memory_bytes: 256
def is_kaibun(s):
    return s[:len(s)//2] == s[::-1][:len(s)//2]

def is_strong_kaibun(s):
    if not is_kaibun(s):
        return False
    if not is_kaibun(s[:(len(s)-1)//2]):
        return False
    if not is_kaibun(s[(len(s)+3)//2-1:]):
        return False
    return True
  
s = input()
if is_strong_kaibun(s):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
    int a,b,x;
    char op;
    while(1){
        scanf("%d %c %d",&a,&op,&b);
        if(op == '+'){
            x = a+b;
            printf("%d\n",x); }
        else if(op == '-'){
            x = a-b;
            printf("%d\n",x); }
        else if(op == '*'){
            x = a*b;
            printf("%d\n",x); }
        else if(op == '/'){
            x = (double)a/(double)b;
            printf("%d\n",x); }
        else if(op == '?'){ break; }
        }
    return(0);
} 


Measured memory_bytes: 2100
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<tuple>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef unsigned long long int ull;
const int INF=1e9;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=1e5;

struct edge{
    int to,cost;
};

int n;
vector<vector<edge> > G(MAXN);
vector<int> color(MAXN,-1);

void dfs(int u,int c){
    color[u]=c;
    for(auto e:G[u]){
        if(color[e.to]!=-1) continue;
        if(e.cost%2==0) dfs(e.to,c);
        else dfs(e.to,1-c);
    }
    return;
}

int main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int u,v,w;
        cin>>u>>v>>w;
        u--;v--;
        G[u].push_back(edge{v,w});
        G[v].push_back(edge{u,w});
    }
    dfs(0,0);
    for(int i=0;i<n;i++){
        cout<<color[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 10988
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin>>s;
    if(s[0]==s[2]) print("Yes");
    else print("No");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

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

    vector<vector<int>> to(N), cost(N);

    for(int i = 0; i < N-1; i++){
        int a, b, w;
        cin >> a >> b >> w;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
        cost[a].push_back(w);
        cost[b].push_back(w);
    }

    vector<int> ans(N, -1);
    queue<int> que;
    ans[0] = 0;
    que.push(0);
    
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(int i = 0; i < to[v].size(); i++){
            int u = to[v][i];
            int w = cost[v][i];
            if(ans[u] != -1) continue;
            ans[u] = (ans[v] + w) % 2;
            que.push(u);
        }
    }

    for(int i = 0; i < N; i++){
        cout << ans[i] << endl;;
    }
    return 0;
}


Measured memory_bytes: 11904
#include <stdio.h>
#define FOR(i,a,n) for(i=a;i<n;i++)

int binary_lower(int a[],int n,int k){
	int left=-1; int right=n;
	while(right-left>1){
		int mid=(left+right)/2;
		if(a[mid]<k) left=mid;
		else right=mid;
	}
	return right;
}
int binary_upper(int a[],int n,int k){
	int left=-1; int right=n;
	while(right-left>1){
		int mid=(left+right)/2;
		if(a[mid]<=k) left=mid;
		else right=mid;
	}
	return left;
}
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
int pos[100000];
int x[100000],w[100000];
int main(void)
{
	int n,l,t,cnt=0,a,s,k,d,i;
	scanf("%d%d%d",&n,&l,&t);
	FOR(i,0,n){
		scanf("%d%d",&x[i],&w[i]);
		if(w[i]==1) pos[i]=(x[i]+t%l)%l;
		else pos[i]=(x[i]-t%l+l)%l;
	}
	a=pos[0];
	qsort(pos,n,sizeof(int),comp);
	if(w[0]==1){
		FOR(i,0,n){
			d=x[i]-x[0];
			if(w[i]==2&&d<2*t){
				cnt+=1+(2*t-d-1)/l;
				cnt%=n;
			}
		}
		k=cnt%n;
		s=binary_lower(pos,n,a);
	}
	else{
		FOR(i,0,n){
			d=l-x[i]+x[0];
			if(w[i]==1&&d<2*t){
				cnt+=1+(2*t-d-1)/l;
				cnt%=n;
			}
		}
		k=(n-cnt)%n;
		s=binary_upper(pos,n,a);
	}
	d=(s-k+n)%n;
	FOR(i,0,n) printf("%d\n",pos[(d+i)%n]);
	return 0;
}
    
    


Measured memory_bytes: 2292
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define REP3(i,x,n) for(int i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    ll S,W;
    scanf("%lld%lld",&S,&W);
    if(S<=W)printf("unsafe");
    else printf("safe");
    return 0;
}

Measured memory_bytes: 3852
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	sc.Split(bufio.ScanWords)

	var h, w int
	fmt.Scan(&h, &w)
	s := make([]string, h)
	hc := make([][]int, h)
	vc := make([][]int, h)
	for i := 0; i < h; i++ {
		s[i] = next()
		hc[i] = make([]int, w)
		vc[i] = make([]int, w)
	}

	for i := 0; i < h; i++ {
		cnt := 0
		for j := 0; j < w; j++ {
			if s[i][j] == '#' {
				cnt = 0
			} else {
				cnt++
			}
			hc[i][j] = cnt
		}
		for j := w - 2; j >= 0; j-- {
			if hc[i][j] > 0 {
				hc[i][j] = max(hc[i][j], hc[i][j+1])
			}
		}
	}

	for j := 0; j < w; j++ {
		cnt := 0
		for i := 0; i < h; i++ {
			if s[i][j] == '#' {
				cnt = 0
			} else {
				cnt++
			}
			vc[i][j] = cnt
		}
		for i := h - 2; i >= 0; i-- {
			if vc[i][j] > 0 {
				vc[i][j] = max(vc[i][j], vc[i+1][j])
			}
		}
	}

	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			ans = max(ans, hc[i][j]+vc[i][j]-1)
		}
	}
	fmt.Println(ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 71552
import java.util.*;

public class Main
{
  public static void main(String args[])
  {
    Scanner scan = new Scanner(System.in);
	int a = scan.nextInt();
	int b = scan.nextInt();
	int count=0,non=1;
	while((a>0)&&(b>0))
	{
		if(non>=b)
		{
			break;
		}
		else
		{
			non=non-1+a;
			count++;
		}
	}
	System.out.println(count);
  }
}
		

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

const ll L = 105;

vector <ll> h;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
 
    ll N;
    cin >> N;

    for(ll i=0; i<N; i++)
    {
        ll a;
        cin >> a;

        h.pb(a);
    }   

    ll cur = 0;
    ll ans = 0;

    while(1)
    {
        // cur = 0;
        while(h[cur]==0)
        {
            cur++;

            if(cur==N)
            {
                cout << ans << endl;
                return 0;
            }
        }

        for(ll i=cur; i<N; i++)
        {
            if(h[i])
            {
                h[i]--;
            }

            else
            {
                break;
            }
        }

        ans++;
    }

    // cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// author:-*mdragneell*

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

#define ll long long
#define ld long double
#define pb push_back
#define pi  pair<int,int>
#define pl  pair<ll,ll>

int const N=500001;
ll min(ll x,ll y) { if(x<y) return x; else return y; }
ll max(ll x,ll y) { if(x>y) return x; else return y; }

ll dp[N],n;
vector<ll>v(N);

ll solve(ll x,ll pre)
{

	if(x>=n) return 0;
	if(dp[x]!=-1) return dp[x];
	return dp[x]=min(abs(v[x+1]-v[x])+solve(x+1,x),abs(v[(x+2>=n?x+1:x+2)]-v[x])+solve((x+2>=n?x+1:x+2),x));
}

int main()
{
	ll i;
	cin>>n;
	memset(dp,-1,sizeof(dp));
	for(i=0;i<n;i++) cin>>v[i];
	v[n]=v[n-1];
	cout<<solve(0,0);

}


Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)


ll kosuu_arr[200005] = {0};

int main(){
	int N;
	vector<ll> arr;
	vector<ll> sum_arr;	
	cin>>N;


	arr.resize(N);
	sum_arr.resize(N);

	REP(i,N){
		ll a;
		cin>>a;
		arr[i] = a;
		kosuu_arr[a]++;
	}
	ll all_sum = 0;
	for(int i = 1; i <= N; i++){
		if(kosuu_arr[i] == 0){
			sum_arr[i-1] = 0;
		}
		else{
			sum_arr[i-1] = (kosuu_arr[i] * (kosuu_arr[i] - 1)) / 2;
//			cout<<"suma : "<<sum_arr[i-1]<<endl;
			all_sum += sum_arr[i-1];
		}
	}

//	cout<<"as : "<<all_sum<<endl;
	for(int i = 1; i <= N; i++){

		ll ans = 0;
		ll index = arr[i-1] ;
		ll dec_kosuu = kosuu_arr[index] - 1;
		
//		cout<<"i : "<<i<<endl;
//		cout<<"index : "<<index<<endl;
//		cout<<"dec_kosuu : "<<dec_kosuu<<endl;
		if(dec_kosuu <= 0){
			ans = all_sum;
		}
		else{
			ans = all_sum - sum_arr[index-1] + (dec_kosuu * (dec_kosuu-1)) / 2;
		}
		cout<<ans<<endl;
	}

	return 0;	

}



Measured memory_bytes: 6272
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;
ll bitpow(ll x,ll n){
    ll ans = 1;
    while(n > 0){
        if(n%2 == 1) ans = ans * x % MOD;
        x = x * x %MOD;
        n = n >> 1;
    }
    return ans;
}
/*----------------------------------------------------------------*/
signed main(){

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

	int bit[61] = {};
	for(auto x:a){
		rep(i,60){
			if(x&(1LL<<i))bit[i]++;
		}
	}
	int ans = 0;
	rep(i,n){
		int res = 0;
		int pre = 0;
		rep(j,80){
			int cnt;
			if(j < 60)cnt = bit[j];
			else cnt = 0;

			if(j < 60 && (a[i]&(1LL<<j)))cnt = n-cnt;
			cnt += pre;
			pre = cnt/2;
			res += cnt%2 * bitpow(2,j);
			res %= MOD;
			// if(i == 0)cerr << bit[j] << " " <<  cnt << " " << res << endl;
		}
		// cerr << i << " : " << res << endl;
		ans = (ans+res)%MOD;
	}
	cout << ans*bitpow(2,MOD-2)%MOD << endl;



	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_b
// rm -r -f test;oj dl https://abc147.contest.atcoder.jp/tasks/abc147_d

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

int main()
{
    int l, a[3];

    int i = 0;
    while (cin >> l) {
        a[i] = l;
        i++;
    }
    
    bool flag = false;
    
    if (a[0] == a[1] && a[0] != a[2]) {
        flag = true;
    } else if (a[0] == a[2] && a[0] != a[1]) {
        flag = true;
    }else if (a[1] == a[2] && a[0] != a[1]) {
        flag = true;
    }
    
    if (flag == false) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    
    

    // for (i = 0; i < 3; i++) {
    //     cout << a[i];
    // }

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  char S[SIZE];

  scanf("%s", S);

  int N = strlen(S);

  vector<ll> now(13), next(13);

  now[0] = 1;

  for (int i=0; i<N; i++) {
    for (int j=0; j<13; j++) {
      for (int k=0; k<10; k++) {
        if (S[i] == '?' || S[i] == '0' + k) {
          next[(j*10+k) % 13] += now[j];
        }
      }
    }

    for (int j=0; j<13; j++) {
      now[j] = next[j] % mod;
      next[j] = 0;
    }
  }

  cout << now[5] << endl;

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

int main() {
    ll N, K;
    cin >> N >> K;

    vector<ll> p(N);
    rep(i, N) cin >> p[i];

    vector<double> e(N);
    rep(i, N) { e[i] = ((double)p[i] * (1 + p[i]) / 2) / p[i]; }

    // rep(i, N) cout << e[i] << " ";
    // cout << endl;

    double current = 0.0;

    rep(i, K) { current += e[i]; }
    double ans = current;

    reps(i, K, N) {
        current = current - e[i - K] + e[i];
        // cout << current << endl;
        ans = max(current, ans);
    }

    cout << fixed << setprecision(12) << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define rFORq(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size,-1) { }

    int root(int x){
        if (data[x] < 0) return x;
        else return data[x] = root(data[x]);
    }

    int size(int x){
        return -data[root(x)];
    }

    bool isConnect(int x,int y){
        return root(x) == root(y);
    }

    bool connect(int x , int y){
        x = root(x);
	    y = root(y);
	
        if(x==y) return false;
        
        if(data[x] > data[y]){
            x ^= y;
            y ^= x;
            x ^= y;
        }
        
        data[x] = data[x] + data[y]; // membersize++
        data[y] = x;
        return true;
    }
};

UnionFind U1(200002);
UnionFind U2(200002);

int main(){ 
    int N,K,L; SCD3(N,K,L);
    REP(i,K){
        int p,q; SCD2(p,q);
        U1.connect(p,q);
    }
    REP(j,L){
        int r,s; SCD2(r,s);
        U2.connect(r,s);
    }

    map< PII ,int> f;

    FORq(i,1,N){
        int a,b;
        a = U1.root(i);
        b = U2.root(i);
        PII p = MP(a,b);
        f[p]++;
    }

    FORq(i,1,N){
        int a,b;
        a = U1.root(i);
        b = U2.root(i);
        PII p = MP(a,b);
        printf("%d ",f[p]);
    }
    printf("\n");
}

Measured memory_bytes: 13696
N,x=map(int,input().split())
a=list(map(int,input().split()))
 
ans=0
for i in range(1,N):
    tmp=a[i-1]+a[i]
    if tmp>x:
        ans+=tmp-x
        if a[i]>=tmp-x:
            a[i]-=tmp-x
        else:
            a[i]=0
    else:
        continue
print(ans)

Measured memory_bytes: 20064
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

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

  for(int i = 1; i <= 2; i++){
    if(S[i] != S[i-1]){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  
  return 0;
}


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

using namespace std;

int main() {
    int n; cin >> n;
    
    vector<string> mat(2 * n - 1);
    for (int i = 0; i < n; ++i) {
        cin >> mat[i];
        mat[i] += mat[i];
        mat[i].pop_back();
    }
    for (int i = 0; i < n - 1; ++i) {
        mat[i + n] = mat[i];
    }
    int sz = 2 * n - 1;
    
    int total = 0;
    for (int diag = -n + 1; diag < n; ++diag) {
        int symms = 0;
        auto add = [&](int ci, int cj, int cnt, int coef) {
            for (int delta = -cnt; delta < n - cnt; ++delta) if (delta)
                symms += coef * (mat[ci + delta][cj] == mat[ci][cj + delta]);
        };
        

        int i = max(0, -diag);

        for (int it = 0; it < n; ++it) {
            add(i, i + diag, it, 1);
            ++i;
        }
        total += (symms == (n - 1) * n);
        while (true) {
            if (i >= sz or i + diag >= sz) break;
            add(i - n, i - n + diag, 0, -2);
            add(i, i + diag, n - 1, 2);  
            total += (symms == (n - 1) * n);
            ++i;
        }
    }

    cout << total << endl;
    
    return 0;
}


Measured memory_bytes: 768
def chess(h,w):
    for height in range(h):
        for width in range(w):
            if (height + width) % 2 == 1:
                print('.',end='')
            else:
                print('#',end='')
        print()
    print()

hws = []
while True:
    hw = list(map(int,input().split()[:2]))
    if hw[0] == hw[1] == 0:
        break
    hws.append(hw)

for hw in hws:
    chess(hw[0],hw[1])


Measured memory_bytes: 7008