akhauriyash/Code-Regression huggingface dataset:
import collections

n = int(input())
v = list(map(int, input().split()))
odd, even = [], []

for i in range(n):
  if i % 2 == 0:
    even.append(v[i])
  else:
    odd.append(v[i])

    
codd = collections.Counter(odd)
ceven = collections.Counter(even)
mostodd = codd.most_common()[0]
mosteven = ceven.most_common()[0]

if mostodd[0] != mosteven[0]:
  ans = n - mostodd[1] - mosteven[1]
else:
  if len(ceven.most_common()) > 1:
    even2nd = ceven.most_common()[1][1]
  else:
    even2nd = 0
  ans1 = n - mostodd[1] - even2nd
  if len(codd.most_common()) > 1:
    odd2nd = codd.most_common()[1][1]
  else:
    odd2nd = 0
  ans2 = n - odd2nd - mosteven[1] 
  ans = min(ans1, ans2)
print(ans)
    

Measured memory_bytes: 20576
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
char s[102];
long long ans,n,t;
long long ww(int b,int l)
{
	long long ret=0,e=b+l-1;
	for(int i=b;i<=e;i++)
		ret=ret*10+s[i]-'0';
	return ret;
}
int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	sscanf(s+1,"%lld",&n);
    for(int i=1;i<=len;i++)
        for(int j=1;j+i-1<=len;j++)
		{
            int c=len-i-1;
            if(1<j&&j<len-i+1)
                c--;
            c=max(0,c);
            t=ww(j,i)*pow(2,c);
            ans+=t;
        }
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
l=list(input())
n,m=len(l),1000000007
dp=[[0,1]]+[[0,0] for i in range(n)]
for i in range(n):
	dp[i+1][0] += dp[i][0]*3
	if int(l[i]):
		dp[i+1][1] += dp[i][1]*2
		dp[i+1][0] += dp[i][1]
	else:
		dp[i+1][1] += dp[i][1]
	dp[i+1][0] %= m
	dp[i+1][1] %= m
print((dp[n][0]+dp[n][1])%m)

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

int main(){
  int n;
  int r[200000];
  cin >> n;

  for(int i=0;i<n;i++){
    cin >> r[i];
  }
  
  int minv=r[0];
  int maxv=r[1]-r[0];
  for(int j=1;j<n;j++){
    maxv=max(maxv,r[j]-minv);
    minv=min(minv,r[j]);
  }

  cout << maxv << endl;
}



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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(3));
    for (int i = 0; i < n; ++i) {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    vector<vector<int>> dp(n, vector<int>(3));
    for (int i = 0; i < 3; ++i) {
        dp[0][i] = a[0][i];
    }
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) if (j != k) {
                dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]);
            }
        }
    }
    cout << max(max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) << endl;
    return 0;
}


Measured memory_bytes: 14288
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int dim = sc.nextInt();
		long point[][] = new long[num][dim];
		for(int i = 0; i < num; i ++) {
			for(int j = 0; j < dim; j ++) {
				point[i][j] = sc.nextLong();
			}
		}

		long count = 0;
		for(int i = 0; i < num; i ++) {
			for(int j = i + 1; j < num; j ++) {
				double dist = 0;
				for(int k = 0; k < dim; k ++) {
					dist += Math.pow(point[i][k] - point[j][k], 2);
				}
				dist = Math.sqrt(dist);
				if(dist % 1 == 0) { count ++; }
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);

/// easy access -------------
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
typedef pair<int,int> pi;
typedef tuple<int, int, int> tp;
///-------------------------

int main()
{
    Phuong_; /// <3333
    int n;
    cin >> n;
    vector<ll> a(n);
    for(ll &x:a) cin >> x;
    sort(a.rbegin(), a.rend());
    ll ans=0;
    int head=0;
    int time=0;
    for(int i=1; i<n; ++i){
        if (head==0){
            ans+=a[head];
            head++;
        } else {
            ans+=a[head];
            if (time==1) {
                head++;
                time=0;
            } else {
                time++;
            }
        }

    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4772
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

using ll = long long int;

int result[100010] = {};

int main(void) {

	int n;
	cin >> n;

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

	int answer = 0;

	for (int i = 0; i < 100010; i++) {
		answer = max(answer,result[i]);
	}

	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void){
  int x,y,z,gcd;
  scanf("%d %d",&x,&y);

  if(x<y){
    z=x;
    x=y;
    y=z;
  }

  gcd=x%y;

  while(gcd!=0){
    x=y;
    y=gcd;
    gcd=x%y;
  }

  printf("%d\n",y);
  return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
#define mod 1000000007

using namespace std;

vector<pair<ll,pair<int, int> > >edges;

int p[100004], rnk[100004];

int findp(int a)
{
    if(p[a]==a)return a;
    return p[a] = findp(p[a]);
}
bool connected(int a,int b)
{
    return findp(a)==findp(b);
}
void connect(int a, int b)
{
    int pa = findp(a), pb =findp(b);
    if(rnk[pa]>rnk[pb])p[pb]=pa;
    else if(rnk[pb]>rnk[pa])p[pa]=pb;
    else p[pb]=pa, rnk[pa]++;
}

int main()
{
    for(int i=0;i<100004;i++)p[i]=i;
    int n;
    cin>>n;
    vector< pair<ll,ll>  > X, Y;
    for(int i=0;i<n;i++)
    {
        int a, b;
        cin>>a>>b;
        X.push_back({a,i+1});
        Y.push_back({b,i+1});
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    for(int i=0;i<X.size()-1;i++)
        edges.push_back({X[i+1].first - X[i].first,{X[i].second, X[i+1].second}});
    for(int i=0;i<Y.size()-1;i++)
        edges.push_back({Y[i+1].first - Y[i].first,{Y[i].second, Y[i+1].second}});


    ll ans=0;
    sort(edges.begin(), edges.end());
    for(int i=0;i<edges.size();i++)
    {
        int a = edges[i].second.first, b=edges[i].second.second, c=edges[i].first;
        if(!connected(a, b))ans+=c, connect(a, b);
    }
    cout<<ans;
    return 0;
}
/*int n;
    cin>>n;
    ll arr[n], ans=1e18;
    ll sum1 = 0 , sum2 = 0;

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


    for(int b=-10;b<=10;b++)
    {
        ll cnt=0;
        ll sum1=0, sum2=0;
        for(int i=0;i<n;i++)
            cnt+=abs(arr[i]-(b+i)),
            sum1+=arr[i],
            sum2+=b+i;
        cout<<b<<' ' <<cnt<<' '<<sum1-sum2<<' '<<sum1<<' '<<sum2<<endl;
    }*/


Measured memory_bytes: 9444
n,a,b,c = map(int,input().split())
t = [int(input()) for i in range(n)]
ans = float('inf')
for i in range(1<<(n*2)):
    tmp,cnt,a_t,b_t,c_t = i,0,0,0,0
    for j in range(n):
        if tmp&3==1:
            a_t+=t[j]
            if a_t!=t[j]: cnt+=10
        elif tmp&3==2:
            b_t+=t[j]
            if b_t!=t[j]: cnt+=10
        elif tmp&3==3:
            c_t+=t[j]
            if c_t!=t[j]: cnt+=10
        tmp >>= 2
    if a_t==0 or b_t==0 or c_t==0: continue
    tmp = abs(a-a_t)+abs(b-b_t)+abs(c-c_t)+cnt
    ans = min(ans,tmp)
print(ans)


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

int main()
{
	//gfedcba
	bool tpr[10][7] = {{0,1,1,1,1,1,1},{0,0,0,0,1,1,0},
						{1,0,1,1,0,1,1},{1,0,0,1,1,1,1},
						{1,1,0,0,1,1,0},{1,1,0,1,1,0,1},
						{1,1,1,1,1,0,1},{0,1,0,0,1,1,1},
						{1,1,1,1,1,1,1},{1,1,0,1,1,1,1}};
	bool now[7];
	int in,n;

	while(scanf("%d",&n) && n != -1){
		for(int i = 0; i < 7; i++)
			now[i] = false;
		for(int i = 0; i < n; i++){
			scanf("%d",&in);
			for(int j = 0; j < 7; j++){
				if(tpr[in][j] == now[j])
					printf("0");
				else{
					now[j] = tpr[in][j];
					printf("1");
				}
			}
			printf("\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<utility>
#include<map>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;

int dx[9]={1,1,0,-1,-1,-1,0,1},dy[9]={0,1,1,1,0,-1,-1,-1};


int main(){
	ll h,w,n,res=0;
	cin>>h>>w>>n;
	p x[n];
	map<p,ll> mp;
	rep(i,n){
		cin>>x[i].first>>x[i].second;
		rep(j,9){
			if(mp.find(p(x[i].first+dy[j],x[i].second+dx[j]))!=mp.end())mp[p(x[i].first+dy[j],x[i].second+dx[j])]++;
			else mp[p(x[i].first+dy[j],x[i].second+dx[j])]=1;
		}
	}
	int cnt[10]={0};
	int all=0;
	for(map<p,ll>::iterator ite=mp.begin();ite!=mp.end();ite++){
		if(ite->first.first<2 || ite->first.first>h-1 || ite->first.second<2 || ite->first.second>w-1)continue;
		if(ite->second<0 || ite->second>9)continue;
		cnt[ite->second]++;
	}
	loop(i,1,10)all+=cnt[i];
	cout<<(w-2)*(h-2)-all<<endl;
	loop(i,1,10)cout<<cnt[i]<<endl;
	return 0;
}

Measured memory_bytes: 58112
import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

p_idx, q_idx = -1, -1
for idx, item in enumerate(itertools.permutations(list(range(1, n+1)))):
    if p == list(item):
        p_idx = idx
    if q == list(item):
        q_idx = idx
    if p_idx > 0 and q_idx > 0:
        break

print(abs(p_idx - q_idx))

Measured memory_bytes: 3316
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let a: Vec<i32> = readnc();

    let mut count = 0;
    for ai in a {
        let mut ai = ai;
        while ai % 2 == 0 {
            ai /= 2;
            count += 1;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

constexpr Int mod = 1e9+7;
Int n, x, y, z;
vector<vector<Int>> dp;
vector<Int> a;

bool ok(Int w){
	if(a[w] != -1) return a[w];
	Int c = 0;
	for(Int j=0; (w>>j)>0; ++j)
		if((w>>j) & 1){
			if(j+1 == z) c += 4;
			if(j+1 == z+y) c += 2;
			if(j+1 == z+y+x) c += 1;
		}
	a[w] = (c != 7);
	return c != 7;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> x >> y >> z;
	dp.resize(n, vector<Int>(1<<(x+y+z)));
	for(Int i=1; i<=10; ++i){
		Int t = (1<<(i-1));
		t &= (1<<(x+y+z))-1;
		++dp[0][t];
	}
	a.resize(1<<(x+y+z), -1);
	for(Int i=0; i<n-1; ++i)
		for(Int j=0; j<(1<<(x+y+z)); ++j)
			for(Int k=1; k<=10; ++k){
//				cout << i << " " << j << " " << k << "\n";
				Int t = j;
				t <<= k;
				t |= (1<<(k-1));
				t &= (1<<(x+y+z))-1;
				if(ok(t)){
					dp[i+1][t] += dp[i][j];
					dp[i+1][t] %= mod;
				}
			}
	Int ans = 1;
	for(Int i=0; i<n; ++i){
		ans *= 10;
		ans %= mod;
	}
	for(Int i=0; i<(1<<(x+y+z)); ++i){
		ans -= dp[n-1][i];
		if(ans < 0) ans += mod;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 42368
import sys
string = input()
K = int(input())

if len(set(string)) == 1:
    print((K * len(string)) // 2)
    sys.exit()


f = string[0]
l = string[-1]
if f == l:
    first = 1
    for i in range(1, len(string)):
        if string[i] == f:
            first += 1
        else:
            break
    last = 1
    for i in range(len(string) - 2, 0, -1):
        if string[i] == l:
            last += 1
        else:
            break
else:
    first = 0
    last = 0

ans = 0
final = 0
if (first + last) % 2 == 0 and first % 2 and last % 2:
    final = K - 1

string = string + '_'

count = 1
for n in range(1, len(string)):
    if string[n - 1] == string[n]:
        count += 1
    elif string[n - 1] != string[n] or n == len(string) - 1:
        if count >= 2:
            ans += (count // 2)
            #print(f'n: {n}')
            #print(count)
            #print(ans)
        count = 1
print(ans * K + final)



Measured memory_bytes: 3064
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 998244353;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll dp[3010][3010] = {};
ll A,B,C,D;
ll calc(ll i, ll j){
    ll &res = dp[i][j];
    if(~res) return res;
    // print(i,j);
    res = 0;
    if(i == A){
        res = calc(i,j-1) * i % MOD;
    }else if(j == B){
        res = calc(i-1,j) * j % MOD;
    }else{
        res = calc(i-1,j) + calc(i,j-1);
        res %= MOD;
        res += (calc(i-1,j) * (j-1) % MOD + calc(i,j-1) * (i-1) % MOD) % MOD - calc(i-1,j-1) * (i-1) % MOD * (j-1) % MOD;
        res = (res + 2 * MOD) % MOD;
    }
    return res;
}


void solve(){
    cin >> A >> B >> C >> D;
    rep(i,0,C+1){
        rep(j,0,D+1){
            dp[i][j] = -1;
        }
    }
    dp[A][B] = 1;
    ll ans = calc(C,D);
    print(ans);

    

}

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

Measured memory_bytes: 74684
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int temp=min(b,d)-max(a,c);
    if(temp<0) cout<<0<<endl;
    else cout<<temp<<endl;
   // cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    while (true) {
        u_int h, w;
        cin >> h >> w;
        if (!h && !w)
            break;
        
        char buf1[w+2], buf2[w+2];
        for (u_int i = 1; i < w-1; i++) {
            buf1[i] = '#';
            buf2[i] = '.';
        }
        buf1[0] = buf1[w-1] = buf2[0] = buf2[w-1] = '#';
        buf1[w] = buf2[w] = '\n';
        buf1[w+1] = buf2[w+1] = '\0';

        printf("%s", buf1);
        for (u_int i = 0; i < h-2; i++)
            printf("%s", buf2);
        printf("%s\n", buf1);
    }
    
    return 0;
}

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

int main() {
	int N;
  	cin >> N;
  	vector<int> A(N);
  	for(int i = 0; i < N; i++) cin >> A.at(i); 
      
  	int count = 1;
  	int max = A.at(0);
  	for(int i = 0; i < N-1; i++){
      if(A.at(i) <= A.at(i+1) && max <= A.at(i+1)) count++;
      if(max < A.at(i+1)) max = A.at(i+1);
    }
    cout << count << endl;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);	
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int n,cnt[maxn],x;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	rep(i,0,n-2){
		cin >> x;
		cnt[x]++;
	}
	rep(i,1,n) cout << cnt[i] << endl;		
	return 0;
}
//do smt instead of nothing! never give up!

Measured memory_bytes: 4420
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::Read;
use std::io::{stdout, BufWriter, Write};
 
fn main() {
    let mut buf = String::new();
    
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
 
    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
 
    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();
 
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    
    let mut a : Vec<(usize, usize)> = (0..n).map(|index| {
        (iter.next().unwrap().parse().unwrap(), index+1)
    }).collect::<Vec<(usize, usize)>>();
    //println!("{:?}", a);
    a.sort();
    
    //println!("{:?}",colors);
    //println!("{:?}", a);
    
    for item in a {
        print!("{} ",item.1);
    }
    
}

Measured memory_bytes: 8956
#include <stdio.h>
#define MOD 998244353
int a,b;
int x[3010];

long long int check[3010][3010];
long long int func(int s, int t)
{
	if(s>a)
	{
		if(t==b) return 1;
		else return 0;
	}
	if(check[s][t]!=-1) return check[s][t];
	
	long long int s1 = 0, s2 = 0;
	if(t+x[s]<=b) s1 = func(s+1,t+x[s]);
	s2 = func(s+1,t);
	return check[s][t] = (s1+2*s2)%MOD;
}

int main()
{
	scanf("%d%d",&a,&b);
	for(int i=0;i<=a+1;i++) for(int j=0;j<=b+1;j++) check[i][j] = -1;
	
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	printf("%lld",func(1,0));
}

Measured memory_bytes: 72520
#include<stdio.h>

int main(void){
  int c=0;
  int c1=0;
  char a[3];
  scanf("%s", &a);
  for(int i=0;i < 3; i++){
    if(a[i] == 'R'){
      c++;
    }
    else if(c==0){
      c=0;
    }
    else{
      c1=c;
      c=0;
    }
  }
  if(c>=c1){
    printf("%d", c);
  }
  else{
    printf("%d", c1);
  }
  
  return 0;
}

Measured memory_bytes: 1728
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) cout<<"Case #"<<i<<": "
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	int n; cin >> n;
	int k = 0;
	while (k * (k + 1) / 2 != n) {
		k++;
		if (k > 1000) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	cout << k+1 << endl;
	vector<vector<int>> ans(k+1);
	int cnt = 0;
	rep(i, 0, k)rep(j, i+1, k+1) {
		cnt++;
		ans[i].push_back(cnt);
		ans[j].push_back(cnt);
	}
	rep(i, 0, k+1) {
		cout << ans[i].size();
		for (int j: ans[i]) {
			cout << " " << j;
		}
		cout << endl;
	}
	return 0;
}


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

int main() {
int h,w;
cin >> h >> w;
vector<vector<char>> A(h+2,vector<char>(w+2));

for(int i = 0; i < h+2; i++){
  for(int j = 0; j < w+2; j++){
    if(i == 0 || i == h+1 || j == 0 || j == w+1) A.at(i).at(j) = '#';
    else{
      char x;
      cin >> x;
      A.at(i).at(j) = x;
    }
  }
}
for(int i = 0; i < h+2; i++){
  for(int j = 0; j < w+2; j++){
    cout << A.at(i).at(j);
    if(j == w+1) cout << endl;
  }
}

  }


Measured memory_bytes: 3588
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[][] a = new int[N][N];
		for (int i = 0; i < N; i++) {
			int A = in.nextInt();
			int[] tmp = new int[N];
			Arrays.fill(tmp, -1);
			tmp[i] = 1;
			for (int j = 0; j < A; j++) {
				tmp[in.nextInt() - 1] = in.nextInt();
			}
			a[i] = tmp;
		}
		int ans = 0;
		for (int i = 0; i < (1 << N); i++) {
			int[] tmp = new int[N];
			for (int j = 0; j < N; j++) {
				if ((i >> j & 1) == 1) {
					tmp[j] = 1;
				}
			}
			boolean isOk = true;
			int count = 0;
			for (int j = 0; j < N; j++) {
				if (tmp[j] == 1) {
					count++;
					for (int j2 = 0; j2 < N; j2++) {
						if (a[j][j2] == -1) {
							continue;
						}
						if (a[j][j2] != tmp[j2]) {
							isOk = false;
						}
					}
				}
			}
			if (isOk) {
				ans = Math.max(ans, count);
			}
			count = 0;
		}
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 24788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long 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; }


int main(){
    ll d,n; cin>>d>>n;
    ll res=n;
    if(n==100) res=101;
    rep(i,d) res*=100;
    cout<<res<<endl;
    
    return 0;
}

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

#define loop(i,n)for(i=0;i<n;i++)
#define INF 1000000000
using ll = long long int;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;


#define MAX 100005


int main()
{
    IOS;
    //freopen("inputfile.txt","r",stdin);
   int x;cin>>x;
   if(x==0)cout<<"1"<<endl;
    else cout<<"0"<<endl;
    return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>

void rotate_x(int* data,int n);
void rotate_y(int* data,int n);
void rotate_z(int* data,int n);
int check(int flag,int* data1,int* data2);

int main(){
    int D[100][7];//サイコロの盤面(わかりやすさのため[1]~[6]を利用)
    int A[7];
    char cmd[100];//コマンドの文字列
    int cp;//一旦対比させる用の変数
    int flag=0;
    int n;

    scanf("%d",&n);//行数を入力

    for(int i=0;i<n;i++){
        scanf("%d %d %d %d %d %d",&D[i][1],&D[i][2],&D[i][3],&D[i][4],&D[i][5],&D[i][6]);//サイコロの盤面入力
    }   

    for(int i=0;i<n;i++){
        for(int f=i+1;f<n;f++){
            rotate_x(D[i],1);
            for(int l=0;l<4;l++){
                rotate_z(D[i],1);
                flag=check(flag,D[i],D[f]);
            }
            rotate_x(D[i],1);
            for(int l=0;l<4;l++){
                rotate_z(D[i],1);
                flag=check(flag,D[i],D[f]);
            }
            rotate_x(D[i],1);
            for(int l=0;l<4;l++){
                rotate_z(D[i],1);
                flag=check(flag,D[i],D[f]);
            }
            rotate_x(D[i],1);
            for(int l=0;l<4;l++){
                rotate_z(D[i],1);
                flag=check(flag,D[i],D[f]);
            }
            rotate_y(D[i],1);
            for(int l=0;l<4;l++){
                rotate_z(D[i],1);
                flag=check(flag,D[i],D[f]);
            }
            rotate_y(D[i],2);
            for(int l=0;l<4;l++){
                rotate_z(D[i],1);
                flag=check(flag,D[i],D[f]);
            }
        }
    }

    if(flag==1)
        printf("No\n");
    else
        printf("Yes\n");
}

void rotate_x(int* data,int n){
    int cp;
    for(int i=0;i<n;i++){
        cp=data[1];
        data[1]=data[4];
        data[4]=data[6];
        data[6]=data[3];
        data[3]=cp;
    }   
} 

void rotate_y(int* data,int n){
    int cp;
    for(int i=0;i<n;i++){
        cp=data[1];
        data[1]=data[2];
        data[2]=data[6];
        data[6]=data[5];
        data[5]=cp;
    }   
} 

void rotate_z(int* data,int n){
    int cp;
    for(int i=0;i<n;i++){
        cp=data[2];
        data[2]=data[3];
        data[3]=data[5];
        data[5]=data[4];
        data[4]=cp;
    }   
} 

int check(int flag,int* p1,int* p2){
    //printf("%d %d %d %d %d %d\n%d %d %d %d %d %d\n",p1[1],p1[2],p1[3],p1[4],p1[5],p1[6],p2[1],p2[2],p2[3],p2[4],p2[5],p2[6]);
    if(p1[1]==p2[1]&&p1[2]==p2[2]&&p1[3]==p2[3]&&p1[4]==p2[4]&&p1[5]==p2[5]&&p1[6]==p2[6])
        flag=1;
    return flag;
}


Measured memory_bytes: 2104
#pragma GCC optimize("unroll-loops,Ofast")
#pragma GCC target("avx,sse,sse2,ssse3,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 1<<18, mod = 1e9 + 7;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	ll ans = 1ll<<60;
	int n;
	cin >> n;
	vector<int> a(n);
	ll sum = 0;
	for(auto &i : a) cin >> i, sum += i;
	ll t= 0;
	a.pop_back();
	for(auto &i : a) {
		t += i;
		sum -= i;
		ans = min(ans, abs(sum-t));
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

bool dp[101][101];

int main() {
	int X;
	cin >> X;
	
	
	dp[0][0] = 1;
	REP(i, 101) REP(j, 101) if (dp[i][j]) {
		FOR(k, 0, 6) if (j + k <= 100 && dp[i][j]) dp[i + 1][j + k] = true;
	}
	
	bool ans = false;
	FOR(i, 1, 1000000) {
		int sum = i * 100;
		if (X < sum) break;
		int d = X - sum;
		if (d <= 100) {
			if (i >= 100) ans = true;
			else ans |= dp[i][d];
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	ll m; cin>>m;
	vector<ll> h(n);
	vector<ll> out(n);
	REP(i,n) cin>>h[i];
	REP(i,m){
		ll a,b;
		cin>>a>>b;
		a--;b--;
		if(h[a]<h[b]){
			out[a]++;
		}else if(h[a]>h[b]){
			out[b]++;
		}else{
			out[a]++;
			out[b]++;
		}
	}
	ll ans=0;
	REP(i,n){
		if(out[i]==0)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4844
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

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

typedef long long ll;

int main()
{
    
    long double a,b;
    cin>>a>>b;
    
    cout<<(ll)(floor(a*b));  //cout<<s;
    
    

    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for( int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)
using lli = long long int;
using ulli = unsigned long long int;
typedef pair<lli,lli> P;

struct edge{ int u, v, cost; };
struct DirectedGraph
{
  int vertex_num;
  int edge_num;
  vector<edge> edge_list;
  vector< vector<int> > adj_list;
};

void displayVector(vector<lli> v)
{
	lli n = v.size();
	REP(i,n){
		cout << v[i] << " " ;
	}
	cout << endl;
}


int main(){
	char a; cin >>  a;
	if( isupper(a) ){ cout << 'A' << endl; }
	else{ cout << 'a' << endl; }
	return 0;
}

Measured memory_bytes: 3628
//file_name:ABC91_B.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);
    vector<string> s1;
    rep(i,n){
        string s;
        cin >> s;
        s1.push_back(s);
    }
    int m;
    scanf("%d",&m);
    vector<string> s2;
    rep(i,m){
        string s;
        cin >> s;
        s2.push_back(s);
    }



    int ans = 0;

    rep(i,n){
        string s;
        s = s1[i];
        int aa = 0;
        rep(j,n){
            if(s==s1[j])aa++;
        }
        rep(j,m){
            if(s==s2[j])aa--;
        }
        if(ans<aa){
            ans=aa;
        }
    }

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



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

using namespace std;
typedef long long ll;

const ll INF=1e18;
int N;
int a[300005],b[300005];
ll fh[300005],lh[300005];

int main() {

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;

for(int i=0; i<3*N; i++){
  cin>>a[i];
}

priority_queue< int,vector<int>,greater<int> > q1;
priority_queue<int> q2;

for(int i=0; i<N; i++){
  q1.push(a[i]);
  fh[N-1]+=a[i];
}

for(int i=N; i<2*N; i++){
  int x=q1.top();
  if(x<a[i]){
    fh[i]=fh[i-1]-x+a[i];
    q1.pop();
    q1.push(a[i]);
  }else{
    fh[i]=fh[i-1];
  }
}

for(int i=2*N; i<3*N; i++){
  q2.push(a[i]);
  lh[2*N]+=a[i];
}

for(int i=2*N-1; i>=N; i--){
  int x=q2.top();
  if(x>a[i]){
    lh[i]=lh[i+1]-x+a[i];
    q2.pop();
    q2.push(a[i]);
  }else{
    lh[i]=lh[i+1];
  }
}

ll ans=-INF;

for(int i=N-1; i<2*N; i++){
  ans=max(ans,fh[i]-lh[i+1]);
}

cout<<ans<<endl;

}


Measured memory_bytes: 6904
#include <stdio.h>
#include <string.h>

int main(void){
    int N;
    int counter = 1;
    scanf("%d", &N);
    char S[N];
    scanf("%s", S);
    for (int i = 0; i < N - 1; i++){
        if (S[i] != S[i + 1]){
            counter++;
        }
    }
    printf("%d\n", counter);

    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
A = [[1 if a == "#" else 0 for a in input()] for _ in range(H)]
X = [[[-2] * (H + 2) for _ in range(W + 2)] for _ in range(H + 2)]
Y = [[[-2] * (W + 2) for _ in range(W + 2)] for _ in range(H + 2)]

for i in range(H):
    for j in range(W):
        X[i][j][i] = j
        Y[i][j][j] = i
for i in range(H):
    for j in range(W-1)[::-1]:
        if A[i][j] == A[i][j+1]:
            X[i][j][i] = X[i][j+1][i]
for i in range(H-1)[::-1]:
    for j in range(W):
        if A[i][j] == A[i+1][j]:
            Y[i][j][j] = Y[i+1][j][j]

for i in range(H):
    for j in range(W):
        for ii in range(i+1, H):
            if A[ii][j] != A[i][j]:
                break
            X[i][j][ii] = min(X[i][j][ii-1], X[ii][j][ii])
for i in range(H):
    for j in range(W):
        for jj in range(j+1, W):
            if A[i][jj] != A[i][j]:
                break
            Y[i][j][jj] = min(Y[i][j][jj-1], Y[i][jj][jj])

for k in range(16):
    if X[0][0][H-1] == W-1:
        print(k)
        break
    elif k == 15:
        print(16)
        break
    for i in range(H):
        Xi = X[i]
        Yi = Y[i]
        for j in range(W):
            Xij = Xi[j]
            Yij = Yi[j]
            for ii in range(i, H):
                Xijii = Xij[ii]
                if Xijii >= 0 and X[i][Xijii + 1][ii] >= 0:
                    Xij[ii] = X[i][Xijii + 1][ii]
            for jj in range(j, W):
                Yijjj = Yij[jj]
                if Yijjj >= 0 and Y[Yijjj + 1][j][jj] >= 0:
                    Yij[jj] = Y[Yijjj + 1][j][jj]
            
            jj = W - 1
            for ii in range(i, H):
                while jj >= j and Yij[jj] < ii:
                    jj -= 1
                if jj >= j:
                    Xij[ii] = max(Xij[ii], jj)
            
            ii = H - 1
            for jj in range(j, W):
                while ii >= i and Xij[ii] < jj:
                    ii -= 1
                if ii >= i:
                    Yij[jj] = max(Yij[jj], ii)

Measured memory_bytes: 182180
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

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

i64 h, w;
vector<string> s, ss;
i64 sum[301][601];
int main() {
  cin >> h >> w;
  read_n(s, h);
  i64 ans = 0;

  ss = s;
  i64 dup = 0;
  for (i64 dir = 0; dir < 2; ++dir) {
    for (i64 i = 0; i < h; ++i) {
      string p = string(i, ' '), q = string(h - i - 1, ' ');
      s[i] = p + s[i] + q;
    }

    for (i64 j = 0; j < s[0].size(); ++j) {
      for (i64 i = 1; i <= h; ++i) {
        sum[i][j] = sum[i - 1][j] + (s[i - 1][j] == '#' ? 1 : 0);
      }
    }

    for (i64 j = 0; j < s[0].size(); ++j) {
      for (i64 i = 0; i < h; ++i) {
        if (s[i][j] == '#') for (i64 k = i + 1; k < h; ++k) {
          if (s[k][j] == '#') {
            i64 l = j + 2 * (k - i), m = j - 2 * (k - i);
            if (l < s[0].size()) {
              ans += sum[min(h, k + (k - i + 1))][l] - sum[k][l];
              if (s[k][l] == '#') dup++;
              if (k + (k - i) < h && s[k + (k - i)][l] == '#') dup++;
            }
            if (m >= 0) {
              ans += sum[i + 1][m] - sum[max(i64(0), i - (k - i))][m];
              if (s[i][m] == '#') dup++;
              if (i - (k - i) >= 0 && s[i - (k - i)][m] == '#') dup++;
            }
          }
        }
      }
    }
    
    s = ss;
    for (auto& t : s) reverse(begin(t), end(t));
  }

  cout << ans - dup / 2 << '\n';
  return 0;
}


Measured memory_bytes: 2160
from collections import *
from heapq import *
N=int(input())
if N==0:
    print(0)
    exit()
num=0
count=0
lst=[]

while N:
    if N%2==1:
        lst.append(1)
        N-=1 * (-1 if count%2 else 1)
    else:
        lst.append(0)
    count+=1
    N//=2
lst=list(reversed(lst))
print("".join([str(i) for i in lst]))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

int main(){
    int n;
    vector<int> r, l;
    vector<int> x,y;
    cin >> n;
    rep(i,n){
        int a;
        cin >> a;
        x.emplace_back(a);
        y.emplace_back(a);
        if(i % 2) r.emplace_back(a);
        else l.emplace_back(a);
    }
    //sort(all(r)); sort(all(l));
    sort(all(x));
    //r.emplace_back(INF); l.emplace_back(INF);

    int cnt = 0;
    rep(i,n){
        int right = n, left = 0;
        if((lower_bound(all(x), y[i]) - x.begin())% 2 != i % 2) cnt++;
    }

    int i = 0, j = 0;
    int ans = 0;
    /*
    while(r[j] != INF){
        //cout << i << ' ' << j << endl;
        //cout << l[i] << ' ' << r[j] << endl;
        if(l[i] < r[j]){
            i++;
        }else{
            j++;
            ans+= abs(i - j);
            //show(abs(i - j)) show(ans)
        }
    }
    */
    for(auto it = r.begin(); it != r.end(); it++){
        /*
        show(*it)
        show( abs(lower_bound(all(l), *it) - l.begin() - 1 - (it - r.begin())));
        show( abs(lower_bound(all(l), *it) - l.begin()));
        show( *lower_bound(all(l), *it));
        */
        ans += abs(lower_bound(all(l), *it) - l.begin() - 1 - (it - r.begin()));
    }

    cout << cnt / 2 << endl;
}


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

#define ll long long
#define pb push_back
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

const ll mod = 1e9 + 7;

ll power(ll a, ll n) {
    if(n == 0) return 1;
    else if(n%2 == 0) {
        return power((a%mod*a%mod)%mod, n/2)%mod;
    }
    else return (a%mod * power((a%mod * a%mod), (n-1)/2)%mod)%mod;
}

ll add(ll a, ll b) {
    ll ans = (a%mod + b%mod)%mod;
    return ans;
}

ll sub(ll a, ll b) {
    ll ans = (a%mod - b%mod + mod)%mod;
    return ans;
}

ll mul(ll a, ll b) {
    ll ans = (a%mod * b%mod)%mod;
    return ans;
}

ll divi(ll a, ll b) {
    ll inv = power(b, mod-2LL);
    ll ans = (a%mod * inv%mod)%mod;
    return ans;
}

void solve() {
    ll n, k;
    cin >> n >> k;
    ll a[n];
    for(ll i = 0; i<n; i++) cin >> a[i];
    sort(a, a+n);
    ll product = 1;

    if(a[n-1] == 0 && (k&1)) {
        cout << 0 << '\n';
        return;
    }

    if(a[n - 1] <= 0 && (k & 1)) {
        for (ll i = n - 1; i >= n - k; i--) {
            product = mul(product, a[i]);
            product = (product + mod)%mod;
        }
        product = (product + mod)%mod;
        cout << product << '\n';
        return;
    }
    ll i = 0, j = n-1;
    if (k & 1) {
        product = mul(product, a[j]);
        product = (product + mod)%mod;
        j--;
        k--;
    }

    k >>= 1LL;

    for (ll itr = 0; itr < k; itr++) {

        // product from left pointers
        ll left_product = (a[i] * a[i + 1]);
        //left_product = (left_product + mod)%mod;
        // product from right pointers
        ll right_product = (a[j] * a[j - 1]);
        //right_product = (right_product + mod)%mod;
        // Taking the max product from two choices
        // Correspondingly changing the pointer's position
        if (left_product > right_product) {
            left_product = (left_product + mod)%mod;
            product = mul(product, left_product);
            product = (product + mod)%mod;
            i += 2;
        }
        else {
            right_product = (right_product + mod)%mod;
            product = mul(product, right_product);
            product = (product + mod)%mod;
            j -= 2;
        }
    }
    product = (product + mod)%mod;
    cout << product << '\n';
}

int main() {_
    int t = 1;
    //cin >> t;
    //Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + 7;

int main() {
  string s;
  cin >> s;
  int n = s.size();

  vector<ll> p(n + 1);
  p[0] = 1;
  for (int i = 0; i < n; i++) {
    p[i + 1] = 3 * p[i] % mod;
  }

  vector<ll> a(n + 1), c(n + 1), q(n + 1);
  for (int i = 0; i < n; i++) {
    switch (s[i]) {
      case 'A':
        a[i + 1] = 1;
        break;
      case 'C':
        c[i + 1] = 1;
        break;
      case '?':
        q[i + 1] = 1;
        break;
    }
  }
  for (int i = 0; i < n; i++) {
    a[i + 1] += a[i];
    c[i + 1] += c[i];
    q[i + 1] += q[i];
  }

  ll r = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'B' || s[i] == '?') {
      ll ra = (a[i] - a[0]) * p[q[i] - q[0]] % mod + (q[i] - q[0]) * p[max(0ll, q[i] - q[0] - 1)] % mod;
      ll rc = (c[n] - c[i + 1]) * p[q[n] - q[i + 1]] % mod + (q[n] - q[i + 1]) * p[max(0ll, q[n] - q[i + 1] - 1)] % mod;
      r = (r + ra * rc) % mod;
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <deque>
#include <bitset>
//#include <unordered_set>
//#include <unordered_map>
#define ll              long long
#define pii             pair<int, int>
#define rep(i,a,b)      for(int  i=a;i<=b;i++)
#define dec(i,a,b)      for(int  i=a;i>=b;i--)
using namespace std;
int dir[4][2] = { { 1,0 },{ 0,1 } ,{ 0,-1 },{ -1,0 } };
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846;
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int N = 3e3 + 5;
//if(x<0 || x>=r || y<0 || y>=c)

inline ll read()
{
    ll x = 0; bool f = true; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
    while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return f ? x : -x;
}
ll gcd(ll m, ll n)
{
    return n == 0 ? m : gcd(n, m % n);
}
ll lcm(ll m, ll n)
{
    return m * n / gcd(m, n);
}
bool prime(int x) {
    if (x < 2) return false;
    for (int i = 2; i * i <= x; ++i) {
        if (x % i == 0) return false;
    }
    return true;
}
ll qpow(ll m, ll k, ll mod)
{
    ll res = 1, t = m;
    while (k)
    {
        if (k & 1)
            res = res * t % mod;
        t = t * t % mod;
        k >>= 1;
    }
    return res;
}
double dp[N][N];
double a[N],ans;
int main()
{
    ll n;
    cin >> n;
    rep(i, 1, n)
        cin >> a[i];
    dp[0][0] = 1;
    rep(i, 1, n)
    {
        rep(j, 0, i)
        {
            int x = j, y = i - j;
            if (x)
                dp[x][y] += dp[x - 1][y] * a[i];
            if (y)
                dp[x][y] += dp[x][y - 1] * (1 - a[i]);
        }
    }
    int l = n, r = 0;
    while (l > r)
    {
        ans += dp[l][r];
        l--, r++;
    }
    printf("%.10f\n", ans);
    return 0;
}

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

int bubble_sort(int A[], int N){
  int sw = 0;
  int temp = 0;
  for(int i=0; i<N; i++){
    for(int j = 0; j < N - i -1; j++){
      if(A[j] > A[j+1]){
        temp = A[j];
        A[j] = A[j+1];
        A[j+1] = temp;
        sw++;
      }
    }
  }

  return sw;
}

int main(int argc, char const *argv[]) {
  int A[100], N, sw;
  cin >> N;
  for(int i=0; i < N; i++){
    cin >> A[i];
  }

  sw = bubble_sort(A, N);

  for(int i=0; i < N; i++){
    if (i) {
      cout << " ";
    }
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair < ll, ll > PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e9+7;
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> cnt(2, 0);
    rep(i, n) cin >> a[i];
    rep(i, n) {
        ll b;
        cin >> b;
        if ( a[i] == b ) continue;
        else if ( a[i] > b ) {
            cnt[1] += a[i] - b;
        }
        else if ( ( b - a[i] ) % 2 == 0 ) {
            cnt[0] += ( b - a[i] ) / 2;
        }
        else {
            cnt[0] += ( b - a[i] ) / 2 + 1;
            cnt[1] += 1;
        }
    }
    if ( cnt[0] <  cnt[1] ) cout << "No" << endl;
    else                    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 384
/**
* Author : zzy
* Date : 2020-04-19-19.59.01 Sunday
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())
#define PI acos(-1)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }



int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    double r;
    scanf("%lf", &r);
    double res = 2*PI*r;
    printf("%.4f\n", res);

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3860
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

H, W, K = map(int, input().split())

B = [[] for _ in range(H)]

for h in range(H):
    B[h] = list(input())

ans = 0
for i in range(1 << H):
    for j in range(1 << W):
        cnt = 0
        for h in range(H):
            for w in range(W):
                if ((i >> h) & 1) == 1 or ((j >> w) & 1) == 1:
                    continue
                if B[h][w] == '#':
                    cnt += 1
        if cnt == K:
            ans += 1

print(ans)

Measured memory_bytes: 9624